Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeout config to RetryTest and CircuitBreakerTimeoutTest #543

Merged
merged 2 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be 2018, 2020

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is wrong, then it's wrong almost everywhere.

If it needs fixed, we should probably do a mass change over the whole repo.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raised #545 for this.

*
* 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2018, 2020

*
* 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2016, 2020

*
* 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