Search in sources :

Example 21 with Subscription

use of org.reactivestreams.Subscription in project cyclops by aol.

the class BaseSequentialTest method subscribeEmpty.

@Test
public void subscribeEmpty() {
    List result = new ArrayList<>();
    Subscription s = of().forEachSubscribe(i -> result.add(i));
    s.request(1l);
    assertThat(result.size(), Matchers.equalTo(0));
    s.request(1l);
    assertThat(result.size(), Matchers.equalTo(0));
    s.request(1l);
    assertThat(result.size(), Matchers.equalTo(0));
}
Also used : Arrays.asList(java.util.Arrays.asList) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 22 with Subscription

use of org.reactivestreams.Subscription in project cyclops by aol.

the class BaseSequentialTest method subscribe.

@Test
public void subscribe() throws InterruptedException {
    List<Integer> result = new ArrayList<>();
    Subscription s = of(1, 2, 3).forEachSubscribe(i -> result.add(i));
    s.request(1l);
    assertThat(result.size(), Matchers.equalTo(1));
    s.request(1l);
    assertThat(result.size(), Matchers.equalTo(2));
    s.request(1l);
    assertThat(result.size(), Matchers.equalTo(3));
    assertThat(result, hasItems(1, 2, 3));
}
Also used : Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 23 with Subscription

use of org.reactivestreams.Subscription in project cyclops by aol.

the class AbstractCollectionXTest method subscribe3ErrorOnComplete.

@Test
public void subscribe3ErrorOnComplete() {
    List<Integer> result = new ArrayList<>();
    AtomicBoolean onComplete = new AtomicBoolean(false);
    Subscription s = of(1, 2, 3).forEachSubscribe(i -> result.add(i), e -> e.printStackTrace(), () -> onComplete.set(true));
    assertThat(onComplete.get(), equalTo(false));
    s.request(4l);
    assertThat(onComplete.get(), equalTo(true));
    assertThat(result.size(), equalTo(3));
    assertThat(result, hasItems(1, 2, 3));
    s.request(1l);
    assertThat(onComplete.get(), equalTo(true));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 24 with Subscription

use of org.reactivestreams.Subscription in project cyclops by aol.

the class AbstractCollectionXTest method subscribeEmpty.

@Test
public void subscribeEmpty() {
    List result = new ArrayList<>();
    Subscription s = of().forEachSubscribe(i -> result.add(i));
    s.request(1l);
    assertThat(result.size(), equalTo(0));
    s.request(1l);
    assertThat(result.size(), equalTo(0));
    s.request(1l);
    assertThat(result.size(), equalTo(0));
}
Also used : Arrays.asList(java.util.Arrays.asList) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 25 with Subscription

use of org.reactivestreams.Subscription in project cyclops by aol.

the class AbstractCollectionXTest method subscribe3Error.

@Test
public void subscribe3Error() {
    List<Integer> result = new ArrayList<>();
    Subscription s = of(1, 2, 3).forEachSubscribe(i -> result.add(i), e -> e.printStackTrace());
    s.request(3l);
    assertThat(result.size(), equalTo(3));
    assertThat(result, hasItems(1, 2, 3));
}
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