use of reactor.core.Disposable in project reactor-core by reactor.
the class FluxPublishTest method disconnect.
@Test
public void disconnect() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
Sinks.Many<Integer> e = Sinks.many().multicast().onBackpressureBuffer();
ConnectableFlux<Integer> p = e.asFlux().publish();
p.subscribe(ts);
Disposable r = p.connect();
e.emitNext(1, FAIL_FAST);
e.emitNext(2, FAIL_FAST);
r.dispose();
ts.assertValues(1, 2).assertError(CancellationException.class).assertNotComplete();
assertThat(e.currentSubscriberCount()).as("still connected").isZero();
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class FluxPublishTest method disconnectBackpressured.
@Test
public void disconnectBackpressured() {
AssertSubscriber<Integer> ts = AssertSubscriber.create(0);
Sinks.Many<Integer> e = Sinks.many().multicast().onBackpressureBuffer();
ConnectableFlux<Integer> p = e.asFlux().publish();
p.subscribe(ts);
Disposable r = p.connect();
r.dispose();
ts.assertNoValues().assertError(CancellationException.class).assertNotComplete();
assertThat(e.currentSubscriberCount()).as("still connected").isZero();
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class FluxRefCountGraceTest method subscribersComeAndGoBelowThreshold.
@Test
public void subscribersComeAndGoBelowThreshold() {
Flux<Integer> p = Flux.range(1, 5).publish().refCount(2, Duration.ofMillis(500));
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 FluxPublishMulticastTest method scenarios_errorFromUpstreamFailure.
@Override
protected List<Scenario<String, String>> scenarios_errorFromUpstreamFailure() {
return Arrays.asList(scenario(f -> f.publish(p -> p)), scenario(f -> f.publish(p -> {
// TODO double check this Sink usage
Sinks.Many<String> sink = Sinks.unsafe().many().unicast().onBackpressureBuffer();
p.subscribe(v -> sink.emitNext(v, FAIL_FAST), e -> sink.emitError(e, FAIL_FAST), () -> sink.emitComplete(FAIL_FAST));
return sink.asFlux();
})).fusionMode(Fuseable.ASYNC), scenario(f -> f.publish(p -> p)).shouldHitDropNextHookAfterTerminate(false), scenario(f -> Flux.never().publish(p -> {
Disposable d = p.subscribe();
Disposable d2 = p.subscribe();
d.dispose();
d2.dispose();
return f;
})).shouldHitDropErrorHookAfterTerminate(false).shouldHitDropNextHookAfterTerminate(false));
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class FluxTests method consistentMultithreadingWithPartition.
@Test
public void consistentMultithreadingWithPartition() throws InterruptedException {
Scheduler supplier1 = afterTest.autoDispose(Schedulers.newParallel("groupByPool", 2));
Scheduler supplier2 = afterTest.autoDispose(Schedulers.newParallel("partitionPool", 5));
CountDownLatch latch = new CountDownLatch(10);
/*Disposable c = */
Flux.range(1, 10).groupBy(n -> n % 2 == 0).flatMap(stream -> stream.publishOn(supplier1).log("groupBy-" + stream.key())).parallel(5).runOn(supplier2).sequential().publishOn(asyncGroup).log("join").subscribe(t -> {
latch.countDown();
});
latch.await(30, TimeUnit.SECONDS);
assertThat(latch.getCount()).as("dispatch count").isEqualTo(0L);
}
Aggregations