Changeset: 05d16754ab00 for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java/rev/05d16754ab00
Modified Files:
        src/test/java/JDBC_API_Tester.java
        src/test/java/org/monetdb/jdbc/ApiTests.java
Branch: default
Log Message:

Convert Test_PSmanycon() -> ApiTests#testManyConnectionsPrepared()


diffs (158 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
@@ -1053,93 +1053,6 @@ public final class JDBC_API_Tester exten
                        "2. empty call... passed\n");
        }
 
-       @Test
-       public void Test_PSmanycon() {
-               sb.setLength(0);        // clear the output log buffer
-
-               final int maxCons = 60; // default max_clients is 64, 2 
connections are already open from this program
-               List<PreparedStatement> pss = new 
ArrayList<PreparedStatement>(maxCons);        // PreparedStatements go in here
-
-               try {
-                       // spawn a lot of Connections with 1 PreparedStatement, 
just for fun...
-                       int i = 1;
-                       sb.append("Establishing Connection ");
-                       for (; i <= maxCons; i++) {
-                               sb.append(i);
-                               Connection conx = 
DriverManager.getConnection(jdbcUrl);
-                               sb.append(",");
-
-                               // do something with the connection to test if 
it works
-                               PreparedStatement pstmt = 
conx.prepareStatement("select " + i);
-                               sb.append(" ");
-
-                               pss.add(pstmt);
-                       }
-                       sb.append("\n");
-
-                       // now try to nicely execute them
-                       i = 1;
-                       sb.append("Executing PreparedStatement\n");
-                       for (Iterator<PreparedStatement> it = pss.iterator(); 
it.hasNext(); i++) {
-                               PreparedStatement pstmt = it.next();
-
-                               // see if the connection still works
-                               sb.append(i).append("...");
-                               if (!pstmt.execute())
-                                       sb.append("should have seen a 
ResultSet!");
-
-                               ResultSet rs = pstmt.getResultSet();
-                               if (rs != null) {
-                                       if (!rs.next())
-                                               sb.append("ResultSet is empty");
-                                       sb.append(" result: 
").append(rs.getString(1));
-                               }
-
-                               // close the connection and associated resources
-                               pstmt.getConnection().close();
-                               sb.append(", closed. ");
-
-                               if (i % 5 == 0) {
-                                       // inject a failed transaction
-                                       Connection conZZ = 
DriverManager.getConnection(jdbcUrl);
-                                       Statement stmt = con.createStatement();
-                                       try {
-                                               int affrows = 
stmt.executeUpdate("update foo where bar is wrong");
-                                               sb.append("oops, faulty 
statement just got through");
-                                       } catch (SQLException e) {
-                                               sb.append("Forced transaction 
failure");
-                                       }
-                                       sb.append("\n");
-                                       closeStmtResSet(stmt, null);
-                                       conZZ.close();
-                               }
-                       }
-               } catch (SQLException e) {
-                       sb.append("FAILED: 
").append(e.getMessage()).append("\n");
-               }
-
-               compareExpectedOutput("Test_PSmanycon",
-                       "Establishing Connection 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 
" +
-                       "11, 12, 13, 14, 15, 16, 17, 18, 19, 20, " +
-                       "21, 22, 23, 24, 25, 26, 27, 28, 29, 30, " +
-                       "31, 32, 33, 34, 35, 36, 37, 38, 39, 40, " +
-                       "41, 42, 43, 44, 45, 46, 47, 48, 49, 50, " +
-                       "51, 52, 53, 54, 55, 56, 57, 58, 59, 60, \n" +
-                       "Executing PreparedStatement\n" +
-                       "1... result: 1, closed. 2... result: 2, closed. 3... 
result: 3, closed. 4... result: 4, closed. 5... result: 5, closed. Forced 
transaction failure\n" +
-                       "6... result: 6, closed. 7... result: 7, closed. 8... 
result: 8, closed. 9... result: 9, closed. 10... result: 10, closed. Forced 
transaction failure\n" +
-                       "11... result: 11, closed. 12... result: 12, closed. 
13... result: 13, closed. 14... result: 14, closed. 15... result: 15, closed. 
Forced transaction failure\n" +
-                       "16... result: 16, closed. 17... result: 17, closed. 
18... result: 18, closed. 19... result: 19, closed. 20... result: 20, closed. 
Forced transaction failure\n" +
-                       "21... result: 21, closed. 22... result: 22, closed. 
23... result: 23, closed. 24... result: 24, closed. 25... result: 25, closed. 
Forced transaction failure\n" +
-                       "26... result: 26, closed. 27... result: 27, closed. 
28... result: 28, closed. 29... result: 29, closed. 30... result: 30, closed. 
Forced transaction failure\n" +
-                       "31... result: 31, closed. 32... result: 32, closed. 
33... result: 33, closed. 34... result: 34, closed. 35... result: 35, closed. 
Forced transaction failure\n" +
-                       "36... result: 36, closed. 37... result: 37, closed. 
38... result: 38, closed. 39... result: 39, closed. 40... result: 40, closed. 
Forced transaction failure\n" +
-                       "41... result: 41, closed. 42... result: 42, closed. 
43... result: 43, closed. 44... result: 44, closed. 45... result: 45, closed. 
Forced transaction failure\n" +
-                       "46... result: 46, closed. 47... result: 47, closed. 
48... result: 48, closed. 49... result: 49, closed. 50... result: 50, closed. 
Forced transaction failure\n" +
-                       "51... result: 51, closed. 52... result: 52, closed. 
53... result: 53, closed. 54... result: 54, closed. 55... result: 55, closed. 
Forced transaction failure\n" +
-                       "56... result: 56, closed. 57... result: 57, closed. 
58... result: 58, closed. 59... result: 59, closed. 60... result: 60, closed. 
Forced transaction failure\n");
-       }
-
        @Test    // CHANGED supportsNestedTypes
        public void Test_PSmetadata() {
                sb.setLength(0);        // clear the output log buffer
diff --git a/src/test/java/org/monetdb/jdbc/ApiTests.java 
b/src/test/java/org/monetdb/jdbc/ApiTests.java
--- a/src/test/java/org/monetdb/jdbc/ApiTests.java
+++ b/src/test/java/org/monetdb/jdbc/ApiTests.java
@@ -783,4 +783,57 @@ public class ApiTests {
 
                stmt.executeUpdate("DROP TABLE test_largeval");
        }
+
+       @Test
+       public void testManyConnectionsPrepared() throws SQLException {
+               Connection[] conns = new Connection[60];
+               PreparedStatement[] stmts = new PreparedStatement[conns.length];
+
+               try {
+                       // connect them all
+                       for (int i = 0; i < conns.length; i++) {
+                               try {
+                                       conns[i] = newConnection();
+                                       stmts[i] = 
conns[i].prepareStatement("SELECT " + i);
+                               } catch (SQLException e) {
+                                       fail("Caught exception while opening 
connection #" + i, e);
+                               }
+                       }
+
+                       // Check and disconnect them all
+                       // Occasionally force an error on another connection
+                       // to prove that doesn't affect other connections
+                       for (int i = 0; i < conns.length; i++) {
+                               try {
+                                       try (ResultSet rs = 
stmts[i].executeQuery()) {
+                                               assertTrue(rs.next());
+                                               assertEquals(i, rs.getInt(1));
+                                               assertFalse(rs.next());
+                                       }
+                                       stmts[i].close();
+                                       conns[i].close();
+                                       conns[i] = null;
+                               } catch (SQLException e) {
+                                       fail("Caught exception while checking 
connection #" + i, e);
+                               }
+
+                               // Force an error on a throwaway connection.
+                               // Shouldn't affect ours.
+                               try (Connection c = newConnection(); Statement 
s = c.createStatement()) {
+                                       s.execute("SELECT bad FROM FROM wrong");
+                                       fail("expected the statement above to 
raise an exception");
+                               } catch (SQLException ignored) {}
+                       }
+               } finally {
+                       // all connections must be closed even if errors 
happened
+                       for (int i = 0; i < conns.length; i++) {
+                               if (conns[i] != null) {
+                                       try {
+                                               conns[i].close();
+                                       } catch (SQLException ignored) {}
+                               }
+                       }
+               }
+       }
+
 }
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to