Search in sources :

Example 66 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class SjmsBatchConsumerTest method testConsumptionMultipleConsumerEndpoints.

/**
     * Checks whether multiple consumer endpoints can operate in parallel.
     */
@Test
public void testConsumptionMultipleConsumerEndpoints() throws Exception {
    final int completionTimeout = 2000;
    final int completionSize = 5;
    final String queueName = getQueueName();
    context.addRoutes(new RouteBuilder() {

        public void configure() throws Exception {
            from("direct:in").split().body().multicast().toF("sjms:%s", queueName + "A").toF("sjms:%s", queueName + "B").end();
            fromF("sjms-batch:%s?completionTimeout=%s&completionSize=%s&aggregationStrategy=#testStrategy", queueName + "A", completionTimeout, completionSize).routeId("batchConsumerA").to("mock:outA");
            fromF("sjms-batch:%s?completionTimeout=%s&completionSize=%s&aggregationStrategy=#testStrategy", queueName + "B", completionTimeout, completionSize).routeId("batchConsumerB").to("mock:outB");
        }
    });
    context.start();
    int messageCount = 5;
    assertTrue(messageCount < SjmsBatchEndpoint.DEFAULT_COMPLETION_SIZE);
    MockEndpoint mockOutA = getMockEndpoint("mock:outA");
    // everything batched together
    mockOutA.expectedMessageCount(1);
    MockEndpoint mockOutB = getMockEndpoint("mock:outB");
    // everything batched together
    mockOutB.expectedMessageCount(1);
    template.sendBody("direct:in", generateStrings(messageCount));
    assertMockEndpointsSatisfied();
    assertFirstMessageBodyOfLength(mockOutA, messageCount);
    assertFirstMessageBodyOfLength(mockOutB, messageCount);
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 67 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class SjmsBatchConsumerTest method testConsumptionCompletionSize.

@Test
public void testConsumptionCompletionSize() throws Exception {
    final int completionSize = 5;
    // size-based only
    final int completionTimeout = -1;
    final String queueName = getQueueName();
    context.addRoutes(new TransactedSendHarness(queueName));
    context.addRoutes(new RouteBuilder() {

        public void configure() throws Exception {
            fromF("sjms-batch:%s?completionTimeout=%s&completionSize=%s&aggregationStrategy=#testStrategy", queueName, completionTimeout, completionSize).routeId("batchConsumer").startupOrder(10).log(LoggingLevel.DEBUG, "${body.size}").to("mock:batches");
        }
    });
    context.start();
    int messageCount = 100;
    MockEndpoint mockBatches = getMockEndpoint("mock:batches");
    mockBatches.expectedMessageCount(messageCount / completionSize);
    template.sendBody("direct:in", generateStrings(messageCount));
    mockBatches.assertIsSatisfied();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 68 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class SjmsBatchConsumerTest method testConsumptionSendEmptyMessageWhenIdle.

@Test
public void testConsumptionSendEmptyMessageWhenIdle() throws Exception {
    final int completionInterval = 2000;
    // timeout-based only
    final int completionSize = -1;
    final String queueName = getQueueName();
    context.addRoutes(new TransactedSendHarness(queueName));
    context.addRoutes(new RouteBuilder() {

        public void configure() throws Exception {
            fromF("sjms-batch:%s?completionInterval=%s&completionSize=%s&sendEmptyMessageWhenIdle=true&aggregationStrategy=#testStrategy", queueName, completionInterval, completionSize).routeId("batchConsumer").startupOrder(10).to("mock:batches");
        }
    });
    context.start();
    int messageCount = 50;
    assertTrue(messageCount < SjmsBatchEndpoint.DEFAULT_COMPLETION_SIZE);
    MockEndpoint mockBatches = getMockEndpoint("mock:batches");
    // trigger a couple of empty messages
    mockBatches.expectedMinimumMessageCount(3);
    template.sendBody("direct:in", generateStrings(messageCount));
    mockBatches.assertIsSatisfied();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 69 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class SjmsBatchEndpointTest method testConsumerTopic.

@Test(expected = FailedToCreateRouteException.class)
public void testConsumerTopic() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("sjms-batch:topic:in?aggregationStrategy=#aggStrategy").to("mock:out");
        }
    });
    context.start();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) Test(org.junit.Test)

Example 70 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class SjmsBatchEndpointTest method testProducerFailure.

@Test(expected = FailedToCreateRouteException.class)
public void testProducerFailure() throws Exception {
    context.addRoutes(new RouteBuilder() {

        public void configure() throws Exception {
            from("direct:in").to("sjms-batch:testQueue?aggregationStrategy=#unknown");
        }
    });
    context.start();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) Test(org.junit.Test)

Aggregations

RouteBuilder (org.apache.camel.builder.RouteBuilder)1759 Exchange (org.apache.camel.Exchange)628 Processor (org.apache.camel.Processor)545 Test (org.junit.Test)476 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)341 CamelExecutionException (org.apache.camel.CamelExecutionException)135 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)119 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)104 File (java.io.File)68 CamelContext (org.apache.camel.CamelContext)64 IOException (java.io.IOException)61 ResolveEndpointFailedException (org.apache.camel.ResolveEndpointFailedException)42 HashMap (java.util.HashMap)35 Path (org.apache.hadoop.fs.Path)34 CountDownLatch (java.util.concurrent.CountDownLatch)32 Configuration (org.apache.hadoop.conf.Configuration)32 Endpoint (org.apache.camel.Endpoint)30 ArrayFile (org.apache.hadoop.io.ArrayFile)30 SequenceFile (org.apache.hadoop.io.SequenceFile)30 RuntimeCamelException (org.apache.camel.RuntimeCamelException)26