use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class BatchingInvestigationsTest method streamBatch.
@Test
public void streamBatch() {
Queue<String> queue = QueueFactories.<String>unboundedQueue().build();
new Thread(() -> {
for (int i = 0; i < 10; i++) {
queue.offer("New message " + i);
sleep(10000);
}
queue.close();
}).start();
long toRun = TimeUnit.MILLISECONDS.toNanos(500l);
queue.streamBatch(new Subscription(), source -> {
return () -> {
List<String> result = new ArrayList<>();
long start = System.nanoTime();
while (result.size() < 10 && (System.nanoTime() - start) < toRun) {
try {
String next = source.apply(1l, TimeUnit.MILLISECONDS);
if (next != null) {
result.add(next);
}
} catch (Queue.QueueTimeoutException e) {
}
}
if (result.size() > 0) {
System.out.println("Result " + result);
}
start = System.nanoTime();
return result;
};
}).filter(l -> l.size() > 0).to(s -> new LazyReact(ThreadPools.getSequential()).fromStream(s)).async().peek(System.out::println).run();
while (true) {
}
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class BatchingInvestigationsTest method batchIssue.
@Test
public void batchIssue() throws InterruptedException {
Queue<String> queue = QueueFactories.<String>unboundedQueue().build();
new Thread(() -> {
for (int i = 0; i < 10; i++) {
queue.offer("New message " + i);
sleep(10000);
}
}).start();
queue.stream().groupedBySizeAndTime(10, 500, TimeUnit.MILLISECONDS).to(s -> new LazyReact(ThreadPools.getSequential()).fromStream(s)).async().peek(System.out::println).run();
while (true) {
}
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class BatchingInvestigationsTest method batchIssueStreamSource.
@Test
public void batchIssueStreamSource() throws InterruptedException {
Queue<String> queue = QueueFactories.<String>unboundedQueue().build();
new Thread(() -> {
while (true) {
sleep(1000);
queue.offer("New message " + System.currentTimeMillis());
}
}).start();
StreamSource.futureStream(queue, new LazyReact(ThreadPools.getSequential())).groupedBySizeAndTime(10, 500, TimeUnit.MILLISECONDS).forEach(i -> System.out.println(i + " Batch Time:" + System.currentTimeMillis()));
while (true) {
}
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class MiscTest method pVectorX.
@Test
public void pVectorX() {
ReactiveSeq<String> seq = Spouts.from(VectorX.of(1, 2, 3, 4).plus(5).map(i -> "connect toNested Akka, RxJava and more with reactiveBuffer-streams" + i));
PersistentSetX<String> setX = seq.to(s -> new LazyReact().fromStream(s)).map(data -> "fan out across threads with futureStreams" + data).to(ReactiveConvertableSequence::converter).persistentSetX();
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class PipesTest method futureStreamTest.
@Test
public void futureStreamTest() {
Pipes<String, Integer> bus = Pipes.of();
bus.register("reactor", QueueFactories.<Integer>boundedNonBlockingQueue(1000).build());
bus.publishTo("reactor", ReactiveSeq.of(10, 20, 30));
bus.close("reactor");
System.out.println(Thread.currentThread().getId());
List<String> res = bus.futureStream("reactor", new LazyReact()).toOptional().get().map(i -> "fan-out toNested handle blocking I/O:" + Thread.currentThread().getId() + ":" + i).toList();
System.out.println(res);
assertThat(res.size(), equalTo(3));
}
Aggregations