tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fha...@apache.org
Subject svn commit: r1311841 - in /tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test: BorrowWaitTest.java DefaultProperties.java TestInterceptorShortName.java
Date Tue, 10 Apr 2012 16:28:31 GMT
Author: fhanik
Date: Tue Apr 10 16:28:31 2012
New Revision: 1311841

URL: http://svn.apache.org/viewvc?rev=1311841&view=rev
Log:
fix unit tests

Modified:
    tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/BorrowWaitTest.java
    tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/DefaultProperties.java
    tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/TestInterceptorShortName.java

Modified: tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/BorrowWaitTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/BorrowWaitTest.java?rev=1311841&r1=1311840&r2=1311841&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/BorrowWaitTest.java
(original)
+++ tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/BorrowWaitTest.java
Tue Apr 10 16:28:31 2012
@@ -27,21 +27,21 @@ public class BorrowWaitTest extends Defa
     }
 
     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);
             con2.close();
         }catch (SQLException x) {
-            long delta = System.currentTimeMillis();
-            boolean inrange = Math.abs(wait-delta) < 1000;
-            assertTrue(
-                    "Connection should have been acquired within +/- 1 second.",
-                    inrange);
+            long delta = System.currentTimeMillis() - start;
+            boolean inrange = Math.abs(wait-delta) <= 1000;
+            assertTrue("Connection should have been acquired within +/- 1 second, but was
"+(wait-delta)+" ms.",inrange);
         }
         con.close();
     }

Modified: tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/DefaultProperties.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/DefaultProperties.java?rev=1311841&r1=1311840&r2=1311841&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/DefaultProperties.java
(original)
+++ tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/DefaultProperties.java
Tue Apr 10 16:28:31 2012
@@ -29,7 +29,7 @@ public class DefaultProperties extends P
     private static final long serialVersionUID = 1L;
 
     public DefaultProperties() {
-        dbProperties = new Properties();
+        setDbProperties(new Properties());
 
         //mysql
         //url = System.getProperty("url","jdbc:mysql://localhost:3306/mysql?autoReconnect=true");
@@ -39,38 +39,38 @@ public class DefaultProperties extends P
         //url = System.getProperty("url","jdbc:derby:derbyDB;create=true");
         //driverClassName = System.getProperty("driverClassName","org.apache.derby.jdbc.EmbeddedDriver");
 
-        url = System.getProperty("url","jdbc:h2:~/.h2/test;QUERY_TIMEOUT=0;DB_CLOSE_ON_EXIT=FALSE");
-        driverClassName = System.getProperty("driverClassName","org.h2.Driver");
+        setUrl(System.getProperty("url","jdbc:h2:~/.h2/test;QUERY_TIMEOUT=0;DB_CLOSE_ON_EXIT=FALSE"));
+        setDriverClassName(System.getProperty("driverClassName","org.h2.Driver"));
         System.setProperty("h2.serverCachedObjects", "10000");
 
-        password = System.getProperty("password","password");
-        username = System.getProperty("username","root");
+        setPassword(System.getProperty("password","password"));
+        setUsername(System.getProperty("username","root"));
 
-        validationQuery = System.getProperty("validationQuery","SELECT 1");
-        defaultAutoCommit = Boolean.TRUE;
-        defaultReadOnly = Boolean.FALSE;
-        defaultTransactionIsolation = DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION;
-        connectionProperties = null;
-        defaultCatalog = null;
-        initialSize = 10;
-        maxActive = 100;
-        maxIdle = initialSize;
-        minIdle = initialSize;
-        maxWait = 10000;
-
-        testOnBorrow = true;
-        testOnReturn = false;
-        testWhileIdle = true;
-        timeBetweenEvictionRunsMillis = 5000;
-        numTestsPerEvictionRun = 0;
-        minEvictableIdleTimeMillis = 1000;
-        removeAbandoned = true;
-        removeAbandonedTimeout = 5000;
-        logAbandoned = true;
-        validationInterval = 0; //always validate
-        initSQL = null;
-        testOnConnect = false;
-        dbProperties.setProperty("user",username);
-        dbProperties.setProperty("password",password);
+        setValidationQuery(System.getProperty("validationQuery","SELECT 1"));
+        setDefaultAutoCommit(Boolean.TRUE);
+        setDefaultReadOnly(Boolean.FALSE);
+        setDefaultTransactionIsolation(DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION);
+        setConnectionProperties(null);
+        setDefaultCatalog(null);
+        setInitialSize(10);
+        setMaxActive(100);
+        setMaxIdle(getInitialSize());
+        setMinIdle(getInitialSize());
+        setMaxWait(10000);
+
+        setTestOnBorrow(true);
+        setTestOnReturn(false);
+        setTestWhileIdle(true);
+        setTimeBetweenEvictionRunsMillis(5000);
+        setNumTestsPerEvictionRun(0);
+        setMinEvictableIdleTimeMillis(1000);
+        setRemoveAbandoned(true);
+        setRemoveAbandonedTimeout(5000);
+        setLogAbandoned(true);
+        setValidationInterval(0); //always validate
+        setInitSQL(null);
+        setTestOnConnect(false);
+        getDbProperties().setProperty("user",getUsername());
+        getDbProperties().setProperty("password",getPassword());
     }
 }

Modified: tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/TestInterceptorShortName.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/TestInterceptorShortName.java?rev=1311841&r1=1311840&r2=1311841&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/TestInterceptorShortName.java
(original)
+++ tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/TestInterceptorShortName.java
Tue Apr 10 16:28:31 2012
@@ -30,10 +30,14 @@ public class TestInterceptorShortName ex
     public void testShortInterceptor() throws Exception {
         this.datasource = this.createDefaultDataSource();
         this.datasource.setJdbcInterceptors("TestInterceptor");
+        this.datasource.setUseDisposableConnectionFacade(false);
         this.datasource.setMaxActive(1);
+        this.datasource.createPool();
+        assertEquals("Only one interceptor should have been called setProperties[1]",1,TestInterceptor.instancecount.get());
+        TestInterceptor.instancecount.set(0);
         Connection con = this.datasource.getConnection();
         assertTrue("Pool should have been started.",TestInterceptor.poolstarted);
-        assertEquals("Only one interceptor should have been called setProperties",1,TestInterceptor.instancecount.get());
+        assertEquals("Only one interceptor should have been called setProperties[2]",1,TestInterceptor.instancecount.get());
         con.close();
         this.datasource.close();
         assertTrue("Pool should have been closed.",TestInterceptor.poolclosed);



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message