Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -56,4 +60,33 @@ public List<Map<String, Object>> queryOms() {
public List<Map<String, Object>> queryCamunda() {
return camundaJdbc.queryForList("SELECT 1 AS camunda_check");
}

/**
* Re-executes a server-prepared statement {@code n} times on the SAME
* JDBC connection. With useServerPrepStmts=true + useCursorFetch=true,
* Connector/J 8.x opportunistically emits COM_STMT_RESET before each
* COM_STMT_EXECUTE after the first, to clear cursor / long-data state.
*
* During Keploy replay this exercises the synthetic-OK fallback added
* in keploy/keploy#4217 — without it, the unmocked COM_STMT_RESET would
* cascade into "Connection closing due to no matching mock found" and
* tear down the TCP connection.
*/
@GetMapping("/api/oms/stmt-reset/{n}")
public List<Integer> stmtReset(@PathVariable("n") int n) {
return omsJdbc.execute((java.sql.Connection conn) -> {
List<Integer> values = new ArrayList<>(n);
try (PreparedStatement ps = conn.prepareStatement("SELECT ? AS v")) {
for (int i = 0; i < n; i++) {
ps.setInt(1, i);
try (ResultSet rs = ps.executeQuery()) {
if (rs.next()) {
values.add(rs.getInt(1));
}
}
}
}
return values;
});
}
}
7 changes: 6 additions & 1 deletion mysql-dual-conn/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
server.port=8080

# --- OMS DataSource (primary) ---
datasource.oms.jdbc-url=jdbc:mysql://localhost:3306/myntra_oms?useSSL=false&allowPublicKeyRetrieval=true
# useServerPrepStmts + cachePrepStmts + useCursorFetch force Connector/J 8.x
# to issue COM_STMT_PREPARE / COM_STMT_EXECUTE (and COM_STMT_RESET between
# re-executions on the same connection) instead of plain COM_QUERY.
# This lets /api/oms/stmt-reset/{n} exercise the COM_STMT_RESET synthetic-OK
# fallback added in keploy/keploy#4217.
datasource.oms.jdbc-url=jdbc:mysql://localhost:3306/myntra_oms?useSSL=false&allowPublicKeyRetrieval=true&useServerPrepStmts=true&cachePrepStmts=true&useCursorFetch=true
datasource.oms.username=omsAppUser
datasource.oms.password=omsPassword
datasource.oms.driver-class-name=com.mysql.cj.jdbc.Driver
Expand Down
Loading