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

Convert Test_Cmanycon() -> ApiTests#testManyConnections()


diffs (110 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
@@ -175,60 +175,6 @@ public final class JDBC_API_Tester exten
        }
 
        @Test
-       public void Test_Cmanycon() {
-               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<Connection> cons = new ArrayList<Connection>(maxCons);     
// Connections go in here
-               try {
-                       // spawn a lot of Connections, just for fun...
-                       int i = 1;
-                       sb.append("Establishing Connection ");
-                       for (; i <= maxCons; i++) {
-                               sb.append(i);
-                               Connection conx = 
DriverManager.getConnection(jdbcUrl);
-                               sb.append(",");
-                               cons.add(conx);
-
-                               // do something with the connection to test if 
it works
-                               conx.setAutoCommit(false);
-                               sb.append(" ");
-                               conx.createStatement();
-                       }
-                       sb.append("\n");
-
-                       // now try to nicely close them
-                       i = 1;
-                       sb.append("Closing Connection ");
-                       for (Iterator<Connection> it = cons.iterator(); 
it.hasNext(); i++) {
-                               Connection conx = it.next();
-                               // see if the connection still works
-                               sb.append(i);
-                               conx.setAutoCommit(true);
-                               sb.append(",");
-                               conx.close();   // this will also implicitly 
close the created statement object
-                               sb.append(" ");
-                       }
-               } catch (SQLException e) {
-                       sb.append(" FAILED: 
").append(e.getMessage()).append("\n");
-               }
-
-               compareExpectedOutput("Test_Cmanycon",
-                       "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" +
-                       "Closing 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, ");
-       }
-
-       @Test
        public void Test_Creplysize() {
                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
@@ -166,5 +166,42 @@ public class ApiTests {
 
                assertEquals(nrepetitions, count);
        }
+
+       @Test
+       public void testManyConnections() throws SQLException {
+               Connection[] conns = new Connection[60];
+
+               try {
+                       // connect them all
+                       for (int i = 0; i < conns.length; i++) {
+                               try {
+                                       conns[i] = newConnection();
+                                       conns[i].setAutoCommit(false);
+                               } catch (SQLException e) {
+                                       fail("Caught exception while opening 
connection #" + i, e);
+                               }
+                       }
+
+                       // check and disconnect them all
+                       for (int i = 0; i < conns.length; i++) {
+                               try {
+                                       conns[i].setAutoCommit(true); // do 
something with it
+                                       conns[i].close();
+                                       conns[i] = null;
+                               } catch (SQLException e) {
+                                       fail("Caught exception while closing 
connection #" + i, e);
+                               }
+                       }
+               } 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