Search in sources :

Example 51 with Subscription

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

the class FluxCreateTest method gh613.

@Test
public void gh613() {
    AtomicBoolean cancelled = new AtomicBoolean();
    AtomicBoolean completed = new AtomicBoolean();
    AtomicBoolean errored = new AtomicBoolean();
    AtomicInteger i = new AtomicInteger();
    Flux<Integer> source = Flux.create(e -> {
        e.next(1);
        cancelled.set(e.isCancelled());
        e.next(2);
        e.next(3);
        e.complete();
    });
    source.subscribe(new Subscriber<Integer>() {

        @Override
        public void onSubscribe(Subscription s) {
            s.request(Long.MAX_VALUE);
        }

        @Override
        public void onNext(Integer integer) {
            i.incrementAndGet();
            throw new RuntimeException();
        }

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

        @Override
        public void onComplete() {
            completed.set(true);
        }
    });
    assertThat(cancelled.get()).isTrue();
    assertThat(completed.get()).isFalse();
    assertThat(errored.get()).isFalse();
    assertThat(i.get()).isEqualTo(1);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 52 with Subscription

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

the class FluxDefaultIfEmptyTest method scanSubscriberCancelled.

@Test
public void scanSubscriberCancelled() {
    CoreSubscriber<String> actual = new LambdaSubscriber<>(null, e -> {
    }, null, null);
    FluxDefaultIfEmpty.DefaultIfEmptySubscriber<String> test = new FluxDefaultIfEmpty.DefaultIfEmptySubscriber<>(actual, "bar");
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);
    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 53 with Subscription

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

the class BlockingIterableTest method scanSubscriber.

@Test
public void scanSubscriber() {
    BlockingIterable.SubscriberIterator<String> subscriberIterator = new BlockingIterable.SubscriberIterator<>(Queues.<String>one().get(), 123);
    Subscription s = Operators.emptySubscription();
    subscriberIterator.onSubscribe(s);
    assertThat(subscriberIterator.scan(Scannable.Attr.PARENT)).describedAs("PARENT").isSameAs(s);
    assertThat(subscriberIterator.scan(Scannable.Attr.TERMINATED)).describedAs("TERMINATED").isFalse();
    assertThat(subscriberIterator.scan(Scannable.Attr.CANCELLED)).describedAs("CANCELLED").isFalse();
    assertThat(subscriberIterator.scan(Scannable.Attr.ERROR)).describedAs("ERROR").isNull();
    // FIXME
    assertThat(subscriberIterator.scan(Attr.PREFETCH)).describedAs("PREFETCH").isEqualTo(123);
}
Also used : Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 54 with Subscription

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

the class BlockingSingleSubscriberTest method scanMain.

@Test
public void scanMain() {
    Subscription s = Operators.emptySubscription();
    test.onSubscribe(s);
    assertThat(test.scan(Scannable.Attr.PARENT)).describedAs("PARENT").isSameAs(s);
    assertThat(test.scan(Scannable.Attr.TERMINATED)).describedAs("TERMINATED").isFalse();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).describedAs("CANCELLED").isFalse();
    assertThat(test.scan(Scannable.Attr.ERROR)).describedAs("ERROR").isNull();
    assertThat(test.scan(Scannable.Attr.PREFETCH)).describedAs("PREFETCH").isEqualTo(Integer.MAX_VALUE);
}
Also used : Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 55 with Subscription

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

the class EmitterProcessorTest method scanMain.

@Test
public void scanMain() {
    EmitterProcessor<Integer> test = EmitterProcessor.create(123);
    assertThat(test.scan(BUFFERED)).isEqualTo(0);
    assertThat(test.scan(CANCELLED)).isFalse();
    assertThat(test.scan(PREFETCH)).isEqualTo(123);
    assertThat(test.scan(CAPACITY)).isEqualTo(123);
    Disposable d1 = test.subscribe();
    FluxSink<Integer> sink = test.sink();
    sink.next(2);
    sink.next(3);
    sink.next(4);
    assertThat(test.scan(BUFFERED)).isEqualTo(0);
    AtomicReference<Subscription> d2 = new AtomicReference<>();
    test.subscribe(new CoreSubscriber<Integer>() {

        @Override
        public void onSubscribe(Subscription s) {
            d2.set(s);
        }

        @Override
        public void onNext(Integer integer) {
        }

        @Override
        public void onError(Throwable t) {
        }

        @Override
        public void onComplete() {
        }
    });
    sink.next(5);
    sink.next(6);
    sink.next(7);
    assertThat(test.scan(BUFFERED)).isEqualTo(3);
    assertThat(test.scan(TERMINATED)).isFalse();
    sink.complete();
    assertThat(test.scan(TERMINATED)).isFalse();
    d1.dispose();
    d2.get().cancel();
    assertThat(test.scan(TERMINATED)).isTrue();
    // other values
    assertThat(test.scan(Scannable.Attr.PARENT)).isNotNull();
    assertThat(test.scan(Attr.ERROR)).isNull();
}
Also used : Disposable(reactor.core.Disposable) 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