@@ -11562,4 +11562,69 @@ public void testBug28725534() throws Exception {
11562
11562
11563
11563
assertTrue(end - start < 250, ".equals() took too long to exectute, the method is being locked by a synchronized block.");
11564
11564
}
11565
+
11566
+ /**
11567
+ * Tests fix for Bug#104067 (33054827), No reset autoCommit after unknown issue occurs.
11568
+ *
11569
+ * @throws Exception
11570
+ */
11571
+ @Test
11572
+ public void testBug104067() throws Exception {
11573
+ Properties props = new Properties();
11574
+ props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
11575
+ props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
11576
+ props.setProperty(PropertyKey.queryInterceptors.getKeyName(), Bug104067QueryInterceptor.class.getName());
11577
+ Connection testConn = getConnectionWithProps(props);
11578
+ Statement testStmt = testConn.createStatement();
11579
+
11580
+ // Connection vs session autocommit value:
11581
+ // 1. Default value.
11582
+ assertTrue(testConn.getAutoCommit());
11583
+ this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11584
+ assertTrue(this.rs.next());
11585
+ assertTrue(this.rs.getString(2).equalsIgnoreCase("ON"));
11586
+
11587
+ // 2. After Connection.setAutcommit(true).
11588
+ try {
11589
+ testConn.setAutoCommit(true);
11590
+ } catch (SQLException e) {
11591
+ fail("Exception not expected.", e);
11592
+ }
11593
+ assertTrue(testConn.getAutoCommit());
11594
+ this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11595
+ assertTrue(this.rs.next());
11596
+ assertTrue(this.rs.getString(2).equalsIgnoreCase("ON"));
11597
+
11598
+ // 3. After Connection.setAutcommit(false).
11599
+ assertThrows(SQLException.class, () -> {
11600
+ testConn.setAutoCommit(false);
11601
+ return null;
11602
+ });
11603
+ assertTrue(testConn.getAutoCommit());
11604
+ this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11605
+ this.rs.next();
11606
+ assertTrue(this.rs.getString(2).equalsIgnoreCase("ON"));
11607
+
11608
+ // 4. After Connection.setAutcommit(true).
11609
+ try {
11610
+ testConn.setAutoCommit(true);
11611
+ } catch (SQLException e) {
11612
+ fail("Exception not expected.", e);
11613
+ }
11614
+ assertTrue(testConn.getAutoCommit());
11615
+ this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11616
+ assertTrue(this.rs.next());
11617
+ assertTrue(this.rs.getString(2).equalsIgnoreCase("ON"));
11618
+ }
11619
+
11620
+ public static class Bug104067QueryInterceptor extends BaseQueryInterceptor {
11621
+ @Override
11622
+ public <T extends Resultset> T preProcess(Supplier<String> str, Query interceptedQuery) {
11623
+ String sql = str.get();
11624
+ if (sql.equalsIgnoreCase("SET autocommit=0")) {
11625
+ throw ExceptionFactory.createException("Artificial non-connection related exception while executing \"" + sql + "\"");
11626
+ }
11627
+ return super.preProcess(str, interceptedQuery);
11628
+ }
11629
+ }
11565
11630
}
0 commit comments