@@ -11562,63 +11562,109 @@ public void testBug28725534() throws Exception {
1156211562
1156311563 /**
1156411564 * Tests fix for Bug#104067 (33054827), No reset autoCommit after unknown issue occurs.
11565+ * Tests fix for Bug#106435 (33850099), 8.0.28 Connector/J has regressive in setAutoCommit after Bug#104067 (33054827).
1156511566 *
1156611567 * @throws Exception
1156711568 */
1156811569 @Test
11569- public void testBug104067 () throws Exception {
11570+ public void testBug104067AndBug106435 () throws Exception {
1157011571 Properties props = new Properties();
1157111572 props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
1157211573 props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
1157311574 props.setProperty(PropertyKey.queryInterceptors.getKeyName(), Bug104067QueryInterceptor.class.getName());
11574- Connection testConn = getConnectionWithProps(props);
11575- Statement testStmt = testConn.createStatement();
1157611575
11577- // Connection vs session autocommit value:
11578- // 1. Default value.
11579- assertTrue(testConn.getAutoCommit());
11580- this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11581- assertTrue(this.rs.next());
11582- assertTrue(this.rs.getString(2).equalsIgnoreCase("ON"));
11576+ // Connection vs session autocommit value - error on setAutoCommit(false).
11577+ try (Connection testConn = getConnectionWithProps(props); Statement testStmt = testConn.createStatement()) {
11578+ // 1. Initial value - true.
11579+ assertTrue(testConn.getAutoCommit());
11580+ this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11581+ assertTrue(this.rs.next());
11582+ assertEquals("ON", this.rs.getString(2).toUpperCase());
1158311583
11584- // 2. After Connection.setAutcommit(true).
11585- try {
11586- testConn.setAutoCommit(true);
11587- } catch (SQLException e) {
11588- fail("Exception not expected.", e);
11584+ // 2. After Connection.setAutcommit(true).
11585+ try {
11586+ testConn.setAutoCommit(true);
11587+ } catch (SQLException e) {
11588+ fail("Exception not expected.", e);
11589+ }
11590+ assertTrue(testConn.getAutoCommit());
11591+ this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11592+ assertTrue(this.rs.next());
11593+ assertEquals("ON", this.rs.getString(2).toUpperCase());
11594+
11595+ // 3. After Connection.setAutcommit(false) & ERROR.
11596+ assertThrows(SQLException.class, () -> {
11597+ testConn.setAutoCommit(false);
11598+ return null;
11599+ });
11600+ assertTrue(testConn.getAutoCommit());
11601+ this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11602+ this.rs.next();
11603+ assertEquals("ON", this.rs.getString(2).toUpperCase());
11604+
11605+ // 4. After Connection.setAutcommit(true).
11606+ try {
11607+ testConn.setAutoCommit(true);
11608+ } catch (SQLException e) {
11609+ fail("Exception not expected.", e);
11610+ }
11611+ assertTrue(testConn.getAutoCommit());
11612+ this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11613+ assertTrue(this.rs.next());
11614+ assertEquals("ON", this.rs.getString(2).toUpperCase());
1158911615 }
11590- assertTrue(testConn.getAutoCommit());
11591- this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11592- assertTrue(this.rs.next());
11593- assertTrue(this.rs.getString(2).equalsIgnoreCase("ON"));
1159411616
11595- // 3. After Connection.setAutcommit(false).
11596- assertThrows(SQLException.class, () -> {
11597- testConn.setAutoCommit(false);
11598- return null;
11599- });
11600- assertTrue(testConn.getAutoCommit());
11601- this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11602- this.rs.next();
11603- assertTrue(this.rs.getString(2).equalsIgnoreCase("ON"));
11617+ // Connection vs session autocommit value - error on setAutoCommit(true).
11618+ try (Connection testConn = getConnectionWithProps(props); Statement testStmt = testConn.createStatement()) {
11619+ Bug104067QueryInterceptor.errorOnSetTrue = true;
1160411620
11605- // 4. After Connection.setAutcommit(true).
11606- try {
11607- testConn.setAutoCommit(true);
11608- } catch (SQLException e) {
11609- fail("Exception not expected.", e);
11621+ // 1. Initial value - true.
11622+ assertTrue(testConn.getAutoCommit());
11623+ this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11624+ assertTrue(this.rs.next());
11625+ assertEquals("ON", this.rs.getString(2).toUpperCase());
11626+
11627+ // 2. After Connection.setAutcommit(false)
11628+ try {
11629+ testConn.setAutoCommit(false);
11630+ } catch (SQLException e) {
11631+ fail("Exception not expected.", e);
11632+ }
11633+ assertFalse(testConn.getAutoCommit());
11634+ this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11635+ assertTrue(this.rs.next());
11636+ assertEquals("OFF", this.rs.getString(2).toUpperCase());
11637+
11638+ // 3. After Connection.setAutcommit(true) & ERROR.
11639+ assertThrows(SQLException.class, () -> {
11640+ testConn.setAutoCommit(true);
11641+ return null;
11642+ });
11643+ assertFalse(testConn.getAutoCommit());
11644+ this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11645+ assertTrue(this.rs.next());
11646+ assertEquals("OFF", this.rs.getString(2).toUpperCase());
11647+
11648+ // 4. After Connection.setAutcommit(false).
11649+ try {
11650+ testConn.setAutoCommit(false);
11651+ } catch (SQLException e) {
11652+ fail("Exception not expected.", e);
11653+ }
11654+ assertFalse(testConn.getAutoCommit());
11655+ this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11656+ this.rs.next();
11657+ assertEquals("OFF", this.rs.getString(2).toUpperCase());
1161011658 }
11611- assertTrue(testConn.getAutoCommit());
11612- this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11613- assertTrue(this.rs.next());
11614- assertTrue(this.rs.getString(2).equalsIgnoreCase("ON"));
1161511659 }
1161611660
1161711661 public static class Bug104067QueryInterceptor extends BaseQueryInterceptor {
11662+ public static boolean errorOnSetTrue = false;
11663+
1161811664 @Override
1161911665 public <T extends Resultset> T preProcess(Supplier<String> str, Query interceptedQuery) {
1162011666 String sql = str.get();
11621- if (sql.equalsIgnoreCase("SET autocommit=0")) {
11667+ if (errorOnSetTrue && sql.equalsIgnoreCase("SET autocommit=1") || !errorOnSetTrue && sql.equalsIgnoreCase("SET autocommit=0")) {
1162211668 throw ExceptionFactory.createException("Artificial non-connection related exception while executing \"" + sql + "\"");
1162311669 }
1162411670 return super.preProcess(str, interceptedQuery);
0 commit comments