Search in sources :

Example 41 with Service

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);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ArrayList(java.util.ArrayList) Service(com.adaptris.core.Service) AddTimestampMetadataService(com.adaptris.core.services.metadata.AddTimestampMetadataService) PooledConnectionHelper(com.adaptris.core.jdbc.PooledConnectionHelper) ComponentLifecycle(com.adaptris.core.ComponentLifecycle) AdvancedJdbcPooledConnection(com.adaptris.core.jdbc.AdvancedJdbcPooledConnection) JdbcPooledConnection(com.adaptris.core.jdbc.JdbcPooledConnection) Test(org.junit.Test)

Example 42 with Service

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());
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExampleBranchingService(com.adaptris.core.stubs.ExampleBranchingService) NullService(com.adaptris.core.NullService) Service(com.adaptris.core.Service) Test(org.junit.Test)

Example 43 with Service

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());
            }
        }
    }
}
Also used : Service(com.adaptris.core.Service) CoreException(com.adaptris.core.CoreException) Test(org.junit.Test)

Example 44 with Service

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);
}
Also used : ServiceCollectionImp(com.adaptris.core.ServiceCollectionImp) NullService(com.adaptris.core.NullService) NullService(com.adaptris.core.NullService) Service(com.adaptris.core.Service) EventHandlerAwareService(com.adaptris.core.stubs.EventHandlerAwareService) WaitService(com.adaptris.core.services.WaitService) Test(org.junit.Test)

Example 45 with Service

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));
}
Also used : WaitService(com.adaptris.core.services.WaitService) ServiceCollectionImp(com.adaptris.core.ServiceCollectionImp) NullService(com.adaptris.core.NullService) NullService(com.adaptris.core.NullService) Service(com.adaptris.core.Service) EventHandlerAwareService(com.adaptris.core.stubs.EventHandlerAwareService) WaitService(com.adaptris.core.services.WaitService) Test(org.junit.Test)

Aggregations

Service (com.adaptris.core.Service)49 Test (org.junit.Test)38 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)28 ServiceList (com.adaptris.core.ServiceList)16 ArrayList (java.util.ArrayList)16 ComponentLifecycle (com.adaptris.core.ComponentLifecycle)14 AdvancedJdbcPooledConnection (com.adaptris.core.jdbc.AdvancedJdbcPooledConnection)12 PooledConnectionHelper (com.adaptris.core.jdbc.PooledConnectionHelper)12 ServiceException (com.adaptris.core.ServiceException)11 MetadataElement (com.adaptris.core.MetadataElement)10 NullService (com.adaptris.core.NullService)10 StandaloneProducer (com.adaptris.core.StandaloneProducer)10 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)10 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)9 LogMessageService (com.adaptris.core.services.LogMessageService)8 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)7 MockChannel (com.adaptris.core.stubs.MockChannel)7 StandardProcessingExceptionHandler (com.adaptris.core.StandardProcessingExceptionHandler)6 JdbcPooledConnection (com.adaptris.core.jdbc.JdbcPooledConnection)6 GuidGenerator (com.adaptris.util.GuidGenerator)6