Changeset: 3549efece061 for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java/rev/3549efece061
Modified Files:
src/test/java/JDBC_API_Tester.java
Branch: default
Log Message:
Move Test_CautocommitWithErrors to the bottom of the file
to avoid merge conflicts
diffs (truncated from 389 to 300 lines):
diff --git a/src/test/java/JDBC_API_Tester.java
b/src/test/java/JDBC_API_Tester.java
--- a/src/test/java/JDBC_API_Tester.java
+++ b/src/test/java/JDBC_API_Tester.java
@@ -265,192 +265,6 @@ public final class JDBC_API_Tester exten
}
@Test
- public void Test_CautocommitWithErrors() {
- Connection helper = null;
- Statement stmt = null;
- ResultSet rs = null;
- sb.setLength(0);
-
- // Older versions forget to send autocommit status change
- // notifications when transaction fails
- assumeTrue(isAtLeast56);
-
- try {
- // Connections
- stmt = con.createStatement();
- helper = DriverManager.getConnection(jdbcUrl);
-
- // Used for autocommit verification
- stmt.executeUpdate(
- "DROP TABLE IF EXISTS
autocommitcheck;\n" +
- "CREATE TABLE
autocommitcheck(i INT);");
-
- sb.append("1a. initially auto commit mode is on\n");
- checkReportedAutocommit(true, helper);
-
- sb.append("1b. after an error it's still on\n");
- try {
- stmt.execute("SELECT x FROM autocommitcheck --
column x does not exist");
- } catch (SQLException ignored) {
- sb.append(" statement failed as expected\n");
- }
- checkReportedAutocommit(true, helper);
-
- sb.append("\n2a. START TRANSACTION turns it off\n");
- stmt.execute("START TRANSACTION");
- checkReportedAutocommit(false, helper);
-
- sb.append("2b. COMMIT turns it on\n");
- stmt.execute("COMMIT");
- checkReportedAutocommit(true, helper);
-
- sb.append("\n3a. START TRANSACTION turns it off
again\n");
- stmt.execute("START TRANSACTION");
- checkReportedAutocommit(false, helper);
-
- sb.append("3b. after an error it's still off\n");
- try {
- stmt.execute("SELECT x FROM autocommitcheck --
column x does not exist");
- } catch (SQLException ignored) {
- sb.append(" statement failed as expected\n");
- }
- checkReportedAutocommit(false, helper);
-
- sb.append("3c. after ROLLBACK it's on again\n");
- stmt.execute("ROLLBACK");
- checkReportedAutocommit(true, helper);
-
- sb.append("\n4a. START TRANSACTION turns it off
again\n");
- stmt.execute("START TRANSACTION");
- checkReportedAutocommit(false, helper);
-
- sb.append("4b. after an error it's still off\n");
- try {
- stmt.execute("SELECT x FROM autocommitcheck --
column x does not exist");
- } catch (SQLException ignored) {
- sb.append(" statement failed as expected\n");
- }
- checkReportedAutocommit(false, helper);
-
- sb.append("4c. COMMIT fails, autocommit is on again\n");
- try {
- stmt.execute("COMMIT");
- } catch (SQLException ignored) {
- sb.append(" statement failed as expected\n");
- }
- checkReportedAutocommit(true, helper);
- } catch (SQLException e) {
- sb.append("FAILED: " + e.getMessage() + "\n");
- closeConx(helper);
- closeStmtResSet(stmt, rs);
- sb.append("ABORTING TEST!!!");
- }
-
- //language=TEXT
- compareExpectedOutput("Test_Cautocommit_errors", ""
- + "1a. initially auto commit mode is on\n"
- + " reported autocommit = true, as expected\n"
- + " the inserted test data is visible, as
expected\n"
- + "1b. after an error it's still on\n"
- + " statement failed as expected\n"
- + " reported autocommit = true, as expected\n"
- + " the inserted test data is visible, as
expected\n"
- + "\n"
- + "2a. START TRANSACTION turns it off\n"
- + " reported autocommit = false, as expected\n"
- + " the inserted test data is not visible, as
expected\n"
- + "2b. COMMIT turns it on\n"
- + " reported autocommit = true, as expected\n"
- + " the inserted test data is visible, as
expected\n"
- + "\n"
- + "3a. START TRANSACTION turns it off again\n"
- + " reported autocommit = false, as expected\n"
- + " the inserted test data is not visible, as
expected\n"
- + "3b. after an error it's still off\n"
- + " statement failed as expected\n"
- + " reported autocommit = false, as expected\n"
- + " connection indeed in autocommit mode\n"
- + "3c. after ROLLBACK it's on again\n"
- + " reported autocommit = true, as expected\n"
- + " the inserted test data is visible, as
expected\n"
- + "\n"
- + "4a. START TRANSACTION turns it off again\n"
- + " reported autocommit = false, as expected\n"
- + " the inserted test data is not visible, as
expected\n"
- + "4b. after an error it's still off\n"
- + " statement failed as expected\n"
- + " reported autocommit = false, as expected\n"
- + " connection indeed in autocommit mode\n"
- + "4c. COMMIT fails, autocommit is on again\n"
- + " statement failed as expected\n"
- + " reported autocommit = true, as expected\n"
- + " the inserted test data is visible, as
expected\n");
- }
-
- /**
- * Verify 'con' believes it's in autocommit mode.
- * @param expectedAutocommit
- * @param helper Helper connection used to check if it's really the case
- * @throws SQLException
- */
- private void checkReportedAutocommit(boolean expectedAutocommit,
Connection helper) throws SQLException {
- boolean reportedAutocommit = con.getAutoCommit();
- if (reportedAutocommit == expectedAutocommit)
- sb.append(" reported autocommit = " +
reportedAutocommit + ", as expected\n");
- else
- sb.append(" ERROR: reported autocommit = " +
reportedAutocommit + ", expected " + expectedAutocommit + "\n");
-
- if (helper != null)
- verifyAutocommit(expectedAutocommit, helper);
- }
-
- /**
- * Append some data to table 'autocommitcheck', see if it shows up in
the
- * other connection
- * @param expectedAutocommit
- * @param helper
- */
- private void verifyAutocommit(boolean expectedAutocommit, Connection
helper) throws SQLException {
- int value = counter++;
-
- // Append the data
- try (PreparedStatement ps = con.prepareStatement("INSERT INTO
autocommitcheck VALUES (?)")) {
- ps.setInt(1, value);
- ps.execute();
- } catch (SQLException e) {
- // We only care about 25005!Current transaction is
aborted (please ROLLBACK)
- if (!e.getSQLState().equals("25005"))
- throw e;
- // 25005 implies we're not in auto commit mode
- if (expectedAutocommit) {
- sb.append(" ERROR: expected to be in
autocommit mode but inserting test data gave " + e.getMessage() + "\n");
- } else {
- sb.append(" connection indeed in autocommit
mode\n");
- }
- return;
- }
-
- // We didn't get an error inserting the data, is it visible
from the other connection?
- final boolean visible;
- try (PreparedStatement ps = helper.prepareStatement("SELECT *
FROM autocommitcheck WHERE i = ?")) {
- ps.setInt(1, value);
- try (ResultSet rs = ps.executeQuery()) {
- visible = rs.next();
- }
- }
- if (expectedAutocommit)
- if (visible)
- sb.append(" the inserted test data is visible,
as expected\n");
- else
- sb.append(" ERROR: the inserted test data is
not visible, but we're supposed to be in auto commit mode\n");
- else
- if (visible)
- sb.append(" ERROR: the inserted test data is is
visible but we're supposed to not be in auto commit mode\n");
- else
- sb.append(" the inserted test data is not visible, as
expected\n");
- }
-
- @Test
public void Test_CisValid() {
sb.setLength(0); // clear the output log buffer
@@ -7745,6 +7559,192 @@ public final class JDBC_API_Tester exten
);
}
+ @Test
+ public void Test_CautocommitWithErrors() {
+ Connection helper = null;
+ Statement stmt = null;
+ ResultSet rs = null;
+ sb.setLength(0);
+
+ // Older versions forget to send autocommit status change
+ // notifications when transaction fails
+ assumeTrue(isAtLeast56);
+
+ try {
+ // Connections
+ stmt = con.createStatement();
+ helper = DriverManager.getConnection(jdbcUrl);
+
+ // Used for autocommit verification
+ stmt.executeUpdate(
+ "DROP TABLE IF EXISTS
autocommitcheck;\n" +
+ "CREATE TABLE
autocommitcheck(i INT);");
+
+ sb.append("1a. initially auto commit mode is on\n");
+ checkReportedAutocommit(true, helper);
+
+ sb.append("1b. after an error it's still on\n");
+ try {
+ stmt.execute("SELECT x FROM autocommitcheck --
column x does not exist");
+ } catch (SQLException ignored) {
+ sb.append(" statement failed as expected\n");
+ }
+ checkReportedAutocommit(true, helper);
+
+ sb.append("\n2a. START TRANSACTION turns it off\n");
+ stmt.execute("START TRANSACTION");
+ checkReportedAutocommit(false, helper);
+
+ sb.append("2b. COMMIT turns it on\n");
+ stmt.execute("COMMIT");
+ checkReportedAutocommit(true, helper);
+
+ sb.append("\n3a. START TRANSACTION turns it off
again\n");
+ stmt.execute("START TRANSACTION");
+ checkReportedAutocommit(false, helper);
+
+ sb.append("3b. after an error it's still off\n");
+ try {
+ stmt.execute("SELECT x FROM autocommitcheck --
column x does not exist");
+ } catch (SQLException ignored) {
+ sb.append(" statement failed as expected\n");
+ }
+ checkReportedAutocommit(false, helper);
+
+ sb.append("3c. after ROLLBACK it's on again\n");
+ stmt.execute("ROLLBACK");
+ checkReportedAutocommit(true, helper);
+
+ sb.append("\n4a. START TRANSACTION turns it off
again\n");
+ stmt.execute("START TRANSACTION");
+ checkReportedAutocommit(false, helper);
+
+ sb.append("4b. after an error it's still off\n");
+ try {
+ stmt.execute("SELECT x FROM autocommitcheck --
column x does not exist");
+ } catch (SQLException ignored) {
+ sb.append(" statement failed as expected\n");
+ }
+ checkReportedAutocommit(false, helper);
+
+ sb.append("4c. COMMIT fails, autocommit is on again\n");
+ try {
+ stmt.execute("COMMIT");
+ } catch (SQLException ignored) {
+ sb.append(" statement failed as expected\n");
+ }
+ checkReportedAutocommit(true, helper);
+ } catch (SQLException e) {
+ sb.append("FAILED: " + e.getMessage() + "\n");
+ closeConx(helper);
+ closeStmtResSet(stmt, rs);
+ sb.append("ABORTING TEST!!!");
+ }
+
+ //language=TEXT
+ compareExpectedOutput("Test_Cautocommit_errors", ""
+ + "1a. initially auto commit mode is on\n"
+ + " reported autocommit = true, as expected\n"
+ + " the inserted test data is visible, as
expected\n"
+ + "1b. after an error it's still on\n"
+ + " statement failed as expected\n"
+ + " reported autocommit = true, as expected\n"
+ + " the inserted test data is visible, as
expected\n"
+ + "\n"
+ + "2a. START TRANSACTION turns it off\n"
+ + " reported autocommit = false, as expected\n"
+ + " the inserted test data is not visible, as
expected\n"
+ + "2b. COMMIT turns it on\n"
+ + " reported autocommit = true, as expected\n"
+ + " the inserted test data is visible, as
expected\n"
+ + "\n"
+ + "3a. START TRANSACTION turns it off again\n"
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]