use of io.smallrye.mutiny.subscription.MultiSubscriber in project smallrye-mutiny by smallrye.
the class MultiSelectFirstOrLastTest method testSelectByTimeWithRogueUpstreamSendingFailureAfterCompletion.
@Test
public void testSelectByTimeWithRogueUpstreamSendingFailureAfterCompletion() {
Multi<Integer> rogue = new AbstractMulti<Integer>() {
@Override
public void subscribe(MultiSubscriber<? super Integer> subscriber) {
subscriber.onItem(1);
subscriber.onItem(2);
subscriber.onComplete();
subscriber.onItem(3);
subscriber.onError(new IOException("boom"));
}
};
AssertSubscriber<Integer> subscriber = rogue.select().first(Duration.ofMillis(1000)).subscribe().withSubscriber(AssertSubscriber.create(100)).awaitCompletion();
assertThat(subscriber.getItems()).hasSize(2);
}
use of io.smallrye.mutiny.subscription.MultiSubscriber in project smallrye-mutiny by smallrye.
the class MultiSelectFirstOrLastTest method testSelectByTimeWithRogueUpstreamSendingCompletionAfterFailure.
@Test
public void testSelectByTimeWithRogueUpstreamSendingCompletionAfterFailure() {
Multi<Integer> rogue = new AbstractMulti<Integer>() {
@Override
public void subscribe(MultiSubscriber<? super Integer> subscriber) {
subscriber.onItem(1);
subscriber.onItem(2);
subscriber.onError(new IOException("boom"));
subscriber.onItem(3);
subscriber.onComplete();
}
};
AssertSubscriber<Integer> subscriber = rogue.select().first(Duration.ofMillis(1000)).subscribe().withSubscriber(AssertSubscriber.create(100)).awaitFailure().assertFailedWith(IOException.class, "boom");
assertThat(subscriber.getItems()).hasSize(2);
}
use of io.smallrye.mutiny.subscription.MultiSubscriber in project smallrye-mutiny by smallrye.
the class MultiGroupTest method testSkipGroupWithRogueFailures.
@Test
public void testSkipGroupWithRogueFailures() {
AtomicReference<Throwable> caught = new AtomicReference<>();
Infrastructure.setDroppedExceptionHandler(caught::set);
AbstractMulti<Integer> rogue = new AbstractMulti<Integer>() {
@Override
public void subscribe(MultiSubscriber<? super Integer> subscriber) {
subscriber.onSubscribe(mock(Subscription.class));
subscriber.onItem(1);
subscriber.onItem(2);
subscriber.onItem(3);
subscriber.onItem(4);
subscriber.onFailure(new IOException("boom-1"));
subscriber.onItem(5);
subscriber.onItem(6);
subscriber.onFailure(new IOException("boom-2"));
subscriber.onCompletion();
}
};
AssertSubscriber<List<Integer>> subscriber = rogue.group().intoLists().of(2, 4).subscribe().withSubscriber(AssertSubscriber.create(Long.MAX_VALUE));
subscriber.assertFailedWith(IOException.class, "boom-1");
assertThat(caught.get()).hasMessageContaining("boom-2");
}
use of io.smallrye.mutiny.subscription.MultiSubscriber in project smallrye-mutiny by smallrye.
the class MultiGroupTest method testOverlapGroupAsMultisWithRogueFailures.
@Test
public void testOverlapGroupAsMultisWithRogueFailures() {
AtomicReference<Throwable> caught = new AtomicReference<>();
Infrastructure.setDroppedExceptionHandler(caught::set);
AbstractMulti<Integer> rogue = new AbstractMulti<Integer>() {
@Override
public void subscribe(MultiSubscriber<? super Integer> subscriber) {
subscriber.onSubscribe(mock(Subscription.class));
subscriber.onItem(1);
subscriber.onItem(2);
subscriber.onItem(3);
subscriber.onItem(4);
subscriber.onFailure(new IOException("boom-1"));
subscriber.onItem(5);
subscriber.onItem(6);
subscriber.onFailure(new IOException("boom-2"));
subscriber.onCompletion();
}
};
AssertSubscriber<Integer> subscriber = rogue.group().intoMultis().of(4, 2).onItem().transformToMultiAndConcatenate(m -> m).subscribe().withSubscriber(AssertSubscriber.create(Long.MAX_VALUE));
subscriber.assertFailedWith(IOException.class, "boom-1");
assertThat(caught.get()).hasMessageContaining("boom-2");
}
use of io.smallrye.mutiny.subscription.MultiSubscriber in project smallrye-mutiny by smallrye.
the class ResourceMulti method subscribe.
@Override
public void subscribe(MultiSubscriber<? super I> subscriber) {
R resource;
try {
resource = resourceSupplier.get();
if (resource == null) {
throw new IllegalArgumentException(ParameterValidation.SUPPLIER_PRODUCED_NULL);
}
} catch (Throwable e) {
Subscriptions.fail(subscriber, e);
return;
}
Publisher<? extends I> stream;
try {
stream = streamSupplier.apply(resource);
if (stream == null) {
throw new IllegalArgumentException(ParameterValidation.SUPPLIER_PRODUCED_NULL);
}
} catch (Throwable e) {
try {
Uni<Void> uni = onFailure.apply(resource, e);
if (uni == null) {
Subscriptions.fail(subscriber, new NullPointerException("Unable to call the finalizer - it returned `null`"));
} else {
uni.subscribe().with(completed -> Subscriptions.fail(subscriber, e), failed -> Subscriptions.fail(subscriber, new CompositeException(e, failed)));
}
} catch (Throwable ex) {
Subscriptions.fail(subscriber, new CompositeException(e, ex));
return;
}
Subscriptions.fail(subscriber, e);
return;
}
ResourceSubscriber<I, R> us = new ResourceSubscriber<>(subscriber, resource, onCompletion, onFailure, onCancellation);
stream.subscribe(us);
}
Aggregations