Search in sources :

Example 21 with WaitService

use of com.adaptris.core.services.WaitService 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)

Example 22 with WaitService

use of com.adaptris.core.services.WaitService in project interlok by adaptris.

the class ServiceCollectionCase method testSetAtPosition.

@Test
public void testSetAtPosition() 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.set(1, new NullService(UUID.randomUUID().toString()));
    assertEquals(WaitService.class, s.getClass());
    assertEquals(wait, s);
    assertEquals(3, 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)

Example 23 with WaitService

use of com.adaptris.core.services.WaitService in project interlok by adaptris.

the class ShortCutJettyResponseTest method testService.

@Test
public void testService() throws Exception {
    HttpConnection connection = createConnection(Integer.parseInt(PROPERTIES.getProperty(JETTY_HTTP_PORT)));
    MockMessageProducer mockProducer = new StaticMockMessageProducer();
    mockProducer.getMessages().clear();
    JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
    PoolingWorkflow workflow = new PoolingWorkflow();
    workflow.setShutdownWaitTime(new TimeInterval(1L, TimeUnit.SECONDS));
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    workflow.setConsumer(consumer);
    workflow.getServiceCollection().add(new WaitService(new TimeInterval(1L, TimeUnit.SECONDS)));
    workflow.getServiceCollection().add(new StandaloneProducer(mockProducer));
    workflow.getServiceCollection().add(new StandaloneProducer(responder));
    workflow.getServiceCollection().add(new ShortCutJettyResponse());
    // Workflow won't get to this before we get the response.
    workflow.getServiceCollection().add(new WaitService(new TimeInterval(10L, TimeUnit.SECONDS)));
    workflow.addInterceptor(new JettyPoolingWorkflowInterceptor());
    Channel channel = JettyHelper.createChannel(connection, workflow);
    HttpRequestService service = JettyHelper.createService(connection.getPort());
    try {
        start(channel);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
        msg.addMetadata(HttpConsumerTest.CONTENT_TYPE_METADATA_KEY, "text/xml");
        long start = System.currentTimeMillis();
        ExampleServiceCase.execute(service, msg);
        ;
        long end = System.currentTimeMillis();
        assertTrue(end - start < TimeUnit.SECONDS.toMillis(10));
    } finally {
        stop(channel);
    }
}
Also used : WaitService(com.adaptris.core.services.WaitService) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) HttpRequestService(com.adaptris.core.http.client.net.HttpRequestService) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 24 with WaitService

use of com.adaptris.core.services.WaitService in project interlok by adaptris.

the class EmbeddedHttpConsumerTest method testPoolingWorkflow_WithInterceptor.

@Test
public void testPoolingWorkflow_WithInterceptor() throws Exception {
    EmbeddedJettyHelper helper = new EmbeddedJettyHelper();
    helper.startServer();
    MockMessageProducer mockProducer = new StaticMockMessageProducer();
    mockProducer.getMessages().clear();
    JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
    PoolingWorkflow workflow = new PoolingWorkflow();
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    workflow.setConsumer(consumer);
    workflow.getServiceCollection().add(new WaitService(new TimeInterval(1L, TimeUnit.SECONDS)));
    workflow.getServiceCollection().add(new StandaloneProducer(mockProducer));
    workflow.getServiceCollection().add(new StandaloneProducer(responder));
    workflow.addInterceptor(new JettyPoolingWorkflowInterceptor());
    Channel channel = JettyHelper.createChannel(new EmbeddedConnection(), workflow);
    try {
        channel.requestStart();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
        msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
        httpProducer.setUrl(helper.createProduceDestination());
        start(httpProducer);
        AdaptrisMessage reply = httpProducer.request(msg);
        assertEquals("Reply Payloads", XML_PAYLOAD, reply.getContent());
        doAssertions(mockProducer);
    } finally {
        stop(httpProducer);
        channel.requestClose();
        helper.stopServer();
    }
}
Also used : WaitService(com.adaptris.core.services.WaitService) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 25 with WaitService

use of com.adaptris.core.services.WaitService in project interlok by adaptris.

the class HttpConsumerTest method testPoolingWorkflow_WithoutInterceptor.

@Test
public void testPoolingWorkflow_WithoutInterceptor() throws Exception {
    HttpConnection connection = createConnection(null);
    MockMessageProducer mockProducer = new StaticMockMessageProducer();
    mockProducer.getMessages().clear();
    JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
    PoolingWorkflow workflow = new PoolingWorkflow();
    workflow.addInterceptor(new MockWorkflowInterceptor());
    workflow.setShutdownWaitTime(new TimeInterval(100L, TimeUnit.MILLISECONDS));
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    workflow.setConsumer(consumer);
    workflow.getServiceCollection().add(new WaitService(new TimeInterval(1L, TimeUnit.SECONDS)));
    workflow.getServiceCollection().add(new StandaloneProducer(mockProducer));
    workflow.getServiceCollection().add(new StandaloneProducer(responder));
    Channel channel = JettyHelper.createChannel(connection, workflow);
    try {
        channel.requestStart();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
        msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
        httpProducer.setUrl(createProduceDestinationUrl(connection.getPort()));
        start(httpProducer);
        AdaptrisMessage reply = httpProducer.request(msg);
        // Because of redmineID #4715 it should just "return immediatel" which flushes the stream so there's no content.
        assertEquals("Reply Payloads", "", reply.getContent());
    } finally {
        stop(httpProducer);
        channel.requestClose();
    }
}
Also used : WaitService(com.adaptris.core.services.WaitService) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) MockWorkflowInterceptor(com.adaptris.core.stubs.MockWorkflowInterceptor) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Aggregations

WaitService (com.adaptris.core.services.WaitService)28 Test (org.junit.Test)26 TimeInterval (com.adaptris.util.TimeInterval)21 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)16 Channel (com.adaptris.core.Channel)11 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)11 PoolingWorkflow (com.adaptris.core.PoolingWorkflow)8 StandaloneProducer (com.adaptris.core.StandaloneProducer)8 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)8 NullService (com.adaptris.core.NullService)7 ServiceCollectionImp (com.adaptris.core.ServiceCollectionImp)7 StandardWorkflow (com.adaptris.core.StandardWorkflow)5 Adapter (com.adaptris.core.Adapter)4 AppendingMessageAggregator (com.adaptris.core.services.aggregator.AppendingMessageAggregator)4 ServiceException (com.adaptris.core.ServiceException)3 BaseComponentMBean (com.adaptris.core.runtime.BaseComponentMBean)3 SimpleNotificationListener (com.adaptris.core.runtime.SimpleNotificationListener)3 DefaultEventHandler (com.adaptris.core.DefaultEventHandler)2 ProduceException (com.adaptris.core.ProduceException)2 Service (com.adaptris.core.Service)2