Search in sources :

Example 86 with Subscription

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

the class MonoCollectListTest method scanBufferAllSubscriber.

@Test
public void scanBufferAllSubscriber() {
    CoreSubscriber<List<String>> actual = new LambdaMonoSubscriber<>(null, e -> {
    }, null, null);
    MonoCollectList.MonoBufferAllSubscriber<String, List<String>> test = new MonoCollectList.MonoBufferAllSubscriber<String, List<String>>(actual, new ArrayList<>());
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);
    assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(Integer.MAX_VALUE);
    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.cancel();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 87 with Subscription

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

the class MonoDelayUntilTest method scanTrigger.

@Test
public void scanTrigger() {
    CoreSubscriber<String> actual = new LambdaMonoSubscriber<>(null, e -> {
    }, null, null);
    @SuppressWarnings("unchecked") Function<? super String, ? extends Publisher<?>>[] otherGenerators = new Function[3];
    MonoDelayUntil.DelayUntilCoordinator<String> main = new MonoDelayUntil.DelayUntilCoordinator<>(actual, otherGenerators);
    MonoDelayUntil.DelayUntilTrigger<String> test = new MonoDelayUntil.DelayUntilTrigger<>(main);
    Subscription subscription = Operators.emptySubscription();
    test.onSubscribe(subscription);
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(subscription);
    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(main);
    assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(Integer.MAX_VALUE);
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
    test.cancel();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
    test.error = new IllegalStateException("boom");
    assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom");
}
Also used : Publisher(org.reactivestreams.Publisher) Function(java.util.function.Function) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 88 with Subscription

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

the class MonoElementAtTest method scanSubscriber.

@Test
public void scanSubscriber() {
    CoreSubscriber<String> actual = new LambdaMonoSubscriber<>(null, e -> {
    }, null, null);
    MonoElementAt.ElementAtSubscriber<String> test = new MonoElementAt.ElementAtSubscriber<>(actual, 1, "foo");
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);
    assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(Integer.MAX_VALUE);
    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.cancel();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
Also used : Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 89 with Subscription

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

the class MonoCountTest method scanCountSubscriber.

@Test
public void scanCountSubscriber() {
    CoreSubscriber<Long> actual = new LambdaMonoSubscriber<>(null, e -> {
    }, null, null);
    MonoCount.CountSubscriber<String> test = new MonoCount.CountSubscriber<>(actual);
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);
    assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(Integer.MAX_VALUE);
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
    // only TERMINATED state evaluated is one from Operators: hasValue
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
    test.onComplete();
    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 : Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 90 with Subscription

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

the class MonoCreateTest method monoCreateCancelOnNext.

@Test
public void monoCreateCancelOnNext() {
    AtomicInteger onCancel = new AtomicInteger();
    AtomicInteger onDispose = new AtomicInteger();
    AtomicReference<Subscription> subscription = new AtomicReference<>();
    Mono<String> created = Mono.create(s -> {
        s.onDispose(onDispose::getAndIncrement).onCancel(onCancel::getAndIncrement).success("done");
    });
    created = created.doOnSubscribe(s -> subscription.set(s)).doOnNext(n -> subscription.get().cancel());
    StepVerifier.create(created).expectNext("done").verifyComplete();
    assertThat(onDispose.get()).isEqualTo(1);
    assertThat(onCancel.get()).isEqualTo(0);
}
Also used : CoreSubscriber(reactor.core.CoreSubscriber) StepVerifier(reactor.test.StepVerifier) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Scannable(reactor.core.Scannable) Subscription(org.reactivestreams.Subscription) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Assertions(org.assertj.core.api.Assertions) Schedulers(reactor.core.scheduler.Schedulers) Test(org.junit.Test) Exceptions(reactor.core.Exceptions) AtomicReference(java.util.concurrent.atomic.AtomicReference) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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