use of com.adaptris.core.jdbc.JdbcPooledConnection in project interlok by adaptris.
the class MetadataIdentitySequenceNumberServiceTest 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<Service>();
String name = Thread.currentThread().getName();
Thread.currentThread().setName(getName());
JdbcPooledConnection conn = PooledConnectionHelper.createPooledConnection(PROPERTIES.getProperty(JDBC_SEQUENCENUMBER_DRIVER), PROPERTIES.getProperty(JDBC_SEQUENCENUMBER_URL), poolsize);
try {
for (int i = 0; i < maxServices; i++) {
MetadataIdentitySequenceNumberService service = configureForTests(createService(), false);
service.setConnection(conn);
serviceList.add(service);
start(service);
}
PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() {
@Override
public AdaptrisMessage createMsgForPooledConnectionTest() throws Exception {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
msg.addMetadata(DEFAULT_IDENTITY_METADATA_KEY, new GuidGenerator().safeUUID());
return msg;
}
});
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 JdbcServiceListTest method testServiceList_PooledConnection.
@Test
public void testServiceList_PooledConnection() throws Exception {
int maxServices = 5;
final int iterations = 5;
int poolsize = maxServices - 1;
createDatabase();
List<Service> serviceList = new ArrayList<Service>();
String name = Thread.currentThread().getName();
Thread.currentThread().setName(getName());
JdbcPooledConnection conn = PooledConnectionHelper.createPooledConnection(PROPERTIES.getProperty(CFG_JDBC_DRIVER), PROPERTIES.getProperty(CFG_JDBC_URL), poolsize);
try {
GuidGenerator guid = new GuidGenerator();
for (int i = 0; i < maxServices; i++) {
// The Connection should never be used by the wrappedService, as it will exist in objectMetadata.
JdbcServiceList service = createServiceCollection(createSequenceNumberService(conn, guid.safeUUID()), createSequenceNumberService(conn, guid.safeUUID()));
service.setConnection(conn);
serviceList.add(service);
start(service);
}
PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() {
@Override
public AdaptrisMessage createMsgForPooledConnectionTest() throws Exception {
return AdaptrisMessageFactory.getDefaultInstance().newMessage();
}
});
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 JdbcDataCaptureServiceCase 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 = createPooledJdbcConnection(poolsize);
try {
for (int i = 0; i < maxServices; i++) {
JdbcIteratingDataCaptureServiceImpl service = createBasicService(false);
service.setConnection(conn);
serviceList.add(service);
start(service);
}
PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() {
@Override
public AdaptrisMessage createMsgForPooledConnectionTest() {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_DOCUMENT);
msg.addMetadata(METADATA_KEY, METADATA_VALUE);
return msg;
}
});
assertEquals(0, conn.currentBusyConnectionCount());
assertEquals(poolsize, conn.currentIdleConnectionCount());
assertEquals(poolsize, conn.currentConnectionCount());
doBasicCaptureAsserts(maxServices * iterations);
} 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 StaticIdentitySequenceNumberServiceTest 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<Service>();
String name = Thread.currentThread().getName();
Thread.currentThread().setName(getName());
JdbcPooledConnection conn = PooledConnectionHelper.createPooledConnection(PROPERTIES.getProperty(JDBC_SEQUENCENUMBER_DRIVER), PROPERTIES.getProperty(JDBC_SEQUENCENUMBER_URL), poolsize);
try {
for (int i = 0; i < maxServices; i++) {
StaticIdentitySequenceNumberService service = createServiceForTests(false);
service.setConnection(conn);
service.setIdentity(new GuidGenerator().safeUUID());
serviceList.add(service);
start(service);
}
PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() {
@Override
public AdaptrisMessage createMsgForPooledConnectionTest() throws Exception {
return createMessageForTests();
}
});
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 JndiHelperTest method testUnbindJdbcConnection.
@Test
public void testUnbindJdbcConnection() 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);
JndiHelper.bind(initialContext, connection, true);
JndiHelper.unbind(initialContext, connection, true);
JndiHelper.bind(initialContext, connection, false);
JndiHelper.unbind(initialContext, connection, false);
}
Aggregations