use of cyclops.reactive.ReactiveSeq in project cyclops by aol.
the class SyncZippingTest method testUnzip4WithLimits.
@Test
public void testUnzip4WithLimits() {
Supplier<ReactiveSeq<Tuple4<Integer, String, Long, Character>>> s = () -> of(new Tuple4(1, "a", 2l, 'z'), new Tuple4(2, "b", 3l, 'y'), new Tuple4(3, "c", 4l, 'x'));
Tuple4<ReactiveSeq<Integer>, ReactiveSeq<String>, ReactiveSeq<Long>, ReactiveSeq<Character>> u1 = ReactiveSeq.unzip4(s.get());
assertTrue(u1._1().limit(1).toList().containsAll(Arrays.asList(1)));
assertTrue(u1._2().limit(2).toList().containsAll(asList("a", "b")));
assertTrue(u1._3().limit(3).toList().containsAll(asList(2l, 3l, 4l)));
assertTrue(u1._4().limit(4).toList().containsAll(asList('z', 'y', 'x')));
}
use of cyclops.reactive.ReactiveSeq in project cyclops by aol.
the class SyncZippingTest method testUnzip3WithLimits.
@Test
public void testUnzip3WithLimits() {
Supplier<ReactiveSeq<Tuple3<Integer, String, Long>>> s = () -> of(new Tuple3(1, "a", 2l), new Tuple3(2, "b", 3l), new Tuple3(3, "c", 4l));
Tuple3<ReactiveSeq<Integer>, ReactiveSeq<String>, ReactiveSeq<Long>> u1 = ReactiveSeq.unzip3(s.get());
assertTrue(u1._1().limit(1).toList().containsAll(Arrays.asList(1)));
assertTrue(u1._2().limit(2).toList().containsAll(asList("a", "b")));
assertTrue(u1._3().toList().containsAll(asList(2l, 3l, 4l)));
}
use of cyclops.reactive.ReactiveSeq in project cyclops by aol.
the class SyncZippingTest method testUnzip3.
@Test
public void testUnzip3() {
Supplier<ReactiveSeq<Tuple3<Integer, String, Long>>> s = () -> of(new Tuple3(1, "a", 2l), new Tuple3(2, "b", 3l), new Tuple3(3, "c", 4l));
Tuple3<ReactiveSeq<Integer>, ReactiveSeq<String>, ReactiveSeq<Long>> u1 = ReactiveSeq.unzip3(s.get());
assertTrue(u1._1().toList().containsAll(Arrays.asList(1, 2, 3)));
assertTrue(u1._2().toList().containsAll(asList("a", "b", "c")));
assertTrue(u1._3().toList().containsAll(asList(2l, 3l, 4l)));
}
use of cyclops.reactive.ReactiveSeq in project cyclops by aol.
the class FutureStreamImplTest method subcribeOnce.
public void subcribeOnce() {
AtomicBoolean called1 = new AtomicBoolean(false);
AtomicBoolean called2 = new AtomicBoolean(false);
ReactiveSeq<Integer> initialStream = ReactiveSeq.of(1, 2, 3, 4, 5, 6);
ReactiveSubscriber<Integer> sub1 = Spouts.reactiveSubscriber();
ReactiveSubscriber<Integer> sub2 = Spouts.reactiveSubscriber();
FutureStream<Integer> futureStream = FutureStream.builder().fromStream(initialStream).map(v -> v - 1);
futureStream.subscribe(sub1);
futureStream.subscribe(sub2);
CompletableFuture future1 = CompletableFuture.runAsync(() -> sub1.reactiveStream().peek(a -> called1.set(true)).forEach(v -> System.out.println("1 -> " + v)));
CompletableFuture future2 = CompletableFuture.runAsync(() -> sub2.reactiveStream().peek(a -> called2.set(true)).forEach(v -> System.out.println("2 -> " + v)));
try {
future1.get();
future2.get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
assertThat(called1.get(), equalTo(true));
assertThat(called1.get(), equalTo(false));
}
use of cyclops.reactive.ReactiveSeq in project cyclops by aol.
the class TopicTest method concurrentSub.
@Test
public void concurrentSub() {
ReactiveSeq<Integer> initialStream = ReactiveSeq.of(1, 2, 3, 4, 5, 6);
FutureStream<Integer> futureStream = FutureStream.builder().fromStream(initialStream).map(v -> v - 1);
Queue<Integer> queue = QueueFactories.<Integer>boundedNonBlockingQueue(1000).build();
Topic<Integer> topic = new Topic<Integer>(queue, QueueFactories.<Integer>boundedNonBlockingQueue(1000));
ReactiveSeq<Integer> s2 = topic.stream();
ReactiveSeq<Integer> s1 = topic.stream();
Thread t = new Thread(() -> {
topic.fromStream(futureStream);
topic.close();
});
t.start();
CompletableFuture future1 = CompletableFuture.runAsync(() -> s1.forEach(v -> System.out.println("1 -> " + v)));
CompletableFuture future2 = CompletableFuture.runAsync(() -> s2.forEach(v -> System.out.println("2 -> " + v)));
try {
future1.get();
future2.get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
Aggregations