Speedup test

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5b14e46c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5b14e46c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5b14e46c

Branch: refs/heads/master
Commit: 5b14e46c38d1da813ad77485e1159f2ed70f05e1
Parents: 5974b3f
Author: Claus Ibsen <davscl...@apache.org>
Authored: Wed Sep 6 10:49:41 2017 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Wed Sep 6 10:49:41 2017 +0200

----------------------------------------------------------------------
 components/camel-spring-boot/pom.xml            |  5 +++
 .../SupervisingRouteControllerRestartTest.java  | 35 +++++++++++---------
 2 files changed, 24 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5b14e46c/components/camel-spring-boot/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/pom.xml 
b/components/camel-spring-boot/pom.xml
index 1b814e6..a6090c4 100644
--- a/components/camel-spring-boot/pom.xml
+++ b/components/camel-spring-boot/pom.xml
@@ -93,6 +93,11 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>org.awaitility</groupId>
+      <artifactId>awaitility</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
       <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/camel/blob/5b14e46c/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SupervisingRouteControllerRestartTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SupervisingRouteControllerRestartTest.java
 
b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SupervisingRouteControllerRestartTest.java
index 3d8b815..605cf01 100644
--- 
a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SupervisingRouteControllerRestartTest.java
+++ 
b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SupervisingRouteControllerRestartTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.spring.boot;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.ServiceStatus;
 import org.apache.camel.builder.RouteBuilder;
@@ -32,6 +34,8 @@ import org.springframework.context.annotation.Configuration;
 import org.springframework.test.annotation.DirtiesContext;
 import org.springframework.test.context.junit4.SpringRunner;
 
+import static org.awaitility.Awaitility.await;
+
 @DirtiesContext
 @RunWith(SpringRunner.class)
 @SpringBootTest(
@@ -58,27 +62,25 @@ public class SupervisingRouteControllerRestartTest {
     private CamelContext context;
 
     @Test
-    public void test() throws Exception {
+    public void testRouteRestart() throws Exception {
         Assert.assertNotNull(context.getRouteController());
         Assert.assertTrue(context.getRouteController() instanceof 
SupervisingRouteController);
 
         SupervisingRouteController controller = 
context.getRouteController().unwrap(SupervisingRouteController.class);
 
         // Wait for the controller to start the routes
-        Thread.sleep(2500);
-
-        Assert.assertEquals(ServiceStatus.Started, 
context.getRouteStatus("foo"));
-        Assert.assertEquals(ServiceStatus.Started, 
context.getRouteStatus("bar"));
-        Assert.assertEquals(ServiceStatus.Started, 
context.getRouteStatus("dummy"));
-
-        // Wait a little
-        Thread.sleep(250);
-
+        await().atMost(3, TimeUnit.SECONDS).untilAsserted(() -> {
+            // now its suspended by the policy
+            Assert.assertEquals(ServiceStatus.Started, 
context.getRouteStatus("foo"));
+            Assert.assertEquals(ServiceStatus.Started, 
context.getRouteStatus("bar"));
+            Assert.assertEquals(ServiceStatus.Started, 
context.getRouteStatus("dummy"));
+        });
+
+        // restart the dummy route which should fail on first attempt
         controller.stopRoute("dummy");
 
         
Assert.assertNull(context.getRoute("dummy").getRouteContext().getRouteController());
 
-        // dummy will fail on first restart
         try {
             controller.startRoute("dummy");
         } catch (Exception e) {
@@ -90,11 +92,12 @@ public class SupervisingRouteControllerRestartTest {
         
Assert.assertTrue(controller.getBackOffContext("dummy").get().getCurrentAttempts()
 > 0);
 
         // Wait for wile to give time to the controller to start the route
-        Thread.sleep(1500);
-
-        Assert.assertEquals(ServiceStatus.Started, 
context.getRouteStatus("dummy"));
-        
Assert.assertNotNull(context.getRoute("dummy").getRouteContext().getRouteController());
-        Assert.assertFalse(controller.getBackOffContext("dummy").isPresent());
+        await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> {
+            // now its suspended by the policy
+            Assert.assertEquals(ServiceStatus.Started, 
context.getRouteStatus("dummy"));
+            
Assert.assertNotNull(context.getRoute("dummy").getRouteContext().getRouteController());
+            
Assert.assertFalse(controller.getBackOffContext("dummy").isPresent());
+        });
     }
 
     // *************************************

Reply via email to