use of io.smallrye.mutiny.CompositeException in project smallrye-mutiny by smallrye.
the class UniOnEventTest method testEventuallyActionThrowingException.
@Test
public void testEventuallyActionThrowingException() {
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();
}
use of io.smallrye.mutiny.CompositeException in project smallrye-mutiny by smallrye.
the class UniOnFailureInvokeTest method testInvokeOnFailureWithExceptionThrownByCallback.
@Test
public void testInvokeOnFailureWithExceptionThrownByCallback() {
AtomicReference<Throwable> container = new AtomicReference<>();
assertThatThrownBy(() -> failure.onFailure().invoke(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 UniOnFailureInvokeTest method testCallOnFailureWithCallbackReturningNull.
@Test
public void testCallOnFailureWithCallbackReturningNull() {
AtomicReference<Throwable> container = new AtomicReference<>();
assertThatThrownBy(() -> failure.onFailure().call(t -> {
container.set(t);
return null;
}).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 MultiOnTerminationUniInvokeTest method testTerminationWhenErrorIsEmittedButUniInvokeIsFailed.
@Test
public void testTerminationWhenErrorIsEmittedButUniInvokeIsFailed() {
AssertSubscriber<Object> subscriber = AssertSubscriber.create();
AtomicReference<Subscription> subscription = new AtomicReference<>();
AtomicReference<Object> item = new AtomicReference<>();
AtomicReference<Throwable> failure = new AtomicReference<>();
AtomicBoolean completion = new AtomicBoolean();
AtomicLong requests = new AtomicLong();
AtomicBoolean cancellation = new AtomicBoolean();
AtomicBoolean termination = new AtomicBoolean();
AtomicReference<Throwable> terminationException = new AtomicReference<>();
AtomicBoolean terminationCancelledFlag = new AtomicBoolean();
Multi.createFrom().failure(new IOException("boom")).onSubscription().invoke(subscription::set).onItem().invoke(item::set).onFailure().invoke(failure::set).onCompletion().invoke(() -> completion.set(true)).onTermination().call((t, c) -> {
termination.set(true);
terminationException.set(t);
terminationCancelledFlag.set(c);
return Uni.createFrom().failure(new RuntimeException("tada"));
}).onRequest().invoke(requests::set).onCancellation().invoke(() -> cancellation.set(true)).subscribe().withSubscriber(subscriber);
subscriber.request(20).assertHasNotReceivedAnyItem().assertFailedWith(CompositeException.class, "boom");
assertThat(subscriber.getFailure()).isNotNull();
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("tada");
assertThat(subscription.get()).isNotNull();
assertThat(item.get()).isNull();
assertThat(failure.get()).isNotNull().isInstanceOf(IOException.class).hasMessageContaining("boom");
assertThat(completion.get()).isFalse();
assertThat(requests.get()).isEqualTo(0L);
assertThat(cancellation.get()).isFalse();
assertThat(termination.get()).isTrue();
assertThat(terminationException.get()).isNotNull().isInstanceOf(IOException.class).hasMessageContaining("boom");
assertThat(terminationCancelledFlag.get()).isFalse();
}
use of io.smallrye.mutiny.CompositeException in project smallrye-mutiny by smallrye.
the class MultiMergeTest method testWithFailureCollectionWithMerge.
@Test
public void testWithFailureCollectionWithMerge() {
IllegalStateException boom = new IllegalStateException("boom");
IllegalStateException boom2 = new IllegalStateException("boom2");
AssertSubscriber<Integer> subscriber = Multi.createBy().merging().collectFailures().streams(Multi.createFrom().item(5), Multi.createFrom().failure(boom), Multi.createFrom().item(6), Multi.createFrom().failure(boom2)).subscribe().withSubscriber(new AssertSubscriber<>(5));
subscriber.assertTerminated().assertItems(5, 6).assertFailedWith(CompositeException.class, "boom").assertFailedWith(CompositeException.class, "boom2");
assertThat(subscriber.getFailure()).isInstanceOf(CompositeException.class);
CompositeException ce = (CompositeException) subscriber.getFailure();
assertThat(ce.getCauses()).hasSize(2);
subscriber = Multi.createBy().merging().streams(Multi.createFrom().item(5), Multi.createFrom().failure(boom), Multi.createFrom().item(6), Multi.createFrom().failure(boom)).subscribe().withSubscriber(new AssertSubscriber<>(5));
subscriber.assertTerminated().assertItems(5).assertFailedWith(IllegalStateException.class, "boom");
}
Aggregations