use of io.smallrye.mutiny.Uni in project smallrye-mutiny by smallrye.
the class MultiFromResourceTest method cancellationShouldBePossible.
@Test
public void cancellationShouldBePossible() {
AssertSubscriber<Integer> subscriber = AssertSubscriber.create(20);
Supplier<Integer> supplier = () -> 1;
AtomicInteger onFailure = new AtomicInteger();
AtomicInteger onComplete = new AtomicInteger();
AtomicInteger onCancellation = new AtomicInteger();
BiFunction<Integer, Throwable, Uni<Void>> onFailureCallback = (s, f) -> {
onFailure.set(s);
return Uni.createFrom().voidItem();
};
Function<Integer, Uni<Void>> onCompletionCallback = s -> {
onComplete.set(s);
return Uni.createFrom().voidItem();
};
Function<Integer, Uni<Void>> onCancellationCallback = s -> {
onCancellation.set(s);
return Uni.createFrom().voidItem();
};
Multi.createFrom().<Integer, Integer>resource(supplier, r -> Multi.createFrom().nothing()).withFinalizer(onCompletionCallback, onFailureCallback, onCancellationCallback).subscribe(subscriber);
subscriber.cancel();
assertThat(onFailure).hasValue(0);
assertThat(onCancellation).hasValue(1);
assertThat(onComplete).hasValue(0);
}
use of io.smallrye.mutiny.Uni in project smallrye-mutiny by smallrye.
the class UniOnItemTransformToUniTest method testWithAnUniResolvedAsynchronouslyWithAFailure.
@Test
public void testWithAnUniResolvedAsynchronouslyWithAFailure() {
UniAssertSubscriber<Integer> test = UniAssertSubscriber.create();
Uni<Integer> uni = Uni.createFrom().item(1).onItem().transformToUni(v -> Uni.createFrom().emitter(emitter -> new Thread(() -> emitter.fail(new IOException("boom"))).start()));
uni.subscribe().withSubscriber(test);
test.awaitFailure().assertFailedWith(IOException.class, "boom");
}
use of io.smallrye.mutiny.Uni in project smallrye-health by smallrye.
the class SmallRyeHealthReporter method getHealthAsync.
private Uni<SmallRyeHealth> getHealthAsync(Collection<Uni<HealthCheckResponse>> checks) {
List<Uni<HealthCheckResponse>> healthCheckUnis = new ArrayList<>();
if (checks != null) {
healthCheckUnis.addAll(checks);
}
if (!additionalChecks.isEmpty()) {
healthCheckUnis.addAll(additionalChecks.values());
}
if (healthCheckUnis.isEmpty()) {
return Uni.createFrom().item(createEmptySmallRyeHealth(emptyChecksOutcome));
}
return Uni.combine().all().unis(healthCheckUnis).combinedWith(responses -> {
JsonArrayBuilder results = jsonProvider.createArrayBuilder();
HealthCheckResponse.Status status = HealthCheckResponse.Status.UP;
for (Object o : responses) {
HealthCheckResponse response = (HealthCheckResponse) o;
status = handleResponse(response, results, status);
}
return createSmallRyeHealth(results, status, emptyChecksOutcome);
});
}
use of io.smallrye.mutiny.Uni in project smallrye-health by smallrye.
the class SmallRyeHealthReporter method computeHealth.
private Uni<SmallRyeHealth> computeHealth(HealthType[] types) {
List<Uni<HealthCheckResponse>> checks = new ArrayList<>();
for (HealthType type : types) {
switch(type) {
case LIVENESS:
checks.addAll(livenessUnis);
checks.addAll(livenessHealthRegistry.getChecks(healthChecksConfigs));
break;
case READINESS:
checks.addAll(readinessUnis);
checks.addAll(readinessHealthRegistry.getChecks(healthChecksConfigs));
break;
case WELLNESS:
checks.addAll(wellnessUnis);
checks.addAll(wellnessHealthRegistry.getChecks(healthChecksConfigs));
break;
case STARTUP:
checks.addAll(startupUnis);
checks.addAll(startupHealthRegistry.getChecks(healthChecksConfigs));
break;
}
}
return getHealthAsync(checks);
}
use of io.smallrye.mutiny.Uni in project hibernate-reactive by hibernate.
the class MultipleContextTest method testOnPersistWithMutiny.
@Test
public void testOnPersistWithMutiny(TestContext testContext) {
final Async async = testContext.async();
Uni<Mutiny.Session> sessionUni = getMutinySessionFactory().openSession();
currentSession = sessionUni;
Context testVertxContext = Vertx.currentContext();
// Create a different new context
Context newContext = Vertx.vertx().getOrCreateContext();
Assertions.assertThat(testVertxContext).isNotEqualTo(newContext);
test(testContext, sessionUni.invoke(session -> newContext.runOnContext(event -> test(async, testContext, session.persist(new Competition("Cheese Rolling")).onItemOrFailure().transformToUni((unused, e) -> Uni.createFrom().completionStage(assertExceptionThrown(e)))))));
}
Aggregations