org.apache.camel.builder.NotifyBuilder Java Examples
The following examples show how to use
org.apache.camel.builder.NotifyBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NotifyTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testNotifyWhenAnyDoneMatches() throws Exception { // use a predicate to indicate when a certain message is done NotifyBuilder notify = new NotifyBuilder(context) .from("seda:order").whenAnyDoneMatches(body().isEqualTo("OK,123,2017-04-20'T'15:48:00,2222,3333")).create(); // send in 2 messages. Its the 2nd message we want to test template.sendBody("seda:order", "123,2017-04-20'T'15:47:59,4444,5555"); template.sendBody("seda:order", "123,2017-04-20'T'15:48:00,2222,3333"); boolean matches = notify.matches(5, TimeUnit.SECONDS); assertTrue(matches); SedaEndpoint confirm = context.getEndpoint("seda:confirm", SedaEndpoint.class); // there should be 2 messages on the confirm queue assertEquals(2, confirm.getExchanges().size()); // and the 2nd message should be the message we wanted to test for assertEquals("OK,123,2017-04-20'T'15:48:00,2222,3333", confirm.getExchanges().get(1).getIn().getBody()); }
Example #2
Source File: RiderThrottlerTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testThrottlerReporter() throws Exception { // use notifier to known when we have processed all the messages NotifyBuilder notify = new NotifyBuilder(context).whenDone(size).create(); // create the reporter using injector so Camel can do dependency injection RiderThrottlerReporter reporter = context.getInjector().newInstance(RiderThrottlerReporter.class); // schedule a background task that logs the current throttle count scheduler = context.getExecutorServiceManager().newSingleThreadScheduledExecutor(this, "ThrottleReporter"); scheduler.scheduleAtFixedRate(new ThrottleTask(reporter), 1, 1, TimeUnit.SECONDS); // send some orders for (int i = 0; i < size; i++) { template.sendBody("seda:orders", "Order " + size); } // wait for all messages to be done log.info("Waiting to process all the messages..."); assertTrue("Should process all messages", notify.matches(1, TimeUnit.MINUTES)); // shutdown thread pool context.getExecutorServiceManager().shutdown(scheduler); }
Example #3
Source File: OrderTest.java From camelinaction with Apache License 2.0 | 6 votes |
@Test public void testOrderClientInvalid() throws Exception { NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create(); Calendar cal = Calendar.getInstance(Locale.US); cal.set(Calendar.YEAR, 2010); cal.set(Calendar.MONTH, Calendar.APRIL); cal.set(Calendar.DAY_OF_MONTH, 20); cal.set(Calendar.HOUR_OF_DAY, 7); cal.set(Calendar.MINUTE, 47); cal.set(Calendar.SECOND, 58); Date date = cal.getTime(); OrderClient client = new OrderClient("tcp://localhost:61616"); // when using customer id 999 we force an invalid order client.sendOrder(999, date, "5555", "2222"); boolean matches = notify.matches(5, TimeUnit.SECONDS); assertTrue(matches); // should be one message in confirm queue BrowsableEndpoint be = context.getEndpoint("activemq:queue:invalid", BrowsableEndpoint.class); List<Exchange> list = be.getExchanges(); assertEquals(1, list.size()); assertEquals("999,2010-04-20T07:47:58,5555,2222", list.get(0).getIn().getBody(String.class)); }
Example #4
Source File: RiderAutoPartsPartnerTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testSendPartnerReportIntoDatabase() throws Exception { NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create(); // start Camel manually as we use advice-with in this unit tests class context.start(); // there should be 0 row in the database when we start int rows = jdbc.queryForObject("select count(*) from partner_metric", Integer.class); assertEquals(0, rows); String xml = "<?xml version=\"1.0\"?><partner id=\"123\"><date>201702250815</date><code>200</code><time>4387</time></partner>"; template.sendBody("activemq:queue:partners", xml); // wait for the route to complete one message assertTrue(notify.matches(10, TimeUnit.SECONDS)); // there should be 1 row in the database rows = jdbc.queryForObject("select count(*) from partner_metric", Integer.class); assertEquals(1, rows); }
Example #5
Source File: OrderTest.java From camelinaction with Apache License 2.0 | 6 votes |
@Test public void testOrderClientFailure() throws Exception { // now we expect the message to fail so we use whenFailed NotifyBuilder notify = new NotifyBuilder(context).whenFailed(1).create(); Calendar cal = Calendar.getInstance(Locale.US); cal.set(Calendar.YEAR, 2010); cal.set(Calendar.MONTH, Calendar.APRIL); cal.set(Calendar.DAY_OF_MONTH, 20); cal.set(Calendar.HOUR_OF_DAY, 7); cal.set(Calendar.MINUTE, 47); cal.set(Calendar.SECOND, 58); Date date = cal.getTime(); OrderClient client = new OrderClient("tcp://localhost:61616"); // by using 9999 as the last item id we force an exception to occur client.sendOrder(123, date, "4444", "9999"); boolean matches = notify.matches(5, TimeUnit.SECONDS); assertTrue(matches); }
Example #6
Source File: NotifyTest.java From camelinaction with Apache License 2.0 | 6 votes |
@Test public void testNotifyWhenAnyDoneMatches() throws Exception { // use a predicate to indicate when a certain message is done NotifyBuilder notify = new NotifyBuilder(context) .from("seda:order").whenAnyDoneMatches(body().isEqualTo("OK,123,2010-04-20'T'15:48:00,2222,3333")).create(); // send in 2 messages. Its the 2nd message we want to test template.sendBody("seda:order", "123,2010-04-20'T'15:47:59,4444,5555"); template.sendBody("seda:order", "123,2010-04-20'T'15:48:00,2222,3333"); boolean matches = notify.matches(5, TimeUnit.SECONDS); assertTrue(matches); SedaEndpoint confirm = context.getEndpoint("seda:confirm", SedaEndpoint.class); // there should be 2 messages on the confirm queue assertEquals(2, confirm.getExchanges().size()); // and the 2nd message should be the message we wanted to test for assertEquals("OK,123,2010-04-20'T'15:48:00,2222,3333", confirm.getExchanges().get(1).getIn().getBody()); }
Example #7
Source File: FixedEndpointsNotifyBuilderSpringTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Test public void testSingleMessageDoneSentToOutAndMatched() throws InterruptedException { final String messageText = "testMessage"; MockEndpoint mock = camelContext.getEndpoint("mock:nameDoesNotMatter", MockEndpoint.class); mock.message(0).inMessage().contains(messageText); mock.message(0).header("count").isNull(); NotifyBuilder notify = new NotifyBuilder(camelContext) .from("activemq:in") .whenDone(1).wereSentTo("activemq:out") .whenDoneSatisfied(mock) .create(); sendMessageBody(messageText); assertTrue(notify.matches(10, TimeUnit.SECONDS)); }
Example #8
Source File: SpringFileThreadsTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testFileThreads() throws Exception { log.info("Creating {} files...", files); // create many files for (int i = 0; i < files; i++) { template.sendBodyAndHeader("file:target/inbox", "Message " + i, Exchange.FILE_NAME, "file-" + i + ".txt"); } log.info("Starting route"); // keep track of completed files NotifyBuilder notify = new NotifyBuilder(context).whenCompleted(files).create(); // start route context.startRoute("myRoute"); // wait for all files to be processed assertTrue("Should complete all files", notify.matches(60, TimeUnit.SECONDS)); }
Example #9
Source File: FileThreadsTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testFileThreads() throws Exception { log.info("Creating {} files...", files); // create many files for (int i = 0; i < files; i++) { template.sendBodyAndHeader("file:target/inbox", "Message " + i, Exchange.FILE_NAME, "file-" + i + ".txt"); } log.info("Starting route"); // keep track of completed files NotifyBuilder notify = new NotifyBuilder(context).whenCompleted(files).create(); // start route context.startRoute("myRoute"); // wait for all files to be processed assertTrue("Should complete all files", notify.matches(60, TimeUnit.SECONDS)); }
Example #10
Source File: NotifyTest.java From camelinaction with Apache License 2.0 | 6 votes |
@Test public void testNotifyFrom() throws Exception { // use from to indicate it should only be messages originating from the given endpoint NotifyBuilder notify = new NotifyBuilder(context) .from("seda:order").whenDone(1).create(); template.sendBody("seda:quote", "Camel rocks"); template.sendBody("seda:order", "123,2010-04-20'T'15:47:59,4444,5555"); boolean matches = notify.matches(5, TimeUnit.SECONDS); assertTrue(matches); SedaEndpoint confirm = context.getEndpoint("seda:confirm", SedaEndpoint.class); assertEquals(1, confirm.getExchanges().size()); assertEquals("OK,123,2010-04-20'T'15:47:59,4444,5555", confirm.getExchanges().get(0).getIn().getBody()); }
Example #11
Source File: RiderAutoPartsPartnerTransactedTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testSendPartnerReportIntoDatabase() throws Exception { NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create(); // there should be 0 row in the database when we start int rows = jdbc.queryForObject("select count(*) from partner_metric", Integer.class); assertEquals(0, rows); String xml = "<?xml version=\"1.0\"?><partner id=\"123\"><date>201702250815</date><code>200</code><time>4387</time></partner>"; template.sendBody("activemq:queue:partners", xml); // wait for the route to complete one message assertTrue(notify.matches(10, TimeUnit.SECONDS)); // there should be 1 row in the database rows = jdbc.queryForObject("select count(*) from partner_metric", Integer.class); assertEquals(1, rows); }
Example #12
Source File: RiderAutoPartsPartnerClientAcknowledgeModeTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testSendPartnerReportIntoDatabase() throws Exception { NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create(); // start Camel manually as we use advice-with in this unit tests class context.start(); // there should be 0 row in the database when we start int rows = jdbc.queryForObject("select count(*) from partner_metric", Integer.class); assertEquals(0, rows); String xml = "<?xml version=\"1.0\"?><partner id=\"123\"><date>201702250815</date><code>200</code><time>4387</time></partner>"; template.sendBody("activemq:queue:partners", xml); // wait for the route to complete one message assertTrue(notify.matches(10, TimeUnit.SECONDS)); // there should be 1 row in the database rows = jdbc.queryForObject("select count(*) from partner_metric", Integer.class); assertEquals(1, rows); }
Example #13
Source File: SpringXARollbackBeforeActiveMQTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testRollbackBeforeActiveMQ() throws Exception { NotifyBuilder notify = new NotifyBuilder(context).whenReceived(10).create(); jdbc.execute("insert into partner_metric (partner_id, time_occurred, status_code, perf_time) values ('123', '20170315183457', '200', '1503')"); assertTrue(notify.matches(15, TimeUnit.SECONDS)); // and there should be 1 row in the database as it keep rolling back int rows = jdbc.queryForObject("select count(*) from partner_metric", Integer.class); assertEquals(1, rows); String order = consumer.receiveBody("activemq:queue:order", 2000, String.class); assertNull("Should NOT be in order queue", order); context.stop(); }
Example #14
Source File: SpringXARollbackAfterActiveMQTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testRollbackAfterActiveMQ() throws Exception { NotifyBuilder notify = new NotifyBuilder(context).whenReceived(10).create(); jdbc.execute("insert into partner_metric (partner_id, time_occurred, status_code, perf_time) values ('123', '20170315183457', '200', '1503')"); assertTrue(notify.matches(15, TimeUnit.SECONDS)); // and there should be 1 row in the database as it keep rolling back int rows = jdbc.queryForObject("select count(*) from partner_metric", Integer.class); assertEquals(1, rows); String order = consumer.receiveBody("activemq:queue:order", 2000, String.class); assertNull("Should NOT be in order queue", order); context.stop(); }
Example #15
Source File: AsyncProcessRevisitedTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Test @Deployment(resources = { "process/revisited/async-revisited.bpmn20.xml" }) public void testRunProcess() throws Exception { NotifyBuilder oneExchangeSendToFlowableReceive1 = new NotifyBuilder(camelContext).from("seda:continueAsync1").whenExactlyCompleted(1).create(); NotifyBuilder oneExchangeSendToFlowableReceive2 = new NotifyBuilder(camelContext).from("seda:continueAsync2").whenExactlyCompleted(1).create(); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("asyncCamelProcessRevisited"); List<Execution> executionList = runtimeService.createExecutionQuery().list(); assertThat(executionList).hasSize(3); waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs(7000, 200); assertThat(oneExchangeSendToFlowableReceive1.matchesMockWaitTime()).isTrue(); assertThat(oneExchangeSendToFlowableReceive2.matchesMockWaitTime()).isTrue(); assertThat(runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).count()).isZero(); }
Example #16
Source File: NotifyTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testNotifyFrom() throws Exception { // use from to indicate it should only be messages originating from the given endpoint NotifyBuilder notify = new NotifyBuilder(context) .from("seda:order").whenDone(1).create(); template.sendBody("seda:quote", "Camel rocks"); template.sendBody("seda:order", "123,2017-04-20'T'15:47:59,4444,5555"); boolean matches = notify.matches(5, TimeUnit.SECONDS); assertTrue(matches); SedaEndpoint confirm = context.getEndpoint("seda:confirm", SedaEndpoint.class); assertEquals(1, confirm.getExchanges().size()); assertEquals("OK,123,2017-04-20'T'15:47:59,4444,5555", confirm.getExchanges().get(0).getIn().getBody()); }
Example #17
Source File: OrderTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testOrderClientFailure() throws Exception { // now we expect the message to fail so we use whenFailed NotifyBuilder notify = new NotifyBuilder(context).whenFailed(1).create(); Calendar cal = Calendar.getInstance(Locale.US); cal.set(Calendar.YEAR, 2017); cal.set(Calendar.MONTH, Calendar.APRIL); cal.set(Calendar.DAY_OF_MONTH, 20); cal.set(Calendar.HOUR_OF_DAY, 7); cal.set(Calendar.MINUTE, 47); cal.set(Calendar.SECOND, 58); Date date = cal.getTime(); OrderClient client = new OrderClient("tcp://localhost:61616"); // by using 9999 as the last item id we force an exception to occur client.sendOrder(123, date, "4444", "9999"); boolean matches = notify.matches(5, TimeUnit.SECONDS); assertTrue(matches); }
Example #18
Source File: OrderTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testOrderClientInvalid() throws Exception { NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create(); Calendar cal = Calendar.getInstance(Locale.US); cal.set(Calendar.YEAR, 2017); cal.set(Calendar.MONTH, Calendar.APRIL); cal.set(Calendar.DAY_OF_MONTH, 20); cal.set(Calendar.HOUR_OF_DAY, 7); cal.set(Calendar.MINUTE, 47); cal.set(Calendar.SECOND, 58); Date date = cal.getTime(); OrderClient client = new OrderClient("tcp://localhost:61616"); // when using customer id 999 we force an invalid order client.sendOrder(999, date, "5555", "2222"); boolean matches = notify.matches(5, TimeUnit.SECONDS); assertTrue(matches); // should be one message in confirm queue BrowsableEndpoint be = context.getEndpoint("activemq:queue:invalid", BrowsableEndpoint.class); List<Exchange> list = be.getExchanges(); assertEquals(1, list.size()); assertEquals("999,2017-04-20T07:47:58,5555,2222", list.get(0).getIn().getBody(String.class)); }
Example #19
Source File: FirstTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testMoveFile() throws Exception { // use NotifyBuilder to wait for the file to be routed NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create(); // create a new file in the inbox folder with the name hello.txt and containing Hello World as body template.sendBodyAndHeader("file://target/inbox", "Hello World", Exchange.FILE_NAME, "hello.txt"); // notifier will wait for the file to be processed // and if that never happen it will time out after 10 seconds (default mock timeout) assertTrue(notify.matchesMockWaitTime()); // test the file was moved File target = new File("target/outbox/hello.txt"); assertTrue("File should have been moved", target.exists()); // test that its content is correct as well String content = context.getTypeConverter().convertTo(String.class, target); assertEquals("Hello World", content); }
Example #20
Source File: RunWithFirstTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testMoveFile() throws Exception { // use NotifyBuilder to wait for the file to be routed NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create(); // create a new file in the inbox folder with the name hello.txt and containing Hello World as body template.sendBodyAndHeader("file://target/inbox", "Hello World", Exchange.FILE_NAME, "hello.txt"); // notifier will wait for the file to be processed // and if that never happen it will time out after 10 seconds (default mock timeout) assertTrue(notify.matchesMockWaitTime()); // test the file was moved File target = new File("target/outbox/hello.txt"); assertTrue("File should have been moved", target.exists()); // test that its content is correct as well String content = context.getTypeConverter().convertTo(String.class, target); assertEquals("Hello World", content); }
Example #21
Source File: FirstTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testMoveFile() throws Exception { // use NotifyBuilder to wait for the file to be routed NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create(); // create a new file in the inbox folder with the name hello.txt and containing Hello World as body template.sendBodyAndHeader("file://target/inbox", "Hello World", Exchange.FILE_NAME, "hello.txt"); // notifier will wait for the file to be processed // and if that never happen it will time out after 10 seconds (default mock timeout) assertTrue(notify.matchesMockWaitTime()); // test the file was moved File target = new File("target/outbox/hello.txt"); assertTrue("File should have been moved", target.exists()); // test that its content is correct as well String content = context.getTypeConverter().convertTo(String.class, target); assertEquals("Hello World", content); }
Example #22
Source File: FooTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testFoo() throws Exception { // assert the message is routed to foo // use NotifyBuilder to wait for the file to be routed NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create(); // create a new file in the inbox folder with the name hello.txt and containing Hello World as body template.sendBodyAndHeader("file://target/inbox", "Hello Foo", Exchange.FILE_NAME, "hello.txt"); // notifier will wait for the file to be processed // and if that never happen it will time out after 10 seconds (default mock timeout) assertTrue(notify.matchesMockWaitTime()); // test the file was moved to the foo folder File target = new File("target/foo/hello.txt"); assertTrue("File should have been moved", target.exists()); // test that its content is correct as well String content = context.getTypeConverter().convertTo(String.class, target); assertEquals("Hello Foo", content); }
Example #23
Source File: BarTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testBar() throws Exception { // assert the message is routed to foo // use NotifyBuilder to wait for the file to be routed NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create(); // create a new file in the inbox folder with the name hello.txt and containing Hello World as body template.sendBodyAndHeader("file://target/inbox", "Hello Bar", Exchange.FILE_NAME, "hello.txt"); // notifier will wait for the file to be processed // and if that never happen it will time out after 10 seconds (default mock timeout) assertTrue(notify.matchesMockWaitTime()); // test the file was moved to the foo folder File target = new File("target/bar/hello.txt"); assertTrue("File should have been moved", target.exists()); // test that its content is correct as well String content = context.getTypeConverter().convertTo(String.class, target); assertEquals("Hello Bar", content); }
Example #24
Source File: ExistingRouteBuilderTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testMoveFile() throws Exception { // use NotifyBuilder to wait for the file to be routed NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create(); // create a new file in the inbox folder with the name hello.txt and containing Hello World as body template.sendBodyAndHeader("file://target/inbox", "Hello World", Exchange.FILE_NAME, "hello.txt"); // notifier will wait for the file to be processed // and if that never happen it will time out after 10 seconds (default mock timeout) assertTrue(notify.matchesMockWaitTime()); // test the file was moved File target = new File("target/outbox/hello.txt"); assertTrue("File should have been moved", target.exists()); // test that its content is correct as well String content = context.getTypeConverter().convertTo(String.class, target); assertEquals("Hello World", content); }
Example #25
Source File: FirstNoSleepTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testMoveFile() throws Exception { // use NotifyBuilder to wait for the file to be routed NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create(); // create a new file in the inbox folder with the name hello.txt and containing Hello World as body template.sendBodyAndHeader("file://target/inbox", "Hello World", Exchange.FILE_NAME, "hello.txt"); // notifier will wait for the file to be processed // and if that never happen it will time out after 10 seconds (default mock timeout) assertTrue(notify.matchesMockWaitTime()); // test the file was moved File target = new File("target/outbox/hello.txt"); assertTrue("File should have been moved", target.exists()); // test that its content is correct as well String content = context.getTypeConverter().convertTo(String.class, target); assertEquals("Hello World", content); }
Example #26
Source File: SpringXACommitTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testCommit() throws Exception { NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create(); jdbc.execute("insert into partner_metric (partner_id, time_occurred, status_code, perf_time) values ('123', '20170315183457', '200', '1503')"); assertTrue(notify.matches(10, TimeUnit.SECONDS)); // give time for database Thread.sleep(1000); // and there should be 0 rows in the database int rows = jdbc.queryForObject("select count(*) from partner_metric", Integer.class); assertEquals(0, rows); String order = consumer.receiveBody("activemq:queue:order", 2000, String.class); assertNotNull("Should be in order queue", order); context.stop(); }
Example #27
Source File: BigFileTest.java From camelinaction with Apache License 2.0 | 5 votes |
@Test public void testBigFile() throws Exception { // when the first exchange is done NotifyBuilder notify = new NotifyBuilder(context).whenDoneByIndex(0).create(); long start = System.currentTimeMillis(); System.out.println("Waiting to be done with 2 min timeout (use ctrl + c to stop)"); notify.matches(2 * 60, TimeUnit.SECONDS); long delta = System.currentTimeMillis() - start; System.out.println("Took " + delta / 1000 + " seconds"); }
Example #28
Source File: OpenTracingIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testOpenTracingComponent() throws Exception { CamelContext camelctx = new DefaultCamelContext(); OpenTracingTracer tracer = new OpenTracingTracer(); tracer.init(camelctx); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("seda:dude").routeId("dude") .log("routing at ${routeId}") .delay(simple("${random(1000,2000)}")); } }); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); NotifyBuilder notify = new NotifyBuilder(camelctx).whenDone(5).create(); for (int i = 0; i < 5; i++) { template.sendBody("seda:dude", "Hello World"); } Assert.assertTrue(notify.matches(30, TimeUnit.SECONDS)); } finally { camelctx.close(); } }
Example #29
Source File: SpringBigFileFixedThreadPoolTest.java From camelinaction with Apache License 2.0 | 5 votes |
@Test public void testBigFile() throws Exception { // when the first exchange is done NotifyBuilder notify = new NotifyBuilder(context).whenDoneByIndex(0).create(); long start = System.currentTimeMillis(); System.out.println("Waiting to be done with 2 min timeout (use ctrl + c to stop)"); notify.matches(2 * 60, TimeUnit.SECONDS); long delta = System.currentTimeMillis() - start; System.out.println("Took " + delta / 1000 + " seconds"); }
Example #30
Source File: OrderTest.java From camelinaction with Apache License 2.0 | 5 votes |
@Test public void testOrderClientValid() throws Exception { // notify when one message is done NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create(); // setup order information Calendar cal = Calendar.getInstance(Locale.US); cal.set(Calendar.YEAR, 2010); cal.set(Calendar.MONTH, Calendar.APRIL); cal.set(Calendar.DAY_OF_MONTH, 20); cal.set(Calendar.HOUR_OF_DAY, 7); cal.set(Calendar.MINUTE, 47); cal.set(Calendar.SECOND, 58); Date date = cal.getTime(); // send an order using the client OrderClient client = new OrderClient("tcp://localhost:61616"); client.sendOrder(123, date, "4444", "5555"); // use the notifier to wait for Camel to process the message // wait at most 5 seconds to avoid blocking forever if something goes wrong boolean matches = notify.matches(5, TimeUnit.SECONDS); // true means the notifier condition matched (= 1 message is done) assertTrue(matches); // should be one message in confirm queue BrowsableEndpoint be = context.getEndpoint("activemq:queue:confirm", BrowsableEndpoint.class); List<Exchange> list = be.getExchanges(); assertEquals(1, list.size()); assertEquals("OK,123,2010-04-20T07:47:58,4444,5555", list.get(0).getIn().getBody(String.class)); }