use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class ParallelTest method runOnCurrent.
@Test
public void runOnCurrent() {
LazyReact lazy = LazyReact.parallelBuilder().autoOptimizeOn();
System.out.println("Starting");
lazy.range(0, 100).map(i -> i + 2).thenSync(i -> {
try {
Thread.sleep(500);
} catch (Exception e) {
}
return i;
}).thenSync(i -> "hello" + i).peekSync(val -> value = val).runOnCurrent();
assertNotNull(value);
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class LazySeqTest method shouldZipTwoInfiniteSequences.
@Test
@Ignore
public void shouldZipTwoInfiniteSequences() throws Exception {
final FutureStream<Integer> units = new LazyReact(ThreadPools.getCommonFreeThread()).iterate(1, n -> n + 1);
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()));
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class BatchingTest method windowByTimeFiltered.
@Test
public void windowByTimeFiltered() {
for (int x = 0; x < 10; x++) {
count2 = new AtomicInteger(0);
List<Collection<Map>> result = new ArrayList<>();
new LazyReact(ThreadPools.getCommonFreeThread()).iterate("", last -> "hello").limit(1000).peek(i -> System.out.println(++otherCount)).groupedByTime(1, TimeUnit.MICROSECONDS).peek(batch -> System.out.println("batched : " + batch + ":" + (++peek))).peek(batch -> count3 = count3 + (int) batch.stream().count()).forEach(next -> {
count2.getAndAdd((int) next.stream().count());
});
System.out.println("In flight count " + count3 + " :" + otherCount);
System.out.println(result.size());
System.out.println(result);
System.out.println("x" + x);
assertThat(count2.get(), equalTo(1000));
}
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class AutoMemoizationTest method autoMemoizeSet.
@Test
public void autoMemoizeSet() {
called.set(0);
Map cache = new ConcurrentHashMap<>();
LazyReact react = new LazyReact().autoMemoizeOn((key, fn) -> cache.computeIfAbsent(key, fn));
Set<Integer> result = react.of(1, 1, 1, 1).capture(e -> e.printStackTrace()).map(i -> calc(i)).peek(System.out::println).toSet();
System.out.println(result);
assertThat(called.get(), equalTo(1));
assertThat(result.size(), equalTo(1));
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class AutoMemoizationTest method autoMemoize.
@Test
public void autoMemoize() {
called.set(0);
Map cache = new ConcurrentHashMap<>();
LazyReact react = new LazyReact().autoMemoizeOn((key, fn) -> cache.computeIfAbsent(key, fn));
List result = react.of(1, 1, 1, 1).capture(e -> e.printStackTrace()).map(i -> calc(i)).peek(System.out::println).toList();
System.out.println(result);
assertThat(called.get(), equalTo(1));
assertThat(result.size(), equalTo(4));
}
Aggregations