Search in sources :

Example 26 with WaitService

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

the class StandardHttpProducerTest method testRequest_Get_ExpectHeader.

// HttpURLConnection doesn't support the Expect: 102-Processing
// So this should throw a Produce Exception
@Test
public void testRequest_Get_ExpectHeader() throws Exception {
    MockMessageProducer mock = new MockMessageProducer();
    HttpConnection jc = HttpHelper.createConnection();
    JettyMessageConsumer mc = createConsumer(HttpHelper.URL_TO_POST_TO);
    mc.setSendProcessingInterval(new TimeInterval(100L, TimeUnit.MILLISECONDS));
    ServiceList services = new ServiceList();
    services.add(new PayloadFromTemplateService().withTemplate(TEXT));
    services.add(new WaitService(new TimeInterval(2L, TimeUnit.SECONDS)));
    services.add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)));
    Channel c = createChannel(jc, createWorkflow(mc, mock, services));
    StandardWorkflow workflow = (StandardWorkflow) c.getWorkflowList().get(0);
    workflow.getServiceCollection().add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)));
    StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
    ;
    stdHttp.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethodProvider.RequestMethod.GET));
    stdHttp.setRequestHeaderProvider(new ConfiguredRequestHeaders().withHeaders(new KeyValuePair(HttpConstants.EXPECT, "102-Processing")));
    StandaloneRequestor producer = new StandaloneRequestor(stdHttp);
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(ALT_TEXT);
    try {
        start(c);
        start(producer);
        producer.doService(msg);
        fail();
    } catch (ProduceException | ServiceException e) {
        assertTrue(e.getMessage().contains("Failed to send payload, got 102"));
    } finally {
        stop(c);
        stop(producer);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) WaitService(com.adaptris.core.services.WaitService) StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) KeyValuePair(com.adaptris.util.KeyValuePair) HttpConnection(com.adaptris.core.http.jetty.HttpConnection) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) ProduceException(com.adaptris.core.ProduceException) StandaloneRequestor(com.adaptris.core.StandaloneRequestor) ServiceException(com.adaptris.core.ServiceException) StandardResponseProducer(com.adaptris.core.http.jetty.StandardResponseProducer) JettyMessageConsumer(com.adaptris.core.http.jetty.JettyMessageConsumer) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) StandaloneProducer(com.adaptris.core.StandaloneProducer) ConfiguredRequestMethodProvider(com.adaptris.core.http.client.ConfiguredRequestMethodProvider) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest) Test(org.junit.Test)

Example 27 with WaitService

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

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

the class HttpConsumerTest method testBasicConsumeWorkflow_LongLived_Expect.

@Test
public void testBasicConsumeWorkflow_LongLived_Expect() throws Exception {
    HttpConnection connection = createConnection(null);
    MockMessageProducer mockProducer = new MockMessageProducer();
    JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO, getName());
    consumer.setSendProcessingInterval(new TimeInterval(1L, TimeUnit.SECONDS));
    StandardWorkflow wf = (StandardWorkflow) JettyHelper.createWorkflow(consumer, mockProducer);
    wf.getServiceCollection().add(new WaitService(new TimeInterval(3L, TimeUnit.SECONDS)));
    Channel channel = JettyHelper.createChannel(connection, wf);
    try {
        channel.requestStart();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
        msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
        httpProducer.getAdditionalHeaders().add(new KeyValuePair("Expect", "102-Processing"));
        httpProducer.setUrl(createProduceDestinationUrl(connection.getPort()));
        start(httpProducer);
        AdaptrisMessage reply = httpProducer.request(msg);
        assertEquals("Reply Payloads", XML_PAYLOAD, reply.getContent());
        doAssertions(mockProducer);
    } finally {
        stop(httpProducer);
        channel.requestClose();
        PortManager.release(connection.getPort());
    }
}
Also used : WaitService(com.adaptris.core.services.WaitService) StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) KeyValuePair(com.adaptris.util.KeyValuePair) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) 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