Java Code Examples for org.apache.tomcat.jdbc.test.driver.Driver

The following examples show how to use org.apache.tomcat.jdbc.test.driver.Driver. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Tomcat8-Source-Read   Source File: TestConcurrency.java    License: MIT License 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    ds = createDefaultDataSource();
    ds.getPoolProperties().setDriverClassName(Driver.class.getName());
    ds.getPoolProperties().setUrl(Driver.url);
    ds.getPoolProperties().setInitialSize(0);
    ds.getPoolProperties().setMaxIdle(0);
    ds.getPoolProperties().setMinIdle(0);
    ds.getPoolProperties().setMaxActive(10);
    ds.getPoolProperties().setRemoveAbandoned(true);
    ds.getPoolProperties().setLogAbandoned(true);
    ds.getPoolProperties().setTestWhileIdle(true);
    ds.getPoolProperties().setMinEvictableIdleTimeMillis(750);
    ds.getPoolProperties().setTimeBetweenEvictionRunsMillis(25);
    ds.setFairQueue(true);
}
 
Example 2
Source Project: Tomcat8-Source-Read   Source File: ConnectCountTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testDBCPThreads20Connections10() throws Exception {
    System.out.println("[testDBCPThreads20Connections10] Starting fairness - DBCP");
    this.threadcount = 20;
    this.transferProperties();
    this.tDatasource.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-dbcp-"+i);
        threads[i].d = this.tDatasource;

    }
    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,"testDBCPThreads20Connections10",Driver.connectCount.get(),10);
    System.out.println("Test completed in: " + delta + "ms.");
}
 
Example 3
Source Project: Tomcat8-Source-Read   Source File: ConnectCountTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testPoolThreads20Connections10() throws Exception {
    System.out.println("[testPoolThreads20Connections10] Starting fairness - Tomcat JDBC - Non Fair");
    this.threadcount = 20;
    this.transferProperties();
    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.datasource;

    }
    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,"testPoolThreads20Connections10",Driver.connectCount.get(),10);
    System.out.println("Test completed in: " + delta + "ms.");
}
 
Example 4
Source Project: Tomcat8-Source-Read   Source File: JmxPasswordTest.java    License: MIT License 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    this.datasource.setDriverClassName(Driver.class.getName());
    this.datasource.setUrl("jdbc:tomcat:test");
    this.datasource.setPassword(password);
    this.datasource.setUsername(username);
    this.datasource.getConnection().close();
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    String domain = "tomcat.jdbc";
    Hashtable<String,String> properties = new Hashtable<>();
    properties.put("type", "ConnectionPool");
    properties.put("class", this.getClass().getName());
    oname = new ObjectName(domain,properties);
    ConnectionPool pool = datasource.createPool();
    org.apache.tomcat.jdbc.pool.jmx.ConnectionPool jmxPool = new org.apache.tomcat.jdbc.pool.jmx.ConnectionPool(pool);
    mbs.registerMBean(jmxPool, oname);

}
 
Example 5
Source Project: Tomcat8-Source-Read   Source File: TestSizePreservation.java    License: MIT License 6 votes vote down vote up
private void initSimplePoolProperties() {
    PoolConfiguration p = new DefaultProperties();
    ds = new org.apache.tomcat.jdbc.pool.DataSource();
    ds.setPoolProperties(p);

    ds.getPoolProperties().setDriverClassName(Driver.class.getName());
    ds.getPoolProperties().setUrl(Driver.url);
    ds.getPoolProperties().setFairQueue(true);
    ds.getPoolProperties().setJmxEnabled(false);
    ds.getPoolProperties().setTestWhileIdle(true);
    ds.getPoolProperties().setTestOnBorrow(false);
    ds.getPoolProperties().setTestOnReturn(false);
    ds.getPoolProperties().setValidationInterval(30000);
    ds.getPoolProperties().setTimeBetweenEvictionRunsMillis(30000);
    ds.getPoolProperties().setInitialSize(100);
    ds.getPoolProperties().setMaxActive(100);
    ds.getPoolProperties().setMinIdle(0);
    ds.getPoolProperties().setMaxIdle(0);
    ds.getPoolProperties().setMaxWait(10000);
    ds.getPoolProperties().setRemoveAbandonedTimeout(10);
    ds.getPoolProperties().setMinEvictableIdleTimeMillis(10000);
    ds.getPoolProperties().setLogAbandoned(false);
    ds.getPoolProperties().setRemoveAbandoned(false);
    ds.getPoolProperties().setUseLock(true);
}
 
Example 6
Source Project: Tomcat8-Source-Read   Source File: TestQueryTimeoutInterceptor.java    License: MIT License 6 votes vote down vote up
@Test
public void testTimeout() throws Exception {
    int timeout = 10;
    int withoutuser =10;
    int withuser = withoutuser;
    this.datasource.setMaxActive(withuser+withoutuser);
    this.datasource.setJdbcInterceptors(QueryTimeoutInterceptor.class.getName()+"(queryTimeout="+timeout+")");
    this.datasource.setDriverClassName(Driver.class.getName());
    this.datasource.setUrl("jdbc:tomcat:test");
    Connection con = this.datasource.getConnection();
    Statement st = con.createStatement();
    Assert.assertEquals(st.getClass().getName(),timeout,st.getQueryTimeout());
    st.close();
    st = con.prepareStatement("");
    Assert.assertEquals(st.getClass().getName(),timeout,st.getQueryTimeout());
    st.close();
    st = con.prepareCall("");
    Assert.assertEquals(st.getClass().getName(),timeout,st.getQueryTimeout());
    st.close();
    con.close();
}
 
Example 7
Source Project: Tomcat7.0.67   Source File: TestConcurrency.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    ds = createDefaultDataSource();
    ds.getPoolProperties().setDriverClassName(Driver.class.getName());
    ds.getPoolProperties().setUrl(Driver.url);
    ds.getPoolProperties().setInitialSize(0);
    ds.getPoolProperties().setMaxIdle(0);
    ds.getPoolProperties().setMinIdle(0);
    ds.getPoolProperties().setMaxActive(10);
    ds.getPoolProperties().setRemoveAbandoned(true);
    ds.getPoolProperties().setLogAbandoned(true);
    ds.getPoolProperties().setTestWhileIdle(true);
    ds.getPoolProperties().setMinEvictableIdleTimeMillis(750);
    ds.getPoolProperties().setTimeBetweenEvictionRunsMillis(25);
    ds.setFairQueue(true);
}
 
Example 8
Source Project: Tomcat7.0.67   Source File: ConnectCountTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDBCPThreads20Connections10() throws Exception {
    System.out.println("[testDBCPThreads20Connections10] Starting fairness - DBCP");
    this.threadcount = 20;
    this.transferProperties();
    this.tDatasource.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-dbcp-"+i);
        threads[i].d = this.tDatasource;

    }
    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,"testDBCPThreads20Connections10",Driver.connectCount.get(),10);
    System.out.println("Test completed in: " + delta + "ms.");
}
 
Example 9
Source Project: Tomcat7.0.67   Source File: ConnectCountTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPoolThreads20Connections10() throws Exception {
    System.out.println("[testPoolThreads20Connections10] Starting fairness - Tomcat JDBC - Non Fair");
    this.threadcount = 20;
    this.transferProperties();
    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.datasource;

    }
    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,"testPoolThreads20Connections10",Driver.connectCount.get(),10);
    System.out.println("Test completed in: " + delta + "ms.");
}
 
Example 10
Source Project: Tomcat7.0.67   Source File: JmxPasswordTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    this.datasource.setDriverClassName(Driver.class.getName());
    this.datasource.setUrl("jdbc:tomcat:test");
    this.datasource.setPassword(password);
    this.datasource.setUsername(username);
    this.datasource.getConnection().close();
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    String domain = "tomcat.jdbc";
    Hashtable<String,String> properties = new Hashtable<String,String>();
    properties.put("type", "ConnectionPool");
    properties.put("class", this.getClass().getName());
    oname = new ObjectName(domain,properties);
    ConnectionPool pool = datasource.createPool();
    org.apache.tomcat.jdbc.pool.jmx.ConnectionPool jmxPool = new org.apache.tomcat.jdbc.pool.jmx.ConnectionPool(pool);
    mbs.registerMBean(jmxPool, oname);

}
 
Example 11
Source Project: Tomcat7.0.67   Source File: TestSizePreservation.java    License: Apache License 2.0 6 votes vote down vote up
private void initSimplePoolProperties() {
    PoolConfiguration p = new DefaultProperties();
    ds = new org.apache.tomcat.jdbc.pool.DataSource();
    ds.setPoolProperties(p);

    ds.getPoolProperties().setDriverClassName(Driver.class.getName());
    ds.getPoolProperties().setUrl(Driver.url);
    ds.getPoolProperties().setFairQueue(true);
    ds.getPoolProperties().setJmxEnabled(false);
    ds.getPoolProperties().setTestWhileIdle(true);
    ds.getPoolProperties().setTestOnBorrow(false);
    ds.getPoolProperties().setTestOnReturn(false);
    ds.getPoolProperties().setValidationInterval(30000);
    ds.getPoolProperties().setTimeBetweenEvictionRunsMillis(30000);
    ds.getPoolProperties().setInitialSize(100);
    ds.getPoolProperties().setMaxActive(100);
    ds.getPoolProperties().setMinIdle(0);
    ds.getPoolProperties().setMaxIdle(0);
    ds.getPoolProperties().setMaxWait(10000);
    ds.getPoolProperties().setRemoveAbandonedTimeout(10);
    ds.getPoolProperties().setMinEvictableIdleTimeMillis(10000);
    ds.getPoolProperties().setLogAbandoned(false);
    ds.getPoolProperties().setRemoveAbandoned(false);
    ds.getPoolProperties().setUseLock(true);
}
 
Example 12
Source Project: Tomcat7.0.67   Source File: TestQueryTimeoutInterceptor.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTimeout() throws Exception {
    int timeout = 10;
    int withoutuser =10;
    int withuser = withoutuser;
    this.datasource.setMaxActive(withuser+withoutuser);
    this.datasource.setJdbcInterceptors(QueryTimeoutInterceptor.class.getName()+"(queryTimeout="+timeout+")");
    this.datasource.setDriverClassName(Driver.class.getName());
    this.datasource.setUrl("jdbc:tomcat:test");
    Connection con = this.datasource.getConnection();
    Statement st = con.createStatement();
    Assert.assertEquals(st.getClass().getName(),timeout,st.getQueryTimeout());
    st.close();
    st = con.prepareStatement("");
    Assert.assertEquals(st.getClass().getName(),timeout,st.getQueryTimeout());
    st.close();
    st = con.prepareCall("");
    Assert.assertEquals(st.getClass().getName(),timeout,st.getQueryTimeout());
    st.close();
    con.close();
}
 
Example 13
Source Project: tomcatsrc   Source File: TestConcurrency.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    ds = createDefaultDataSource();
    ds.getPoolProperties().setDriverClassName(Driver.class.getName());
    ds.getPoolProperties().setUrl(Driver.url);
    ds.getPoolProperties().setInitialSize(0);
    ds.getPoolProperties().setMaxIdle(0);
    ds.getPoolProperties().setMinIdle(0);
    ds.getPoolProperties().setMaxActive(10);
    ds.getPoolProperties().setRemoveAbandoned(true);
    ds.getPoolProperties().setLogAbandoned(true);
    ds.getPoolProperties().setTestWhileIdle(true);
    ds.getPoolProperties().setMinEvictableIdleTimeMillis(750);
    ds.getPoolProperties().setTimeBetweenEvictionRunsMillis(25);
    ds.setFairQueue(true);
}
 
Example 14
Source Project: tomcatsrc   Source File: ConnectCountTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDBCPThreads20Connections10() throws Exception {
    System.out.println("[testDBCPThreads20Connections10] Starting fairness - DBCP");
    this.threadcount = 20;
    this.transferProperties();
    this.tDatasource.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-dbcp-"+i);
        threads[i].d = this.tDatasource;

    }
    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,"testDBCPThreads20Connections10",Driver.connectCount.get(),10);
    System.out.println("Test completed in: " + delta + "ms.");
}
 
Example 15
Source Project: tomcatsrc   Source File: ConnectCountTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPoolThreads20Connections10() throws Exception {
    System.out.println("[testPoolThreads20Connections10] Starting fairness - Tomcat JDBC - Non Fair");
    this.threadcount = 20;
    this.transferProperties();
    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.datasource;

    }
    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,"testPoolThreads20Connections10",Driver.connectCount.get(),10);
    System.out.println("Test completed in: " + delta + "ms.");
}
 
Example 16
Source Project: tomcatsrc   Source File: JmxPasswordTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    this.datasource.setDriverClassName(Driver.class.getName());
    this.datasource.setUrl("jdbc:tomcat:test");
    this.datasource.setPassword(password);
    this.datasource.setUsername(username);
    this.datasource.getConnection().close();
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    String domain = "tomcat.jdbc";
    Hashtable<String,String> properties = new Hashtable<String,String>();
    properties.put("type", "ConnectionPool");
    properties.put("class", this.getClass().getName());
    oname = new ObjectName(domain,properties);
    ConnectionPool pool = datasource.createPool();
    org.apache.tomcat.jdbc.pool.jmx.ConnectionPool jmxPool = new org.apache.tomcat.jdbc.pool.jmx.ConnectionPool(pool);
    mbs.registerMBean(jmxPool, oname);

}
 
Example 17
Source Project: tomcatsrc   Source File: TestSizePreservation.java    License: Apache License 2.0 6 votes vote down vote up
private void initSimplePoolProperties() {
    PoolConfiguration p = new DefaultProperties();
    ds = new org.apache.tomcat.jdbc.pool.DataSource();
    ds.setPoolProperties(p);

    ds.getPoolProperties().setDriverClassName(Driver.class.getName());
    ds.getPoolProperties().setUrl(Driver.url);
    ds.getPoolProperties().setFairQueue(true);
    ds.getPoolProperties().setJmxEnabled(false);
    ds.getPoolProperties().setTestWhileIdle(true);
    ds.getPoolProperties().setTestOnBorrow(false);
    ds.getPoolProperties().setTestOnReturn(false);
    ds.getPoolProperties().setValidationInterval(30000);
    ds.getPoolProperties().setTimeBetweenEvictionRunsMillis(30000);
    ds.getPoolProperties().setInitialSize(100);
    ds.getPoolProperties().setMaxActive(100);
    ds.getPoolProperties().setMinIdle(0);
    ds.getPoolProperties().setMaxIdle(0);
    ds.getPoolProperties().setMaxWait(10000);
    ds.getPoolProperties().setRemoveAbandonedTimeout(10);
    ds.getPoolProperties().setMinEvictableIdleTimeMillis(10000);
    ds.getPoolProperties().setLogAbandoned(false);
    ds.getPoolProperties().setRemoveAbandoned(false);
    ds.getPoolProperties().setUseLock(true);
}
 
Example 18
Source Project: tomcatsrc   Source File: TestQueryTimeoutInterceptor.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTimeout() throws Exception {
    int timeout = 10;
    int withoutuser =10;
    int withuser = withoutuser;
    this.datasource.setMaxActive(withuser+withoutuser);
    this.datasource.setJdbcInterceptors(QueryTimeoutInterceptor.class.getName()+"(queryTimeout="+timeout+")");
    this.datasource.setDriverClassName(Driver.class.getName());
    this.datasource.setUrl("jdbc:tomcat:test");
    Connection con = this.datasource.getConnection();
    Statement st = con.createStatement();
    Assert.assertEquals(st.getClass().getName(),timeout,st.getQueryTimeout());
    st.close();
    st = con.prepareStatement("");
    Assert.assertEquals(st.getClass().getName(),timeout,st.getQueryTimeout());
    st.close();
    st = con.prepareCall("");
    Assert.assertEquals(st.getClass().getName(),timeout,st.getQueryTimeout());
    st.close();
    con.close();
}
 
Example 19
Source Project: Tomcat8-Source-Read   Source File: PoolPurgeTest.java    License: MIT License 5 votes vote down vote up
@Override
public org.apache.tomcat.jdbc.pool.DataSource createDefaultDataSource() {
    // TODO Auto-generated method stub
    org.apache.tomcat.jdbc.pool.DataSource ds = super.createDefaultDataSource();
    ds.getPoolProperties().setDriverClassName(Driver.class.getName());
    ds.getPoolProperties().setUrl(Driver.url);
    ds.getPoolProperties().setInitialSize(expectedSize);
    ds.getPoolProperties().setMaxIdle(expectedSize);
    ds.getPoolProperties().setMinIdle(expectedSize);
    ds.getPoolProperties().setMaxActive(expectedSize);
    ds.getPoolProperties().setTimeBetweenEvictionRunsMillis(30000);
    ds.getPoolProperties().setMaxAge(Long.MAX_VALUE);
    return ds;
}
 
Example 20
Source Project: Tomcat8-Source-Read   Source File: AlternateUsernameTest.java    License: MIT License 5 votes vote down vote up
private void testUsername(boolean allowUsernameChange) throws Exception {
    long start = System.currentTimeMillis();
    int withoutuser =10;
    int withuser = withoutuser;
    this.datasource.setMaxActive(withuser+withoutuser);
    this.datasource.setDriverClassName(Driver.class.getName());
    this.datasource.setUrl("jdbc:tomcat:test");
    this.datasource.setAlternateUsernameAllowed(allowUsernameChange);
    this.datasource.getConnection().close();

    TestRunner[] runners = new TestRunner[withuser+withoutuser];
    for (int i=0; i<withuser; i++) {
        TestRunner with = new TestRunner("foo","bar",datasource.getPoolProperties().getUsername(),datasource.getPoolProperties().getPassword());
        TestRunner without = new TestRunner(null,null,datasource.getPoolProperties().getUsername(),datasource.getPoolProperties().getPassword());
        runners[i] = allowUsernameChange?with:without;
        runners[i+withuser] = without;
    }
    ExecutorService svc = Executors.newFixedThreadPool(withuser+withoutuser);
    List<Future<TestResult>> results =  svc.invokeAll(Arrays.asList(runners));
    int failures = 0;
    int total = 0;
    for (int i=0; i<withuser; i++) {
        failures += results.get(i).get().failures;
        total+=results.get(i).get().iterations;
        failures += results.get(i+withuser).get().failures;
        total+=results.get(i+withuser).get().iterations;
    }
    long stop = System.currentTimeMillis();
    Assert.assertEquals("Nr of failures was:"+failures,0, failures);
    svc.shutdownNow();
    this.datasource.close();
    System.out.println("Nr of connect() calls:"+Driver.connectCount.get());
    System.out.println("Nr of disconnect() calls:"+Driver.disconnectCount.get());
    System.out.println("Nr of iterations:"+total+" over "+(stop-start)+ " ms.");

}
 
Example 21
Source Project: Tomcat8-Source-Read   Source File: TestConcurrency.java    License: MIT License 5 votes vote down vote up
@Override
@After
public void tearDown() throws Exception {
    ds.close(true);
    Driver.reset();
    super.tearDown();
}
 
Example 22
Source Project: Tomcat8-Source-Read   Source File: ConnectCountTest.java    License: MIT License 5 votes vote down vote up
@Override
public org.apache.tomcat.jdbc.pool.DataSource createDefaultDataSource() {
    // TODO Auto-generated method stub
    org.apache.tomcat.jdbc.pool.DataSource ds = super.createDefaultDataSource();
    ds.getPoolProperties().setDriverClassName(Driver.class.getName());
    ds.getPoolProperties().setUrl(Driver.url);
    ds.getPoolProperties().setInitialSize(0);
    ds.getPoolProperties().setMaxIdle(10);
    ds.getPoolProperties().setMinIdle(10);
    ds.getPoolProperties().setMaxActive(10);
    return ds;
}
 
Example 23
Source Project: Tomcat8-Source-Read   Source File: ConnectCountTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testPoolThreads20Connections10Fair() throws Exception {
    System.out.println("[testPoolThreads20Connections10Fair] Starting fairness - Tomcat JDBC - Fair");
    this.threadcount = 20;
    this.datasource.getPoolProperties().setFairQueue(true);
    this.transferProperties();
    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.datasource;

    }
    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,"testPoolThreads20Connections10Fair",Driver.connectCount.get(),10);
    System.out.println("Test completed in: " + delta + "ms.");
}
 
Example 24
Source Project: Tomcat8-Source-Read   Source File: ConnectCountTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testPoolThreads20Connections10FairAsync() throws Exception {
    System.out.println("[testPoolThreads20Connections10FairAsync] Starting fairness - Tomcat JDBC - Fair - Async");
    this.threadcount = 20;
    this.datasource.getPoolProperties().setFairQueue(true);
    this.datasource.getPoolProperties().setInitialSize(this.datasource.getPoolProperties().getMaxActive());
    this.transferProperties();
    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].async = true;
        threads[i].d = this.datasource;

    }
    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,"testPoolThreads20Connections10FairAsync",Driver.connectCount.get(),10);
    System.out.println("Test completed in: " + delta + "ms.");
}
 
Example 25
Source Project: Tomcat8-Source-Read   Source File: EqualsHashCodeTest.java    License: MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    this.datasource.setDriverClassName(Driver.class.getName());
    this.datasource.setUrl("jdbc:tomcat:test");
    this.datasource.setPassword(password);
    this.datasource.setMaxActive(1);
    this.datasource.setMinIdle(datasource.getMaxActive());
    this.datasource.setMaxIdle(datasource.getMaxActive());
    this.datasource.setUsername(username);
    this.datasource.getConnection().close();
    datasource.createPool();
}
 
Example 26
Source Project: Tomcat8-Source-Read   Source File: TestSizePreservation.java    License: MIT License 5 votes vote down vote up
@Test
public void testSimple() throws Exception {
    initSimplePoolProperties();
    common();
    ds.close(true);
    Driver.reset();
}
 
Example 27
Source Project: Tomcat8-Source-Read   Source File: TestSizePreservation.java    License: MIT License 5 votes vote down vote up
@Test
public void testEvicting() throws Exception {
    initEvictingPool();
    common();
    ds.close(true);
    Driver.reset();
}
 
Example 28
Source Project: Tomcat8-Source-Read   Source File: MultipleCloseTest.java    License: MIT License 5 votes vote down vote up
@Override
public org.apache.tomcat.jdbc.pool.DataSource createDefaultDataSource() {
    org.apache.tomcat.jdbc.pool.DataSource ds = super.createDefaultDataSource();
    ds.getPoolProperties().setDriverClassName(Driver.class.getName());
    ds.getPoolProperties().setUrl(Driver.url);
    ds.getPoolProperties().setInitialSize(0);
    ds.getPoolProperties().setMaxIdle(1);
    ds.getPoolProperties().setMinIdle(1);
    ds.getPoolProperties().setMaxActive(1);
    ds.getPoolProperties().setUseDisposableConnectionFacade(true);
    return ds;
}
 
Example 29
Source Project: Tomcat7.0.67   Source File: PoolPurgeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public org.apache.tomcat.jdbc.pool.DataSource createDefaultDataSource() {
    // TODO Auto-generated method stub
    org.apache.tomcat.jdbc.pool.DataSource ds = super.createDefaultDataSource();
    ds.getPoolProperties().setDriverClassName(Driver.class.getName());
    ds.getPoolProperties().setUrl(Driver.url);
    ds.getPoolProperties().setInitialSize(expectedSize);
    ds.getPoolProperties().setMaxIdle(expectedSize);
    ds.getPoolProperties().setMinIdle(expectedSize);
    ds.getPoolProperties().setMaxActive(expectedSize);
    ds.getPoolProperties().setTimeBetweenEvictionRunsMillis(30000);
    ds.getPoolProperties().setMaxAge(Long.MAX_VALUE);
    return ds;
}
 
Example 30
Source Project: Tomcat7.0.67   Source File: AlternateUsernameTest.java    License: Apache License 2.0 5 votes vote down vote up
private void testUsername(boolean allowUsernameChange) throws Exception {
    long start = System.currentTimeMillis();
    int withoutuser =10;
    int withuser = withoutuser;
    this.datasource.setMaxActive(withuser+withoutuser);
    this.datasource.setDriverClassName(Driver.class.getName());
    this.datasource.setUrl("jdbc:tomcat:test");
    this.datasource.setAlternateUsernameAllowed(allowUsernameChange);
    this.datasource.getConnection().close();

    TestRunner[] runners = new TestRunner[withuser+withoutuser];
    for (int i=0; i<withuser; i++) {
        TestRunner with = new TestRunner("foo","bar",datasource.getPoolProperties().getUsername(),datasource.getPoolProperties().getPassword());
        TestRunner without = new TestRunner(null,null,datasource.getPoolProperties().getUsername(),datasource.getPoolProperties().getPassword());
        runners[i] = allowUsernameChange?with:without;
        runners[i+withuser] = without;
    }
    ExecutorService svc = Executors.newFixedThreadPool(withuser+withoutuser);
    List<Future<TestResult>> results =  svc.invokeAll(Arrays.asList(runners));
    int failures = 0;
    int total = 0;
    for (int i=0; i<withuser; i++) {
        failures += results.get(i).get().failures;
        total+=results.get(i).get().iterations;
        failures += results.get(i+withuser).get().failures;
        total+=results.get(i+withuser).get().iterations;
    }
    long stop = System.currentTimeMillis();
    Assert.assertEquals("Nr of failures was:"+failures,0, failures);
    svc.shutdownNow();
    this.datasource.close();
    System.out.println("Nr of connect() calls:"+Driver.connectCount.get());
    System.out.println("Nr of disconnect() calls:"+Driver.disconnectCount.get());
    System.out.println("Nr of iterations:"+total+" over "+(stop-start)+ " ms.");

}