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/08/10 15:53:04 UTC

[camel] branch flaky2 created (now fd9270a2dc9)

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

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


      at fd9270a2dc9 CAMEL-19684: Fix flaky test

This branch includes the following new commits:

     new fd9270a2dc9 CAMEL-19684: Fix flaky test

The 1 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/01: CAMEL-19684: Fix flaky test

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

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

commit fd9270a2dc93fe5aeaa6425ead2a6adf3ba0cf0c
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Aug 10 17:52:46 2023 +0200

    CAMEL-19684: Fix flaky test
---
 .../org/apache/camel/impl/ScheduledPollConsumerTest.java    | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/ScheduledPollConsumerTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/ScheduledPollConsumerTest.java
index 7e9f69a8f76..84c4ec97d98 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/ScheduledPollConsumerTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/ScheduledPollConsumerTest.java
@@ -20,8 +20,11 @@ import org.apache.camel.Consumer;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Endpoint;
 import org.apache.camel.spi.PollingConsumerPollStrategy;
+import org.junit.jupiter.api.RepeatedTest;
 import org.junit.jupiter.api.Test;
 
+import java.util.concurrent.atomic.AtomicInteger;
+
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -29,12 +32,10 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 public class ScheduledPollConsumerTest extends ContextTestSupport {
 
     private static boolean rollback;
-    private static int counter;
     private static String event = "";
 
     @Test
     public void testExceptionOnPollAndCanStartAgain() throws Exception {
-
         final Exception expectedException = new Exception("Hello, I should be thrown on shutdown only!");
         final Endpoint endpoint = getMockEndpoint("mock:foo");
         MockScheduledPollConsumer consumer = new MockScheduledPollConsumer(endpoint, expectedException);
@@ -77,7 +78,7 @@ public class ScheduledPollConsumerTest extends ContextTestSupport {
 
     @Test
     public void testRetryAtMostThreeTimes() throws Exception {
-        counter = 0;
+        final AtomicInteger counter = new AtomicInteger();
         event = "";
 
         final Exception expectedException = new Exception("Hello, I should be thrown on shutdown only!");
@@ -95,8 +96,8 @@ public class ScheduledPollConsumerTest extends ContextTestSupport {
 
             public boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception e) throws Exception {
                 event += "rollback";
-                counter++;
-                if (retryCounter < 3) {
+                int cnt = counter.incrementAndGet();
+                if (cnt <= 3) {
                     return true;
                 }
                 return false;
@@ -111,7 +112,7 @@ public class ScheduledPollConsumerTest extends ContextTestSupport {
         consumer.stop();
 
         // 3 retries + 1 last failed attempt when we give up
-        assertEquals(4, counter);
+        assertEquals(4, counter.get());
         assertEquals("rollbackrollbackrollbackrollback", event);
     }