Search in sources :

Example 66 with Subscription

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

the class ParallelMergeSequentialTest method scanInnerSubscriber.

@Test
public void scanInnerSubscriber() {
    CoreSubscriber<Integer> mainActual = new LambdaSubscriber<>(null, e -> {
    }, null, null);
    MergeSequentialMain<Integer> main = new MergeSequentialMain<>(mainActual, 2, 123, Queues.small());
    MergeSequentialInner<Integer> test = new MergeSequentialInner<>(main, 456);
    Subscription subscription = Operators.emptySubscription();
    test.onSubscribe(subscription);
}
Also used : MergeSequentialMain(reactor.core.publisher.ParallelMergeSequential.MergeSequentialMain) MergeSequentialInner(reactor.core.publisher.ParallelMergeSequential.MergeSequentialInner) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 67 with Subscription

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

the class ParallelSourceTest method scanMainSubscriber.

@Test
public void scanMainSubscriber() {
    @SuppressWarnings("unchecked") CoreSubscriber<String>[] subs = new CoreSubscriber[1];
    subs[0] = new LambdaSubscriber<>(null, e -> {
    }, null, null);
    ParallelSource.ParallelSourceMain<String> test = new ParallelSource.ParallelSourceMain<>(subs, 123, Queues.one());
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
    assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(123);
    assertThat(test.scan(Scannable.Attr.BUFFERED)).isZero();
    test.queue.offer("foo");
    assertThat(test.scan(Scannable.Attr.BUFFERED)).isEqualTo(1);
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
    assertThat(test.scan(Scannable.Attr.ERROR)).isNull();
    test.onError(new IllegalStateException("boom"));
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
    assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom");
    test.cancel();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
Also used : CoreSubscriber(reactor.core.CoreSubscriber) Scannable(reactor.core.Scannable) Subscription(org.reactivestreams.Subscription) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Queues(reactor.util.concurrent.Queues) CoreSubscriber(reactor.core.CoreSubscriber) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 68 with Subscription

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

the class ParallelCollectTest method scanSubscriber.

@Test
public void scanSubscriber() {
    CoreSubscriber<List<Integer>> subscriber = new LambdaSubscriber<>(null, e -> {
    }, null, null);
    ParallelCollectSubscriber<Integer, List<Integer>> test = new ParallelCollectSubscriber<>(subscriber, new ArrayList<>(), List::add);
    Subscription s = Operators.emptySubscription();
    test.onSubscribe(s);
    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(subscriber);
    assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(Integer.MAX_VALUE);
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
    test.complete(Collections.emptyList());
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
    test.cancel();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
Also used : ParallelCollectSubscriber(reactor.core.publisher.ParallelCollect.ParallelCollectSubscriber) ArrayList(java.util.ArrayList) List(java.util.List) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 69 with Subscription

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

the class ParallelGroupTest method scanInnerGroup.

@Test
public void scanInnerGroup() {
    ParallelInnerGroup<Integer> test = new ParallelInnerGroup<>(1023);
    CoreSubscriber<Integer> subscriber = new LambdaSubscriber<>(null, e -> {
    }, null, sub -> sub.request(3));
    Subscription s = Operators.emptySubscription();
    test.onSubscribe(s);
    test.subscribe(subscriber);
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(s);
    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(subscriber);
    // see other test for request
    assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isZero();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
    test.cancel();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
Also used : ParallelInnerGroup(reactor.core.publisher.ParallelGroup.ParallelInnerGroup) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 70 with Subscription

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

the class ParallelGroupTest method scanInnerGroupRequestNotTrackedWhenParent.

@Test
public void scanInnerGroupRequestNotTrackedWhenParent() {
    ParallelInnerGroup<Integer> test = new ParallelInnerGroup<>(1023);
    CoreSubscriber<Integer> subscriber = new LambdaSubscriber<>(null, e -> {
    }, null, sub -> sub.request(3));
    Subscription s = Operators.emptySubscription();
    test.onSubscribe(s);
    test.subscribe(subscriber);
    assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isZero();
    test.request(2);
    assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isZero();
}
Also used : ParallelInnerGroup(reactor.core.publisher.ParallelGroup.ParallelInnerGroup) Subscription(org.reactivestreams.Subscription) 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