use of org.apache.camel.ProducerTemplate in project camel by apache.
the class RouteContextProcessorTest method xxxTestForkAndJoin.
public void xxxTestForkAndJoin() throws InterruptedException {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(NUMBER_OF_MESSAGES);
ProducerTemplate template = context.createProducerTemplate();
for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
template.sendBodyAndHeader("seda:fork", "Test Message: " + i, "seqnum", new Long(i));
}
long expectedTime = NUMBER_OF_MESSAGES * (RandomSleepProcessor.MAX_PROCESS_TIME + RandomSleepProcessor.MIN_PROCESS_TIME) / 2 / CONCURRENCY + TIMEOUT;
Thread.sleep(expectedTime);
assertMockEndpointsSatisfied();
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class SftpPollEnrichConsumeWithDisconnectAndDeleteTest method testSftpSimpleConsume.
@Test
public void testSftpSimpleConsume() throws Exception {
if (!canTest()) {
return;
}
String expected = "Hello World";
// create file using regular file
template.sendBodyAndHeader("file://" + FTP_ROOT_DIR, expected, Exchange.FILE_NAME, "hello.txt");
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
mock.expectedHeaderReceived(Exchange.FILE_NAME, "hello.txt");
mock.expectedBodiesReceived(expected);
ProducerTemplate triggerTemplate = context.createProducerTemplate();
triggerTemplate.sendBody("vm:trigger", "");
assertMockEndpointsSatisfied();
long startFileDeletionCheckTime = System.currentTimeMillis();
boolean fileExists = true;
while (System.currentTimeMillis() - startFileDeletionCheckTime < 3000) {
// wait up to 3000ms for file to be deleted
File file = new File(FTP_ROOT_DIR + "/hello.txt");
fileExists = file.exists();
if (fileExists) {
log.info("Will check that file has been deleted again in 200ms");
Thread.sleep(200);
}
}
assertFalse("The file should have been deleted", fileExists);
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class VmMultipleConsumersKeepRouteTest method testVmMultipleConsumersKeepRoute.
public void testVmMultipleConsumersKeepRoute() throws Exception {
CamelContext camelContext = new DefaultCamelContext();
ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
RouteBuilder builder = new RouteBuilder(camelContext) {
@Override
public void configure() throws Exception {
from("vm:producer?multipleConsumers=true").routeId("route1").to("mock:route1");
}
};
RouteBuilder builder2 = new RouteBuilder(camelContext) {
@Override
public void configure() throws Exception {
from("vm:producer?multipleConsumers=true").routeId("route2").to("mock:route2");
}
};
camelContext.addRoutes(builder);
camelContext.addRoutes(builder2);
camelContext.start();
MockEndpoint mock1 = (MockEndpoint) camelContext.getEndpoint("mock:route1");
MockEndpoint mock2 = (MockEndpoint) camelContext.getEndpoint("mock:route2");
mock1.expectedMessageCount(100);
mock2.expectedMessageCount(100);
for (int i = 0; i < 100; i++) {
producerTemplate.sendBody("vm:producer?multipleConsumers=true", i);
}
MockEndpoint.assertIsSatisfied(mock1, mock2);
camelContext.stop();
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class ProducerTemplateDisableEventNotifierTest method testExchangeSent.
public void testExchangeSent() throws Exception {
getMockEndpoint("mock:result").expectedMessageCount(1);
// we dont want events for producer template itself so disable that
ProducerTemplate other = context.createProducerTemplate();
other.setEventNotifierEnabled(false);
other.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
assertEquals(2, notifier.getEvents().size());
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class DefaultProducerTemplateTest method testSendUsingDefaultEndpoint.
public void testSendUsingDefaultEndpoint() throws Exception {
ProducerTemplate producer = new DefaultProducerTemplate(context, context.getEndpoint("direct:in"));
producer.start();
getMockEndpoint("mock:result").expectedMessageCount(3);
producer.sendBody("Hello");
producer.sendBodyAndHeader("Hello", "foo", 123);
Map<String, Object> headers = new HashMap<String, Object>();
producer.sendBodyAndHeaders("Hello", headers);
assertMockEndpointsSatisfied();
producer.stop();
}
Aggregations