use of reactor.core.Disposable in project reactor-core by reactor.
the class FluxRefCountGrace method timeout.
void timeout(RefConnection rc) {
Disposable dispose = null;
synchronized (this) {
if (rc.subscriberCount == 0 && rc == connection) {
connection = null;
dispose = RefConnection.SOURCE_DISCONNECTOR.getAndSet(rc, Disposables.disposed());
}
}
if (dispose != null) {
dispose.dispose();
}
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class FluxDelayUntilTest method immediateCancel.
@Test
public void immediateCancel() {
AtomicReference<String> value = new AtomicReference<>();
AtomicReference<Throwable> error = new AtomicReference<>();
Disposable s = Flux.just("foo", "bar").delayUntil(v -> Mono.just(1)).subscribeWith(new LambdaSubscriber<>(value::set, error::set, () -> {
}, Subscription::cancel));
assertThat(value.get()).isNull();
// would be a NPE if trigger array wasn't pre-initialized
assertThat(error.get()).isNull();
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class PublisherProbeTest method wasCancelledMono.
@Test
public void wasCancelledMono() {
PublisherProbe<Void> probe = PublisherProbe.of(Mono.never());
Disposable d = probe.mono().subscribe();
assertThat(probe.wasCancelled()).isFalse();
d.dispose();
assertThat(probe.wasCancelled()).isTrue();
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class PublisherProbeTest method assertWasNotCancelledMono.
@Test
public void assertWasNotCancelledMono() {
PublisherProbe<Void> probe = PublisherProbe.of(Mono.never());
Disposable d = probe.mono().subscribe();
probe.assertWasNotCancelled();
d.dispose();
assertThatExceptionOfType(AssertionError.class).isThrownBy(probe::assertWasNotCancelled).withMessage("PublisherProbe should not have been cancelled but it was");
}
use of reactor.core.Disposable in project wildfly-camel by wildfly-extras.
the class ReactorIntegrationTest method testMultipleSubscriptionsWithTimer.
@Test
public void testMultipleSubscriptionsWithTimer() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("timer:tick?period=50").setBody().header(Exchange.TIMER_COUNTER).to("reactive-streams:tick");
}
});
CountDownLatch latch1 = new CountDownLatch(5);
CamelReactiveStreamsService crs = CamelReactiveStreams.get(camelctx);
Disposable disp1 = Flux.from(crs.fromStream("tick", Integer.class)).subscribe(res -> latch1.countDown());
camelctx.start();
try {
// Add another subscription
CountDownLatch latch2 = new CountDownLatch(5);
Disposable disp2 = Flux.from(crs.fromStream("tick", Integer.class)).subscribe(res -> latch2.countDown());
Assert.assertTrue(latch1.await(5, TimeUnit.SECONDS));
Assert.assertTrue(latch2.await(5, TimeUnit.SECONDS));
// Un subscribe both
disp1.dispose();
disp2.dispose();
// No active subscriptions, warnings expected
Thread.sleep(60);
// Add another subscription
CountDownLatch latch3 = new CountDownLatch(5);
Disposable disp3 = Flux.from(crs.fromStream("tick", Integer.class)).subscribe(res -> latch3.countDown());
Assert.assertTrue(latch3.await(5, TimeUnit.SECONDS));
disp3.dispose();
} finally {
camelctx.stop();
}
}
Aggregations