Search in sources :

Example 16 with PoolingWorkflow

use of com.adaptris.core.PoolingWorkflow 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 17 with PoolingWorkflow

use of com.adaptris.core.PoolingWorkflow 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 18 with PoolingWorkflow

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

Example 19 with PoolingWorkflow

use of com.adaptris.core.PoolingWorkflow in project interlok by adaptris.

the class JettyNoBacklogInterceptorTest method testInterceptor.

@Test
public void testInterceptor() throws Exception {
    int jettyPort = PortManager.nextUnusedPort(Integer.parseInt(PROPERTIES.getProperty(JETTY_HTTP_PORT)));
    HttpConnection connection = createConnection(jettyPort);
    JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
    PoolingWorkflow workflow = new PoolingWorkflow();
    workflow.setPoolSize(1);
    workflow.addInterceptor(new JettyPoolingWorkflowInterceptor());
    workflow.addInterceptor(new JettyNoBacklogInterceptor());
    workflow.setShutdownWaitTime(new TimeInterval(1L, TimeUnit.SECONDS));
    workflow.setConsumer(consumer);
    workflow.getServiceCollection().add(new WaitService(new TimeInterval(3L, TimeUnit.SECONDS)));
    Channel channel = JettyHelper.createChannel(connection, workflow);
    final HttpRequestService httpService = new HttpRequestService();
    httpService.setUrl("http://localhost:" + connection.getPort() + URL_TO_POST_TO);
    httpService.setContentType("text/xml");
    HttpRequestService expect503 = DefaultMarshaller.roundTrip(httpService);
    try {
        start(channel);
        new Thread(runnableWrapper(httpService)).start();
        Awaitility.await().atMost(Duration.ofSeconds(5)).with().pollInterval(Duration.ofMillis(100)).until(() -> workflow.currentlyActiveObjects() == 1);
        // LifecycleHelper.waitQuietly(500);
        // should be waiting in the WaitService.
        ExampleServiceCase.execute(expect503, AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD));
        fail();
    } catch (ServiceException expected) {
        assertEquals(ProduceException.class, expected.getCause().getClass());
        assertTrue(expected.getCause().getMessage().contains("503"));
    } finally {
        stop(channel);
        PortManager.release(jettyPort);
    }
}
Also used : WaitService(com.adaptris.core.services.WaitService) TimeInterval(com.adaptris.util.TimeInterval) Channel(com.adaptris.core.Channel) ProduceException(com.adaptris.core.ProduceException) HttpRequestService(com.adaptris.core.http.client.net.HttpRequestService) ServiceException(com.adaptris.core.ServiceException) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) Test(org.junit.Test)

Example 20 with PoolingWorkflow

use of com.adaptris.core.PoolingWorkflow in project interlok by adaptris.

the class JettyAsyncWorkflowInterceptorTest method testAcrossMultipleWorkflows.

@Test
public void testAcrossMultipleWorkflows() throws Exception {
    HttpConnection connection = createConnection(Integer.parseInt(PROPERTIES.getProperty(JETTY_HTTP_PORT)));
    JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO, getName());
    PoolingWorkflow receivingWF = new PoolingWorkflow();
    receivingWF.addInterceptor(new JettyAsyncWorkflowInterceptor().withMode(JettyAsyncWorkflowInterceptor.Mode.REQUEST));
    receivingWF.setShutdownWaitTime(new TimeInterval(1L, TimeUnit.SECONDS));
    receivingWF.setConsumer(consumer);
    StandardWorkflow respondingWF = new StandardWorkflow();
    // Mainly to keep track of the msgID. we use a standard workflow so new objects aren't created.
    MockMessageProducer producer = new MockMessageProducer();
    respondingWF.addInterceptor(new JettyAsyncWorkflowInterceptor().withMode(JettyAsyncWorkflowInterceptor.Mode.RESPONSE));
    respondingWF.getServiceCollection().add(new PayloadFromTemplateService().withTemplate("hello world"));
    respondingWF.getServiceCollection().add(new JettyResponseService(200, "text/plain"));
    respondingWF.getServiceCollection().add(new StandaloneProducer(producer));
    receivingWF.setProducer(new WorkflowProducer(respondingWF));
    Channel channel = JettyHelper.createChannel(connection, receivingWF, respondingWF);
    HttpRequestService httpService = createRequestor(connection.getPort());
    try {
        start(channel);
        LifecycleHelper.initAndStart(httpService);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
        ExampleServiceCase.execute(httpService, msg);
        assertEquals("hello world", msg.getContent());
        waitForMessages(producer, 1);
        // Grab the message that the standardWorkflow handled; and check the msgId.
        // Should be removed from the static cache.
        assertFalse(JettyAsyncWorkflowInterceptor.cacheContains(producer.getMessages().get(0).getUniqueId()));
    } finally {
        stop(channel);
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) TimeInterval(com.adaptris.util.TimeInterval) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) HttpRequestService(com.adaptris.core.http.client.net.HttpRequestService) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Aggregations

PoolingWorkflow (com.adaptris.core.PoolingWorkflow)21 Test (org.junit.Test)17 Channel (com.adaptris.core.Channel)15 TimeInterval (com.adaptris.util.TimeInterval)10 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)9 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)8 StandaloneProducer (com.adaptris.core.StandaloneProducer)8 WaitService (com.adaptris.core.services.WaitService)8 Adapter (com.adaptris.core.Adapter)7 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)6 ObjectName (javax.management.ObjectName)5 HttpRequestService (com.adaptris.core.http.client.net.HttpRequestService)4 StandardWorkflow (com.adaptris.core.StandardWorkflow)3 Notification (javax.management.Notification)3 NotificationFilterSupport (javax.management.NotificationFilterSupport)3 JettyMessageConsumer (com.adaptris.core.http.jetty.JettyMessageConsumer)2 MessageInFlightMBean (com.adaptris.core.interceptor.MessageInFlightMBean)2 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)2 CoreException (com.adaptris.core.CoreException)1 ProduceException (com.adaptris.core.ProduceException)1