Skip to content
Browse files

camel-283

  • Loading branch information...
1 parent ada4794 commit 3cf72118230dfd006e3af158ca934f5a73c31883 @scranton scranton committed Apr 23, 2012
View
10 chapter13/startup/src/test/java/camelinaction/ManualRouteWithOnCompletionTest.java
@@ -27,7 +27,7 @@
/**
* Testing how to stop a route when its done using on completion.
*
- * @version $Revision: 257 $
+ * @version $Revision: 333 $
*/
public class ManualRouteWithOnCompletionTest extends CamelTestSupport {
@@ -73,11 +73,11 @@ public void testManualRouteWithOnCompletion() throws Exception {
assertMockEndpointsSatisfied();
// wait for the route to be done
- notify.matches(5, TimeUnit.SECONDS);
-
- // we gotta wait just a little extra to stop
- Thread.sleep(5000);
+ boolean matches = notify.matches(5, TimeUnit.SECONDS);
+ assertTrue("Should match notifier", matches);
+ // we gotta wait just a little extra to stop, before querying status
+ Thread.sleep(1000);
// it should have stopped itself
assertTrue("Route should be stopped", context.getRouteStatus("manual").isStopped());
}
View
24 chapter13/startup/src/test/java/camelinaction/ManualRouteWithStop.java
@@ -16,9 +16,14 @@
*/
package camelinaction;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.TimeUnit;
+
import camelinaction.inventory.UpdateInventoryInput;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
+import org.apache.camel.ShutdownRunningTask;
import org.apache.camel.builder.RouteBuilder;
/**
@@ -27,7 +32,7 @@
* <p/>
* You should start the route using JConsole and stop it again after use.
*
- * @version $Revision: 259 $
+ * @version $Revision: 333 $
*/
public class ManualRouteWithStop extends RouteBuilder {
@@ -51,12 +56,25 @@ public void process(Exchange exchange) throws Exception {
// pickup more files then you have to start the route
// manually again.
+ // IMPORTANT: This is no longer possible from Camel 2.8.3 onwards
+ // as stopping the route should be done from a separate thread
// force stopping this route while we are routing an Exchange
// requires two steps:
// 1) unregister from the inflight registry
- // 2) stop the route
+ // 2) stop the route using a separate thread which is required
+ // from Camel 2.8.3 onwards.
getContext().getInflightRepository().remove(exchange);
- getContext().stopRoute("manual");
+
+ // spawn a thread to stop the route
+ ExecutorService executor = getContext().getExecutorServiceStrategy().newSingleThreadExecutor(this, "StopRouteManually");
+ executor.submit(new Callable<Object>() {
+ @Override
+ public Object call() throws Exception {
+ log.info("Stopping route manually");
+ getContext().stopRoute("manual");
+ return null;
+ }
+ });
}
});
}
View
10 chapter13/startup/src/test/java/camelinaction/ManualRouteWithStopTest.java
@@ -27,7 +27,7 @@
/**
* Test to show how to stop a route when its done.
*
- * @version $Revision: 257 $
+ * @version $Revision: 333 $
*/
public class ManualRouteWithStopTest extends CamelTestSupport {
@@ -73,11 +73,11 @@ public void testManualRouteWithStop() throws Exception {
assertMockEndpointsSatisfied();
// wait for the route to be done
- notify.matches(5, TimeUnit.SECONDS);
-
- // we gotta wait just a little extra to stop
- Thread.sleep(3000);
+ boolean matches = notify.matches(5, TimeUnit.SECONDS);
+ assertTrue("Should match notifier", matches);
+ // we gotta wait just a little extra to stop, before querying status
+ Thread.sleep(1000);
// it should have stopped itself
assertTrue("Route should be stopped", context.getRouteStatus("manual").isStopped());
}
View
6 chapter9/xa/src/test/java/camelinaction/AtomikosXARollbackAfterDbTest.java
@@ -28,7 +28,7 @@
import org.springframework.jdbc.core.JdbcTemplate;
/**
- * @version $Revision: 214 $
+ * @version $Revision: 332 $
*/
public class AtomikosXARollbackAfterDbTest extends CamelSpringTestSupport {
@@ -86,10 +86,10 @@ protected RouteBuilder createRouteBuilder() throws Exception {
public void configure() throws Exception {
from("activemq:queue:partners")
.transacted()
- .log("+++ before database +++")
+ .log("*** before database ***")
.bean(PartnerServiceBean.class, "toSql")
.to("jdbc:myDataSource")
- .log("+++ after database +++")
+ .log("*** after database ***")
.throwException(new IllegalArgumentException("Forced failure after DB"));
}
};
View
6 chapter9/xa/src/test/java/camelinaction/AtomikosXARollbackBeforeDbTest.java
@@ -28,7 +28,7 @@
import org.springframework.jdbc.core.JdbcTemplate;
/**
- * @version $Revision: 214 $
+ * @version $Revision: 332 $
*/
public class AtomikosXARollbackBeforeDbTest extends CamelSpringTestSupport {
@@ -87,10 +87,10 @@ protected RouteBuilder createRouteBuilder() throws Exception {
public void configure() throws Exception {
from("activemq:queue:partners")
.transacted()
- .log("+++ before database +++")
+ .log("*** before database ***")
.bean(PartnerServiceBean.class, "toSql")
.to("jdbc:myDataSource")
- .log("+++ after database +++")
+ .log("*** after database ***")
.throwException(new IllegalArgumentException("Forced failure after DB"));
}
};
View
4 pom.xml
@@ -70,8 +70,8 @@
<properties>
<activemq-version>5.5.1</activemq-version>
- <camel-version>2.8.2</camel-version>
- <cxf-version>2.4.3</cxf-version>
+ <camel-version>2.8.3</camel-version>
+ <cxf-version>2.4.4</cxf-version>
<hsqldb-version>1.8.0.7</hsqldb-version>
<junit-version>4.8.1</junit-version>
<log4j-version>1.2.16</log4j-version>

0 comments on commit 3cf7211

Please sign in to comment.
Something went wrong with that request. Please try again.