Changeset: ec7c8dbf9c4d for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java/rev/ec7c8dbf9c4d
Modified Files:
.gitignore
src/test/java/JDBC_API_Tester.java
Branch: mvn
Log Message:
Merge 'default' into 'mvn'
diffs (270 lines):
diff --git a/.gitignore b/.gitignore
--- a/.gitignore
+++ b/.gitignore
@@ -1,11 +1,15 @@
# files created by the normal build process
target
+build
jars
-build
+*.class
# local overrides while testing
test.properties
+
+src/main/java/org/monetdb/jdbc/MonetVersion.java
+
# files generated by various editors
*.swp
*~
@@ -21,6 +25,5 @@ test.properties
# other files we don't want
TAGS
tags
-*.class
*.rej
*.orig
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
@@ -31,6 +31,7 @@ import org.monetdb.testinfra.CloseOnFail
import org.monetdb.testinfra.Config;
import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
/**
* class to test JDBC Driver API methods and behavior of MonetDB server.
@@ -60,12 +61,14 @@ public final class JDBC_API_Tester exten
@CloseOnFailure
private Connection con; // main Connection shared by all tests
private MonetConnection mcon; // same, but as a MonetConnection
+ private int counter = 0; // used to generate unique values in
autccommit tests
private int dbmsMajorVersion;
private int dbmsMinorVersion;
private int dbmsMicroVersion;
private boolean isPostDec2023; // flag to support version specific
output
private boolean isPostMar2025;
private boolean isPostDec2025; // Dec2025-SP1 or later;
+ private boolean isAtLeast56;
private boolean skipMALoutput = Config.isSkipMalOutput();
private boolean supportsNestedTypes;
@@ -94,6 +97,7 @@ public final class JDBC_API_Tester exten
isPostMar2025 = versionIsAtLeast(11, 54, 0);
// post-Dec2025 means Dec2025-SP1 (11.55.2) or later. It has a
new system table: tmp.dependencies
isPostDec2025 = versionIsAtLeast(11, 55, 2);
+ isAtLeast56 = versionIsAtLeast(56, 0, 0);
String checkNested =
"SELECT c.name\n" +
@@ -261,6 +265,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"
+ + " 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
@@ -5182,6 +5372,7 @@ public final class JDBC_API_Tester exten
// test the creation of a table with concurrent clients
sb.append("1.1. create table t1504657 using client
1...\n");
+ stmt1.executeUpdate("DROP TABLE IF EXISTS t1504657");
stmt1.executeUpdate("CREATE TABLE t1504657 ( id int,
name varchar(1024) )");
sb.append("passed :)\n");
@@ -5414,6 +5605,7 @@ public final class JDBC_API_Tester exten
// create a table
sb.append("1. create table tconc_seq using client 1...
");
+ stmt1.executeUpdate("DROP TABLE IF EXISTS tconc_seq");
stmt1.executeUpdate("CREATE TABLE tconc_seq ( id
serial, who varchar(12) )");
sb.append("passed :)\n");
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]