Added couple more tests
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 27 Oct 2008 18:21:07 +0000 (18:21 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 27 Oct 2008 18:21:07 +0000 (18:21 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@708263 13f79535-47bb-0310-9956-ffa450edef68

modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/CheckOutThreadTest.java

index 7b115d7..9b18c66 100644 (file)
@@ -206,11 +206,100 @@ public class CheckOutThreadTest extends DefaultTestCase {
         System.out.println("[testPoolThreads20Connections10Validate]Test complete:"+delta+" ms. Iterations:"+(threadcount*this.iterations));\r
         tearDown();\r
     }\r
+    \r
+    public void testDBCPThreads10Connections10WithQuery() throws Exception {\r
+        init();\r
+        this.datasource.getPoolProperties().setMaxActive(10);\r
+        this.datasource.getPoolProperties().setTestOnBorrow(false);\r
+        this.threadcount = 10;\r
+        this.transferProperties();\r
+        this.tDatasource.getConnection().close();\r
+        latch = new CountDownLatch(threadcount);\r
+        long start = System.currentTimeMillis();\r
+        for (int i=0; i<threadcount; i++) {\r
+            TestThread t = new TestThread();\r
+            t.setName("tomcat-dbcp-"+i);\r
+            t.d = this.tDatasource;\r
+            t.query = "select * from user";\r
+            t.start();\r
+        }\r
+        latch.await();\r
+        long delta = System.currentTimeMillis() - start;\r
+        System.out.println("[testDBCPThreads10Connections10WithQuery]Test complete:"+delta+" ms. Iterations:"+(threadcount*this.iterations));\r
+        tearDown();\r
+    }\r
 \r
+    public void testPoolThreads10Connections10WithQuery() throws Exception {\r
+        init();\r
+        this.datasource.getPoolProperties().setMaxActive(10);\r
+        this.datasource.getPoolProperties().setTestOnBorrow(false);\r
+        this.threadcount = 10;\r
+        this.transferProperties();\r
+        this.datasource.getConnection().close();\r
+        latch = new CountDownLatch(threadcount);\r
+        long start = System.currentTimeMillis();\r
+        for (int i=0; i<threadcount; i++) {\r
+            TestThread t = new TestThread();\r
+            t.setName("tomcat-pool-"+i);\r
+            t.d = DataSourceFactory.getDataSource(this.datasource);\r
+            t.query = "select * from user";\r
+            t.start();\r
+        }\r
+        latch.await();\r
+        long delta = System.currentTimeMillis() - start;\r
+        System.out.println("[testPoolThreads10Connections10WithQuery]Test complete:"+delta+" ms. Iterations:"+(threadcount*this.iterations));\r
+        tearDown();\r
+    }\r
+    \r
+    public void testDBCPThreads10Connections10WithValidateWithQuery() throws Exception {\r
+        init();\r
+        this.datasource.getPoolProperties().setMaxActive(10);\r
+        this.datasource.getPoolProperties().setTestOnBorrow(true);\r
+        this.datasource.getPoolProperties().setValidationQuery("SELECT 1");\r
+        this.threadcount = 10;\r
+        this.transferProperties();\r
+        this.tDatasource.getConnection().close();\r
+        latch = new CountDownLatch(threadcount);\r
+        long start = System.currentTimeMillis();\r
+        for (int i=0; i<threadcount; i++) {\r
+            TestThread t = new TestThread();\r
+            t.setName("tomcat-dbcp-"+i);\r
+            t.d = this.tDatasource;\r
+            t.query = "select * from user";\r
+            t.start();\r
+        }\r
+        latch.await();\r
+        long delta = System.currentTimeMillis() - start;\r
+        System.out.println("[testDBCPThreads10Connections10WithValidateWithQuery]Test complete:"+delta+" ms. Iterations:"+(threadcount*this.iterations));\r
+        tearDown();\r
+    }\r
+\r
+    public void testPoolThreads10Connections10WithValidateWithQuery() throws Exception {\r
+        init();\r
+        this.datasource.getPoolProperties().setMaxActive(10);\r
+        this.datasource.getPoolProperties().setTestOnBorrow(true);\r
+        this.datasource.getPoolProperties().setValidationQuery("SELECT 1");\r
+        this.threadcount = 10;\r
+        this.transferProperties();\r
+        this.datasource.getConnection().close();\r
+        latch = new CountDownLatch(threadcount);\r
+        long start = System.currentTimeMillis();\r
+        for (int i=0; i<threadcount; i++) {\r
+            TestThread t = new TestThread();\r
+            t.setName("tomcat-pool-"+i);\r
+            t.d = DataSourceFactory.getDataSource(this.datasource);\r
+            t.query = "select * from user";\r
+            t.start();\r
+        }\r
+        latch.await();\r
+        long delta = System.currentTimeMillis() - start;\r
+        System.out.println("[testPoolThreads10Connections10WithValidateWithQuery]Test complete:"+delta+" ms. Iterations:"+(threadcount*this.iterations));\r
+        tearDown();\r
+    }\r
     \r
     public class TestThread extends Thread {\r
         protected DataSource d;\r
-        \r
+        protected String query = null;\r
         public void run() {\r
             long max = -1, totalmax=0, totalcmax=0, cmax = -1, nroffetch = 0, totalruntime = 0;\r
             try {\r
@@ -223,6 +312,14 @@ public class CheckOutThreadTest extends DefaultTestCase {
                         totalmax += delta;\r
                         max = Math.max(delta, max);\r
                         nroffetch++;\r
+                        if (query!=null) {\r
+                            Statement st = con.createStatement();\r
+                            ResultSet rs = st.executeQuery(query);\r
+                            while (rs.next()) {\r
+                            }\r
+                            rs.close();\r
+                            st.close();\r
+                        }\r
                     } finally {\r
                         long cstart = System.nanoTime();\r
                         if (con!=null) try {con.close();}catch(Exception x) {x.printStackTrace();}\r