You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/07/25 08:59:16 UTC

[camel] branch polish created (now 7f133b51bc9)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch polish
in repository https://gitbox.apache.org/repos/asf/camel.git


      at 7f133b51bc9 camel-quartz: Use awailability instead of thread sleep in unit tests

This branch includes the following new commits:

     new a3a687f2db3 camel-quartz - Use same version of commons-pool2
     new 7f133b51bc9 camel-quartz: Use awailability instead of thread sleep in unit tests

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[camel] 01/02: camel-quartz - Use same version of commons-pool2

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch polish
in repository https://gitbox.apache.org/repos/asf/camel.git

commit a3a687f2db3f42a75e1575be63018bad251b001f
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Jul 25 10:46:56 2023 +0200

    camel-quartz - Use same version of commons-pool2
---
 components/camel-quartz/pom.xml | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/components/camel-quartz/pom.xml b/components/camel-quartz/pom.xml
index d3599f80275..4524e98d4e3 100644
--- a/components/camel-quartz/pom.xml
+++ b/components/camel-quartz/pom.xml
@@ -85,11 +85,23 @@
             <artifactId>camel-management</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-pool2</artifactId>
+            <version>${commons-pool2-version}</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-dbcp2</artifactId>
             <version>${commons-dbcp2-version}</version>
             <scope>test</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>commons-logging</groupId>
+                    <artifactId>commons-logging</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
 
         <!-- for persistent test -->


[camel] 02/02: camel-quartz: Use awailability instead of thread sleep in unit tests

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch polish
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 7f133b51bc99084783f3bc93746acc6e646c37cf
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Jul 25 10:59:01 2023 +0200

    camel-quartz: Use awailability instead of thread sleep in unit tests
---
 .../quartz/SpringScheduledRoutePolicyTest.java     | 46 +++++++++++-----------
 .../camel/routepolicy/quartz/CronPolicies.xml      |  8 ++--
 .../camel/routepolicy/quartz/SimplePolicies.xml    | 10 ++---
 3 files changed, 33 insertions(+), 31 deletions(-)

diff --git a/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringScheduledRoutePolicyTest.java b/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringScheduledRoutePolicyTest.java
index f0388677b95..1f415bb60ed 100644
--- a/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringScheduledRoutePolicyTest.java
+++ b/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringScheduledRoutePolicyTest.java
@@ -28,9 +28,11 @@ import org.apache.camel.model.ModelCamelContext;
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.spi.RoutePolicy;
 import org.apache.camel.support.service.ServiceHelper;
+import org.awaitility.Awaitility;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 
 import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public abstract class SpringScheduledRoutePolicyTest {
@@ -54,8 +56,10 @@ public abstract class SpringScheduledRoutePolicyTest {
 
         context.getRouteController().stopRoute("testRoute", 1000, TimeUnit.MILLISECONDS);
 
-        Thread.sleep(4000);
-        assertSame(ServiceStatus.Started, context.getRouteController().getRouteStatus("testRoute"));
+        Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
+            assertSame(ServiceStatus.Started, context.getRouteController().getRouteStatus("testRoute"));
+        });
+
         context.createProducerTemplate().sendBody("direct:start?timeout=1000", "Ready or not, Here, I come");
 
         context.stop();
@@ -65,37 +69,32 @@ public abstract class SpringScheduledRoutePolicyTest {
     public void stopTest() throws Exception {
         setUp();
 
-        boolean consumerStopped = false;
-
         CamelContext context = startRouteWithPolicy("stopPolicy");
 
-        Thread.sleep(4000);
-        assertSame(ServiceStatus.Stopped, context.getRouteController().getRouteStatus("testRoute"));
-        try {
-            context.createProducerTemplate().sendBody("direct:start?timeout=1000", "Ready or not, Here, I come");
-        } catch (CamelExecutionException e) {
-            consumerStopped = true;
-        }
+        Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
+            assertSame(ServiceStatus.Stopped, context.getRouteController().getRouteStatus("testRoute"));
+        });
+
+        assertThrows(CamelExecutionException.class,
+                () -> context.createProducerTemplate().sendBody("direct:start?timeout=1000", "Ready or not, Here, I come"));
+
         context.stop();
-        assertTrue(consumerStopped);
     }
 
     public void suspendTest() throws Exception {
         setUp();
 
-        boolean consumerSuspended = false;
-
         CamelContext context = startRouteWithPolicy("suspendPolicy");
 
-        Thread.sleep(4000);
-        try {
-            context.createProducerTemplate().sendBody("direct:start?timeout=1000", "Ready or not, Here, I come");
-        } catch (CamelExecutionException e) {
-            consumerSuspended = true;
-        }
+        // wait for route to suspend
+        Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
+            assertTrue(ServiceHelper.isSuspended(context.getRoute("testRoute").getConsumer()));
+        });
+
+        assertThrows(CamelExecutionException.class,
+                () -> context.createProducerTemplate().sendBody("direct:start?timeout=1000", "Ready or not, Here, I come"));
 
         context.stop();
-        assertTrue(consumerSuspended);
     }
 
     public void resumeTest() throws Exception {
@@ -108,7 +107,10 @@ public abstract class SpringScheduledRoutePolicyTest {
 
         ServiceHelper.suspendService(context.getRoute("testRoute").getConsumer());
 
-        Thread.sleep(4000);
+        Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
+            assertTrue(ServiceHelper.isStarted(context.getRoute("testRoute").getConsumer()));
+        });
+
         context.createProducerTemplate().sendBody("direct:start?timeout=1000", "Ready or not, Here, I come");
 
         context.stop();
diff --git a/components/camel-quartz/src/test/resources/org/apache/camel/routepolicy/quartz/CronPolicies.xml b/components/camel-quartz/src/test/resources/org/apache/camel/routepolicy/quartz/CronPolicies.xml
index edc91aa17d8..4c66166a56e 100644
--- a/components/camel-quartz/src/test/resources/org/apache/camel/routepolicy/quartz/CronPolicies.xml
+++ b/components/camel-quartz/src/test/resources/org/apache/camel/routepolicy/quartz/CronPolicies.xml
@@ -27,19 +27,19 @@
   <bean id="defaultPolicy" class="org.apache.camel.routepolicy.quartz.CronScheduledRoutePolicy"/>
 
   <bean id="startPolicy" class="org.apache.camel.routepolicy.quartz.CronScheduledRoutePolicy">
-    <property name="routeStartTime" value="*/3 * * * * ?"/>
+    <property name="routeStartTime" value="*/1 * * * * ?"/>
   </bean>
 
   <bean id="stopPolicy" class="org.apache.camel.routepolicy.quartz.CronScheduledRoutePolicy">
-    <property name="routeStopTime" value="*/3 * * * * ?"/>
+    <property name="routeStopTime" value="*/1 * * * * ?"/>
   </bean>
 
   <bean id="suspendPolicy" class="org.apache.camel.routepolicy.quartz.CronScheduledRoutePolicy">
-    <property name="routeSuspendTime" value="*/3 * * * * ?"/>
+    <property name="routeSuspendTime" value="*/1 * * * * ?"/>
   </bean>
 
   <bean id="resumePolicy" class="org.apache.camel.routepolicy.quartz.CronScheduledRoutePolicy">
-    <property name="routeResumeTime" value="*/3 * * * * ?"/>
+    <property name="routeResumeTime" value="*/1 * * * * ?"/>
   </bean>
 
   <bean id="direct" class="org.apache.camel.component.direct.DirectComponent">
diff --git a/components/camel-quartz/src/test/resources/org/apache/camel/routepolicy/quartz/SimplePolicies.xml b/components/camel-quartz/src/test/resources/org/apache/camel/routepolicy/quartz/SimplePolicies.xml
index dea8d06104a..c61d0b7b0e6 100644
--- a/components/camel-quartz/src/test/resources/org/apache/camel/routepolicy/quartz/SimplePolicies.xml
+++ b/components/camel-quartz/src/test/resources/org/apache/camel/routepolicy/quartz/SimplePolicies.xml
@@ -25,7 +25,7 @@
     ">
 
   <bean id="now" class="org.apache.camel.routepolicy.quartz.DateFactory" factory-method="createDate">
-    <constructor-arg index="0" value="3000"/>
+    <constructor-arg index="0" value="1000"/>
   </bean>
 
   <bean id="defaultPolicy" class="org.apache.camel.routepolicy.quartz.SimpleScheduledRoutePolicy"/>
@@ -33,25 +33,25 @@
   <bean id="startPolicy" class="org.apache.camel.routepolicy.quartz.SimpleScheduledRoutePolicy">
     <property name="routeStartDate" ref="now"/>
     <property name="routeStartRepeatCount" value="1"/>
-    <property name="routeStartRepeatInterval" value="3000"/>
+    <property name="routeStartRepeatInterval" value="1000"/>
   </bean>
 
   <bean id="stopPolicy" class="org.apache.camel.routepolicy.quartz.SimpleScheduledRoutePolicy">
     <property name="routeStopDate" ref="now"/>
     <property name="routeStopRepeatCount" value="1"/>
-    <property name="routeStopRepeatInterval" value="3000"/>
+    <property name="routeStopRepeatInterval" value="1000"/>
   </bean>
 
   <bean id="suspendPolicy" class="org.apache.camel.routepolicy.quartz.SimpleScheduledRoutePolicy">
     <property name="routeSuspendDate" ref="now"/>
     <property name="routeSuspendRepeatCount" value="1"/>
-    <property name="routeSuspendRepeatInterval" value="3000"/>
+    <property name="routeSuspendRepeatInterval" value="1000"/>
   </bean>
 
   <bean id="resumePolicy" class="org.apache.camel.routepolicy.quartz.SimpleScheduledRoutePolicy">
     <property name="routeResumeDate" ref="now"/>
     <property name="routeResumeRepeatCount" value="1"/>
-    <property name="routeResumeRepeatInterval" value="3000"/>
+    <property name="routeResumeRepeatInterval" value="1000"/>
   </bean>
 
   <bean id="direct" class="org.apache.camel.component.direct.DirectComponent">