use of com.adaptris.core.Service 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);
}
}
use of com.adaptris.core.Service in project interlok by adaptris.
the class StatelessServiceWrapperTest method testService.
@Test
public void testService() throws Exception {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("ABC");
MockMessageProducer prod = new MockMessageProducer();
Service s = create(prod);
execute(s, msg);
assertEquals(ClosedState.getInstance(), prod.retrieveComponentState());
assertEquals(1, prod.getMessages().size());
assertEquals("ABC", prod.getMessages().get(0).getContent());
}
use of com.adaptris.core.Service in project interlok by adaptris.
the class ExampleServiceCase method testServiceStates.
@Test
public void testServiceStates() {
if (doStateTests()) {
Object object = retrieveObjectForCastorRoundTrip();
if (object instanceof Service) {
Service service = (Service) object;
assertEquals(service.retrieveComponentState(), ClosedState.getInstance());
try {
LifecycleHelper.init(service);
assertEquals(InitialisedState.getInstance(), service.retrieveComponentState());
try {
LifecycleHelper.start(service);
assertEquals(StartedState.getInstance(), service.retrieveComponentState());
try {
LifecycleHelper.stop(service);
assertEquals(StoppedState.getInstance(), service.retrieveComponentState());
} catch (Exception ex) {
log.warn("Not able to test stopped state for object " + service.getClass().getSimpleName());
}
try {
LifecycleHelper.close(service);
assertEquals(ClosedState.getInstance(), service.retrieveComponentState());
} catch (Exception ex) {
log.warn("Not able to test closed state for object " + service.getClass().getSimpleName());
}
} catch (Exception ex) {
log.warn("Not able to test started state for object " + service.getClass().getSimpleName());
} catch (LinkageError ex) {
log.warn("Not able to test started state for object " + service.getClass().getSimpleName());
}
} catch (Exception ex) {
log.warn("Not able to test initialized state for object " + service.getClass().getSimpleName());
} catch (LinkageError ex) {
log.warn("Not able to test initialized state for object " + service.getClass().getSimpleName());
}
}
}
}
use of com.adaptris.core.Service in project interlok by adaptris.
the class ServiceCollectionCase method testIterator.
@Test
public void testIterator() throws Exception {
ServiceCollectionImp sc = createServiceCollection();
sc.addAll(Arrays.asList(new Service[] { new NullService(UUID.randomUUID().toString()), new NullService(UUID.randomUUID().toString()) }));
assertEquals(2, sc.size());
assertNotNull(sc.iterator());
int count = 0;
for (Iterator<Service> i = sc.iterator(); i.hasNext(); ) {
assertNotNull(i.next());
count++;
}
assertEquals(2, count);
assertNotNull(sc.listIterator(0));
count = 0;
for (ListIterator<Service> i = sc.listIterator(0); i.hasNext(); ) {
assertNotNull(i.next());
count++;
}
assertEquals(2, count);
assertNotNull(sc.listIterator());
count = 0;
for (ListIterator<Service> i = sc.listIterator(); i.hasNext(); ) {
assertNotNull(i.next());
count++;
}
assertEquals(2, count);
}
use of com.adaptris.core.Service in project interlok by adaptris.
the class ServiceCollectionCase method testRemove.
@Test
public void testRemove() throws Exception {
ServiceCollectionImp sc = createServiceCollection();
sc.addService(new NullService(UUID.randomUUID().toString()));
WaitService wait = new WaitService(UUID.randomUUID().toString());
sc.addService(wait);
sc.addService(new NullService(UUID.randomUUID().toString()));
Service s = sc.remove(1);
assertEquals(WaitService.class, s.getClass());
assertEquals(wait, s);
assertEquals(2, sc.size());
assertFalse(sc.contains(wait));
}
Aggregations