Search in sources :

Example 56 with LazyReact

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

the class ReactToList method main.

public static void main(String[] args) {
    List<Integer> values = new ArrayList();
    for (int i = 0; i < 4000; i++) values.add(i);
    LazyReact lazy = LazyReact.sequentialCurrentBuilder().withAsync(false).withMaxActive(new MaxActive(4010, 1000));
    SimpleTimer t = new SimpleTimer();
    for (int x = 0; x < 1000; x++) {
        res = lazy.from(values).map(i -> i + 2).map(i -> i * 3).collect(Collectors.toList());
    }
    System.out.println(t.getElapsedNanoseconds());
}
Also used : List(java.util.List) LazyReact(cyclops.futurestream.LazyReact) MaxActive(com.oath.cyclops.react.collectors.lazy.MaxActive) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SimpleTimer(com.oath.cyclops.util.SimpleTimer) ArrayList(java.util.ArrayList) LazyReact(cyclops.futurestream.LazyReact) SimpleTimer(com.oath.cyclops.util.SimpleTimer) ArrayList(java.util.ArrayList) MaxActive(com.oath.cyclops.react.collectors.lazy.MaxActive)

Example 57 with LazyReact

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

the class ReactToList method parallel.

@Test
public void parallel() {
    List<Integer> values = new ArrayList();
    for (int i = 0; i < 4000; i++) values.add(i);
    LazyReact lazy = LazyReact.parallelBuilder(8).autoOptimizeOn().withMaxActive(MaxActive.CPU);
    SimpleTimer t = new SimpleTimer();
    for (int x = 0; x < 1000; x++) {
        res = lazy.from(values).map(i -> i + 2).map(i -> i * 3).collect(Collectors.toList());
    }
    System.out.println(t.getElapsedNanoseconds());
}
Also used : List(java.util.List) LazyReact(cyclops.futurestream.LazyReact) MaxActive(com.oath.cyclops.react.collectors.lazy.MaxActive) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SimpleTimer(com.oath.cyclops.util.SimpleTimer) ArrayList(java.util.ArrayList) LazyReact(cyclops.futurestream.LazyReact) SimpleTimer(com.oath.cyclops.util.SimpleTimer) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 58 with LazyReact

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

the class CaptureTest method captureLazy.

@Test
public void captureLazy() {
    t = null;
    new LazyReact().of("hello", "world").capture(e -> t = e).peek(System.out::println).then(this::exception).forEach(System.out::println);
    assertNotNull(t);
    assertFalse(t.toString(), t instanceof SimpleReactFailedStageException);
    assertTrue(t.toString(), t instanceof InternalException);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LazyReact(cyclops.futurestream.LazyReact) Assert.assertFalse(org.junit.Assert.assertFalse) Assert.assertNotNull(org.junit.Assert.assertNotNull) SimpleReact(cyclops.futurestream.SimpleReact) Assert.assertTrue(org.junit.Assert.assertTrue) SimpleReactFailedStageException(com.oath.cyclops.react.SimpleReactFailedStageException) Test(org.junit.Test) Assert.assertEquals(org.junit.Assert.assertEquals) LazyReact(cyclops.futurestream.LazyReact) SimpleReactFailedStageException(com.oath.cyclops.react.SimpleReactFailedStageException) Test(org.junit.Test)

Example 59 with LazyReact

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

the class SimpleReactTest method testLazyParameters.

@Test
public void testLazyParameters() {
    ForkJoinPool fjp = new ForkJoinPool();
    assertThat(new LazyReact(fjp).getExecutor(), is(fjp));
}
Also used : LazyReact(cyclops.futurestream.LazyReact) ForkJoinPool(java.util.concurrent.ForkJoinPool) Test(org.junit.Test)

Example 60 with LazyReact

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

the class ReactPoolTest method testElastic.

@Test
public void testElastic() {
    for (int i = 0; i < 1000; i++) {
        ReactPool<LazyReact> pool = ReactPool.elasticPool(() -> new LazyReact());
        List<String> result = pool.react((er) -> er.ofAsync(() -> "hello", () -> "world").block());
        assertThat(result.size(), is(2));
    }
}
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