From d501265857a157827c64bed1017b852bba873a6c Mon Sep 17 00:00:00 2001 From: Andrew Rouse Date: Thu, 14 May 2020 13:38:11 +0100 Subject: [PATCH 1/2] Add timeout configuration to RetryTest Signed-off-by: Andrew Rouse --- .../fault/tolerance/tck/RetryTest.java | 9 ++++++-- .../clientserver/RetryClientWithDelay.java | 23 +++++++++---------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/RetryTest.java b/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/RetryTest.java index 33d4e4ed..6e260c84 100644 --- a/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/RetryTest.java +++ b/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/RetryTest.java @@ -21,6 +21,7 @@ import javax.inject.Inject; +import org.eclipse.microprofile.fault.tolerance.tck.config.ConfigAnnotationAsset; import org.eclipse.microprofile.fault.tolerance.tck.retry.clientserver.RetryClassLevelClientForMaxRetries; import org.eclipse.microprofile.fault.tolerance.tck.retry.clientserver.RetryClientForMaxRetries; import org.eclipse.microprofile.fault.tolerance.tck.retry.clientserver.RetryClientWithDelay; @@ -50,6 +51,10 @@ public class RetryTest extends Arquillian { @Deployment public static WebArchive deploy() { + + ConfigAnnotationAsset config = new ConfigAnnotationAsset() + .autoscaleMethod(RetryClientWithDelay.class, "serviceA"); + JavaArchive testJar = ShrinkWrap .create(JavaArchive.class, "ftRetry.jar") .addClasses(RetryClientForMaxRetries.class, @@ -57,7 +62,7 @@ public static WebArchive deploy() { RetryClassLevelClientForMaxRetries.class, RetryClientWithNoDelayAndJitter.class) .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") - .as(JavaArchive.class); + .addAsManifestResource(config, "microprofile-config.properties"); WebArchive war = ShrinkWrap .create(WebArchive.class, "ftRetry.war") @@ -129,7 +134,7 @@ public void testRetryWithDelay() { Assert.assertTrue(retryCountForConnectionService > 4, "The max number of execution should be greater than 4 but it was " + retryCountForConnectionService); - Assert.assertTrue(clientForDelay.isDelayInRange(), "The delay between each retry should be 0-800ms"); + clientForDelay.assertDelayInRange(); } /** diff --git a/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/retry/clientserver/RetryClientWithDelay.java b/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/retry/clientserver/RetryClientWithDelay.java index 72d47724..10d6eaad 100644 --- a/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/retry/clientserver/RetryClientWithDelay.java +++ b/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/retry/clientserver/RetryClientWithDelay.java @@ -1,6 +1,6 @@ /* ******************************************************************************* - * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation + * Copyright (c) 2016-2020 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. @@ -19,6 +19,10 @@ *******************************************************************************/ package org.eclipse.microprofile.fault.tolerance.tck.retry.clientserver; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.everyItem; +import static org.hamcrest.Matchers.lessThan; + import java.sql.Connection; import java.time.Duration; import java.util.HashSet; @@ -26,6 +30,7 @@ import javax.enterprise.context.RequestScoped; +import org.eclipse.microprofile.fault.tolerance.tck.util.TCKConfig; import org.eclipse.microprofile.faulttolerance.Retry; /** * A client to demonstrate the delay configurations @@ -38,12 +43,12 @@ public class RetryClientWithDelay { private long timestampForConnectionService = 0; private Set delayTimes = new HashSet<>(); - // Expect delay between 0-800ms. Set limit to 900ms to allow a small buffer - private static final Duration MAX_DELAY = Duration.ofMillis(900); + // Expect delay between 0-800ms. Set limit to 1000ms to allow a small buffer + private static final Duration MAX_DELAY = TCKConfig.getConfig().getTimeoutInDuration(1000); //There should be 0-800ms (jitter is -400ms - 400ms) delays between each invocation //there should be at least 4 retries - @Retry(delay = 400, maxDuration= 3200, jitter= 400, maxRetries = 10) + @Retry(delay = 400, maxDuration = 3200, jitter = 400, maxRetries = 10) // Adjusted by config public Connection serviceA() { return connectionService(); } @@ -61,14 +66,8 @@ private Connection connectionService() { throw new RuntimeException("Connection failed"); } - public boolean isDelayInRange() { - boolean isDelayInRange = true; - for (Duration delayTime : delayTimes) { - if (delayTime.compareTo(MAX_DELAY) > 0) { - return false; - } - } - return isDelayInRange; + public void assertDelayInRange() { + assertThat("Delay longer than expected", delayTimes, everyItem(lessThan(MAX_DELAY))); } public int getRetryCountForConnectionService() { From e9f6fc09e765e45a0366d5fa65248b423f8ad8b9 Mon Sep 17 00:00:00 2001 From: Andrew Rouse Date: Fri, 15 May 2020 10:25:52 +0100 Subject: [PATCH 2/2] Add timeout config to CircuitBreakerTimeoutTest Signed-off-by: Andrew Rouse --- .../tolerance/tck/CircuitBreakerTimeoutTest.java | 9 +++++++-- .../clientserver/CircuitBreakerClientWithTimeout.java | 11 ++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/CircuitBreakerTimeoutTest.java b/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/CircuitBreakerTimeoutTest.java index 54b2ab1b..e7d3d90d 100644 --- a/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/CircuitBreakerTimeoutTest.java +++ b/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/CircuitBreakerTimeoutTest.java @@ -1,6 +1,6 @@ /* ******************************************************************************* - * Copyright (c) 2018 Contributors to the Eclipse Foundation + * Copyright (c) 2018-2020 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. @@ -22,6 +22,7 @@ import javax.inject.Inject; import org.eclipse.microprofile.fault.tolerance.tck.circuitbreaker.clientserver.CircuitBreakerClientWithTimeout; +import org.eclipse.microprofile.fault.tolerance.tck.config.ConfigAnnotationAsset; import org.eclipse.microprofile.fault.tolerance.tck.util.Exceptions; import org.eclipse.microprofile.fault.tolerance.tck.util.Packages; import org.jboss.arquillian.container.test.api.Deployment; @@ -41,11 +42,15 @@ public class CircuitBreakerTimeoutTest extends Arquillian { @Deployment public static WebArchive deploy() { + ConfigAnnotationAsset config = new ConfigAnnotationAsset() + .autoscaleMethod(CircuitBreakerClientWithTimeout.class, "serviceWithTimeout") + .autoscaleMethod(CircuitBreakerClientWithTimeout.class, "serviceWithTimeoutWithoutFailOn"); + JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, "ftCircuitBreakerTimeout.jar") .addClasses(CircuitBreakerClientWithTimeout.class) .addPackage(Packages.UTILS) .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") - .as(JavaArchive.class); + .addAsManifestResource(config, "microprofile-config.properties"); WebArchive war = ShrinkWrap.create(WebArchive.class, "ftCircuitBreakerTimeout.war") .addAsLibrary(testJar); diff --git a/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/circuitbreaker/clientserver/CircuitBreakerClientWithTimeout.java b/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/circuitbreaker/clientserver/CircuitBreakerClientWithTimeout.java index c1853212..59116d97 100644 --- a/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/circuitbreaker/clientserver/CircuitBreakerClientWithTimeout.java +++ b/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/circuitbreaker/clientserver/CircuitBreakerClientWithTimeout.java @@ -1,6 +1,6 @@ /* ******************************************************************************* - * Copyright (c) 2018 Contributors to the Eclipse Foundation + * Copyright (c) 2018-2020 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. @@ -23,6 +23,7 @@ import javax.enterprise.context.RequestScoped; +import org.eclipse.microprofile.fault.tolerance.tck.util.TCKConfig; import org.eclipse.microprofile.faulttolerance.CircuitBreaker; import org.eclipse.microprofile.faulttolerance.Timeout; import org.eclipse.microprofile.faulttolerance.exceptions.BulkheadException; @@ -38,10 +39,10 @@ public class CircuitBreakerClientWithTimeout { * @return should always throw TimeoutException, unless CircuitBreaker prevents execution */ @CircuitBreaker(successThreshold = 2, requestVolumeThreshold = 2, failureRatio = 0.75, delay = 50000) - @Timeout(500) + @Timeout(500) // Adjusted by config public String serviceWithTimeout() { try { - Thread.sleep(1000); + Thread.sleep(TCKConfig.getConfig().getTimeoutInMillis(1000)); fail("Thread not interrupted by timeout"); } catch (InterruptedException e) { @@ -60,10 +61,10 @@ public String serviceWithTimeout() { * @return should always throw TimeoutException */ @CircuitBreaker(successThreshold = 2, requestVolumeThreshold = 2, failureRatio = 0.75, delay = 50000, failOn = BulkheadException.class) - @Timeout(500) + @Timeout(500) // Adjusted by config public String serviceWithTimeoutWithoutFailOn() { try { - Thread.sleep(1000); + Thread.sleep(TCKConfig.getConfig().getTimeoutInMillis(1000)); fail("Thread not interrupted by timeout"); } catch (InterruptedException e) {