@@ -11562,63 +11562,109 @@ public void testBug28725534() throws Exception {
11562
11562
11563
11563
/**
11564
11564
* 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).
11565
11566
*
11566
11567
* @throws Exception
11567
11568
*/
11568
11569
@Test
11569
- public void testBug104067 () throws Exception {
11570
+ public void testBug104067AndBug106435 () throws Exception {
11570
11571
Properties props = new Properties();
11571
11572
props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
11572
11573
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
11573
11574
props.setProperty(PropertyKey.queryInterceptors.getKeyName(), Bug104067QueryInterceptor.class.getName());
11574
- Connection testConn = getConnectionWithProps(props);
11575
- Statement testStmt = testConn.createStatement();
11576
11575
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());
11583
11583
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());
11589
11615
}
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"));
11594
11616
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;
11604
11620
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());
11610
11658
}
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"));
11615
11659
}
11616
11660
11617
11661
public static class Bug104067QueryInterceptor extends BaseQueryInterceptor {
11662
+ public static boolean errorOnSetTrue = false;
11663
+
11618
11664
@Override
11619
11665
public <T extends Resultset> T preProcess(Supplier<String> str, Query interceptedQuery) {
11620
11666
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")) {
11622
11668
throw ExceptionFactory.createException("Artificial non-connection related exception while executing \"" + sql + "\"");
11623
11669
}
11624
11670
return super.preProcess(str, interceptedQuery);
0 commit comments