use of io.smallrye.mutiny.subscription.MultiSubscriber in project smallrye-mutiny by smallrye.
the class MultiGroupTest method testSkipGroupAsMultisWithRogueFailures.
@Test
public void testSkipGroupAsMultisWithRogueFailures() {
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(2, 4).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 MultiGroupTest method testExactGroupAsMultisWithRogueFailures.
@Test
public void testExactGroupAsMultisWithRogueFailures() {
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(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 HalfSerializerTest method testThatOnNextAndOnFailureAreNotReentrant.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testThatOnNextAndOnFailureAreNotReentrant() {
AtomicInteger wip = new AtomicInteger();
AtomicReference<Throwable> failure = new AtomicReference<>();
AtomicReference<Subscriber<Object>> subscriber = new AtomicReference<>();
AssertSubscriber<Object> test = AssertSubscriber.create(10);
MultiSubscriber s = new MultiSubscriber() {
@Override
public void onSubscribe(Subscription s) {
test.onSubscribe(s);
}
@Override
public void onItem(Object t) {
if (t.equals(1)) {
HalfSerializer.onError(subscriber.get(), new IOException("boom"), wip, failure);
}
test.onNext(t);
}
@Override
public void onFailure(Throwable t) {
test.onError(t);
}
@Override
public void onCompletion() {
test.onComplete();
}
};
subscriber.set(s);
Subscription subscription = mock(Subscription.class);
s.onSubscribe(subscription);
HalfSerializer.onNext(s, 1, wip, failure);
test.assertFailedWith(IOException.class, "boom");
}
Aggregations