use of reactor.core.Disposable in project reactor-core by reactor.
the class OperatorDisposablesTest method trySet.
@Test
public void trySet() {
TestDisposable r = new TestDisposable();
Disposable d1 = Disposables.single();
assertThat(OperatorDisposables.trySet(DISPOSABLE_UPDATER, r, d1)).isTrue();
Disposable d2 = Disposables.single();
assertThat(OperatorDisposables.trySet(DISPOSABLE_UPDATER, r, d2)).isFalse();
assertThat(d1.isDisposed()).isFalse();
assertThat(d2.isDisposed()).isFalse();
OperatorDisposables.dispose(DISPOSABLE_UPDATER, r);
Disposable d3 = Disposables.single();
assertThat(OperatorDisposables.trySet(DISPOSABLE_UPDATER, r, d3)).isFalse();
assertThat(d3.isDisposed()).isTrue();
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class FluxWindowPredicateTest method windowWhileNotPropagatingCancelToSource_disposeInnerFirst.
// see https://github.com/reactor/reactor-core/issues/1452
@Test
public void windowWhileNotPropagatingCancelToSource_disposeInnerFirst() {
final AtomicBoolean beforeWindowWhileStageCancelled = new AtomicBoolean();
final AtomicBoolean afterWindowWhileStageCancelled = new AtomicBoolean();
final Flux<String> sourceFlux = Flux.<String>create(fluxSink -> fluxSink.next("0").next("#")).doOnCancel(() -> beforeWindowWhileStageCancelled.set(true));
final AtomicInteger windowCounter = new AtomicInteger();
final Disposable.Swap innerDisposable = Disposables.swap();
final Disposable outerDisposable = sourceFlux.windowWhile(s -> !"#".equals(s)).doOnCancel(() -> afterWindowWhileStageCancelled.set(true)).subscribe(next -> {
final int windowId = windowCounter.getAndIncrement();
innerDisposable.update(next.subscribe());
});
// Dispose inner subscription, outer Flux at before/after the windowWhile stage should not be cancelled yet
innerDisposable.dispose();
assertThat(afterWindowWhileStageCancelled).as("afterWindowWhileStageCancelled cancelled when inner is disposed").isFalse();
assertThat(beforeWindowWhileStageCancelled).as("beforeWindowWhileStageCancelled cancelled when inner is disposed").isFalse();
// Dispose outer subscription; we should see cancellation propagates all the way up
outerDisposable.dispose();
assertThat(afterWindowWhileStageCancelled).as("afterWindowWhileStageCancelled cancelled when outer is disposed").isTrue();
assertThat(beforeWindowWhileStageCancelled).as("beforeWindowWhileStageCancelled cancelled when outer is disposed").isTrue();
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class FluxUsingWhenTest method blockOnNeverResourceCanBeCancelled.
@Test
public void blockOnNeverResourceCanBeCancelled() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
Disposable disposable = Flux.usingWhen(Flux.<String>never(), Flux::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 MonoCollectListTest method cancelPropagatesEvenOnEmptySource.
@Test
// See https://github.com/reactor/reactor-core/issues/2519
void cancelPropagatesEvenOnEmptySource() {
AtomicBoolean cancel1 = new AtomicBoolean();
AtomicBoolean cancel2 = new AtomicBoolean();
Flux<?> publisher = Flux.never().hide().doOnCancel(() -> cancel1.set(true)).collectList().doOnCancel(() -> cancel2.set(true)).flatMapIterable(Function.identity());
Disposable d = publisher.subscribe();
d.dispose();
SoftAssertions.assertSoftly(softly -> {
softly.assertThat(cancel1).as("cancel1").isTrue();
softly.assertThat(cancel2).as("cancel2").isTrue();
});
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class MonoCollectTest method cancelPropagatesEvenOnEmptySource.
@Test
// See https://github.com/reactor/reactor-core/issues/2519
void cancelPropagatesEvenOnEmptySource() {
AtomicBoolean cancel1 = new AtomicBoolean();
AtomicBoolean cancel2 = new AtomicBoolean();
Flux<?> publisher = Flux.never().hide().doOnCancel(() -> cancel1.set(true)).collectMultimap(Function.identity()).doOnCancel(() -> cancel2.set(true)).flatMapIterable(Map::entrySet);
Disposable d = publisher.subscribe();
d.dispose();
SoftAssertions.assertSoftly(softly -> {
softly.assertThat(cancel1).as("cancel1").isTrue();
softly.assertThat(cancel2).as("cancel2").isTrue();
});
}
Aggregations