Java Code Examples for io.github.resilience4j.timelimiter.TimeLimiter#ofDefaults()

The following examples show how to use io.github.resilience4j.timelimiter.TimeLimiter#ofDefaults() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeLimiterTest.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Test
public void unwrapExecutionException() {
    TimeLimiter timeLimiter = TimeLimiter.ofDefaults();
    ExecutorService executorService = Executors.newSingleThreadExecutor();

    Supplier<Future<Integer>> supplier = () -> executorService.submit(() -> {
        throw new RuntimeException();
    });
    Callable<Integer> decorated = TimeLimiter.decorateFutureSupplier(timeLimiter, supplier);

    Try<Integer> decoratedResult = Try.ofCallable(decorated);

    assertThat(decoratedResult.getCause() instanceof RuntimeException).isTrue();
}
 
Example 2
Source File: RxJava2TimeLimiterAspectExtTest.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testRxJava2Types() throws Throwable {
    TimeLimiter timeLimiter = TimeLimiter.ofDefaults("test");

    when(proceedingJoinPoint.proceed()).thenReturn(Single.just("Test"));
    assertThat(rxJava2TimeLimiterAspectExt.handle(proceedingJoinPoint, timeLimiter, "testMethod")).isNotNull();

    when(proceedingJoinPoint.proceed()).thenReturn(Flowable.just("Test"));
    assertThat(rxJava2TimeLimiterAspectExt.handle(proceedingJoinPoint, timeLimiter, "testMethod")).isNotNull();

    when(proceedingJoinPoint.proceed()).thenReturn(Observable.just("Test"));
    assertThat(rxJava2TimeLimiterAspectExt.handle(proceedingJoinPoint, timeLimiter, "testMethod")).isNotNull();

    when(proceedingJoinPoint.proceed()).thenReturn(Completable.complete());
    assertThat(rxJava2TimeLimiterAspectExt.handle(proceedingJoinPoint, timeLimiter, "testMethod")).isNotNull();

    when(proceedingJoinPoint.proceed()).thenReturn(Maybe.just("Test"));
    assertThat(rxJava2TimeLimiterAspectExt.handle(proceedingJoinPoint, timeLimiter, "testMethod")).isNotNull();
}
 
Example 3
Source File: RxJava2TimeLimiterAspectExtTest.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowIllegalArgumentExceptionWithNotRxJava2Type() throws Throwable{
    TimeLimiter timeLimiter = TimeLimiter.ofDefaults("test");
    when(proceedingJoinPoint.proceed()).thenReturn("NOT RXJAVA2 TYPE");

    try {
        rxJava2TimeLimiterAspectExt.handle(proceedingJoinPoint, timeLimiter, "testMethod");
        fail("exception missed");
    } catch (Throwable e) {
        assertThat(e).isInstanceOf(IllegalReturnTypeException.class)
            .hasMessage(
                "java.lang.String testMethod has unsupported by @TimeLimiter return type. RxJava2 expects Flowable/Single/...");
    }
}
 
Example 4
Source File: ReactorTimeLimiterAspectExtTest.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testReactorTypes() throws Throwable {
    TimeLimiter timeLimiter = TimeLimiter.ofDefaults("test");

    when(proceedingJoinPoint.proceed()).thenReturn(Mono.just("Test"));
    assertThat(reactorTimeLimiterAspectExt.handle(proceedingJoinPoint, timeLimiter, "testMethod")).isNotNull();

    when(proceedingJoinPoint.proceed()).thenReturn(Flux.just("Test"));
    assertThat(reactorTimeLimiterAspectExt.handle(proceedingJoinPoint, timeLimiter, "testMethod")).isNotNull();
}
 
Example 5
Source File: ReactorTimeLimiterAspectExtTest.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowIllegalArgumentExceptionWithNotReactorType() throws Throwable{
    TimeLimiter timeLimiter = TimeLimiter.ofDefaults("test");
    when(proceedingJoinPoint.proceed()).thenReturn("NOT REACTOR TYPE");

    try {
        reactorTimeLimiterAspectExt.handle(proceedingJoinPoint, timeLimiter, "testMethod");
        fail("exception missed");
    } catch (Throwable e) {
        assertThat(e).isInstanceOf(IllegalReturnTypeException.class)
            .hasMessage(
                "java.lang.String testMethod has unsupported by @TimeLimiter return type. Reactor expects Mono/Flux.");
    }
}
 
Example 6
Source File: TimeLimiterTest.java    From resilience4j with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldSetGivenName() {
    TimeLimiter timeLimiter = TimeLimiter.ofDefaults("TEST");
    assertThat(timeLimiter.getName()).isEqualTo("TEST");
}