Skip to content

Commit

Permalink
Merge pull request #547 from Azquelt/retry-delay-timeout-config-20
Browse files Browse the repository at this point in the history
[FT 2.0] Add timeout configuration to RetryTest and CircuitBreakerTimeoutTest
  • Loading branch information
Emily-Jiang authored May 18, 2020
2 parents eb56628 + 6747d87 commit a7fe4fd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,14 +51,18 @@ 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,
RetryClientWithDelay.class,
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")
Expand Down Expand Up @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -19,13 +19,18 @@
*******************************************************************************/
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;
import java.util.Set;

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
Expand All @@ -38,12 +43,12 @@ public class RetryClientWithDelay {
private long timestampForConnectionService = 0;
private Set<Duration> 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();
}
Expand All @@ -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() {
Expand Down

0 comments on commit a7fe4fd

Please sign in to comment.