use of io.servicetalk.concurrent.Cancellable in project servicetalk by apple.
the class CompletableProcessorTest method synchronousCancelStillAllowsForGCDoSubscribe.
private WeakReference<Subscriber> synchronousCancelStillAllowsForGCDoSubscribe(CompletableProcessor processor, ReferenceQueue<Subscriber> queue) {
Subscriber subscriber = new Subscriber() {
@Override
public void onSubscribe(final Cancellable cancellable) {
cancellable.cancel();
}
@Override
public void onComplete() {
}
@Override
public void onError(final Throwable t) {
}
};
processor.subscribe(subscriber);
return new WeakReference<>(subscriber, queue);
}
use of io.servicetalk.concurrent.Cancellable in project servicetalk by apple.
the class CompositeCancellableTest method testOne.
@Test
void testOne() {
Cancellable composite = holder.init(1);
assertThat("Composite of 1 must not create a new instance.", composite, is(holder.components[0]));
composite.cancel();
}
use of io.servicetalk.concurrent.Cancellable in project servicetalk by apple.
the class DefaultExecutorTest method cancelExecute.
@ParameterizedTest(name = "{displayName} [{index}] {arguments}")
@EnumSource(ExecutorParam.class)
void cancelExecute(ExecutorParam executorParam) throws Throwable {
executor = executorParam.get();
assumeTrue(executorParam.supportsCancellation(), () -> "Ignoring executor: " + executorParam + ", it does not support cancellation.");
CountDownLatch latch = new CountDownLatch(1);
Task awaitTillCancelled = Task.awaitFor(latch);
Cancellable cancellable = executor.execute(awaitTillCancelled);
awaitTillCancelled.awaitStart();
cancellable.cancel();
Executable executable = () -> awaitTillCancelled.awaitDone();
assertThrows(InterruptedException.class, executable);
}
use of io.servicetalk.concurrent.Cancellable in project servicetalk by apple.
the class AbstractCompositeCancellableTest method testCancel.
@Test
void testCancel() {
T c = newCompositeCancellable();
Cancellable cancellable = mock(Cancellable.class);
add(c, cancellable);
c.cancel();
verify(cancellable).cancel();
}
use of io.servicetalk.concurrent.Cancellable in project servicetalk by apple.
the class AbstractCompositeCancellableTest method multiThreadedAddCancel.
@Test
void multiThreadedAddCancel() throws Exception {
final int addThreads = 1000;
final CyclicBarrier barrier = new CyclicBarrier(addThreads + 1);
final List<Single<Cancellable>> cancellableSingles = new ArrayList<>(addThreads);
T dynamicCancellable = newCompositeCancellable();
for (int i = 0; i < addThreads; ++i) {
cancellableSingles.add(EXECUTOR_RULE.executor().submit(() -> {
Cancellable c = mock(Cancellable.class);
barrier.await();
add(dynamicCancellable, c);
return c;
}));
}
Future<Collection<Cancellable>> future = collectUnordered(cancellableSingles, addThreads).toFuture();
barrier.await();
dynamicCancellable.cancel();
Collection<Cancellable> cancellables = future.get();
for (Cancellable c : cancellables) {
verify(c).cancel();
}
}
Aggregations