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 16:52:33 UTC
[camel] branch main updated: CAMEL-19684: Fix flaky test (#11071)
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 b6da9e2b5bd CAMEL-19684: Fix flaky test (#11071)
b6da9e2b5bd is described below
commit b6da9e2b5bd664ced1b5be3548e215cbd687be54
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Aug 10 18:52:26 2023 +0200
CAMEL-19684: Fix flaky test (#11071)
---
.../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);
}