Skip to content

Commit b0181ba

Browse files
committed
feat(mysql-dual-conn): add endpoint to trigger COM_STMT_RESET
Adds GET /api/oms/stmt-reset/{n} which re-executes a server-side prepared statement n times on the SAME JDBC connection. Updates the OMS JDBC URL with useServerPrepStmts=true, cachePrepStmts=true, and useCursorFetch=true so MySQL Connector/J 8.x emits COM_STMT_RESET between re-executions. This exercises the COM_STMT_RESET synthetic-OK fallback added in keploy/keploy#4217 during keploy record/replay against this existing samples-java CI app, avoiding the need to wire a brand new sample (spring-mysql-redis) into keploy's java_linux pipeline. The existing dual-handshake test path is unchanged — the Camunda pool keeps the original JDBC URL, and the new endpoint is purely additive. Signed-off-by: Yash Khare <khareyash05@gmail.com>
1 parent 080077f commit b0181ba

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

mysql-dual-conn/src/main/java/com/example/mysqlreplicate/QueryController.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
import org.springframework.beans.factory.annotation.Qualifier;
44
import org.springframework.jdbc.core.JdbcTemplate;
55
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.PathVariable;
67
import org.springframework.web.bind.annotation.RestController;
78

9+
import java.sql.PreparedStatement;
10+
import java.sql.ResultSet;
11+
import java.util.ArrayList;
812
import java.util.HashMap;
913
import java.util.List;
1014
import java.util.Map;
@@ -56,4 +60,33 @@ public List<Map<String, Object>> queryOms() {
5660
public List<Map<String, Object>> queryCamunda() {
5761
return camundaJdbc.queryForList("SELECT 1 AS camunda_check");
5862
}
63+
64+
/**
65+
* Re-executes a server-prepared statement {@code n} times on the SAME
66+
* JDBC connection. With useServerPrepStmts=true + useCursorFetch=true,
67+
* Connector/J 8.x opportunistically emits COM_STMT_RESET before each
68+
* COM_STMT_EXECUTE after the first, to clear cursor / long-data state.
69+
*
70+
* During Keploy replay this exercises the synthetic-OK fallback added
71+
* in keploy/keploy#4217 — without it, the unmocked COM_STMT_RESET would
72+
* cascade into "Connection closing due to no matching mock found" and
73+
* tear down the TCP connection.
74+
*/
75+
@GetMapping("/api/oms/stmt-reset/{n}")
76+
public List<Integer> stmtReset(@PathVariable("n") int n) {
77+
return omsJdbc.execute((java.sql.Connection conn) -> {
78+
List<Integer> values = new ArrayList<>(n);
79+
try (PreparedStatement ps = conn.prepareStatement("SELECT ? AS v")) {
80+
for (int i = 0; i < n; i++) {
81+
ps.setInt(1, i);
82+
try (ResultSet rs = ps.executeQuery()) {
83+
if (rs.next()) {
84+
values.add(rs.getInt(1));
85+
}
86+
}
87+
}
88+
}
89+
return values;
90+
});
91+
}
5992
}

mysql-dual-conn/src/main/resources/application.properties

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
server.port=8080
22

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

0 commit comments

Comments
 (0)