Search in sources :

Example 31 with Try

use of io.vavr.control.Try in project resilience4j by resilience4j.

the class IntervalFunctionTest method shouldRejectOutOfBoundsMultiplier.

@Test
public void shouldRejectOutOfBoundsMultiplier() {
    // Given
    final Duration duration = Duration.ofMillis(100);
    final float lessThenOneMultiplier = 0.9999f;
    // When
    final List<Try> tries = List.of(Try.of(() -> IntervalFunction.ofExponentialBackoff(duration, lessThenOneMultiplier)), Try.of(() -> IntervalFunction.ofExponentialRandomBackoff(duration, lessThenOneMultiplier)));
    // Then
    Assertions.assertThat(tries.forAll(Try::isFailure)).isTrue();
    Assertions.assertThat(tries.map(Try::getCause).forAll(t -> t instanceof IllegalArgumentException)).isTrue();
}
Also used : Duration(java.time.Duration) Try(io.vavr.control.Try) Test(org.junit.Test)

Example 32 with Try

use of io.vavr.control.Try in project resilience4j by resilience4j.

the class IntervalFunctionTest method shouldRejectOutOfBoundsRandomizationFactor.

@Test
public void shouldRejectOutOfBoundsRandomizationFactor() {
    // Given
    final Duration duration = Duration.ofMillis(100);
    final float negativeFactor = -0.0001f;
    final float greaterThanOneFactor = 1.0001f;
    // When
    final List<Try> tries = List.of(Try.of(() -> IntervalFunction.ofRandomized(duration, negativeFactor)), Try.of(() -> IntervalFunction.ofRandomized(duration, greaterThanOneFactor)));
    // Then
    Assertions.assertThat(tries.forAll(Try::isFailure)).isTrue();
    Assertions.assertThat(tries.map(Try::getCause).forAll(t -> t instanceof IllegalArgumentException)).isTrue();
}
Also used : Duration(java.time.Duration) Try(io.vavr.control.Try) Test(org.junit.Test)

Aggregations

Try (io.vavr.control.Try)32 Test (org.junit.Test)31 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)10 CharSequence (java.lang.CharSequence)8 CheckedRunnable (io.vavr.CheckedRunnable)6 Duration (java.time.Duration)6 Supplier (java.util.function.Supplier)5 Before (org.junit.Before)4 BDDMockito (org.mockito.BDDMockito)4 HelloWorldService (io.github.resilience4j.test.HelloWorldService)3 API (io.vavr.API)3 API.$ (io.vavr.API.$)3 CheckedFunction0 (io.vavr.CheckedFunction0)3 Predicates (io.vavr.Predicates)3 Function (java.util.function.Function)3 WebServiceException (javax.xml.ws.WebServiceException)3 Mockito (org.mockito.Mockito)3 IntervalFunction (io.github.resilience4j.retry.IntervalFunction)2 Retry (io.github.resilience4j.retry.Retry)2