Search in sources :

Example 46 with Subscription

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

the class FluxDistinctUntilChangedTest method scanConditionalSubscriber.

@Test
public void scanConditionalSubscriber() {
    @SuppressWarnings("unchecked") Fuseable.ConditionalSubscriber<String> actual = Mockito.mock(MockUtils.TestScannableConditionalSubscriber.class);
    FluxDistinctUntilChanged.DistinctUntilChangedConditionalSubscriber<String, Integer> test = new FluxDistinctUntilChanged.DistinctUntilChangedConditionalSubscriber<>(actual, String::hashCode, Objects::equals);
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
    test.onError(new IllegalStateException("boom"));
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
}
Also used : Objects(java.util.Objects) MockUtils(reactor.test.MockUtils) Subscription(org.reactivestreams.Subscription) Fuseable(reactor.core.Fuseable) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest)

Example 47 with Subscription

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

the class FluxDistinctUntilChangedTest method scanSubscriber.

@Test
public void scanSubscriber() {
    CoreSubscriber<String> actual = new LambdaSubscriber<>(null, e -> {
    }, null, null);
    FluxDistinctUntilChanged.DistinctUntilChangedSubscriber<String, Integer> test = new FluxDistinctUntilChanged.DistinctUntilChangedSubscriber<>(actual, String::hashCode, Objects::equals);
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
    test.onError(new IllegalStateException("boom"));
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
}
Also used : Objects(java.util.Objects) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest)

Example 48 with Subscription

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

the class FluxConcatArrayTest method scanDelayErrorSubscriber.

@Test
public void scanDelayErrorSubscriber() {
    CoreSubscriber<String> actual = new LambdaSubscriber<>(null, e -> {
    }, null, null);
    @SuppressWarnings("unchecked") Publisher<String>[] emptyPub = (Publisher<String>[]) new Publisher[0];
    FluxConcatArray.ConcatArrayDelayErrorSubscriber<String> test = new FluxConcatArray.ConcatArrayDelayErrorSubscriber<>(actual, emptyPub);
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);
    assertThat(test.scan(Scannable.Attr.DELAY_ERROR)).isTrue();
    test.missedRequested = 2;
    test.requested = 3;
    test.error = new IllegalStateException("boom");
    assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom");
    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
    assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(5L);
    test.cancel();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
Also used : Publisher(org.reactivestreams.Publisher) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 49 with Subscription

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

the class FluxConcatMapTest method scanConcatMapDelayed.

@Test
public void scanConcatMapDelayed() {
    CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {
    }, null, null);
    FluxConcatMap.ConcatMapDelayed<String, Integer> test = new FluxConcatMap.ConcatMapDelayed<>(actual, s -> Mono.just(s.length()), Queues.one(), 123, true);
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);
    test.error = new IllegalStateException("boom");
    test.queue.offer("foo");
    assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(1);
    assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(123);
    assertThat(test.scan(Scannable.Attr.DELAY_ERROR)).isTrue();
    assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom");
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
    test.onError(new IllegalStateException("boom"));
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
    test.cancelled = true;
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
Also used : Subscription(org.reactivestreams.Subscription) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest)

Example 50 with Subscription

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

the class FluxConcatMapTest method scanConcatMapImmediate.

@Test
public void scanConcatMapImmediate() {
    CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, e -> {
    }, null, null);
    FluxConcatMap.ConcatMapImmediate<String, Integer> test = new FluxConcatMap.ConcatMapImmediate<>(actual, s -> Mono.just(s.length()), Queues.one(), 123);
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);
    test.queue.offer("foo");
    assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(1);
    assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(123);
    assertThat(test.scan(Scannable.Attr.DELAY_ERROR)).isFalse();
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
    test.onComplete();
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
    test.cancelled = true;
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
Also used : Subscription(org.reactivestreams.Subscription) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest)

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