use of io.smallrye.mutiny.subscription.MultiEmitter in project smallrye-mutiny by smallrye.
the class MultiSubscribeTest method testWith2CallbacksAndFailure.
@Test
public void testWith2CallbacksAndFailure() {
List<Integer> items = new CopyOnWriteArrayList<>();
AtomicReference<Throwable> failure = new AtomicReference<>();
AtomicReference<MultiEmitter<? super Integer>> emitter = new AtomicReference<>();
Multi.createFrom().<Integer>emitter(emitter::set).subscribe().with(items::add, failure::set);
assertThat(items).isEmpty();
assertThat(failure.get()).isNull();
emitter.get().emit(1).emit(2).emit(3).fail(new IOException("boom"));
assertThat(items).containsExactly(1, 2, 3);
assertThat(failure.get()).isInstanceOf(IOException.class).hasMessage("boom");
}
use of io.smallrye.mutiny.subscription.MultiEmitter in project smallrye-mutiny by smallrye.
the class MultiSubscribeTest method testWithEmitterWithFailure.
@Test
public void testWithEmitterWithFailure() {
List<Integer> items = new CopyOnWriteArrayList<>();
AtomicBoolean completion = new AtomicBoolean();
AtomicReference<Throwable> failure = new AtomicReference<>();
AtomicReference<MultiEmitter<? super Integer>> emitter = new AtomicReference<>();
Multi.createFrom().<Integer>emitter(emitter::set).subscribe().with(items::add, failure::set, () -> completion.set(true));
assertThat(items).isEmpty();
assertThat(failure.get()).isNull();
assertThat(completion).isFalse();
emitter.get().emit(1).emit(2).emit(3).fail(new IOException("boom"));
assertThat(items).containsExactly(1, 2, 3);
assertThat(failure.get()).isInstanceOf(IOException.class).hasMessage("boom");
assertThat(completion).isFalse();
}
use of io.smallrye.mutiny.subscription.MultiEmitter in project smallrye-mutiny by smallrye.
the class MultiSubscribeTest method testWithEmitterWithCompletion.
@Test
public void testWithEmitterWithCompletion() {
List<Integer> items = new CopyOnWriteArrayList<>();
AtomicBoolean completion = new AtomicBoolean();
AtomicReference<Throwable> failure = new AtomicReference<>();
AtomicReference<MultiEmitter<? super Integer>> emitter = new AtomicReference<>();
Multi.createFrom().<Integer>emitter(emitter::set).subscribe().with(items::add, failure::set, () -> completion.set(true));
assertThat(items).isEmpty();
assertThat(failure.get()).isNull();
assertThat(completion).isFalse();
emitter.get().emit(1).emit(2).emit(3).complete();
assertThat(items).containsExactly(1, 2, 3);
assertThat(failure.get()).isNull();
assertThat(completion).isTrue();
}
use of io.smallrye.mutiny.subscription.MultiEmitter in project smallrye-mutiny by smallrye.
the class EmitterBasedMultiTest method testReplacementOfOnTerminationBeforeCompletion.
@Test
public void testReplacementOfOnTerminationBeforeCompletion() {
AtomicBoolean called1 = new AtomicBoolean();
AtomicBoolean called2 = new AtomicBoolean();
AtomicReference<MultiEmitter<? super Integer>> reference = new AtomicReference<>();
AssertSubscriber<Integer> subscriber = Multi.createFrom().<Integer>emitter(e -> {
e.onTermination(() -> called1.set(true));
reference.set(e);
}).subscribe().withSubscriber(AssertSubscriber.create(2));
subscriber.assertSubscribed().assertNotTerminated();
reference.get().emit(1);
reference.get().emit(2);
subscriber.assertItems(1, 2).assertNotTerminated();
assertThat(called1).isFalse();
reference.get().onTermination(() -> called2.set(true));
reference.get().complete();
subscriber.assertCompleted();
assertThat(called1).isFalse();
assertThat(called2).isTrue();
}
use of io.smallrye.mutiny.subscription.MultiEmitter in project smallrye-mutiny by smallrye.
the class EmitterBasedMultiTest method testLateRegistrationOfOnTerminationAfterCompletion.
@Test
public void testLateRegistrationOfOnTerminationAfterCompletion() {
AtomicBoolean called = new AtomicBoolean();
AtomicReference<MultiEmitter<? super Integer>> reference = new AtomicReference<>();
AssertSubscriber<Integer> subscriber = Multi.createFrom().<Integer>emitter(reference::set).subscribe().withSubscriber(AssertSubscriber.create(2));
subscriber.assertSubscribed().assertNotTerminated();
reference.get().emit(1);
reference.get().emit(2);
subscriber.assertItems(1, 2).assertNotTerminated();
reference.get().complete();
subscriber.assertCompleted();
reference.get().onTermination(() -> called.set(true));
assertThat(called).isTrue();
}
Aggregations