Skip to content

Commit

Permalink
Merge pull request #619 from benjamin-confino/master
Browse files Browse the repository at this point in the history
This PR replaces all expected RuntimeExceptions with TestException. T…
  • Loading branch information
Azquelt authored Feb 20, 2024
2 parents 10975ed + a6fffc7 commit 1527c6a
Show file tree
Hide file tree
Showing 59 changed files with 380 additions and 321 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.eclipse.microprofile.fault.tolerance.tck.Misc.Ints.contains;

import org.eclipse.microprofile.fault.tolerance.tck.circuitbreaker.clientserver.CircuitBreakerClientDefaultSuccessThreshold;
import org.eclipse.microprofile.fault.tolerance.tck.util.TestException;
import org.eclipse.microprofile.faulttolerance.exceptions.CircuitBreakerOpenException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.testng.Arquillian;
Expand Down Expand Up @@ -49,7 +50,8 @@ public class CircuitBreakerInitialSuccessTest extends Arquillian {
public static WebArchive deploy() {
JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, "ftCircuitBreakerInitialSuccess.jar")
.addClasses(CircuitBreakerClientDefaultSuccessThreshold.class,
Misc.class)
Misc.class,
TestException.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
.as(JavaArchive.class);

Expand All @@ -63,12 +65,12 @@ public static WebArchive deploy() {
*
* With requestVolumeThreshold = 4, failureRatio=0.75 and successThreshold = 1 the expected behaviour is,
*
* Execution Behaviour ========= ========= 1 SUCCESS 2 RunTimeException 3 RunTimeException 4 RunTimeException 5
* Execution Behaviour ========= ========= 1 SUCCESS 2 TestException 3 TestException 4 TestException 5
* CircuitBreakerOpenException Pause for longer than CircuitBreaker delay, so that it transitions to half-open 6
* SUCCEED (CircuitBreaker will be re-closed as successThreshold is 1. The impact of the success of the service and
* the closure of the Circuit is to reset the rolling failure window to an empty state. Therefore another 4 requests
* need to be made - of which at least 3 need to fail - for the Circuit to open again) 7 SUCCESS 8 RunTimeException
* 9 RunTimeException 10 RuntimeException 11 CircuitBreakerOpenException
* need to be made - of which at least 3 need to fail - for the Circuit to open again) 7 SUCCESS 8 TestException 9
* TestException 10 TestException 11 CircuitBreakerOpenException
*
*/
@Test
Expand Down Expand Up @@ -97,15 +99,15 @@ public void testCircuitInitialSuccessDefaultSuccessThreshold() {
e.printStackTrace();
}
}
} catch (RuntimeException ex) {
} catch (TestException ex) {
// Expected
if (!contains(new int[]{2, 3, 4, 8, 9, 10}, i)) {
Assert.fail("serviceA should not throw a RuntimeException on iteration " + i);
Assert.fail("serviceA should not throw a TestException on iteration " + i);
}
} catch (Exception ex) {
// Not Expected
Assert.fail(
"serviceA should throw a RuntimeException or CircuitBreakerOpenException in testCircuitDefaultSuccessThreshold "
"serviceA should throw a TestException or CircuitBreakerOpenException in testCircuitDefaultSuccessThreshold "
+ "on iteration " + i);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.eclipse.microprofile.fault.tolerance.tck.Misc.Ints.contains;

import org.eclipse.microprofile.fault.tolerance.tck.circuitbreaker.clientserver.CircuitBreakerClientDefaultSuccessThreshold;
import org.eclipse.microprofile.fault.tolerance.tck.util.TestException;
import org.eclipse.microprofile.faulttolerance.exceptions.CircuitBreakerOpenException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.testng.Arquillian;
Expand Down Expand Up @@ -49,7 +50,8 @@ public class CircuitBreakerLateSuccessTest extends Arquillian {
public static WebArchive deploy() {
JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, "ftCircuitBreakerLateSuccess.jar")
.addClasses(CircuitBreakerClientDefaultSuccessThreshold.class,
Misc.class)
Misc.class,
TestException.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
.as(JavaArchive.class);

Expand Down Expand Up @@ -99,10 +101,10 @@ public void testCircuitLateSuccessDefaultSuccessThreshold() {
e.printStackTrace();
}
}
} catch (RuntimeException ex) {
} catch (TestException ex) {
// Expected
if (!contains(new int[]{1, 2, 3, 7, 8, 9}, i)) {
Assert.fail("serviceA should not throw a RuntimeException on iteration " + i);
Assert.fail("serviceA should not throw a RuntimeException on iteration " + i, ex);
}
} catch (Exception ex) {
// Not Expected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public static WebArchive deploy() {
JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, "ftCircuitBreakerRetry.jar")
.addClasses(CircuitBreakerClientWithRetry.class,
CircuitBreakerClassLevelClientWithRetry.class,
CircuitBreakerClientWithRetryAsync.class)
CircuitBreakerClientWithRetryAsync.class,
TestException.class)
.addPackage(Packages.UTILS)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
.addAsManifestResource(config, "microprofile-config.properties")
Expand Down Expand Up @@ -128,7 +129,7 @@ public void testCircuitOpenWithMoreRetries() {

/**
* A test to exercise Circuit Breaker thresholds with insufficient retries to open the Circuit so that the Circuit
* remains closed and a RuntimeException is caught.
* remains closed and a TestException is caught.
*/
@Test
public void testCircuitOpenWithFewRetries() {
Expand All @@ -145,10 +146,10 @@ public void testCircuitOpenWithFewRetries() {
// Not Expected
invokeCounter = clientForCBWithRetry.getCounterForInvokingServiceB();
Assert.fail(
"serviceB should retry or throw a RuntimeException (not a CBOE) in testCircuitOpenWithFewRetries on iteration "
"serviceB should retry or throw a TestException (not a CBOE) in testCircuitOpenWithFewRetries on iteration "
+ invokeCounter);

} catch (RuntimeException ex) {
} catch (TestException ex) {
// Expected on iteration 3
invokeCounter = clientForCBWithRetry.getCounterForInvokingServiceB();
if (invokeCounter < 3) {
Expand All @@ -159,7 +160,7 @@ public void testCircuitOpenWithFewRetries() {
// Not Expected
invokeCounter = clientForCBWithRetry.getCounterForInvokingServiceB();
Assert.fail(
"serviceB should retry or throw a RuntimeException in testCircuitOpenWithFewRetries on iteration "
"serviceB should retry or throw a TestException in testCircuitOpenWithFewRetries on iteration "
+ invokeCounter);
}

Expand Down Expand Up @@ -220,10 +221,10 @@ public void testClassLevelCircuitOpenWithFewRetries() {
// Not Expected
invokeCounter = clientForClassLevelCBWithRetry.getCounterForInvokingServiceB();
Assert.fail(
"serviceB should retry or throw a RuntimeException (not a CBOE) in testClassLevelCircuitOpenWithFewRetries on iteration "
"serviceB should retry or throw a TestException (not a CBOE) in testClassLevelCircuitOpenWithFewRetries on iteration "
+ invokeCounter);

} catch (RuntimeException ex) {
} catch (TestException ex) {
// Expected on iteration 3
invokeCounter = clientForClassLevelCBWithRetry.getCounterForInvokingServiceB();
if (invokeCounter < 3) {
Expand All @@ -234,7 +235,7 @@ public void testClassLevelCircuitOpenWithFewRetries() {
// Not Expected
invokeCounter = clientForClassLevelCBWithRetry.getCounterForInvokingServiceB();
Assert.fail(
"serviceB should retry or throw a RuntimeException in testClassLevelCircuitOpenWithFewRetries on iteration "
"serviceB should retry or throw a TestException in testClassLevelCircuitOpenWithFewRetries on iteration "
+ invokeCounter);
}

Expand Down Expand Up @@ -407,7 +408,7 @@ public void testCircuitOpenWithMoreRetriesAsync() {

/**
* A test to exercise Circuit Breaker thresholds with insufficient retries to open the Circuit so that the Circuit
* remains closed and a RuntimeException is caught when using an Asynchronous call.
* remains closed and a TestException is caught when using an Asynchronous call.
*/
@Test
public void testCircuitOpenWithFewRetriesAsync() {
Expand Down Expand Up @@ -437,7 +438,7 @@ public void testCircuitOpenWithFewRetriesAsync() {
// Not Expected
invokeCounter = clientForCBWithRetryAsync.getCounterForInvokingServiceB();
Assert.fail(
"serviceB should retry or throw a RuntimeException in testCircuitOpenWithFewRetries on iteration "
"serviceB should retry or throw a TestException in testCircuitOpenWithFewRetries on iteration "
+ invokeCounter);
}

Expand Down
Loading

0 comments on commit 1527c6a

Please sign in to comment.