Skip to content

Commit

Permalink
Merge pull request #546 from Azquelt/retry-delay-timeout-config-21
Browse files Browse the repository at this point in the history
[FT 2.1] Add timeout configuration to RetryTest and CircuitBreakerTimeoutTest
  • Loading branch information
Emily-Jiang committed May 18, 2020
2 parents b26a6d1 + e9f6fc0 commit 126192e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
@@ -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
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
@@ -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
@@ -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 126192e

Please sign in to comment.