Skip to content

Commit

Permalink
#399 - drop TCKConfig CDI injection because of wiring complexity
Browse files Browse the repository at this point in the history
Signed-off-by: brunobat <brunobat@gmail.com>
  • Loading branch information
brunobat authored and Azquelt committed Nov 25, 2019
1 parent 23a0ce1 commit dbd170b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ public void testRetriesSucceedWhenCircuitCloses() {
// Allow a margin of 250ms since there's a retry delay of 100ms
MatcherAssert.assertThat("Call was successful but did not take the expected time",
Duration.ofNanos(endTime - startTime),
DurationMatcher.closeTo(tckConfig.getTimeoutInDuration(1000),
tckConfig.getTimeoutInDuration(250)));
DurationMatcher.closeTo(TCKConfig.getInstance().getTimeoutInDuration(1000),
TCKConfig.getInstance().getTimeoutInDuration(250)));
}

/**
Expand Down Expand Up @@ -329,7 +329,7 @@ public void testNoRetriesIfNotRetryOn() {
// Check that the call took less than 200ms (i.e. we didn't delay and retry)
MatcherAssert.assertThat("Call was successful but did not take the expected time",
Duration.ofNanos(endTime - startTime),
lessThan(tckConfig.getTimeoutInDuration(200)));
lessThan(TCKConfig.getInstance().getTimeoutInDuration(200)));
}

/**
Expand Down Expand Up @@ -358,7 +358,7 @@ public void testNoRetriesIfAbortOn() {
// Check that the call took less than 200ms (i.e. we didn't delay and retry)
MatcherAssert.assertThat("Call was successful but did not take the expected time",
Duration.ofNanos(endTime - startTime),
lessThan(tckConfig.getTimeoutInDuration(200)));
lessThan(TCKConfig.getInstance().getTimeoutInDuration(200)));
}


Expand All @@ -371,7 +371,7 @@ public void testCircuitOpenWithMoreRetriesAsync() {
int invokeCounter = 0;
Future<Connection> result = clientForCBWithRetryAsync.serviceA();
try {
result.get(tckConfig.getTimeoutInMillis(5000), TimeUnit.MILLISECONDS);
result.get(TCKConfig.getInstance().getTimeoutInMillis(5000), TimeUnit.MILLISECONDS);

// serviceA should retry until the CB threshold is reached. At that point a CircuitBreakerOpenException
// should be thrown. Assert if this does not happen.
Expand Down Expand Up @@ -413,7 +413,7 @@ public void testCircuitOpenWithFewRetriesAsync() {
int invokeCounter = 0;
Future<Connection> result = clientForCBWithRetryAsync.serviceB();
try {
result.get(tckConfig.getTimeoutInMillis(5000), TimeUnit.MILLISECONDS);
result.get(TCKConfig.getInstance().getTimeoutInMillis(5000), TimeUnit.MILLISECONDS);

// serviceB should retry until the CB threshold is reached. At that point a CircuitBreakerOpenException
// should be thrown. Assert if this does not happen.
Expand Down Expand Up @@ -451,9 +451,9 @@ public void testCircuitOpenWithFewRetriesAsync() {
@Test
public void testCircuitOpenWithMultiTimeoutsAsync() {
int invokeCounter = 0;
Future<Connection> result = clientForCBWithRetryAsync.serviceC(tckConfig.getTimeoutInMillis(1000));
Future<Connection> result = clientForCBWithRetryAsync.serviceC(TCKConfig.getInstance().getTimeoutInMillis(1000));
try {
result.get(tckConfig.getTimeoutInMillis(10000), TimeUnit.MILLISECONDS); // Expected to finish after about 2 seconds
result.get(TCKConfig.getInstance().getTimeoutInMillis(10000), TimeUnit.MILLISECONDS); // Expected to finish after about 2 seconds

// serviceC should retry until the CB threshold is reached. At that point a CircuitBreakerOpenException
// should be thrown. Assert if this does not happen.
Expand Down Expand Up @@ -507,7 +507,7 @@ public void testRetriesSucceedWhenCircuitClosesAsync() {
long startTime = System.nanoTime();
Future<String> result = clientForCBWithRetryAsync.serviceWithRetryOnCbOpen(false);
try {
result.get(tckConfig.getTimeoutInMillis(10000), TimeUnit.MILLISECONDS);
result.get(TCKConfig.getInstance().getTimeoutInMillis(10000), TimeUnit.MILLISECONDS);
}
catch (TimeoutException e) {
fail("Call to serviceWithRetryOnCbOpen did not succeed within 10 seconds");
Expand All @@ -524,8 +524,8 @@ public void testRetriesSucceedWhenCircuitClosesAsync() {
// Allow a margin of 250ms since there's a retry delay of 100ms
MatcherAssert.assertThat("Call was successful but did not take the expected time",
Duration.ofNanos(endTime - startTime),
DurationMatcher.closeTo(tckConfig.getTimeoutInDuration(1000),
tckConfig.getTimeoutInDuration(250)));
DurationMatcher.closeTo(TCKConfig.getInstance().getTimeoutInDuration(1000),
TCKConfig.getInstance().getTimeoutInDuration(250)));
}

/**
Expand Down Expand Up @@ -554,7 +554,7 @@ public void testNoRetriesIfNotRetryOnAsync() {
// Check that the call took less than 200ms (i.e. we didn't delay and retry)
MatcherAssert.assertThat("Call was successful but did not take the expected time",
Duration.ofNanos(endTime - startTime),
lessThan(tckConfig.getTimeoutInDuration(200)));
lessThan(TCKConfig.getInstance().getTimeoutInDuration(200)));
}

/**
Expand All @@ -581,7 +581,7 @@ public void testNoRetriesIfAbortOnAsync() {
// Check that the call took less than 200ms (i.e. we didn't delay and retry)
MatcherAssert.assertThat("Call was successful but did not take the expected time",
Duration.ofNanos(endTime - startTime),
lessThan(tckConfig.getTimeoutInDuration(200)));
lessThan(TCKConfig.getInstance().getTimeoutInDuration(200)));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ private void assertCompleteExceptionally(final CompletionStage<String> future,
final Class<? extends Throwable> exceptionClass,
final String exceptionMessage) {
try {
CompletableFutureHelper.toCompletableFuture(future).get(tckConfig.getTimeoutInMillis(), TimeUnit.MILLISECONDS);
CompletableFutureHelper.toCompletableFuture(future).get(TCKConfig.getInstance().getTimeoutInMillis(), TimeUnit.MILLISECONDS);
fail("We were expecting an exception: " + exceptionClass.getName() + " with message: " + exceptionMessage);
}
catch (InterruptedException | TimeoutException e) {
Expand All @@ -365,7 +365,7 @@ private void assertCompleteOk(final CompletionStage<String> future, final String
try {
assertEquals(CompletableFutureHelper
.toCompletableFuture(future)
.get(tckConfig.getTimeoutInMillis(), TimeUnit.MILLISECONDS), expectedMessage);
.get(TCKConfig.getInstance().getTimeoutInMillis(), TimeUnit.MILLISECONDS), expectedMessage);
}
catch (Exception e) {
fail("Unexpected exception" + e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.concurrent.TimeoutException;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;

import org.eclipse.microprofile.fault.tolerance.tck.util.Connection;
import org.eclipse.microprofile.fault.tolerance.tck.util.TCKConfig;
Expand Down Expand Up @@ -88,7 +87,7 @@ private CompletionStage<Connection> serviceCS(Future<?> waitCondition, boolean t

Throwable exception = null;
try {
waitCondition.get(tckConfig.getTimeoutInMillis(), TimeUnit.SECONDS);
waitCondition.get(TCKConfig.getInstance().getTimeoutInMillis(), TimeUnit.SECONDS);
}
catch (ExecutionException e) {
exception = e.getCause();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import javax.enterprise.context.RequestScoped;

import org.eclipse.microprofile.fault.tolerance.tck.util.TCKConfig;
import org.eclipse.microprofile.faulttolerance.Asynchronous;
import org.eclipse.microprofile.faulttolerance.Timeout;
import org.eclipse.microprofile.fault.tolerance.tck.util.Connection;
Expand All @@ -50,7 +51,7 @@ public Future<Connection> serviceA() throws InterruptedException {

Connection conn = new Connection() {
{
Thread.sleep(5000);
Thread.sleep(TCKConfig.getInstance().getTimeoutInMillis(5000));
}

@Override
Expand All @@ -74,7 +75,7 @@ public Future<Connection> serviceB() throws InterruptedException {

Connection conn = new Connection() {
{
Thread.sleep(500);
Thread.sleep(TCKConfig.getInstance().getTimeoutInMillis(500));
}

@Override
Expand Down

0 comments on commit dbd170b

Please sign in to comment.