use of reactor.core.Disposable in project reactor-core by reactor.
the class UnicastProcessorTest method subscriptionCancelUpdatesDownstreamCount.
@Test
public void subscriptionCancelUpdatesDownstreamCount() {
UnicastProcessor<String> processor = UnicastProcessor.create();
assertThat(processor.currentSubscriberCount()).as("before subscribe").isZero();
LambdaSubscriber<String> subscriber = new LambdaSubscriber<>(null, null, null, null);
Disposable subscription = processor.subscribeWith(subscriber);
assertThat(processor.currentSubscriberCount()).as("after subscribe").isPositive();
assertThat(processor.actual()).as("after subscribe has actual").isSameAs(subscriber);
subscription.dispose();
assertThat(processor.currentSubscriberCount()).as("after subscription cancel").isZero();
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class UnicastProcessorTest method createOverrideAll.
@Test
public void createOverrideAll() {
Disposable onTerminate = () -> {
};
Consumer<? super Integer> onOverflow = t -> {
};
Queue<Integer> queue = Queues.<Integer>get(10).get();
UnicastProcessor<Integer> processor = UnicastProcessor.create(queue, onOverflow, onTerminate);
assertProcessor(processor, queue, onOverflow, onTerminate);
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class MonoUsingWhenTest method blockOnNeverResourceCanBeCancelled.
@Test
public void blockOnNeverResourceCanBeCancelled() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
Disposable disposable = Mono.usingWhen(Mono.<String>never(), Mono::just, Flux::just, (res, err) -> Flux.just(res), Flux::just).doFinally(f -> latch.countDown()).subscribe();
assertThat(latch.await(500, TimeUnit.MILLISECONDS)).as("hangs before dispose").isFalse();
disposable.dispose();
assertThat(latch.await(100, TimeUnit.MILLISECONDS)).as("terminates after dispose").isTrue();
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class OperatorDisposablesTest method dispose.
@Test
public void dispose() {
Disposable u = Disposables.single();
TestDisposable r = new TestDisposable(u);
OperatorDisposables.dispose(DISPOSABLE_UPDATER, r);
assertThat(u.isDisposed()).isTrue();
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class ParallelFluxTest method parallelSubscribeAndDispose.
@Test
public void parallelSubscribeAndDispose() throws InterruptedException {
AtomicInteger nextCount = new AtomicInteger();
CountDownLatch cancelLatch = new CountDownLatch(1);
TestPublisher<Integer> source = TestPublisher.create();
Disposable d = source.flux().parallel(3).doOnCancel(cancelLatch::countDown).subscribe(i -> nextCount.incrementAndGet());
source.next(1, 2, 3);
d.dispose();
source.emit(4, 5, 6);
boolean finished = cancelLatch.await(300, TimeUnit.MILLISECONDS);
assertThat(finished).as("cancelled latch").isTrue();
assertThat(d.isDisposed()).as("disposed").isTrue();
assertThat(nextCount.get()).as("received count").isEqualTo(3);
}
Aggregations