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 10:44:42 UTC

[camel] branch main updated: Polish (#10816)

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

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


The following commit(s) were added to refs/heads/main by this push:
     new ab327a348b5 Polish (#10816)
ab327a348b5 is described below

commit ab327a348b5fef79e904e464ffc113d9686a82e7
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Jul 25 12:44:36 2023 +0200

    Polish (#10816)
    
    * camel-quartz - Use same version of commons-pool2
    
    * camel-quartz: Use awailability instead of thread sleep in unit tests
    
    * Polish
---
 components/camel-quartz/pom.xml                    | 12 +++++++
 .../quartz/SpringScheduledRoutePolicyTest.java     | 38 +++++++++-------------
 .../camel/routepolicy/quartz/CronPolicies.xml      |  8 ++---
 .../camel/routepolicy/quartz/SimplePolicies.xml    | 10 +++---
 4 files changed, 37 insertions(+), 31 deletions(-)

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 -->
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..40a50180a4e 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,8 @@ 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 +67,28 @@ 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 +101,8 @@ 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">