This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch derby in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/derby by this push: new e488b34aef5 Flaky test e488b34aef5 is described below commit e488b34aef5893e3d3e8405dd440e4fd00443aba Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sat Jul 22 11:13:38 2023 +0200 Flaky test --- .../jdbc/AbstractJdbcAggregationTestSupport.java | 34 ++++++++++++++++++++-- .../JdbcAggregationRepositoryAlotDataTest.java | 6 ++-- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/components/camel-sql/src/test/java/org/apache/camel/processor/aggregate/jdbc/AbstractJdbcAggregationTestSupport.java b/components/camel-sql/src/test/java/org/apache/camel/processor/aggregate/jdbc/AbstractJdbcAggregationTestSupport.java index b4bc1cc8ff3..d30bdda85de 100644 --- a/components/camel-sql/src/test/java/org/apache/camel/processor/aggregate/jdbc/AbstractJdbcAggregationTestSupport.java +++ b/components/camel-sql/src/test/java/org/apache/camel/processor/aggregate/jdbc/AbstractJdbcAggregationTestSupport.java @@ -19,7 +19,9 @@ package org.apache.camel.processor.aggregate.jdbc; import org.apache.camel.AggregationStrategy; import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.spi.OptimisticLockingAggregationRepository; import org.apache.camel.test.spring.junit5.CamelSpringTestSupport; +import org.apache.camel.util.ObjectHelper; import org.springframework.context.support.AbstractApplicationContext; public abstract class AbstractJdbcAggregationTestSupport extends CamelSpringTestSupport { @@ -65,9 +67,35 @@ public abstract class AbstractJdbcAggregationTestSupport extends CamelSpringTest } protected Exchange repoAddAndGet(String key, Exchange exchange) { - repo.add(context, key, exchange); - // recover the exchange with the new version to be able to add again - exchange = repo.get(context, key); + return repoAddAndGet(key, exchange, true); + } + + protected Exchange repoAddAndGet(String key, Exchange exchange, boolean optimistic) { + int retry = optimistic ? 5 : 1; + while (retry-- > 0) { + try { + repo.add(context, key, exchange); + // recover the exchange with the new version to be able to add again + exchange = repo.get(context, key); + return exchange; + } catch (Exception e) { + if (optimistic) { + OptimisticLockingAggregationRepository.OptimisticLockingException ole + = ObjectHelper.getException(OptimisticLockingAggregationRepository.OptimisticLockingException.class, + e); + if (ole != null) { + // okay lets try again + try { + Thread.sleep(50); + } catch (InterruptedException ex) { + // ignore + } + continue; + } + } + throw e; + } + } return exchange; } diff --git a/components/camel-sql/src/test/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepositoryAlotDataTest.java b/components/camel-sql/src/test/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepositoryAlotDataTest.java index 151a135268b..5adf977f952 100644 --- a/components/camel-sql/src/test/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepositoryAlotDataTest.java +++ b/components/camel-sql/src/test/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepositoryAlotDataTest.java @@ -31,7 +31,7 @@ public class JdbcAggregationRepositoryAlotDataTest extends AbstractJdbcAggregati Exchange exchange = new DefaultExchange(context); for (int i = 0; i < 100; i++) { exchange.getIn().setBody("counter:" + i); - exchange = repoAddAndGet(key, exchange); + exchange = repoAddAndGet(key, exchange, false); } // Get it back.. @@ -46,7 +46,7 @@ public class JdbcAggregationRepositoryAlotDataTest extends AbstractJdbcAggregati Exchange exchange = new DefaultExchange(context); exchange.getIn().setBody("counter:" + i); String key = i % 2 == 0 ? "foo" : "bar"; - repoAddAndGet(key, exchange); + repoAddAndGet(key, exchange, false); } }); } @@ -57,7 +57,7 @@ public class JdbcAggregationRepositoryAlotDataTest extends AbstractJdbcAggregati Exchange exchange = new DefaultExchange(context); exchange.getIn().setBody("counter:" + i); String key = "key" + i; - repoAddAndGet(key, exchange); + repoAddAndGet(key, exchange, false); } // Get it back..