Search in sources :

Example 6 with Subscription

use of org.reactivestreams.Subscription in project RxJava by ReactiveX.

the class InnerQueuedSubscriberTest method requestInBatches.

@Test
public void requestInBatches() {
    InnerQueuedSubscriberSupport<Integer> support = new InnerQueuedSubscriberSupport<Integer>() {

        @Override
        public void innerNext(InnerQueuedSubscriber<Integer> inner, Integer value) {
        }

        @Override
        public void innerError(InnerQueuedSubscriber<Integer> inner, Throwable e) {
        }

        @Override
        public void innerComplete(InnerQueuedSubscriber<Integer> inner) {
        }

        @Override
        public void drain() {
        }
    };
    InnerQueuedSubscriber<Integer> inner = new InnerQueuedSubscriber<Integer>(support, 4);
    final List<Long> requests = new ArrayList<Long>();
    inner.onSubscribe(new Subscription() {

        @Override
        public void request(long n) {
            requests.add(n);
        }

        @Override
        public void cancel() {
        // ignore
        }
    });
    inner.request(1);
    inner.request(1);
    inner.request(1);
    inner.request(1);
    inner.request(1);
    assertEquals(Arrays.asList(4L, 3L), requests);
}
Also used : Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 7 with Subscription

use of org.reactivestreams.Subscription in project RxJava by ReactiveX.

the class BlockingSubscriberTest method cancelUpfront.

@Test
public void cancelUpfront() {
    final BlockingFirstSubscriber<Integer> bf = new BlockingFirstSubscriber<Integer>();
    final AtomicBoolean b = new AtomicBoolean();
    bf.cancelled = true;
    Subscription s = new Subscription() {

        @Override
        public void request(long n) {
            b.set(true);
        }

        @Override
        public void cancel() {
        }
    };
    bf.onSubscribe(s);
    assertFalse(b.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Subscription(org.reactivestreams.Subscription) BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 8 with Subscription

use of org.reactivestreams.Subscription in project RxJava by ReactiveX.

the class AsyncSubscriptionTest method testSingleSet.

@Test
public void testSingleSet() {
    AsyncSubscription as = new AsyncSubscription();
    Subscription s = mock(Subscription.class);
    as.setSubscription(s);
    Subscription s1 = mock(Subscription.class);
    as.setSubscription(s1);
    assertSame(as.actual.get(), s);
    verify(s1).cancel();
}
Also used : Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 9 with Subscription

use of org.reactivestreams.Subscription in project RxJava by ReactiveX.

the class AsyncSubscriptionTest method testCancelOnce.

@Test
public void testCancelOnce() {
    Disposable r = mock(Disposable.class);
    AsyncSubscription as = new AsyncSubscription(r);
    Subscription s = mock(Subscription.class);
    as.setSubscription(s);
    as.cancel();
    as.cancel();
    as.cancel();
    verify(s, never()).request(anyLong());
    verify(s).cancel();
    verify(r).dispose();
}
Also used : Disposable(io.reactivex.disposables.Disposable) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 10 with Subscription

use of org.reactivestreams.Subscription in project RxJava by ReactiveX.

the class AsyncSubscriptionTest method testNoResource.

@Test
public void testNoResource() {
    AsyncSubscription as = new AsyncSubscription();
    Subscription s = mock(Subscription.class);
    as.setSubscription(s);
    as.request(1);
    as.cancel();
    verify(s).request(1);
    verify(s).cancel();
}
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