Search in sources :

Example 91 with Subscription

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

the class MonoCreateTest method cancellation.

@Test
public void cancellation() {
    AtomicInteger onDispose = new AtomicInteger();
    AtomicInteger onCancel = new AtomicInteger();
    StepVerifier.create(Mono.create(s -> {
        s.onDispose(onDispose::getAndIncrement).onCancel(onCancel::getAndIncrement);
    })).thenAwait().consumeSubscriptionWith(Subscription::cancel).thenCancel().verify();
    assertThat(onDispose.get()).isEqualTo(1);
    assertThat(onCancel.get()).isEqualTo(1);
}
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) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 92 with Subscription

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

the class MonoFilterWhenTest method take1Cancel.

@Test
public void take1Cancel() {
    AtomicLong onNextCount = new AtomicLong();
    AtomicReference<SignalType> endSignal = new AtomicReference<>();
    BaseSubscriber<Object> bs = new BaseSubscriber<Object>() {

        @Override
        protected void hookOnSubscribe(Subscription subscription) {
            requestUnbounded();
        }

        @Override
        public void hookOnNext(Object t) {
            onNextCount.incrementAndGet();
            cancel();
            onComplete();
        }

        @Override
        protected void hookFinally(SignalType type) {
            endSignal.set(type);
        }
    };
    Mono.just(1).filterWhen(v -> Mono.just(true).hide()).subscribe(bs);
    assertThat(onNextCount.get()).isEqualTo(1);
    assertThat(endSignal.get()).isEqualTo(SignalType.CANCEL);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) TestPublisher(reactor.test.publisher.TestPublisher) CoreSubscriber(reactor.core.CoreSubscriber) StepVerifier(reactor.test.StepVerifier) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Scannable(reactor.core.Scannable) Duration(java.time.Duration) Subscription(org.reactivestreams.Subscription) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) Subscriber(org.reactivestreams.Subscriber) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicReference(java.util.concurrent.atomic.AtomicReference) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 93 with Subscription

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

the class MonoFilterWhenTest method take1CancelBackpressured.

@Test
public void take1CancelBackpressured() {
    AtomicLong onNextCount = new AtomicLong();
    AtomicReference<SignalType> endSignal = new AtomicReference<>();
    BaseSubscriber<Object> bs = new BaseSubscriber<Object>() {

        @Override
        protected void hookOnSubscribe(Subscription subscription) {
            request(1);
        }

        @Override
        public void hookOnNext(Object t) {
            onNextCount.incrementAndGet();
            cancel();
            onComplete();
        }

        @Override
        protected void hookFinally(SignalType type) {
            endSignal.set(type);
        }
    };
    Mono.just(1).filterWhen(v -> Mono.just(true).hide()).subscribe(bs);
    assertThat(onNextCount.get()).isEqualTo(1);
    assertThat(endSignal.get()).isEqualTo(SignalType.CANCEL);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) TestPublisher(reactor.test.publisher.TestPublisher) CoreSubscriber(reactor.core.CoreSubscriber) StepVerifier(reactor.test.StepVerifier) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Scannable(reactor.core.Scannable) Duration(java.time.Duration) Subscription(org.reactivestreams.Subscription) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) Subscriber(org.reactivestreams.Subscriber) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicReference(java.util.concurrent.atomic.AtomicReference) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 94 with Subscription

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

the class MonoFilterWhenTest method scanFilterWhenInner.

@Test
public void scanFilterWhenInner() {
    CoreSubscriber<String> actual = new LambdaMonoSubscriber<>(null, e -> {
    }, null, null);
    MonoFilterWhen.MonoFilterWhenMain<String> main = new MonoFilterWhen.MonoFilterWhenMain<>(actual, s -> Mono.just(false));
    MonoFilterWhen.FilterWhenInner test = new MonoFilterWhen.FilterWhenInner(main, true);
    Subscription innerSubscription = Operators.emptySubscription();
    test.onSubscribe(innerSubscription);
    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(main);
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(innerSubscription);
    assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(Integer.MAX_VALUE);
    assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(1L);
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
    test.onError(new IllegalStateException("boom"));
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
    assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(0L);
    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 95 with Subscription

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

the class MonoFlatMapManyTest method scanInner.

@Test
public void scanInner() {
    CoreSubscriber<Integer> mainActual = new LambdaMonoSubscriber<>(null, e -> {
    }, null, null);
    CoreSubscriber<Integer> actual = new LambdaMonoSubscriber<>(null, e -> {
    }, null, null);
    MonoFlatMapMany.FlatMapManyMain<String, Integer> main = new MonoFlatMapMany.FlatMapManyMain<>(mainActual, s -> Flux.just(1, 2, 3));
    MonoFlatMapMany.FlatMapManyInner<Integer> test = new MonoFlatMapMany.FlatMapManyInner<>(main, actual);
    Subscription innerSubscription = Operators.emptySubscription();
    test.onSubscribe(innerSubscription);
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(innerSubscription);
    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(main);
    main.requested = 3L;
    assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(3L);
}
Also used : 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