Quantcast
Channel: Active questions tagged retry-logic - Stack Overflow
Viewing all articles
Browse latest Browse all 950

Unit testing a stream being retried

$
0
0

I've written a stream that calls the foobarMethod, potentially triggering the mono of a SocketTimeoutException. I want this method to retry 2 times. Manually, this code works but in the junit test I can't get it to retry. Is this because of an environment issue with unit tests or have I dont the tests wrong? Any help gratefully received. Thanks.

public void foobarServiceMethod() {   foobarClient.foobarMethod(foobarParameter)            .onErrorMap(ex -> {                log.error("Code has failed");                if (ex instanceof SocketTimeoutException) {                    return new SocketTimeoutException("");                } else {                    return ex;                }            })            .retryWhen(                    Retry.fixedDelay(3, Duration.ofSeconds(1))                            .filter(SocketTimeoutException.class::isInstance))            .subscribe(foobarResponse -> handleFoobarResoponse(foobarResponse));@Testvoid foobarRest(CapturedOutput capturedOutput) throws SocketTimeoutException, InterruptedException {    foobarParameter = "test";    when(foobarClient.foobarMethod(any()))            .thenReturn(Mono.error(new SocketTimeoutException("First timeout")))            .thenReturn(Mono.error(new SocketTimeoutException("First timeout")));    foobarMethod(foobarParameter);    assertEquals(2, capturedOutputSplit.contains("Code has failed");}

Viewing all articles
Browse latest Browse all 950

Trending Articles