use of com.adaptris.core.stubs.StaticMockMessageProducer in project interlok by adaptris.
the class HttpConsumerTest method testPoolingWorkflow_TimeoutAction_TimeoutExceeded.
@Test
public void testPoolingWorkflow_TimeoutAction_TimeoutExceeded() throws Exception {
HttpConnection connection = createConnection(null);
MockMessageProducer mockProducer = new StaticMockMessageProducer();
mockProducer.getMessages().clear();
JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
consumer.setAdditionalDebug(false);
consumer.setTimeoutAction(new TimeoutAction(new TimeInterval(100L, TimeUnit.MILLISECONDS)));
PoolingWorkflow workflow = new PoolingWorkflow();
workflow.setShutdownWaitTime(new TimeInterval(100L, TimeUnit.MILLISECONDS));
StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
workflow.setConsumer(consumer);
workflow.getServiceCollection().add(new WaitService(new TimeInterval(5L, TimeUnit.SECONDS)));
workflow.getServiceCollection().add(new StandaloneProducer(mockProducer));
workflow.getServiceCollection().add(new StandaloneProducer(responder));
workflow.addInterceptor(new JettyPoolingWorkflowInterceptor());
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);
assertEquals(Integer.valueOf(HttpStatus.ACCEPTED_202.getStatusCode()), Integer.valueOf(reply.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE)));
} finally {
stop(httpProducer);
channel.requestClose();
}
}
use of com.adaptris.core.stubs.StaticMockMessageProducer in project interlok by adaptris.
the class EmbeddedHttpConsumerTest method testPoolingWorkflow_WithoutInterceptor.
@Test
public void testPoolingWorkflow_WithoutInterceptor() 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();
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(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);
// 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();
helper.stopServer();
}
}
use of com.adaptris.core.stubs.StaticMockMessageProducer in project interlok by adaptris.
the class HttpConsumerTest method testPoolingWorkflow_WithInterceptor.
@Test
public void testPoolingWorkflow_WithInterceptor() throws Exception {
HttpConnection connection = createConnection(null);
MockMessageProducer mockProducer = new StaticMockMessageProducer();
mockProducer.getMessages().clear();
JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
consumer.setWarnAfter(new TimeInterval(10L, TimeUnit.MILLISECONDS));
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(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);
assertEquals("Reply Payloads", XML_PAYLOAD, reply.getContent());
doAssertions(mockProducer);
} finally {
stop(httpProducer);
channel.requestClose();
}
}
use of com.adaptris.core.stubs.StaticMockMessageProducer in project interlok by adaptris.
the class PoolingMessageSplitterServiceTest method createMockProducer.
protected StaticMockMessageProducer createMockProducer() {
StaticMockMessageProducer p = new StaticMockMessageProducer();
p.getMessages().clear();
return p;
}
use of com.adaptris.core.stubs.StaticMockMessageProducer in project interlok by adaptris.
the class PoolingWorkflowTest method testOnMessage_SkipProducer.
@Test
public void testOnMessage_SkipProducer() throws Exception {
StaticMockMessageProducer serviceProducer = new StaticMockMessageProducer();
serviceProducer.getMessages().clear();
MockChannel channel = createAndPrepareChannel(Arrays.asList(new Service[] { createService(), new StandaloneProducer(serviceProducer), new MockSkipProducerService() }));
try {
PoolingWorkflow workflow = (PoolingWorkflow) channel.getWorkflowList().get(0);
MockMessageProducer workflowProducer = (MockMessageProducer) workflow.getProducer();
start(channel);
submitMessages(workflow, 10);
waitForMessages(serviceProducer, 10);
// assertEquals(10, serviceProducer.messageCount());
assertEquals(0, workflowProducer.messageCount());
} finally {
stop(channel);
}
}
Aggregations