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);
}
}
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();
}
}
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();
}
}
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);
}
}
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);
}
}
Aggregations