use of com.oath.cyclops.async.QueueFactories in project cyclops by aol.
the class QueueTest method parallelStreamSmallBounds.
@Test
public void parallelStreamSmallBounds() {
for (int x = 0; x < 10; x++) {
System.out.println("Run " + x);
success = false;
AtomicLong threadId = new AtomicLong(Thread.currentThread().getId());
Queue<Integer> q = QueueFactories.<Integer>boundedQueue(100).build();
for (int i = 0; i < 10000; i++) {
q.add(i);
}
System.out.println(" queue " + q.size());
System.out.println(threadId.get());
q.jdkStream().parallel().peek(System.out::println).peek(i -> {
System.out.println(Thread.currentThread().getId());
if (threadId.get() != Thread.currentThread().getId()) {
System.out.println("closing");
success = true;
q.close();
}
}).peek(i -> System.out.println(Thread.currentThread().getId())).forEach(System.out::println);
assertTrue(success);
}
}
use of com.oath.cyclops.async.QueueFactories 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 com.oath.cyclops.async.QueueFactories 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 com.oath.cyclops.async.QueueFactories 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