use of io.smallrye.mutiny.CompositeException in project smallrye-mutiny by smallrye.
the class UniOnEventTest method testEventuallyFailedUniOnFailure.
@Test
public void testEventuallyFailedUniOnFailure() {
AtomicReference<Object> item = new AtomicReference<>();
AtomicBoolean eventuallyCalled = new AtomicBoolean();
UniAssertSubscriber<Object> subscriber = Uni.createFrom().failure(new IOException("boom")).invoke(item::set).eventually(() -> {
eventuallyCalled.set(true);
return Uni.createFrom().failure(new RuntimeException("bam"));
}).subscribe().withSubscriber(UniAssertSubscriber.create());
subscriber.assertFailedWith(CompositeException.class, "boom");
CompositeException compositeException = (CompositeException) subscriber.getFailure();
assertThat(compositeException.getCauses()).hasSize(2);
assertThat(compositeException.getCauses().get(0)).isInstanceOf(IOException.class).hasMessage("boom");
assertThat(compositeException.getCauses().get(1)).isInstanceOf(RuntimeException.class).hasMessage("bam");
assertThat(item.get()).isNull();
assertThat(eventuallyCalled).isTrue();
}
use of io.smallrye.mutiny.CompositeException in project smallrye-mutiny by smallrye.
the class UniOnEventTest method testActionsOnTerminationWithFailure.
@Test
public void testActionsOnTerminationWithFailure() {
AtomicInteger Item = new AtomicInteger();
AtomicReference<Throwable> failure = new AtomicReference<>();
AtomicReference<Subscription> subscription = new AtomicReference<>();
AtomicReference<Throwable> terminate = new AtomicReference<>();
UniAssertSubscriber<? super Integer> subscriber = Uni.createFrom().<Integer>failure(new IOException("boom")).onItem().invoke(Item::set).onFailure().invoke(failure::set).onSubscription().invoke(subscription::set).onTermination().call((r, f, c) -> {
terminate.set(f);
return Uni.createFrom().failure(new IOException("tada"));
}).subscribe().withSubscriber(UniAssertSubscriber.create());
subscriber.assertFailed().assertFailedWith(CompositeException.class, "boom");
CompositeException compositeException = (CompositeException) subscriber.getFailure();
assertThat(compositeException).getRootCause().isInstanceOf(IOException.class).hasMessageContaining("boom");
assertThat(compositeException.getCauses().get(1)).isInstanceOf(IOException.class).hasMessageContaining("tada");
assertThat(Item).doesNotHaveValue(1);
assertThat(subscription.get()).isNotNull();
assertThat(terminate.get()).isInstanceOf(IOException.class).hasMessageContaining("boom");
}
use of io.smallrye.mutiny.CompositeException in project smallrye-mutiny by smallrye.
the class UniOnFailureInvokeTest method testCallOnFailureWithExceptionThrownByCallback.
@Test
public void testCallOnFailureWithExceptionThrownByCallback() {
AtomicReference<Throwable> container = new AtomicReference<>();
assertThatThrownBy(() -> failure.onFailure().call(t -> {
container.set(t);
throw new IllegalStateException("bad");
}).await().indefinitely()).isInstanceOf(CompositeException.class).satisfies(t -> {
CompositeException ex = (CompositeException) t;
assertThat(ex.getCauses()).hasSize(2).contains(BOOM);
});
}
use of io.smallrye.mutiny.CompositeException in project smallrye-mutiny by smallrye.
the class UniOnEventTest method testActionsOnTerminationWithSupplierOnFailure.
@Test
public void testActionsOnTerminationWithSupplierOnFailure() {
AtomicInteger Item = new AtomicInteger();
AtomicReference<Throwable> failure = new AtomicReference<>();
AtomicReference<Subscription> subscription = new AtomicReference<>();
AtomicBoolean terminate = new AtomicBoolean();
UniAssertSubscriber<? super Integer> subscriber = Uni.createFrom().<Integer>failure(new IOException("boom")).onItem().invoke(Item::set).onFailure().invoke(failure::set).onSubscription().invoke(subscription::set).onTermination().call(() -> {
terminate.set(true);
return Uni.createFrom().failure(new IOException("tada"));
}).subscribe().withSubscriber(UniAssertSubscriber.create());
subscriber.assertFailed().assertFailedWith(CompositeException.class, "boom");
CompositeException compositeException = (CompositeException) subscriber.getFailure();
assertThat(compositeException).getRootCause().isInstanceOf(IOException.class).hasMessageContaining("boom");
assertThat(compositeException.getCauses().get(1)).isInstanceOf(IOException.class).hasMessageContaining("tada");
assertThat(Item).doesNotHaveValue(1);
assertThat(subscription.get()).isNotNull();
assertThat(terminate.get()).isTrue();
}
use of io.smallrye.mutiny.CompositeException in project smallrye-mutiny by smallrye.
the class UniOnEventTest method testEventuallyUniThrowingOnFailure.
@Test
public void testEventuallyUniThrowingOnFailure() {
AtomicReference<Object> item = new AtomicReference<>();
AtomicBoolean eventuallyCalled = new AtomicBoolean();
UniAssertSubscriber<Object> subscriber = Uni.createFrom().failure(new IOException("boom")).invoke(item::set).eventually(() -> {
eventuallyCalled.set(true);
throw new RuntimeException("bam");
}).subscribe().withSubscriber(UniAssertSubscriber.create());
subscriber.assertFailedWith(CompositeException.class, "boom");
CompositeException compositeException = (CompositeException) subscriber.getFailure();
assertThat(compositeException.getCauses()).hasSize(2);
assertThat(compositeException.getCauses().get(0)).isInstanceOf(IOException.class).hasMessage("boom");
assertThat(compositeException.getCauses().get(1)).isInstanceOf(RuntimeException.class).hasMessage("bam");
assertThat(item.get()).isNull();
assertThat(eventuallyCalled).isTrue();
}
Aggregations