Search in sources :

Example 96 with NotifyBuilder

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

the class ManagedThrottlerTest method testThrottleAsyncVisableViaJmx.

public void testThrottleAsyncVisableViaJmx() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    if (isPlatform("windows")) {
        // windows needs more sleep to read updated jmx values so we skip as we dont want further delays in core tests
        return;
    }
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    // get the object name for the delayer
    ObjectName throttlerName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mythrottler3\"");
    // use route to get the total time
    ObjectName routeName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route3\"");
    // reset the counters
    mbeanServer.invoke(routeName, "reset", null, null);
    getMockEndpoint("mock:endAsync").expectedMessageCount(10);
    // we pick '5' because we are right in the middle of the number of messages
    // that have been and reduces any race conditions to minimal...
    NotifyBuilder notifier = new NotifyBuilder(context).from("seda:throttleCountAsync").whenReceived(5).create();
    for (int i = 0; i < 10; i++) {
        template.sendBody("seda:throttleCountAsync", "Message " + i);
    }
    assertTrue(notifier.matches(2, TimeUnit.SECONDS));
    assertMockEndpointsSatisfied();
    Long completed = (Long) mbeanServer.getAttribute(routeName, "ExchangesCompleted");
    assertEquals(10, completed.longValue());
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 97 with NotifyBuilder

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

the class ConsumerCompletionTest method testReleaseOnFailure.

@Test
public void testReleaseOnFailure() throws Exception {
    shouldIdie = true;
    final long jobId = 111;
    final long priority = BeanstalkComponent.DEFAULT_PRIORITY;
    final int delay = BeanstalkComponent.DEFAULT_DELAY;
    final byte[] payload = Helper.stringToBytes(testMessage);
    final Job jobMock = mock(Job.class);
    when(jobMock.getJobId()).thenReturn(jobId);
    when(jobMock.getData()).thenReturn(payload);
    when(client.reserve(anyInt())).thenReturn(jobMock).thenReturn(null);
    when(client.statsJob(anyInt())).thenReturn(null);
    when(client.release(anyInt(), anyLong(), anyInt())).thenReturn(true);
    NotifyBuilder notify = new NotifyBuilder(context).whenFailed(1).create();
    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedMessageCount(0);
    context.startRoute("foo");
    assertTrue(notify.matches(5, TimeUnit.SECONDS));
    verify(client, atLeastOnce()).reserve(anyInt());
    verify(client, atLeastOnce()).statsJob(anyInt());
    verify(client).release(jobId, priority, delay);
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Job(com.surftools.BeanstalkClient.Job) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 98 with NotifyBuilder

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

the class NettyConcurrentTest method doSendMessages.

private void doSendMessages(int files, int poolSize) throws Exception {
    StopWatch watch = new StopWatch();
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(files).create();
    ExecutorService executor = Executors.newFixedThreadPool(poolSize);
    // we access the responses Map below only inside the main thread,
    // so no need for a thread-safe Map implementation
    Map<Integer, Future<String>> responses = new HashMap<Integer, Future<String>>();
    for (int i = 0; i < files; i++) {
        final int index = i;
        Future<String> out = executor.submit(new Callable<String>() {

            public String call() throws Exception {
                String reply = template.requestBody("netty:tcp://localhost:{{port}}", index, String.class);
                log.debug("Sent {} received {}", index, reply);
                assertEquals("Bye " + index, reply);
                return reply;
            }
        });
        responses.put(index, out);
    }
    notify.matches(2, TimeUnit.MINUTES);
    log.info("Took " + watch.taken() + " millis to process " + files + " messages using " + poolSize + " client threads.");
    assertEquals(files, responses.size());
    // get all responses
    Set<String> unique = new HashSet<String>();
    for (Future<String> future : responses.values()) {
        unique.add(future.get());
    }
    // should be 'files' unique responses
    assertEquals("Should be " + files + " unique responses", files, unique.size());
    executor.shutdownNow();
}
Also used : HashMap(java.util.HashMap) StopWatch(org.apache.camel.util.StopWatch) NotifyBuilder(org.apache.camel.builder.NotifyBuilder) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) HashSet(java.util.HashSet)

Example 99 with NotifyBuilder

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

the class AbstractTransactionTest method assertResult.

protected void assertResult() throws InterruptedException {
    // should be 1 completed and 1 failed
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(2).create();
    template.sendBody("activemq:queue:foo", "blah");
    notify.matchesMockWaitTime();
    assertTrue("Expected only 2 calls to process() (1 failure, 1 success) but encountered " + getConditionalExceptionProcessor().getCount() + ".", getConditionalExceptionProcessor().getCount() == 2);
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder)

Example 100 with NotifyBuilder

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

the class MllpTcpServerConsumerTest method testMessageReadTimeout.

@Test
public void testMessageReadTimeout() throws Exception {
    result.expectedMessageCount(0);
    timeout.expectedMessageCount(1);
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
    mllpClient.setSendEndOfBlock(false);
    mllpClient.setSendEndOfData(false);
    mllpClient.sendFramedData(generateMessage());
    assertTrue("One exchange should have completed", notify.matches(15, TimeUnit.SECONDS));
    assertMockEndpointsSatisfied();
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) Test(org.junit.Test)

Aggregations

NotifyBuilder (org.apache.camel.builder.NotifyBuilder)109 Test (org.junit.Test)72 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)30 File (java.io.File)24 Exchange (org.apache.camel.Exchange)10 RouteBuilder (org.apache.camel.builder.RouteBuilder)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 HashSet (java.util.HashSet)4 MBeanServer (javax.management.MBeanServer)4 ObjectName (javax.management.ObjectName)4 Processor (org.apache.camel.Processor)4 StopWatch (org.apache.camel.util.StopWatch)4 ConnectException (java.net.ConnectException)3 ExecutorService (java.util.concurrent.ExecutorService)3 Ignore (org.junit.Ignore)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Future (java.util.concurrent.Future)2 ZipFile (java.util.zip.ZipFile)2