use of io.smallrye.mutiny.subscription.MultiSubscriber in project smallrye-mutiny by smallrye.
the class HalfSerializerTest method testThatOnNextIsNotReentrant.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testThatOnNextIsNotReentrant() {
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.onNext(subscriber.get(), 2, 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.assertItems(1).assertNotTerminated();
}
use of io.smallrye.mutiny.subscription.MultiSubscriber in project smallrye-mutiny by smallrye.
the class HalfSerializerTest method testThatOnFailureAndOnFailureAreNotReentrant.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testThatOnFailureAndOnFailureAreNotReentrant() {
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) {
test.onNext(t);
}
@Override
public void onFailure(Throwable t) {
test.onError(t);
HalfSerializer.onError(subscriber.get(), new IOException("boom"), wip, failure);
}
@Override
public void onCompletion() {
test.onComplete();
}
};
subscriber.set(s);
Subscription subscription = mock(Subscription.class);
s.onSubscribe(subscription);
HalfSerializer.onError(s, new IOException("test"), wip, failure);
test.assertFailedWith(IOException.class, "test");
}
use of io.smallrye.mutiny.subscription.MultiSubscriber in project smallrye-mutiny by smallrye.
the class MultiTakeTest method testTakeByTimeWithRogueUpstreamSendingFailureAfterCompletion.
@Test
public void testTakeByTimeWithRogueUpstreamSendingFailureAfterCompletion() {
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 MultiTakeTest method testTakeByTimeWithRogueUpstreamSendingCompletionAfterFailure.
@Test
public void testTakeByTimeWithRogueUpstreamSendingCompletionAfterFailure() {
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 testOverlapGroupWithRogueFailures.
@Test
public void testOverlapGroupWithRogueFailures() {
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(4, 2).subscribe().withSubscriber(AssertSubscriber.create(Long.MAX_VALUE));
subscriber.assertFailedWith(IOException.class, "boom-1");
assertThat(caught.get()).hasMessageContaining("boom-2");
}
Aggregations