On 24/07/2009, fha...@apache.org <fha...@apache.org> wrote: > Author: fhanik > Date: Fri Jul 24 15:25:17 2009 > New Revision: 797529 > > URL: http://svn.apache.org/viewvc?rev=797529&view=rev > Log: > update test cases > > Modified: > > tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/AbandonPercentageTest.java > > tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/BorrowWaitTest.java > > tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultTestCase.java > > tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TestConcurrency.java > > Modified: > tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/AbandonPercentageTest.java > URL: > http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/AbandonPercentageTest.java?rev=797529&r1=797528&r2=797529&view=diff > > ============================================================================== > --- > tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/AbandonPercentageTest.java > (original) > +++ > tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/AbandonPercentageTest.java > Fri Jul 24 15:25:17 2009 > @@ -38,7 +38,6 @@ > this.datasource.getPoolProperties().setRemoveAbandoned(true); > this.datasource.getPoolProperties().setRemoveAbandonedTimeout(1); > Connection con = datasource.getConnection(); > - long start = System.currentTimeMillis(); > assertEquals("Number of connections active/busy should be > 1",1,datasource.getPool().getActive()); > Thread.sleep(2000); > assertEquals("Number of connections active/busy should be > 0",0,datasource.getPool().getActive()); > @@ -56,7 +55,6 @@ > this.datasource.getPoolProperties().setRemoveAbandoned(true); > this.datasource.getPoolProperties().setRemoveAbandonedTimeout(1); > Connection con = datasource.getConnection(); > - long start = System.currentTimeMillis(); > assertEquals("Number of connections active/busy should be > 1",1,datasource.getPool().getActive()); > Thread.sleep(2000); > assertEquals("Number of connections active/busy should be > 1",1,datasource.getPool().getActive()); > @@ -75,7 +73,6 @@ > this.datasource.getPoolProperties().setRemoveAbandonedTimeout(1); > > this.datasource.getPoolProperties().setJdbcInterceptors(ResetAbandonedTimer.class.getName()); > Connection con = datasource.getConnection(); > - long start = System.currentTimeMillis(); > assertEquals("Number of connections active/busy should be > 1",1,datasource.getPool().getActive()); > for (int i=0; i<20; i++) { > Thread.sleep(200); > @@ -97,7 +94,6 @@ > this.datasource.getPoolProperties().setRemoveAbandonedTimeout(1); > Connection[] con = new Connection[size]; > con[0] = datasource.getConnection(); > - long start = System.currentTimeMillis(); > assertEquals("Number of connections active/busy should be > 1",1,datasource.getPool().getActive()); > for (int i=1; i<25; i++) { > con[i] = datasource.getConnection(); > > Modified: > tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/BorrowWaitTest.java > URL: > http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/BorrowWaitTest.java?rev=797529&r1=797528&r2=797529&view=diff > > ============================================================================== > --- > tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/BorrowWaitTest.java > (original) > +++ > tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/BorrowWaitTest.java > Fri Jul 24 15:25:17 2009 > @@ -32,10 +32,10 @@ > 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; > > Modified: > tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultTestCase.java > URL: > http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultTestCase.java?rev=797529&r1=797528&r2=797529&view=diff > > ============================================================================== > --- > tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultTestCase.java > (original) > +++ > tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultTestCase.java > Fri Jul 24 15:25:17 2009 > @@ -52,6 +52,7 @@ > public org.apache.tomcat.jdbc.pool.DataSource createDefaultDataSource() { > org.apache.tomcat.jdbc.pool.DataSource datasource = null; > PoolConfiguration p = new DefaultProperties(); > + p.setFairQueue(false); > p.setJmxEnabled(false); > p.setTestWhileIdle(false); > p.setTestOnBorrow(false); > @@ -77,9 +78,7 @@ > > protected void transferProperties() { > try { > - BasicDataSourceFactory factory = new BasicDataSourceFactory(); > Properties p = new Properties(); > - > for (int i=0; i< ALL_PROPERTIES.length; i++) { > String name = "get" + > Character.toUpperCase(ALL_PROPERTIES[i].charAt(0)) + > ALL_PROPERTIES[i].substring(1); > String bname = "is" + name.substring(3); > > Modified: > tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TestConcurrency.java > URL: > http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TestConcurrency.java?rev=797529&r1=797528&r2=797529&view=diff > > ============================================================================== > --- > tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TestConcurrency.java > (original) > +++ > tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TestConcurrency.java > Fri Jul 24 15:25:17 2009 > @@ -31,11 +31,13 @@ > ds.getPoolProperties().setTestWhileIdle(true); > ds.getPoolProperties().setMinEvictableIdleTimeMillis(750); > ds.getPoolProperties().setTimeBetweenEvictionRunsMillis(25); > + ds.setFairQueue(true); > } > > @Override > protected void tearDown() throws Exception { > Driver.reset(); > + ds.close(true); > super.tearDown(); > } > > @@ -92,8 +94,8 @@ > public void testBrutal() throws Exception { > ds.getPoolProperties().setRemoveAbandoned(false); > ds.getPoolProperties().setRemoveAbandonedTimeout(1); > - ds.getPoolProperties().setMinEvictableIdleTimeMillis(10); > - ds.getPoolProperties().setTimeBetweenEvictionRunsMillis(-1); > + ds.getPoolProperties().setMinEvictableIdleTimeMillis(100); > + ds.getPoolProperties().setTimeBetweenEvictionRunsMillis(10); > ds.getConnection().close(); > final int iter = 100000 * 10; > final AtomicInteger loopcount = new AtomicInteger(0); > @@ -119,7 +121,7 @@ > } > try { > while (loopcount.get()<iter) { > - //assertEquals("Size comparison:",10, > ds.getPool().getSize()); > + assertTrue("Size comparison(less than > 11):",ds.getPool().getSize()<=10);
I think you need to change testSimple() in the same way - either that, or wait a short while after starting the threads to ensure that they have all grabbed their connections. > ds.getPool().testAllIdle(); > ds.getPool().checkAbandoned(); > ds.getPool().checkIdle(); > @@ -137,8 +139,56 @@ > assertEquals("Idle comparison:",10, ds.getPool().getIdle()); > assertEquals("Used comparison:",0, ds.getPool().getActive()); > assertEquals("Connect count",10,Driver.connectCount.get()); > - > } > > + public void testBrutalNonFair() throws Exception { > + ds.getPoolProperties().setRemoveAbandoned(false); > + ds.getPoolProperties().setRemoveAbandonedTimeout(1); > + ds.getPoolProperties().setMinEvictableIdleTimeMillis(100); > + ds.getPoolProperties().setTimeBetweenEvictionRunsMillis(10); > + ds.getConnection().close(); > + final int iter = 100000 * 10; > + final AtomicInteger loopcount = new AtomicInteger(0); > + final Runnable run = new Runnable() { > + public void run() { > + try { > + while (loopcount.incrementAndGet() < iter) { > + Connection con = ds.getConnection(); > + con.close(); > + } > + }catch (Exception x) { > + loopcount.set(iter); //stops the test > + x.printStackTrace(); > + } > + } > + }; > + Thread[] threads = new Thread[20]; > + for (int i=0; i<threads.length; i++) { > + threads[i] = new Thread(run); > + } > + for (int i=0; i<threads.length; i++) { > + threads[i].start(); > + } > + try { > + while (loopcount.get()<iter) { > + assertTrue("Size comparison(less than > 11):",ds.getPool().getSize()<=10); > + ds.getPool().testAllIdle(); > + ds.getPool().checkAbandoned(); > + ds.getPool().checkIdle(); > + } > + }catch (Exception x) { > + loopcount.set(iter); //stops the test > + x.printStackTrace(); > + } > + for (int i=0; i<threads.length; i++) { > + threads[i].join(); > + } > + System.out.println("Connect count:"+Driver.connectCount.get()); > + System.out.println("DisConnect > count:"+Driver.disconnectCount.get()); > + assertEquals("Size comparison:",10, ds.getPool().getSize()); > + assertEquals("Idle comparison:",10, ds.getPool().getIdle()); > + assertEquals("Used comparison:",0, ds.getPool().getActive()); > + assertEquals("Connect count",10,Driver.connectCount.get()); > + } > > } > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org > For additional commands, e-mail: dev-h...@tomcat.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org