diff --git a/mysql-dual-conn/src/main/java/com/example/mysqlreplicate/QueryController.java b/mysql-dual-conn/src/main/java/com/example/mysqlreplicate/QueryController.java index 376ac6e0..8802d0b2 100644 --- a/mysql-dual-conn/src/main/java/com/example/mysqlreplicate/QueryController.java +++ b/mysql-dual-conn/src/main/java/com/example/mysqlreplicate/QueryController.java @@ -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; @@ -56,4 +60,33 @@ public List> queryOms() { public List> 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 stmtReset(@PathVariable("n") int n) { + return omsJdbc.execute((java.sql.Connection conn) -> { + List 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; + }); + } } diff --git a/mysql-dual-conn/src/main/resources/application.properties b/mysql-dual-conn/src/main/resources/application.properties index 199098e7..6bad40c0 100644 --- a/mysql-dual-conn/src/main/resources/application.properties +++ b/mysql-dual-conn/src/main/resources/application.properties @@ -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