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