use of com.adaptris.core.jdbc.JdbcPooledConnection in project interlok by adaptris.
the class FirstRowMetadataTranslatorTest method testService_PooledConnection.
@Test
public void testService_PooledConnection() throws Exception {
int maxServices = 5;
final int iterations = 5;
int poolsize = maxServices - 1;
String name = Thread.currentThread().getName();
Thread.currentThread().setName(getName());
createDatabase();
List<AdapterTypeVersion> dbItems = generate(10);
final AdapterTypeVersion entry = dbItems.get(0);
populateDatabase(dbItems, false);
List<Service> serviceList = new ArrayList<Service>();
JdbcPooledConnection conn = PooledConnectionHelper.createPooledConnection(PROPERTIES.getProperty(JDBC_QUERYSERVICE_DRIVER), PROPERTIES.getProperty(JDBC_QUERYSERVICE_URL), poolsize);
try {
for (int i = 0; i < maxServices; i++) {
JdbcDataQueryService service = createMetadataService(false);
service.setConnection(conn);
serviceList.add(service);
start(service);
}
PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() {
@Override
public AdaptrisMessage createMsgForPooledConnectionTest() throws Exception {
return createMessage(entry);
}
});
assertEquals(0, conn.currentBusyConnectionCount());
assertEquals(poolsize, conn.currentIdleConnectionCount());
assertEquals(poolsize, conn.currentConnectionCount());
} finally {
stop(serviceList.toArray(new ComponentLifecycle[0]));
Thread.currentThread().setName(name);
}
}
use of com.adaptris.core.jdbc.JdbcPooledConnection in project interlok by adaptris.
the class JdbcBatchingDataCaptureServiceTest method createPooledJdbcConnection.
@Override
protected JdbcPooledConnection createPooledJdbcConnection(int poolsize) {
JdbcPooledConnection conn = PooledConnectionHelper.createPooledConnection(PROPERTIES.getProperty(JDBC_CAPTURE_SERVICE_DRIVER), PROPERTIES.getProperty(JDBC_CAPTURE_SERVICE_URL), poolsize);
conn.setAutoCommit(false);
return conn;
}
use of com.adaptris.core.jdbc.JdbcPooledConnection in project interlok by adaptris.
the class JndiHelperTest method testBindJdbcConnection.
@Test
public void testBindJdbcConnection() throws Exception {
JdbcPooledConnection connection = new JdbcPooledConnection();
connection.setConnectUrl("jdbc:derby:memory:" + new GuidGenerator().safeUUID() + ";create=true");
connection.setDriverImp("org.apache.derby.jdbc.EmbeddedDriver");
connection.setMinimumPoolSize(1);
connection.setAcquireIncrement(1);
connection.setMaximumPoolSize(7);
connection.setUniqueId(getName());
InitialContext initialContext = new InitialContext(env);
try {
JndiHelper.bind(initialContext, connection, true);
JdbcPooledConnection lookedup = (JdbcPooledConnection) initialContext.lookup("adapter:comp/env/" + getName());
assertEquals(getName(), lookedup.getUniqueId());
assertNotNull(initialContext.lookup("adapter:comp/env/jdbc/" + getName()));
} finally {
JndiHelper.unbindQuietly(initialContext, connection, true);
}
try {
JndiHelper.bind(initialContext, connection, false);
JdbcPooledConnection lookedup = (JdbcPooledConnection) initialContext.lookup("adapter:comp/env/" + getName());
assertEquals(getName(), lookedup.getUniqueId());
assertNotNull(initialContext.lookup("adapter:comp/env/jdbc/" + getName()));
} finally {
JndiHelper.unbindQuietly(initialContext, connection, false);
}
}
use of com.adaptris.core.jdbc.JdbcPooledConnection in project interlok by adaptris.
the class JdbcRawDataCaptureServiceTest method testService_PooledConnection.
@Test
public void testService_PooledConnection() throws Exception {
int maxServices = 5;
final int iterations = 5;
int poolsize = maxServices - 1;
createDatabase();
List<Service> serviceList = new ArrayList<>();
String name = Thread.currentThread().getName();
Thread.currentThread().setName(getName());
JdbcPooledConnection conn = PooledConnectionHelper.createPooledConnection(PROPERTIES.getProperty(JDBC_CAPTURE_SERVICE_DRIVER), PROPERTIES.getProperty(JDBC_CAPTURE_SERVICE_URL), poolsize);
try {
for (int i = 0; i < maxServices; i++) {
JdbcRawDataCaptureService service = createService(false);
service.setConnection(conn);
serviceList.add(service);
start(service);
}
PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() {
@Override
public AdaptrisMessage createMsgForPooledConnectionTest() throws Exception {
return createMessage();
}
});
assertEquals(0, conn.currentBusyConnectionCount());
assertEquals(poolsize, conn.currentIdleConnectionCount());
assertEquals(poolsize, conn.currentConnectionCount());
doBasicCaptureAsserts(iterations * maxServices);
} finally {
stop(serviceList.toArray(new ComponentLifecycle[0]));
Thread.currentThread().setName(name);
}
}
Aggregations