use of io.servicetalk.concurrent.Cancellable.IGNORE_CANCEL in project servicetalk by apple.
the class CompletableConcatWithCompletablesTest method testSourceSuccessReentrant.
@ParameterizedTest
@ValueSource(ints = { 1, 2, 10000 })
void testSourceSuccessReentrant(int num) {
Completable[] mockCompletables = new Completable[num];
for (int i = 0; i < mockCompletables.length; ++i) {
CompletableSource mockCompletable = mock(CompletableSource.class);
doAnswer((Answer<Void>) invocation -> {
CompletableSource.Subscriber sub = invocation.getArgument(0);
sub.onSubscribe(IGNORE_CANCEL);
sub.onComplete();
return null;
}).when(mockCompletable).subscribe(any());
mockCompletables[i] = fromSource(mockCompletable);
}
toSource(source.concat(mockCompletables)).subscribe(subscriber);
source.onComplete();
subscriber.awaitOnComplete();
}
use of io.servicetalk.concurrent.Cancellable.IGNORE_CANCEL in project servicetalk by apple.
the class ReactiveStreamsAdaptersTest method completableToRSFromSourceSuccess.
@Test
void completableToRSFromSourceSuccess() {
CompletableSource source = s -> {
s.onSubscribe(IGNORE_CANCEL);
s.onComplete();
};
verifyRSSuccess(toRSPublisherFromSourceAndSubscribe(source), false);
}
use of io.servicetalk.concurrent.Cancellable.IGNORE_CANCEL in project servicetalk by apple.
the class ServiceTalkThreadContextMapTest method testAsyncExecution.
@Test
void testAsyncExecution() throws Exception {
ExecutorService executor = Executors.newSingleThreadExecutor();
try {
MDC.clear();
MDC.put("a", "1");
MDC.put("b", "2");
// human inspection as sanity check
logger.info("expected a=1 b=2");
Thread original = Thread.currentThread();
Single<String> single = new Single<String>() {
@Override
protected void handleSubscribe(Subscriber<? super String> singleSubscriber) {
executor.execute(() -> {
singleSubscriber.onSubscribe(IGNORE_CANCEL);
singleSubscriber.onSuccess("1");
});
}
}.map(v -> {
assertNotEquals(Thread.currentThread(), original);
assertEquals("1", MDC.get("a"));
assertEquals("2", MDC.get("b"));
MDC.put("b", "22");
return v;
}).beforeFinally(() -> {
// human inspection as sanity check
logger.info("expected a=1 b=22");
assertEquals("1", MDC.get("a"));
assertEquals("22", MDC.get("b"));
});
single.toFuture().get();
} finally {
executor.shutdown();
}
}
use of io.servicetalk.concurrent.Cancellable.IGNORE_CANCEL in project servicetalk by apple.
the class SourceAdaptersTest method completableFromSourceSuccess.
@Test
void completableFromSourceSuccess() throws Exception {
CompletableSource src = s -> {
s.onSubscribe(IGNORE_CANCEL);
s.onComplete();
};
fromSource(src).toFuture().get();
}
use of io.servicetalk.concurrent.Cancellable.IGNORE_CANCEL in project servicetalk by apple.
the class SourceAdaptersTest method completableFromSourceError.
@Test
void completableFromSourceError() {
CompletableSource src = s -> {
s.onSubscribe(IGNORE_CANCEL);
s.onError(DELIBERATE_EXCEPTION);
};
Future<Void> future = fromSource(src).toFuture();
Exception e = assertThrows(ExecutionException.class, () -> future.get());
assertThat(e.getCause(), sameInstance(DELIBERATE_EXCEPTION));
}
Aggregations