Add timeout test
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 17 Nov 2008 04:42:29 +0000 (04:42 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 17 Nov 2008 04:42:29 +0000 (04:42 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@718170 13f79535-47bb-0310-9956-ffa450edef68

modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/BorrowWaitTest.java [new file with mode: 0644]

diff --git a/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/BorrowWaitTest.java b/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/BorrowWaitTest.java
new file mode 100644 (file)
index 0000000..d9b3552
--- /dev/null
@@ -0,0 +1,55 @@
+package org.apache.tomcat.jdbc.test;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+public class BorrowWaitTest extends DefaultTestCase {
+
+    public BorrowWaitTest(String name) {
+        super(name);
+    }
+    
+    public void testWaitTime() throws Exception {
+        int wait = 10000;
+        this.init();
+        this.datasource.setMaxActive(1);
+        this.datasource.setMaxWait(wait);
+        Connection con = datasource.getConnection();
+        long start = System.currentTimeMillis();
+        try {
+            Connection con2 = datasource.getConnection();
+            assertFalse("This should not happen, connection should be unavailable.",true);
+        }catch (SQLException x) {
+            long delta = System.currentTimeMillis();
+            boolean inrange = Math.abs(wait-delta) < 1000;
+            assertTrue("Connection should have been acquired within +/- 1 second.",true);
+        }
+        con.close();
+    }
+    
+    public void testWaitTimeInfinite() throws Exception {
+        if(true){
+            System.err.println("testWaitTimeInfinite() test is disabled.");
+            return;//this would lock up the test suite
+        }
+        int wait = -1;
+        this.init();
+        this.datasource.setMaxActive(1);
+        this.datasource.setMaxWait(wait);
+        Connection con = datasource.getConnection();
+        long start = System.currentTimeMillis();
+        try {
+            Connection con2 = datasource.getConnection();
+            assertFalse("This should not happen, connection should be unavailable.",true);
+        }catch (SQLException x) {
+            long delta = System.currentTimeMillis();
+            boolean inrange = Math.abs(wait-delta) < 1000;
+            assertTrue("Connection should have been acquired within +/- 1 second.",true);
+        }
+        con.close();
+    }
+    
+    
+    
+    
+}