use of cyclops.reactive.ReactiveSeq in project cyclops by aol.
the class BaseSeqTest method testShuffleRandom.
@Test
public void testShuffleRandom() {
Random r = new Random();
Supplier<ReactiveSeq<Integer>> s = () -> of(1, 2, 3);
assertEquals(3, s.get().shuffle(r).toList().size());
assertThat(s.get().shuffle(r).toList(), hasItems(1, 2, 3));
}
use of cyclops.reactive.ReactiveSeq in project cyclops by aol.
the class TopicTest method disconnectAllStreamsAndReconnect.
@Test
public void disconnectAllStreamsAndReconnect() {
for (int i = 0; i < 100_000; i++) {
Topic<Integer> topic = new Topic<>();
ReactiveSeq s1 = topic.stream();
// 3 Queues
ReactiveSeq s2 = topic.stream();
topic.disconnect(s1);
topic.disconnect(s2);
assertThat("" + topic.getDistributor().getSubscribers(), topic.getDistributor().getSubscribers().size(), is(0));
assertThat(topic.getStreamToQueue().size(), is(0));
topic.stream();
assertThat(topic.getDistributor().getSubscribers().size(), is(1));
assertThat(topic.getStreamToQueue().size(), is(1));
}
}
use of cyclops.reactive.ReactiveSeq in project cyclops by aol.
the class TopicTest method disconnectStreams.
@Test
public void disconnectStreams() {
Topic<Integer> topic = new Topic<>();
ReactiveSeq s1 = topic.stream();
// 3 Queues
ReactiveSeq s2 = topic.stream();
topic.disconnect(s1);
assertThat(topic.getDistributor().getSubscribers().size(), is(1));
assertThat(topic.getStreamToQueue().size(), is(1));
}
use of cyclops.reactive.ReactiveSeq in project cyclops by aol.
the class Queue method streamGroupedBySizeAndTime.
public ReactiveSeq<Seq<T>> streamGroupedBySizeAndTime(int size, long time, TimeUnit t) {
long toRun = t.toNanos(time);
return streamBatch(new Subscription(), source -> {
return () -> {
List<T> result = new ArrayList<>();
long start = System.nanoTime();
try {
while (result.size() < size && checkTime(System.nanoTime(), start, toRun)) {
try {
T next = source.apply(100l, TimeUnit.MICROSECONDS);
if (next != null) {
result.add(next);
}
} catch (Queue.QueueTimeoutException e) {
}
}
} catch (Queue.ClosedQueueException e) {
if (result.size() > 0) {
List list = new ArrayList<>();
list.add(result);
throw new ClosedQueueException(list);
}
}
return result;
};
}).filter(l -> l.size() > 0).map(Seq::fromIterable);
}
use of cyclops.reactive.ReactiveSeq 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")));
}
Aggregations