Changeset: 5f15cf9b8786 for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java/rev/5f15cf9b8786
Added Files:
src/test/java/org/monetdb/jdbc/ApiTests.java
Modified Files:
src/test/java/JDBC_API_Tester.java
Branch: default
Log Message:
Introduce ApiTests
diffs (119 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
@@ -50,6 +50,7 @@ import static org.junit.jupiter.api.Assu
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Tag("api")
+@Tag("unconverted")
public final class JDBC_API_Tester extends JUnitTester {
// This is where we gather test output which is then verified
// in compareExpectedOutput()
@@ -5419,8 +5420,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) )");
+ stmt1.executeUpdate("DROP TABLE IF EXISTS tconc_seq;
CREATE TABLE tconc_seq ( id serial, who varchar(12) )");
sb.append("passed :)\n");
// test the insertion of values with concurrent clients
diff --git a/src/test/java/org/monetdb/jdbc/ApiTests.java
b/src/test/java/org/monetdb/jdbc/ApiTests.java
new file mode 100644
--- /dev/null
+++ b/src/test/java/org/monetdb/jdbc/ApiTests.java
@@ -0,0 +1,93 @@
+package org.monetdb.jdbc;
+
+import org.junit.jupiter.api.*;
+import org.monetdb.testinfra.CloseOnFailure;
+import org.monetdb.testinfra.Config;
+import org.monetdb.testinfra.MonetVersionNumber;
+
+import java.sql.*;
+import java.util.ArrayList;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Tests migrated from JDBC_API_Testser
+ *
+ * Uses PER_CLASS so the connection is re-used between tests.
+ * The @CloseOnFailure annotation closes the connection if a test fails
+ * so the next test doesn't run in an uncommited transaction etc.
+ */
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+@Tag("api")
+@Tag("converted")
+public class ApiTests {
+ @CloseOnFailure
+ Connection conn;
+ MonetVersionNumber monetVersion;
+ Statement stmt;
+ PreparedStatement pstmt;
+
+ // Skip all tests if the test database isn't running
+ @BeforeAll
+ public static void checkConnection() throws SQLException {
+ DriverManager.getConnection(Config.getServerURL()).close();
+ }
+
+ // The @CloseOnFailure annotation closes 'conn' if tests fail.
+ // Make sure the next test has a connection.
+ @BeforeEach
+ protected void ensureConnection() throws SQLException {
+ if (conn == null || conn.isClosed()) {
+ conn = newConnection();
+ monetVersion = MonetVersionNumber.retrieve(conn);
+ }
+ stmt = conn.createStatement();
+ }
+
+ // After each test, check for abandoned transactions and unclosed
+ // result sets
+ @AfterEach
+ protected void checkLingeringState() throws SQLException {
+ if (conn == null || conn.isClosed()) {
+ stmt = null;
+ pstmt = null;
+ return;
+ }
+
+ assertTrue(conn.getAutoCommit());
+
+ if (monetVersion.serverCanQueryUnclosedResultSets()) {
+ ArrayList<String> unclosed = new ArrayList<>();
+ String query = "SELECT 'query_id=' || query_id ||
'/res_id=' || res_id FROM sys.unclosed_result_sets()";
+ try (ResultSet rs = stmt.executeQuery(query)) {
+ while (rs.next())
+ unclosed.add(rs.getString(1));
+ }
+ String unclosedResultSets = String.join(", ", unclosed);
+ assertEquals("", unclosedResultSets, "this test forgot
to close one or more result sets");
+ }
+
+ stmt.close();
+ stmt = null;
+ if (pstmt != null) {
+ pstmt.close();
+ pstmt = null;
+ }
+ }
+
+ @AfterAll
+ protected void dropConnection() {
+ if (conn != null) {
+ try {
+ conn.close();
+ } catch (SQLException ignored) {}
+ }
+ }
+
+ private Connection newConnection() throws SQLException {
+ return DriverManager.getConnection(Config.getServerURL());
+ }
+
+}
+
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]