Search in sources :

Example 61 with Disposable

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();
    }
}
Also used : Disposable(reactor.core.Disposable)

Example 62 with Disposable

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();
}
Also used : Disposable(reactor.core.Disposable) Test(org.junit.jupiter.api.Test) Disposable(reactor.core.Disposable) StepVerifier(reactor.test.StepVerifier) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Publisher(org.reactivestreams.Publisher) Subscription(org.reactivestreams.Subscription) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 63 with Disposable

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();
}
Also used : Disposable(reactor.core.Disposable) Test(org.junit.jupiter.api.Test)

Example 64 with Disposable

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");
}
Also used : Disposable(reactor.core.Disposable) Test(org.junit.jupiter.api.Test)

Example 65 with Disposable

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();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Disposable(reactor.core.Disposable) RouteBuilder(org.apache.camel.builder.RouteBuilder) CamelReactiveStreamsService(org.apache.camel.component.reactive.streams.api.CamelReactiveStreamsService) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Aggregations

Disposable (reactor.core.Disposable)118 Test (org.junit.jupiter.api.Test)99 CountDownLatch (java.util.concurrent.CountDownLatch)33 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)32 StepVerifier (reactor.test.StepVerifier)29 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)25 AtomicReference (java.util.concurrent.atomic.AtomicReference)18 Duration (java.time.Duration)15 List (java.util.List)15 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)15 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)15 Subscription (org.reactivestreams.Subscription)15 TimeUnit (java.util.concurrent.TimeUnit)14 Timeout (org.junit.jupiter.api.Timeout)13 CoreSubscriber (reactor.core.CoreSubscriber)12 ArrayList (java.util.ArrayList)11 Arrays (java.util.Arrays)11 Disabled (org.junit.jupiter.api.Disabled)11 Scannable (reactor.core.Scannable)11 Fuseable (reactor.core.Fuseable)10