/** * The constructor with default retry properties. */ public InMemoryRetryRegistry() { this.defaultRetryConfig = RetryConfig.ofDefaults(); this.retries = new ConcurrentHashMap<>(); }
/** * The constructor with default retry properties. */ public InMemoryAsyncRetryRegistry() { this.defaultRetryConfig = RetryConfig.ofDefaults(); this.retries = new ConcurrentHashMap<>(); }
/** * Creates a Retry with default configuration. * * @param name the ID of the Retry * @return a Retry with default configuration */ static Retry ofDefaults(String name){ return new RetryImpl(name, RetryConfig.ofDefaults()); }
/** * Creates a Retry with default configuration. * * @param id the ID of the Retry * @return a Retry with default configuration */ static AsyncRetry ofDefaults(String id){ return of(id, RetryConfig.ofDefaults()); }
@Test public void shouldReturnOnCompleteUsingSingle() { RetryConfig config = RetryConfig.ofDefaults(); Retry retry = Retry.of("testName", config); RetryTransformer<Object> retryTransformer = RetryTransformer.of(retry);
@Test public void shouldReturnOnErrorUsingFlowable() { //Given RetryConfig config = RetryConfig.ofDefaults(); Retry retry = Retry.of("testName", config); RetryTransformer<Object> retryTransformer = RetryTransformer.of(retry); given(helloWorldService.returnHelloWorld()) .willThrow(new WebServiceException("BAM!")); //When Flowable.fromCallable(helloWorldService::returnHelloWorld) .compose(retryTransformer) .test() .assertError(WebServiceException.class) .assertNotComplete() .assertSubscribed(); Flowable.fromCallable(helloWorldService::returnHelloWorld) .compose(retryTransformer) .test() .assertError(WebServiceException.class) .assertNotComplete() .assertSubscribed(); //Then BDDMockito.then(helloWorldService).should(Mockito.times(6)).returnHelloWorld(); Retry.Metrics metrics = retry.getMetrics(); assertThat(metrics.getNumberOfFailedCallsWithRetryAttempt()).isEqualTo(2); assertThat(metrics.getNumberOfFailedCallsWithoutRetryAttempt()).isEqualTo(0); }
@Test public void shouldReturnOnErrorUsingObservable() { //Given RetryConfig config = RetryConfig.ofDefaults(); Retry retry = Retry.of("testName", config); RetryTransformer<Object> retryTransformer = RetryTransformer.of(retry); given(helloWorldService.returnHelloWorld()) .willThrow(new WebServiceException("BAM!")); //When Observable.fromCallable(helloWorldService::returnHelloWorld) .compose(retryTransformer) .test() .assertError(WebServiceException.class) .assertNotComplete() .assertSubscribed(); Observable.fromCallable(helloWorldService::returnHelloWorld) .compose(retryTransformer) .test() .assertError(WebServiceException.class) .assertNotComplete() .assertSubscribed(); //Then BDDMockito.then(helloWorldService).should(Mockito.times(6)).returnHelloWorld(); Retry.Metrics metrics = retry.getMetrics(); assertThat(metrics.getNumberOfFailedCallsWithRetryAttempt()).isEqualTo(2); assertThat(metrics.getNumberOfFailedCallsWithoutRetryAttempt()).isEqualTo(0); }
@Test public void shouldReturnOnErrorUsingSingle() { //Given RetryConfig config = RetryConfig.ofDefaults(); Retry retry = Retry.of("testName", config); RetryTransformer<Object> retryTransformer = RetryTransformer.of(retry); given(helloWorldService.returnHelloWorld()) .willThrow(new WebServiceException("BAM!")); //When Single.fromCallable(helloWorldService::returnHelloWorld) .compose(retryTransformer) .test() .assertError(WebServiceException.class) .assertNotComplete() .assertSubscribed(); Single.fromCallable(helloWorldService::returnHelloWorld) .compose(retryTransformer) .test() .assertError(WebServiceException.class) .assertNotComplete() .assertSubscribed(); //Then BDDMockito.then(helloWorldService).should(Mockito.times(6)).returnHelloWorld(); Retry.Metrics metrics = retry.getMetrics(); assertThat(metrics.getNumberOfFailedCallsWithRetryAttempt()).isEqualTo(2); assertThat(metrics.getNumberOfFailedCallsWithoutRetryAttempt()).isEqualTo(0); }
@Test public void shouldReturnOnCompleteUsingObservable() { //Given RetryConfig config = RetryConfig.ofDefaults(); Retry retry = Retry.of("testName", config); RetryTransformer<Object> retryTransformer = RetryTransformer.of(retry); given(helloWorldService.returnHelloWorld()) .willThrow(new WebServiceException("BAM!")); //When Observable.fromCallable(helloWorldService::returnHelloWorld) .compose(retryTransformer) .test() .assertError(WebServiceException.class) .assertNotComplete() .assertSubscribed(); Observable.fromCallable(helloWorldService::returnHelloWorld) .compose(retryTransformer) .test() .assertError(WebServiceException.class) .assertNotComplete() .assertSubscribed(); //Then BDDMockito.then(helloWorldService).should(Mockito.times(6)).returnHelloWorld(); Retry.Metrics metrics = retry.getMetrics(); assertThat(metrics.getNumberOfFailedCallsWithRetryAttempt()).isEqualTo(2); assertThat(metrics.getNumberOfFailedCallsWithoutRetryAttempt()).isEqualTo(0); }
@Test public void shouldReturnOnCompleteUsingFlowable() { //Given RetryConfig config = RetryConfig.ofDefaults(); Retry retry = Retry.of("testName", config); RetryTransformer<Object> retryTransformer = RetryTransformer.of(retry); given(helloWorldService.returnHelloWorld()) .willThrow(new WebServiceException("BAM!")); //When Flowable.fromCallable(helloWorldService::returnHelloWorld) .compose(retryTransformer) .test() .assertError(WebServiceException.class) .assertNotComplete() .assertSubscribed(); Flowable.fromCallable(helloWorldService::returnHelloWorld) .compose(retryTransformer) .test() .assertError(WebServiceException.class) .assertNotComplete() .assertSubscribed(); //Then BDDMockito.then(helloWorldService).should(Mockito.times(6)).returnHelloWorld(); Retry.Metrics metrics = retry.getMetrics(); assertThat(metrics.getNumberOfFailedCallsWithRetryAttempt()).isEqualTo(2); assertThat(metrics.getNumberOfFailedCallsWithoutRetryAttempt()).isEqualTo(0); }