use of io.smallrye.mutiny.subscription.UniSubscription in project smallrye-mutiny by smallrye.
the class UniCallbackSubscriber method onFailure.
@Override
public final void onFailure(Throwable t) {
UniSubscription sub = SUBSCRIPTION_UPDATER.getAndSet(this, CANCELLED);
if (sub == CANCELLED) {
// Already cancelled, do nothing
return;
}
onFailureCallback.accept(t);
}
use of io.smallrye.mutiny.subscription.UniSubscription in project smallrye-mutiny by smallrye.
the class UniSerializedSubscriberTest method testDroppedExceptionsWhenOnFailureCalledMultipleTimes.
@Test
public void testDroppedExceptionsWhenOnFailureCalledMultipleTimes() {
AtomicReference<Throwable> received = new AtomicReference<>();
AtomicReference<Throwable> captured = new AtomicReference<>();
Infrastructure.setDroppedExceptionHandler(captured::set);
AtomicReference<UniSubscriber<? super Integer>> sub = new AtomicReference<>();
AbstractUni<Integer> uni = new AbstractUni<Integer>() {
@Override
public void subscribe(UniSubscriber<? super Integer> subscriber) {
sub.set(subscriber);
}
};
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) {
received.set(failure);
}
});
sub.get().onSubscribe(mock(UniSubscription.class));
sub.get().onFailure(new IOException("I/O"));
assertThat(captured.get()).isNull();
assertThat(received.get()).isInstanceOf(IOException.class).hasMessageContaining("I/O");
sub.get().onFailure(new IllegalStateException("boom"));
assertThat(captured.get()).isNotNull().isInstanceOf(IllegalStateException.class).hasMessageContaining("boom");
assertThat(received.get()).isInstanceOf(IOException.class).hasMessageContaining("I/O");
}
use of io.smallrye.mutiny.subscription.UniSubscription in project smallrye-mutiny by smallrye.
the class UniOnSubscribeTest method testOnSubscribed.
@Test
public void testOnSubscribed() {
AtomicInteger count = new AtomicInteger();
AtomicReference<UniSubscription> reference = new AtomicReference<>();
Uni<Integer> uni = Uni.createFrom().item(1).onSubscription().invoke(s -> {
reference.set(s);
count.incrementAndGet();
});
UniAssertSubscriber<Integer> subscriber = UniAssertSubscriber.create();
assertThat(count).hasValue(0);
assertThat(reference).hasValue(null);
uni.subscribe().withSubscriber(subscriber);
assertThat(count).hasValue(1);
assertThat(reference).doesNotHaveValue(null);
uni.subscribe().withSubscriber(subscriber);
assertThat(count).hasValue(2);
assertThat(reference).doesNotHaveValue(null);
}
use of io.smallrye.mutiny.subscription.UniSubscription in project smallrye-mutiny by smallrye.
the class UniOnSubscribeTest method testCallWithSupplier.
@Test
public void testCallWithSupplier() {
AtomicInteger count = new AtomicInteger();
AtomicReference<UniSubscription> sub = new AtomicReference<>();
Uni<Integer> uni = Uni.createFrom().item(1).onSubscription().call(() -> {
count.incrementAndGet();
return Uni.createFrom().nullItem().onSubscription().invoke(sub::set);
});
UniAssertSubscriber<Integer> subscriber = UniAssertSubscriber.create();
assertThat(count).hasValue(0);
assertThat(sub).hasValue(null);
uni.subscribe().withSubscriber(subscriber);
assertThat(count).hasValue(1);
assertThat(sub).doesNotHaveValue(null);
uni.subscribe().withSubscriber(subscriber);
assertThat(count).hasValue(2);
assertThat(sub).doesNotHaveValue(null);
}
use of io.smallrye.mutiny.subscription.UniSubscription in project smallrye-mutiny by smallrye.
the class UniOnSubscribeTest method testDelayedCallAfterFailure.
@Test
public void testDelayedCallAfterFailure() {
AtomicInteger count = new AtomicInteger();
AtomicReference<UniSubscription> reference = new AtomicReference<>();
AtomicReference<UniSubscription> sub = new AtomicReference<>();
Uni<Object> uni = Uni.createFrom().failure(new IOException("boom")).onSubscription().call(s -> {
reference.set(s);
count.incrementAndGet();
return Uni.createFrom().emitter(e -> {
new Thread(() -> {
await().during(100, TimeUnit.MILLISECONDS);
e.complete("yo");
}).start();
}).onSubscription().invoke(sub::set);
});
UniAssertSubscriber<Object> subscriber = UniAssertSubscriber.create();
assertThat(count).hasValue(0);
assertThat(reference).hasValue(null);
assertThat(sub).hasValue(null);
uni.subscribe().withSubscriber(subscriber);
assertThat(count).hasValue(1);
assertThat(reference).doesNotHaveValue(null);
assertThat(sub).doesNotHaveValue(null);
uni.subscribe().withSubscriber(subscriber);
assertThat(count).hasValue(2);
assertThat(reference).doesNotHaveValue(null);
assertThat(sub).doesNotHaveValue(null);
}
Aggregations