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

The following examples show how to use org.apache.tomcat.jdbc.test.driver.Driver. 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 File: ConnectCountTest.java    From tomcatsrc with 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 #2
Source File: TestSizePreservation.java    From Tomcat7.0.67 with 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 #3
Source File: JmxPasswordTest.java    From Tomcat7.0.67 with 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 #4
Source File: ConnectCountTest.java    From Tomcat7.0.67 with 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 #5
Source File: ConnectCountTest.java    From Tomcat7.0.67 with 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 #6
Source File: TestQueryTimeoutInterceptor.java    From Tomcat7.0.67 with 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 #7
Source File: TestConcurrency.java    From Tomcat7.0.67 with 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 File: TestConcurrency.java    From tomcatsrc with 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 #9
Source File: TestQueryTimeoutInterceptor.java    From Tomcat8-Source-Read with 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 #10
Source File: ConnectCountTest.java    From tomcatsrc with 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 #11
Source File: TestSizePreservation.java    From Tomcat8-Source-Read with 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 #12
Source File: TestQueryTimeoutInterceptor.java    From tomcatsrc with 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 File: JmxPasswordTest.java    From tomcatsrc with 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 #14
Source File: TestConcurrency.java    From Tomcat8-Source-Read with 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 #15
Source File: ConnectCountTest.java    From Tomcat8-Source-Read with 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 #16
Source File: ConnectCountTest.java    From Tomcat8-Source-Read with 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 #17
Source File: JmxPasswordTest.java    From Tomcat8-Source-Read with 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 #18
Source File: TestSizePreservation.java    From tomcatsrc with 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 #19
Source File: AlternateUsernameTest.java    From tomcatsrc with 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.");

}
 
Example #20
Source File: MultipleCloseTest.java    From tomcatsrc with Apache License 2.0 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 #21
Source File: TestSizePreservation.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimple() throws Exception {
    initSimplePoolProperties();
    common();
    ds.close(true);
    Driver.reset();
}
 
Example #22
Source File: TestSizePreservation.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testEvicting() throws Exception {
    initEvictingPool();
    common();
    ds.close(true);
    Driver.reset();
}
 
Example #23
Source File: TestSizePreservation.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testEvicting() throws Exception {
    initEvictingPool();
    common();
    ds.close(true);
    Driver.reset();
}
 
Example #24
Source File: MultipleCloseTest.java    From Tomcat7.0.67 with Apache License 2.0 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 #25
Source File: TestSizePreservation.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimple() throws Exception {
    initSimplePoolProperties();
    common();
    ds.close(true);
    Driver.reset();
}
 
Example #26
Source File: PoolPurgeTest.java    From tomcatsrc with 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 #27
Source File: TestConcurrency.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
@After
public void tearDown() throws Exception {
    ds.close(true);
    Driver.reset();
    super.tearDown();
}
 
Example #28
Source File: ConnectCountTest.java    From tomcatsrc with 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(0);
    ds.getPoolProperties().setMaxIdle(10);
    ds.getPoolProperties().setMinIdle(10);
    ds.getPoolProperties().setMaxActive(10);
    return ds;
}
 
Example #29
Source File: ConnectCountTest.java    From Tomcat7.0.67 with Apache License 2.0 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 #30
Source File: EqualsHashCodeTest.java    From tomcatsrc with Apache License 2.0 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();
}