Search in sources :

Example 31 with Tuple2

use of cyclops.data.tuple.Tuple2 in project cyclops by aol.

the class AutoclosingTest method autoClosingZipLots.

@Test
public void autoClosingZipLots() throws InterruptedException {
    for (int i = 0; i < 1500; i++) {
        close = new AtomicInteger();
        added = new AtomicInteger();
        // subscription fills from outside in (lazyRight to lazyLeft), need to store open / closed for each queue
        List<Tuple2<List<List<String>>, Integer>> results = new LazyReact().generate(() -> nextValues()).withQueueFactory(() -> eventQueue()).zip(new LazyReact().of(1, 2, 3)).collect(Collectors.toList());
        System.out.println("finished");
        int localAdded = added.get();
        assertThat(close.get(), greaterThan(0));
        assertThat(results.size(), is(3));
        assertThat(localAdded, is(added.get()));
    }
}
Also used : LazyReact(cyclops.futurestream.LazyReact) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Tuple2(cyclops.data.tuple.Tuple2) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Test(org.junit.Test)

Example 32 with Tuple2

use of cyclops.data.tuple.Tuple2 in project cyclops by aol.

the class AutoclosingTest method autoClosingZip.

@Test
public void autoClosingZip() throws InterruptedException {
    System.out.println("Started!");
    close = new AtomicInteger();
    added = new AtomicInteger();
    // subscription fills from outside in (lazyRight to lazyLeft), need to store open / closed for each queue
    List<Tuple2<List<List<String>>, Integer>> results = new LazyReact().generateAsync(() -> nextValues()).withQueueFactory(() -> eventQueue()).zip(new LazyReact().of(1, 2, 3)).collect(Collectors.toList());
    System.out.println("finished");
    int localAdded = added.get();
    assertThat(close.get(), greaterThan(0));
    assertThat(results.size(), is(3));
    assertThat(localAdded, is(added.get()));
}
Also used : LazyReact(cyclops.futurestream.LazyReact) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Tuple2(cyclops.data.tuple.Tuple2) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Test(org.junit.Test)

Example 33 with Tuple2

use of cyclops.data.tuple.Tuple2 in project cyclops by aol.

the class LazySeqAgronaTest method testZipWithFuturesStream.

@Test
public void testZipWithFuturesStream() {
    Stream stream = of("a", "b");
    FutureStream<Tuple2<Integer, String>> seq = of(1, 2).actOnFutures().zip(stream);
    // .map(tuple -> Tuple.tuple(tuple.v1.join(),tuple.v2)).collect(CyclopsCollectors.toList());
    List<Tuple2<Integer, String>> result = seq.block();
    assertThat(result.size(), is(asList(tuple(1, "a"), tuple(2, "b")).size()));
}
Also used : Tuple2(cyclops.data.tuple.Tuple2) FutureStream(cyclops.futurestream.FutureStream) Stream(java.util.stream.Stream) BaseSeqTest(cyclops.futurestream.react.base.BaseSeqTest) Test(org.junit.Test)

Example 34 with Tuple2

use of cyclops.data.tuple.Tuple2 in project cyclops by aol.

the class AsyncRSZippingTest method testUnzipWithLimits.

@Test
public void testUnzipWithLimits() {
    Supplier<ReactiveSeq<Tuple2<Integer, String>>> s = () -> of(new Tuple2(1, "a"), new Tuple2(2, "b"), new Tuple2(3, "c"));
    Tuple2<ReactiveSeq<Integer>, ReactiveSeq<String>> u1 = ReactiveSeq.unzip(s.get());
    assertTrue(u1._1().limit(2).toList().containsAll(Arrays.asList(1, 2)));
    assertTrue(u1._2().toList().containsAll(asList("a", "b", "c")));
}
Also used : Tuple2(cyclops.data.tuple.Tuple2) FlowableReactiveSeq(cyclops.reactive.FlowableReactiveSeq) ReactiveSeq(cyclops.reactive.ReactiveSeq) Test(org.junit.Test)

Example 35 with Tuple2

use of cyclops.data.tuple.Tuple2 in project cyclops by aol.

the class AsyncRSZippingTest method testUnzip.

@Test
public void testUnzip() {
    Supplier<ReactiveSeq<Tuple2<Integer, String>>> s = () -> of(new Tuple2(1, "a"), new Tuple2(2, "b"), new Tuple2(3, "c"));
    Tuple2<ReactiveSeq<Integer>, ReactiveSeq<String>> u1 = ReactiveSeq.unzip(s.get());
    assertTrue(u1._1().toList().containsAll(Arrays.asList(1, 2, 3)));
    assertTrue(u1._2().toList().containsAll(asList("a", "b", "c")));
}
Also used : Tuple2(cyclops.data.tuple.Tuple2) FlowableReactiveSeq(cyclops.reactive.FlowableReactiveSeq) ReactiveSeq(cyclops.reactive.ReactiveSeq) Test(org.junit.Test)

Aggregations

Tuple2 (cyclops.data.tuple.Tuple2)43 Test (org.junit.Test)35 ReactiveSeq (cyclops.reactive.ReactiveSeq)23 Stream (java.util.stream.Stream)17 FutureStream (cyclops.futurestream.FutureStream)16 Tuple (cyclops.data.tuple.Tuple)10 BaseSeqTest (cyclops.futurestream.react.base.BaseSeqTest)9 Collectors (java.util.stream.Collectors)7 FlowableReactiveSeq (cyclops.reactive.FlowableReactiveSeq)6 FluxReactiveSeq (cyclops.reactive.FluxReactiveSeq)6 java.util (java.util)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Queue (com.oath.cyclops.async.adapters.Queue)5 Vector (cyclops.data.Vector)5 Tuple3 (cyclops.data.tuple.Tuple3)5 LazyReact (cyclops.futurestream.LazyReact)5 Streams (cyclops.companion.Streams)4 Executor (java.util.concurrent.Executor)4 Function (java.util.function.Function)4