Search in sources :

Example 21 with Spouts.of

use of cyclops.reactive.Spouts.of in project cyclops by aol.

the class IterableFlatMapTest method flatMapAsyncRS.

@Test
public void flatMapAsyncRS() {
    for (int k = 0; k < 1000; k++) {
        complete = new AtomicBoolean(false);
        count = new AtomicInteger(0);
        ReactiveSubscriber<Integer> sub = Spouts.reactiveSubscriber();
        Spouts.of(1, 2, 3).peek(System.out::println).concatMap(i -> nextAsyncRS()).subscribe(new Subscriber<Integer>() {

            @Override
            public void onSubscribe(Subscription s) {
                subs = s;
            }

            @Override
            public void onNext(Integer integer) {
                System.out.println("RECIEVED " + integer);
                assertThat(integer, Matchers.isOneOf(1, 2));
                System.out.println("count " + count.incrementAndGet());
            }

            @Override
            public void onError(Throwable t) {
            }

            @Override
            public void onComplete() {
                complete.set(true);
            }
        });
        subs.request(Long.MAX_VALUE);
        while (!complete.get()) {
        }
        assertThat(count.get(), equalTo(6));
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Maybe(cyclops.control.Maybe) Arrays(java.util.Arrays) Spouts.of(cyclops.reactive.Spouts.of) Spouts(cyclops.reactive.Spouts) ReactiveSubscriber(com.oath.cyclops.types.reactive.ReactiveSubscriber) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Matchers(org.hamcrest.Matchers) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Matchers.hasItems(org.hamcrest.Matchers.hasItems) ReactiveSeq(cyclops.reactive.ReactiveSeq) Flux(reactor.core.publisher.Flux) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ForkJoinPool(java.util.concurrent.ForkJoinPool) Subscription(org.reactivestreams.Subscription) Schedulers(reactor.core.scheduler.Schedulers) AsyncSubscriber(com.oath.cyclops.types.reactive.AsyncSubscriber) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assert(org.junit.Assert) Subscriber(org.reactivestreams.Subscriber) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 22 with Spouts.of

use of cyclops.reactive.Spouts.of in project cyclops by aol.

the class FlatMapTest method flatMapAsyncRS.

@Test
public void flatMapAsyncRS() {
    for (int k = 0; k < 1000; k++) {
        complete = new AtomicBoolean(false);
        count = new AtomicInteger(0);
        ReactiveSubscriber<Integer> sub = Spouts.reactiveSubscriber();
        Spouts.of(1, 2, 3).peek(System.out::println).flatMap(i -> nextAsyncRS()).subscribe(new Subscriber<Integer>() {

            @Override
            public void onSubscribe(Subscription s) {
                subs = s;
            }

            @Override
            public void onNext(Integer integer) {
                System.out.println("RECIEVED " + integer);
                assertThat(integer, Matchers.isOneOf(1, 2));
                System.out.println("count " + count.incrementAndGet());
            }

            @Override
            public void onError(Throwable t) {
            }

            @Override
            public void onComplete() {
                complete.set(true);
            }
        });
        subs.request(Long.MAX_VALUE);
        while (!complete.get()) {
        }
        assertThat(count.get(), equalTo(6));
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Maybe(cyclops.control.Maybe) Arrays(java.util.Arrays) Spouts.of(cyclops.reactive.Spouts.of) Spouts(cyclops.reactive.Spouts) ReactiveSubscriber(com.oath.cyclops.types.reactive.ReactiveSubscriber) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Matchers(org.hamcrest.Matchers) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Matchers.hasItems(org.hamcrest.Matchers.hasItems) ReactiveSeq(cyclops.reactive.ReactiveSeq) Flux(reactor.core.publisher.Flux) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Stream(java.util.stream.Stream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ForkJoinPool(java.util.concurrent.ForkJoinPool) Subscription(org.reactivestreams.Subscription) Schedulers(reactor.core.scheduler.Schedulers) AsyncSubscriber(com.oath.cyclops.types.reactive.AsyncSubscriber) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assert(org.junit.Assert) Subscriber(org.reactivestreams.Subscriber) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 23 with Spouts.of

use of cyclops.reactive.Spouts.of in project cyclops by aol.

the class IterableFlatMapTest method flatMapAsyncRS2.

@Test
public void flatMapAsyncRS2() {
    for (int k = 0; k < 1000; k++) {
        System.out.println("********0---------------------K " + k);
        ReactiveSubscriber<Integer> sub = Spouts.reactiveSubscriber();
        Spouts.of(1, 2, 3).peek(System.out::println).concatMap(i -> nextAsyncRS()).subscribe(sub);
        List<Integer> res = sub.reactiveStream().collect(Collectors.toList());
        System.out.println(res);
        assertThat(res.size(), equalTo(Arrays.asList(1, 2, 1, 2, 1, 2).size()));
        assertThat(res, hasItems(1, 2));
        int one = 0;
        int two = 0;
        for (Integer next : res) {
            if (next == 1) {
                one++;
            }
            if (next == 2) {
                two++;
            }
        }
        assertThat(one, equalTo(3));
        assertThat(two, equalTo(3));
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Maybe(cyclops.control.Maybe) Arrays(java.util.Arrays) Spouts.of(cyclops.reactive.Spouts.of) Spouts(cyclops.reactive.Spouts) ReactiveSubscriber(com.oath.cyclops.types.reactive.ReactiveSubscriber) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Matchers(org.hamcrest.Matchers) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Matchers.hasItems(org.hamcrest.Matchers.hasItems) ReactiveSeq(cyclops.reactive.ReactiveSeq) Flux(reactor.core.publisher.Flux) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ForkJoinPool(java.util.concurrent.ForkJoinPool) Subscription(org.reactivestreams.Subscription) Schedulers(reactor.core.scheduler.Schedulers) AsyncSubscriber(com.oath.cyclops.types.reactive.AsyncSubscriber) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assert(org.junit.Assert) Subscriber(org.reactivestreams.Subscriber) Test(org.junit.Test)

Example 24 with Spouts.of

use of cyclops.reactive.Spouts.of in project cyclops by aol.

the class IterableFlatMapTest method flatMapAsyncRS.

@Test
public void flatMapAsyncRS() {
    for (int k = 0; k < 1000; k++) {
        complete = new AtomicBoolean(false);
        count = new AtomicInteger(0);
        ReactiveSubscriber<Integer> sub = Spouts.reactiveSubscriber();
        Spouts.of(1, 2, 3).peek(System.out::println).concatMap(i -> nextAsyncRS()).subscribe(new Subscriber<Integer>() {

            @Override
            public void onSubscribe(Subscription s) {
                subs = s;
            }

            @Override
            public void onNext(Integer integer) {
                System.out.println("RECIEVED " + integer);
                assertThat(integer, Matchers.isOneOf(1, 2));
                System.out.println("count " + count.incrementAndGet());
            }

            @Override
            public void onError(Throwable t) {
            }

            @Override
            public void onComplete() {
                complete.set(true);
            }
        });
        subs.request(Long.MAX_VALUE);
        while (!complete.get()) {
        }
        assertThat(count.get(), equalTo(6));
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Maybe(cyclops.control.Maybe) Arrays(java.util.Arrays) Spouts.of(cyclops.reactive.Spouts.of) Spouts(cyclops.reactive.Spouts) ReactiveSubscriber(com.oath.cyclops.types.reactive.ReactiveSubscriber) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Matchers(org.hamcrest.Matchers) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Matchers.hasItems(org.hamcrest.Matchers.hasItems) ReactiveSeq(cyclops.reactive.ReactiveSeq) Flux(reactor.core.publisher.Flux) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ForkJoinPool(java.util.concurrent.ForkJoinPool) Subscription(org.reactivestreams.Subscription) Schedulers(reactor.core.scheduler.Schedulers) AsyncSubscriber(com.oath.cyclops.types.reactive.AsyncSubscriber) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assert(org.junit.Assert) Subscriber(org.reactivestreams.Subscriber) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 25 with Spouts.of

use of cyclops.reactive.Spouts.of in project cyclops by aol.

the class FlatMapTest method flatMapAsyncRS.

@Test
public void flatMapAsyncRS() {
    for (int k = 0; k < 1000; k++) {
        complete = new AtomicBoolean(false);
        count = new AtomicInteger(0);
        ReactiveSubscriber<Integer> sub = Spouts.reactiveSubscriber();
        Spouts.of(1, 2, 3).peek(System.out::println).flatMap(i -> nextAsyncRS()).subscribe(new Subscriber<Integer>() {

            @Override
            public void onSubscribe(Subscription s) {
                subs = s;
            }

            @Override
            public void onNext(Integer integer) {
                System.out.println("RECIEVED " + integer);
                assertThat(integer, Matchers.isOneOf(1, 2));
                System.out.println("count " + count.incrementAndGet());
            }

            @Override
            public void onError(Throwable t) {
            }

            @Override
            public void onComplete() {
                complete.set(true);
            }
        });
        subs.request(Long.MAX_VALUE);
        while (!complete.get()) {
        }
        assertThat(count.get(), equalTo(6));
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Maybe(cyclops.control.Maybe) Arrays(java.util.Arrays) Spouts.of(cyclops.reactive.Spouts.of) Spouts(cyclops.reactive.Spouts) ReactiveSubscriber(com.oath.cyclops.types.reactive.ReactiveSubscriber) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Matchers(org.hamcrest.Matchers) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Matchers.hasItems(org.hamcrest.Matchers.hasItems) ReactiveSeq(cyclops.reactive.ReactiveSeq) Flux(reactor.core.publisher.Flux) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Stream(java.util.stream.Stream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ForkJoinPool(java.util.concurrent.ForkJoinPool) Subscription(org.reactivestreams.Subscription) Schedulers(reactor.core.scheduler.Schedulers) AsyncSubscriber(com.oath.cyclops.types.reactive.AsyncSubscriber) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assert(org.junit.Assert) Subscriber(org.reactivestreams.Subscriber) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Aggregations

ReactiveSubscriber (com.oath.cyclops.types.reactive.ReactiveSubscriber)26 Maybe (cyclops.control.Maybe)26 ReactiveSeq (cyclops.reactive.ReactiveSeq)26 Spouts (cyclops.reactive.Spouts)26 Spouts.of (cyclops.reactive.Spouts.of)26 Arrays (java.util.Arrays)26 List (java.util.List)26 ForkJoinPool (java.util.concurrent.ForkJoinPool)26 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)26 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)26 Collectors (java.util.stream.Collectors)26 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)26 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)26 Matchers (org.hamcrest.Matchers)26 Matchers.hasItems (org.hamcrest.Matchers.hasItems)26 Assert (org.junit.Assert)26 Test (org.junit.Test)26 Subscriber (org.reactivestreams.Subscriber)26 Subscription (org.reactivestreams.Subscription)26 Flux (reactor.core.publisher.Flux)26