Add c3p0 as a comparison in the fairness test
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 23 Apr 2009 16:40:28 +0000 (16:40 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 23 Apr 2009 16:40:28 +0000 (16:40 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@767969 13f79535-47bb-0310-9956-ffa450edef68

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

index 83ba388..aa587a9 100644 (file)
@@ -118,6 +118,7 @@ public class CheckOutThreadTest extends DefaultTestCase {
     public void testPoolThreads20Connections10() throws Exception {
         init();
         this.datasource.getPoolProperties().setMaxActive(10);
+        this.datasource.getPoolProperties().setFairQueue(false);
         this.threadcount = 20;
         this.transferProperties();
         this.datasource.getConnection().close();
index e61e995..1f2b95b 100644 (file)
@@ -25,7 +25,6 @@ import java.sql.ResultSet;
 
 import javax.sql.DataSource;
 
-import org.apache.tomcat.jdbc.pool.DataSourceFactory;
 import org.apache.tomcat.jdbc.pool.DataSourceProxy;
 
 /**
@@ -106,7 +105,7 @@ public class FairnessTest extends DefaultTestCase {
         for (int i=0; i<threadcount; i++) {
             threads[i] = new TestThread();
             threads[i].setName("tomcat-pool-"+i);
-            threads[i].d = DataSourceFactory.getDataSource(this.datasource);
+            threads[i].d = this.datasource;
             
         }
         for (int i=0; i<threadcount; i++) {
@@ -136,7 +135,7 @@ public class FairnessTest extends DefaultTestCase {
         for (int i=0; i<threadcount; i++) {
             threads[i] = new TestThread();
             threads[i].setName("tomcat-pool-"+i);
-            threads[i].d = DataSourceFactory.getDataSource(this.datasource);
+            threads[i].d = this.datasource;
             
         }
         for (int i=0; i<threadcount; i++) {
@@ -166,7 +165,7 @@ public class FairnessTest extends DefaultTestCase {
             threads[i] = new TestThread();
             threads[i].setName("tomcat-pool-"+i);
             threads[i].async = true;
-            threads[i].d = DataSourceFactory.getDataSource(this.datasource);
+            threads[i].d = this.datasource;
             
         }
         for (int i=0; i<threadcount; i++) {
@@ -181,6 +180,37 @@ public class FairnessTest extends DefaultTestCase {
         tearDown();
     }
     
+    public void testC3P0Threads20Connections10() throws Exception {
+        System.out.println("[testC3P0Threads20Connections10] Starting fairness - C3P0");
+        init();
+        this.datasource.getPoolProperties().setMaxActive(10);
+        this.datasource.getPoolProperties().setFairQueue(false);
+        this.threadcount = 20;
+        this.transferPropertiesToC3P0();
+        this.datasource.getConnection().close();
+        latch = new CountDownLatch(threadcount);
+        long start = System.currentTimeMillis();
+        TestThread[] threads = new TestThread[threadcount];
+        for (int i=0; i<threadcount; i++) {
+            threads[i] = new TestThread();
+            threads[i].setName("tomcat-pool-"+i);
+            threads[i].d = this.c3p0Datasource;
+            
+        }
+        for (int i=0; i<threadcount; i++) {
+            threads[i].start();
+        }
+        if (!latch.await(complete+1000,TimeUnit.MILLISECONDS)) {
+            System.out.println("Latch timed out.");
+        }
+        this.run = false;
+        long delta = System.currentTimeMillis() - start;
+        printThreadResults(threads,"testC3P0Threads20Connections10");
+        tearDown();
+
+    }
+
+    
     public class TestThread extends Thread {
         protected DataSource d;
         protected String query = null;