Search in sources :

Example 26 with LazyReact

use of cyclops.futurestream.LazyReact in project cyclops by aol.

the class Tutorial method IO.

@Test
public void IO() {
    // stream builder with 50 threads and 50 active futures
    LazyReact react = new LazyReact(50, 50).autoOptimizeOn();
    react.generateAsync(this::loadNext).takeWhile(this::isActive).map(this::process).peek(this::save).run();
}
Also used : LazyReact(cyclops.futurestream.LazyReact) Test(org.junit.Test)

Example 27 with LazyReact

use of cyclops.futurestream.LazyReact in project cyclops by aol.

the class RxJavaConversionTest method rxConversionTestSkip.

@Test
public void rxConversionTestSkip() throws InterruptedException, ExecutionException {
    List<String> titles = new LazyReact().from(query("Hello, world!").get()).<String>then(url -> getTitle(url)).filter(Objects::nonNull).skip(5).peek(title -> saveTitle(title)).peek(System.out::println).block();
    assertThat(titles.size(), is(4));
    assertThat(savedCalled, is(4));
}
Also used : Assert.assertThat(org.junit.Assert.assertThat) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) Arrays(java.util.Arrays) List(java.util.List) Stream(java.util.stream.Stream) LazyReact(cyclops.futurestream.LazyReact) Collection(java.util.Collection) Matchers.is(org.hamcrest.Matchers.is) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test) LazyReact(cyclops.futurestream.LazyReact) Objects(java.util.Objects) Test(org.junit.Test)

Example 28 with LazyReact

use of cyclops.futurestream.LazyReact in project cyclops by aol.

the class RxJavaConversionTest method rxConversion.

@Test
public void rxConversion() throws InterruptedException, ExecutionException {
    // conversion of non-concurrent RxJava code here :- http://blog.danlew.net/2014/09/22/grokking-rxjava-part-2/
    List<String> titles = new LazyReact().fromStreamFutures(Stream.of(query("Hello, world!"))).flatMap(Collection::stream).peek(System.out::println).<String>then(url -> getTitle(url)).filter(Objects::nonNull).limit(5).peek(title -> saveTitle(title)).peek(System.out::println).block();
    assertThat(titles.size(), is(5));
    assertThat(savedCalled, is(5));
}
Also used : Assert.assertThat(org.junit.Assert.assertThat) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) Arrays(java.util.Arrays) List(java.util.List) Stream(java.util.stream.Stream) LazyReact(cyclops.futurestream.LazyReact) Collection(java.util.Collection) Matchers.is(org.hamcrest.Matchers.is) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test) LazyReact(cyclops.futurestream.LazyReact) Objects(java.util.Objects) Test(org.junit.Test)

Example 29 with LazyReact

use of cyclops.futurestream.LazyReact in project cyclops by aol.

the class AutoMemoizationTest method autoMemoizeOff.

@Test
public void autoMemoizeOff() {
    called.set(0);
    Map cache = new ConcurrentHashMap<>();
    LazyReact react = new LazyReact();
    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(result.size(), equalTo(4));
    assertThat(called.get(), greaterThan(3));
}
Also used : Assert.assertThat(org.junit.Assert.assertThat) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LazyReact(cyclops.futurestream.LazyReact) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Test(org.junit.Test) LazyReact(cyclops.futurestream.LazyReact) List(java.util.List) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 30 with LazyReact

use of cyclops.futurestream.LazyReact in project cyclops by aol.

the class FastFutureConversionTest method conversion.

@Test
public void conversion() {
    CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> "hello");
    assertThat(new LazyReact().from(future).peek(System.out::println).then(action -> "result").singleOrElse(null), equalTo("result"));
}
Also used : LazyReact(cyclops.futurestream.LazyReact) Test(org.junit.Test)

Aggregations

LazyReact (cyclops.futurestream.LazyReact)60 Test (org.junit.Test)58 List (java.util.List)27 Assert.assertThat (org.junit.Assert.assertThat)25 Queue (com.oath.cyclops.async.adapters.Queue)21 Matchers.equalTo (org.hamcrest.Matchers.equalTo)21 Ignore (org.junit.Ignore)20 ReactiveSeq (cyclops.reactive.ReactiveSeq)19 Matchers.greaterThan (org.hamcrest.Matchers.greaterThan)19 QueueFactories (com.oath.cyclops.async.QueueFactories)17 Arrays.asList (java.util.Arrays.asList)16 Collectors (java.util.stream.Collectors)16 Matchers.is (org.hamcrest.Matchers.is)16 ArrayList (java.util.ArrayList)15 ForkJoinPool (java.util.concurrent.ForkJoinPool)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 Tuple2 (cyclops.data.tuple.Tuple2)14 FutureStream (cyclops.futurestream.FutureStream)13 ThreadPools (com.oath.cyclops.react.ThreadPools)12 Tuple.tuple (cyclops.data.tuple.Tuple.tuple)12