Search in sources :

Example 61 with Subscription

use of org.reactivestreams.Subscription in project reactor-core by reactor.

the class StrictSubscriberTest method requestDelayed.

@Test
public void requestDelayed() {
    AtomicBoolean state = new AtomicBoolean();
    AtomicReference<Throwable> e = new AtomicReference<>();
    Flux.just(1).subscribe(new Subscriber<Integer>() {

        boolean open;

        @Override
        public void onSubscribe(Subscription s) {
            s.request(1);
            open = true;
        }

        @Override
        public void onNext(Integer t) {
            state.set(open);
        }

        @Override
        public void onError(Throwable t) {
            e.set(t);
        }

        @Override
        public void onComplete() {
        }
    });
    Assert.assertNull("Error: " + e.get(), e.get());
    Assert.assertTrue("Not open!", state.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 62 with Subscription

use of org.reactivestreams.Subscription in project reactor-core by reactor.

the class StrictSubscriberTest method requestNotDelayed.

@Test
public void requestNotDelayed() {
    AtomicBoolean state = new AtomicBoolean();
    AtomicReference<Throwable> e = new AtomicReference<>();
    Flux.just(1).subscribe(new CoreSubscriber<Integer>() {

        boolean open;

        @Override
        public void onSubscribe(Subscription s) {
            s.request(1);
            open = true;
        }

        @Override
        public void onNext(Integer t) {
            state.set(open);
        }

        @Override
        public void onError(Throwable t) {
            e.set(t);
        }

        @Override
        public void onComplete() {
        }
    });
    Assert.assertNull("Error: " + e.get(), e.get());
    Assert.assertFalse("Request delayed!", state.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 63 with Subscription

use of org.reactivestreams.Subscription in project reactor-core by reactor.

the class TopicProcessorTest method scanProcessor.

@Test
public void scanProcessor() {
    TopicProcessor<String> test = TopicProcessor.create("name", 16);
    Subscription subscription = Operators.emptySubscription();
    test.onSubscribe(subscription);
    assertThat(test.scan(Scannable.Attr.PARENT)).isEqualTo(subscription);
    assertThat(test.scan(Scannable.Attr.CAPACITY)).isEqualTo(16);
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
    assertThat(test.scan(Scannable.Attr.ERROR)).isNull();
    test.onError(new IllegalStateException("boom"));
    assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom");
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
}
Also used : Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 64 with Subscription

use of org.reactivestreams.Subscription in project reactor-core by reactor.

the class OperatorsTest method drainSubscriber.

@Test
public void drainSubscriber() {
    AtomicBoolean requested = new AtomicBoolean();
    AtomicBoolean errored = new AtomicBoolean();
    try {
        Hooks.onErrorDropped(e -> {
            assertThat(Exceptions.isErrorCallbackNotImplemented(e)).isTrue();
            assertThat(e.getCause()).hasMessage("test");
            errored.set(true);
        });
        Flux.from(s -> {
            assertThat(s).isEqualTo(Operators.drainSubscriber());
            s.onSubscribe(new Subscription() {

                @Override
                public void request(long n) {
                    assertThat(n).isEqualTo(Long.MAX_VALUE);
                    requested.set(true);
                }

                @Override
                public void cancel() {
                }
            });
            // dropped
            s.onNext("ignored");
            // dropped
            s.onComplete();
            s.onError(new Exception("test"));
        }).subscribe(Operators.drainSubscriber());
        assertThat(requested.get()).isTrue();
        assertThat(errored.get()).isTrue();
    } finally {
        Hooks.resetOnErrorDropped();
    }
}
Also used : Scannable(reactor.core.Scannable) BiFunction(java.util.function.BiFunction) Context(reactor.util.context.Context) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLongFieldUpdater(java.util.concurrent.atomic.AtomicLongFieldUpdater) Test(org.junit.Test) MultiSubscriptionSubscriber(reactor.core.publisher.Operators.MultiSubscriptionSubscriber) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) List(java.util.List) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) CoreSubscriber(reactor.core.CoreSubscriber) Fuseable(reactor.core.Fuseable) CancelledSubscription(reactor.core.publisher.Operators.CancelledSubscription) Subscription(org.reactivestreams.Subscription) ScalarSubscription(reactor.core.publisher.Operators.ScalarSubscription) Exceptions(reactor.core.Exceptions) Nullable(javax.annotation.Nullable) MonoSubscriber(reactor.core.publisher.Operators.MonoSubscriber) DeferredSubscription(reactor.core.publisher.Operators.DeferredSubscription) EmptySubscription(reactor.core.publisher.Operators.EmptySubscription) RaceTestUtils(reactor.test.RaceTestUtils) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CancelledSubscription(reactor.core.publisher.Operators.CancelledSubscription) Subscription(org.reactivestreams.Subscription) ScalarSubscription(reactor.core.publisher.Operators.ScalarSubscription) DeferredSubscription(reactor.core.publisher.Operators.DeferredSubscription) EmptySubscription(reactor.core.publisher.Operators.EmptySubscription) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Test(org.junit.Test)

Example 65 with Subscription

use of org.reactivestreams.Subscription in project reactor-core by reactor.

the class OperatorsTest method scanMultiSubscriptionSubscriber.

@Test
public void scanMultiSubscriptionSubscriber() {
    CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, null, null, null);
    MultiSubscriptionSubscriber<Integer, Integer> test = new MultiSubscriptionSubscriber<Integer, Integer>(actual) {

        @Override
        public void onNext(Integer t) {
        }
    };
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);
    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
    test.request(34);
    assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(34);
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
    test.cancel();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
Also used : MultiSubscriptionSubscriber(reactor.core.publisher.Operators.MultiSubscriptionSubscriber) CancelledSubscription(reactor.core.publisher.Operators.CancelledSubscription) Subscription(org.reactivestreams.Subscription) ScalarSubscription(reactor.core.publisher.Operators.ScalarSubscription) DeferredSubscription(reactor.core.publisher.Operators.DeferredSubscription) EmptySubscription(reactor.core.publisher.Operators.EmptySubscription) Test(org.junit.Test)

Aggregations

Subscription (org.reactivestreams.Subscription)627 Test (org.junit.Test)506 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)158 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)131 ArrayList (java.util.ArrayList)117 AtomicReference (java.util.concurrent.atomic.AtomicReference)105 List (java.util.List)80 FluxOperatorTest (reactor.test.publisher.FluxOperatorTest)74 Subscriber (org.reactivestreams.Subscriber)68 AtomicLong (java.util.concurrent.atomic.AtomicLong)56 Assert (org.junit.Assert)56 Arrays (java.util.Arrays)43 BaseSequentialTest (com.oath.cyclops.streams.BaseSequentialTest)42 Vector (cyclops.data.Vector)39 ReactiveSeq (cyclops.reactive.ReactiveSeq)39 Executor (java.util.concurrent.Executor)38 Spouts (cyclops.reactive.Spouts)36 Arrays.asList (java.util.Arrays.asList)36 Executors (java.util.concurrent.Executors)35 StepVerifier (reactor.test.StepVerifier)34