use of reactor.core.Disposable in project reactor-core by reactor.
the class OldBoundedElasticScheduler method schedulePeriodically.
@Override
public Disposable schedulePeriodically(Runnable task, long initialDelay, long period, TimeUnit unit) {
final BoundedState picked = BOUNDED_SERVICES.get(this).pick();
Disposable scheduledTask = Schedulers.directSchedulePeriodically(picked.executor, task, initialDelay, period, unit);
// (ie decreases its usage by one)
return Disposables.composite(scheduledTask, picked);
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class FluxWindowPredicateTest method windowWhileNotPropagatingCancelToSource_withConcat.
// see https://github.com/reactor/reactor-core/issues/1452
@Test
public void windowWhileNotPropagatingCancelToSource_withConcat() {
// Similar to windowWhileNotPropagatingCancelToSource_disposeOuterFirst
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 Disposable disposable = sourceFlux.windowWhile(s -> !"#".equals(s)).doOnCancel(() -> afterWindowWhileStageCancelled.set(true)).as(Flux::concat).subscribe();
disposable.dispose();
assertThat(afterWindowWhileStageCancelled).as("afterWindowWhileStageCancelled cancelled").isTrue();
assertThat(beforeWindowWhileStageCancelled).as("beforeWindowWhileStageCancelled cancelled").isTrue();
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class FluxWindowPredicateTest method windowWhilePropagatingCancelToSource_disposeOuterFirst.
// see https://github.com/reactor/reactor-core/issues/1452
@Test
public void windowWhilePropagatingCancelToSource_disposeOuterFirst() {
final AtomicBoolean beforeWindowWhileStageCancelled = new AtomicBoolean();
final AtomicBoolean afterWindowWhileStageCancelled = new AtomicBoolean();
TestPublisher<String> testPublisher = TestPublisher.create();
final Flux<String> sourceFlux = testPublisher.flux().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());
});
testPublisher.next("1");
// Dispose outer subscription; we should see cancellation at stage after windowWhile, but not before
outerDisposable.dispose();
assertThat(afterWindowWhileStageCancelled).as("afterWindowWhileStageCancelled cancelled when outer is disposed").isTrue();
assertThat(beforeWindowWhileStageCancelled).as("beforeWindowWhileStageCancelled cancelled when outer is disposed").isFalse();
// Dispose inner subscription; we should see cancellation propagates all the way up
innerDisposable.dispose();
assertThat(afterWindowWhileStageCancelled).as("afterWindowWhileStageCancelled cancelled when inner is disposed").isTrue();
assertThat(beforeWindowWhileStageCancelled).as("beforeWindowWhileStageCancelled cancelled when inner is disposed").isTrue();
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class FluxRefCountTest method subscribersComeAndGoBelowThreshold.
@Test
public void subscribersComeAndGoBelowThreshold() {
Flux<Integer> p = Flux.range(1, 5).publish().refCount(2);
Disposable r = p.subscribe();
r.dispose();
p.subscribe().dispose();
p.subscribe().dispose();
p.subscribe().dispose();
p.subscribe().dispose();
AssertSubscriber<Integer> ts1 = AssertSubscriber.create();
p.subscribe(ts1);
ts1.assertValueCount(0);
AssertSubscriber<Integer> ts2 = AssertSubscriber.create();
p.subscribe(ts2);
ts1.assertValues(1, 2, 3, 4, 5);
ts2.assertValues(1, 2, 3, 4, 5);
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class FluxRefCountTest method reconnectsAfterRefCountZero.
@Test
public void reconnectsAfterRefCountZero() {
AtomicLong subscriptionCount = new AtomicLong();
AtomicReference<SignalType> termination = new AtomicReference<>();
Flux<Integer> source = Flux.range(1, 50).delayElements(Duration.ofMillis(100)).doFinally(termination::set).doOnSubscribe(s -> subscriptionCount.incrementAndGet());
Flux<Integer> refCounted = source.publish().refCount(2);
Disposable sub1 = refCounted.subscribe();
assertThat(subscriptionCount.get()).isZero();
assertThat(termination.get()).isNull();
Disposable sub2 = refCounted.subscribe();
assertThat(subscriptionCount).hasValue(1);
assertThat(termination.get()).isNull();
sub1.dispose();
assertThat(subscriptionCount).hasValue(1);
assertThat(termination.get()).isNull();
sub2.dispose();
assertThat(subscriptionCount).hasValue(1);
assertThat(termination).hasValue(SignalType.CANCEL);
try {
sub1 = refCounted.subscribe();
sub2 = refCounted.subscribe();
assertThat(subscriptionCount).hasValue(2);
} finally {
sub1.dispose();
sub2.dispose();
}
}
Aggregations