use of io.smallrye.mutiny.CompositeException in project smallrye-mutiny by smallrye.
the class MultiOnTerminationUniInvokeTest method testTerminationWhenErrorIsEmittedButUniInvokeThrowsException.
@Test
public void testTerminationWhenErrorIsEmittedButUniInvokeThrowsException() {
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);
throw 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 testWithFailureCollectionWithConcatenation.
@Test
public void testWithFailureCollectionWithConcatenation() {
IllegalStateException boom = new IllegalStateException("boom");
IllegalStateException boom2 = new IllegalStateException("boom2");
AssertSubscriber<Integer> subscriber = Multi.createBy().concatenating().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().concatenating().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");
}
use of io.smallrye.mutiny.CompositeException in project smallrye-mutiny by smallrye.
the class MultiOnEventTest method testThatPredicateFailureProduceCompositeException.
@Test
public void testThatPredicateFailureProduceCompositeException() {
AtomicBoolean called = new AtomicBoolean();
AssertSubscriber<Object> subscriber = Multi.createFrom().failure(new IOException("boom")).onFailure(t -> {
throw new NullPointerException();
}).invoke(t -> called.set(true)).subscribe().withSubscriber(AssertSubscriber.create(1));
subscriber.assertFailedWith(CompositeException.class, "boom");
CompositeException failure = (CompositeException) subscriber.getFailure();
assertThat(failure.getCauses()).hasSize(2);
assertThat(called).isFalse();
}
use of io.smallrye.mutiny.CompositeException in project smallrye-mutiny by smallrye.
the class UniOnEventTest method testInvokeOnFailureWithPredicate.
@Test
public void testInvokeOnFailureWithPredicate() {
AtomicBoolean noPredicate = new AtomicBoolean();
AtomicBoolean exactClassMatch = new AtomicBoolean();
AtomicBoolean parentClassMatch = new AtomicBoolean();
AtomicBoolean predicateMatch = new AtomicBoolean();
AtomicBoolean predicateNoMatch = new AtomicBoolean();
AtomicBoolean classNoMatch = new AtomicBoolean();
UniAssertSubscriber<Object> subscriber = Uni.createFrom().failure(new IOException("boom")).onFailure().invoke(t -> noPredicate.set(true)).onFailure(IOException.class).invoke(t -> exactClassMatch.set(true)).onFailure(Exception.class).invoke(t -> parentClassMatch.set(true)).onFailure(IllegalArgumentException.class).invoke(t -> classNoMatch.set(true)).onFailure(t -> t.getMessage().equalsIgnoreCase("boom")).invoke(t -> predicateMatch.set(true)).onFailure(t -> t.getMessage().equalsIgnoreCase("nope")).invoke(t -> predicateNoMatch.set(true)).subscribe().withSubscriber(UniAssertSubscriber.create());
subscriber.assertFailed().assertFailedWith(IOException.class, "boom");
assertThat(noPredicate).isTrue();
assertThat(exactClassMatch).isTrue();
assertThat(parentClassMatch).isTrue();
assertThat(predicateMatch).isTrue();
assertThat(predicateNoMatch).isFalse();
assertThat(classNoMatch).isFalse();
AtomicBoolean called = new AtomicBoolean();
subscriber = Uni.createFrom().failure(new IOException("boom")).onFailure(t -> {
throw new NullPointerException();
}).invoke(t -> called.set(true)).subscribe().withSubscriber(UniAssertSubscriber.create());
subscriber.assertFailed().assertFailedWith(CompositeException.class, "boom");
CompositeException composite = (CompositeException) subscriber.getFailure();
assertThat(composite.getCauses()).hasSize(2).anySatisfy(t -> assertThat(t).isInstanceOf(NullPointerException.class)).anySatisfy(t -> assertThat(t).isInstanceOf(IOException.class));
assertThat(called).isFalse();
}
use of io.smallrye.mutiny.CompositeException in project smallrye-mutiny by smallrye.
the class UniOnEventTest method testActionsOnTerminationWithMapperThrowingException.
@Test
public void testActionsOnTerminationWithMapperThrowingException() {
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);
throw new RuntimeException("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(RuntimeException.class).hasMessageContaining("tada");
assertThat(Item).doesNotHaveValue(1);
assertThat(subscription.get()).isNotNull();
assertThat(terminate.get()).isInstanceOf(IOException.class).hasMessageContaining("boom");
}
Aggregations