use of com.oath.cyclops.async.adapters.Queue in project cyclops by aol.
the class LazySeqTest method zipFastSlow.
@Test
public void zipFastSlow() {
Queue q = new Queue();
LazyReact.parallelBuilder().generate(() -> sleep(100)).then(it -> q.add("100")).runThread(new Thread());
new LazyReact().of(1, 2, 3, 4, 5, 6).zip(q.stream()).peek(it -> System.out.println(it)).collect(Collectors.toList());
}
use of com.oath.cyclops.async.adapters.Queue in project cyclops by aol.
the class BaseSequentialSeqTest method shard.
@Test
public void shard() {
for (int i = 0; i < 100; i++) {
Map<Integer, Queue<Integer>> shards = new HashMap<>();
shards.put(1, new Queue());
shards.put(2, new Queue());
shards.put(3, new Queue());
shards.put(4, new Queue());
shards.put(5, new Queue());
shards.put(6, new Queue());
assertThat(of(1, 2, 3, 4, 5, 6).shard(MapX.fromMap(shards), Function.identity()).size(), is(6));
}
}
use of com.oath.cyclops.async.adapters.Queue in project cyclops by aol.
the class LazySeqObjectPoolingTest method testBackPressureWhenZippingUnevenStreams2.
@Test
public void testBackPressureWhenZippingUnevenStreams2() {
Queue fast = LazyReact.parallelBuilder().withExecutor(new ForkJoinPool(2)).generateAsync(() -> "100").peek(System.out::println).withQueueFactory(QueueFactories.boundedQueue(10)).toQueue();
new Thread(() -> {
LazyReact.parallelBuilder().withExecutor(new ForkJoinPool(2)).range(0, 1000).peek(System.out::println).peek(c -> sleep(10)).zip(fast.stream()).forEach(it -> {
});
}).start();
;
fast.setSizeSignal(Signal.queueBackedSignal());
int max = fast.getSizeSignal().getContinuous().stream().mapToInt(it -> (int) it).limit(50).max().getAsInt();
assertThat(max, lessThan(11));
}
use of com.oath.cyclops.async.adapters.Queue in project cyclops by aol.
the class LazySeqObjectPoolingTest method shouldZipFiniteWithInfiniteSeq.
@Test
public void shouldZipFiniteWithInfiniteSeq() throws Exception {
ThreadPools.setUseCommon(false);
final ReactiveSeq<Integer> units = new LazyReact(ThreadPools.getCommonFreeThread()).iterate(1, n -> n + 1).limit(5);
// <-- MEMORY LEAK! - no auto-closing yet, so writes infinetely to it's async queue
final FutureStream<Integer> hundreds = new LazyReact(ThreadPools.getCommonFreeThread()).iterate(100, n -> n + 100);
final ReactiveSeq<String> zipped = units.zip(hundreds, (n, p) -> n + ": " + p);
assertThat(zipped.limit(5).join(), equalTo(of("1: 100", "2: 200", "3: 300", "4: 400", "5: 500").join()));
ThreadPools.setUseCommon(true);
}
use of com.oath.cyclops.async.adapters.Queue in project bender by Nextdoor.
the class ForkOperationTest method testTwoForks.
@Test
public void testTwoForks() {
/*
* Setup the pipeline of operation processors
*/
List<List<OperationProcessor>> forks = new ArrayList<List<OperationProcessor>>();
List<OperationProcessor> fork1 = new ArrayList<OperationProcessor>();
fork1.add(new OperationProcessor(new DummyOperationFactory()));
forks.add(fork1);
List<OperationProcessor> fork2 = new ArrayList<OperationProcessor>();
fork2.add(new OperationProcessor(new DummyOperationFactory()));
forks.add(fork2);
ForkOperation op = new ForkOperation(forks);
/*
* Create thread that supplies input events
*/
Queue<InternalEvent> inputQueue = new Queue<InternalEvent>();
supply(2, inputQueue);
/*
* Process
*/
Stream<InternalEvent> input = inputQueue.stream();
Stream<InternalEvent> output = op.getOutputStream(input);
List<String> actual = output.map(InternalEvent::getEventString).collect(Collectors.toList());
List<String> expected = Arrays.asList("0", "1", "0", "1");
assertEquals(4, actual.size());
assertTrue(expected.containsAll(actual));
}
Aggregations