use of io.smallrye.mutiny.Context in project smallrye-mutiny by smallrye.
the class UniSerializedSubscriberTest method testDroppedExceptionsWhenOnFailureThrowsAnException.
@Test
public void testDroppedExceptionsWhenOnFailureThrowsAnException() {
AtomicReference<Throwable> captured = new AtomicReference<>();
Infrastructure.setDroppedExceptionHandler(captured::set);
AtomicReference<UniEmitter<? super Integer>> reference = new AtomicReference<>();
AbstractUni<Integer> uni = (AbstractUni<Integer>) Uni.createFrom().<Integer>emitter(reference::set);
UniSerializedSubscriber.subscribe(uni, new UniSubscriber<Integer>() {
@Override
public Context context() {
return Context.empty();
}
@Override
public void onSubscribe(UniSubscription subscription) {
// Do nothing
}
@Override
public void onItem(Integer item) {
// Do nothing
}
@Override
public void onFailure(Throwable failure) {
throw new IllegalArgumentException("boom");
}
});
try {
reference.get().fail(new IOException("I/O"));
fail("Exception expected");
} catch (IllegalArgumentException e) {
// Expected.
}
assertThat(captured.get()).isNotNull().isInstanceOf(CompositeException.class).hasMessageContaining("boom").hasMessageContaining("I/O");
}
use of io.smallrye.mutiny.Context in project smallrye-mutiny by smallrye.
the class UniSerializedSubscriberTest method testDroppedExceptionsWhenOnItemThrowsAnException.
@Test
public void testDroppedExceptionsWhenOnItemThrowsAnException() {
AtomicBoolean called = new AtomicBoolean();
AtomicReference<Throwable> captured = new AtomicReference<>();
Infrastructure.setDroppedExceptionHandler(captured::set);
AtomicReference<UniEmitter<? super Integer>> reference = new AtomicReference<>();
AbstractUni<Integer> uni = (AbstractUni<Integer>) Uni.createFrom().<Integer>emitter(reference::set);
UniSerializedSubscriber.subscribe(uni, new UniSubscriber<Integer>() {
@Override
public Context context() {
return Context.empty();
}
@Override
public void onSubscribe(UniSubscription subscription) {
// Do nothing
}
@Override
public void onItem(Integer item) {
throw new IllegalArgumentException("boom");
}
@Override
public void onFailure(Throwable failure) {
called.set(true);
}
});
try {
reference.get().complete(1);
fail("Exception expected");
} catch (IllegalArgumentException e) {
// Exception expected
}
assertThat(captured.get()).isNotNull().isInstanceOf(IllegalArgumentException.class).hasMessageContaining("boom");
assertThat(called).isFalse();
}
use of io.smallrye.mutiny.Context in project smallrye-mutiny by smallrye.
the class UniCreateFromEmitterTest method testFailureThrownBySubscribersOnFailure.
@Test
public void testFailureThrownBySubscribersOnFailure() {
AtomicBoolean onTerminationCalled = new AtomicBoolean();
Uni.createFrom().<Integer>emitter(emitter -> {
emitter.onTermination(() -> onTerminationCalled.set(true));
try {
emitter.fail(new Exception("boom"));
fail("Exception expected");
} catch (Exception ex) {
// expected
}
}).subscribe().withSubscriber(new UniSubscriber<Integer>() {
@Override
public Context context() {
return Context.empty();
}
@Override
public void onSubscribe(UniSubscription subscription) {
}
@Override
public void onItem(Integer ignored) {
}
@Override
public void onFailure(Throwable failure) {
throw new NullPointerException("boom");
}
});
assertThat(onTerminationCalled).isFalse();
}
use of io.smallrye.mutiny.Context in project smallrye-mutiny by smallrye.
the class UniCreateFromEmitterTest method testFailureThrownBySubscribersOnItem.
@Test
public void testFailureThrownBySubscribersOnItem() {
AtomicBoolean called = new AtomicBoolean();
AtomicBoolean onTerminationCalled = new AtomicBoolean();
Uni.createFrom().<Integer>emitter(emitter -> {
emitter.onTermination(() -> onTerminationCalled.set(true));
try {
emitter.complete(1);
fail("Exception expected");
} catch (Exception ex) {
// expected
}
}).subscribe().withSubscriber(new UniSubscriber<Integer>() {
@Override
public Context context() {
return Context.empty();
}
@Override
public void onSubscribe(UniSubscription subscription) {
}
@Override
public void onItem(Integer ignored) {
throw new NullPointerException("boom");
}
@Override
public void onFailure(Throwable failure) {
called.set(true);
}
});
assertThat(called).isFalse();
assertThat(onTerminationCalled).isFalse();
}
use of io.smallrye.mutiny.Context in project smallrye-mutiny by smallrye.
the class UniWithContext method subscribe.
@Override
public void subscribe(UniSubscriber<? super O> downstream) {
Context context = downstream.context();
Uni<O> uni;
try {
uni = builder.apply(upstream, context);
if (uni == null) {
downstream.onSubscribe(EmptyUniSubscription.DONE);
downstream.onFailure(new NullPointerException("The builder function returned null"));
return;
}
} catch (Throwable err) {
downstream.onSubscribe(EmptyUniSubscription.DONE);
downstream.onFailure(err);
return;
}
Uni<O> pipelineWithContext = Infrastructure.onUniCreation(uni);
AbstractUni.subscribe(pipelineWithContext, downstream);
}
Aggregations