Search in sources :

Example 41 with SimpleReact

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

the class BlockingTest method testBreakoutAllCompletedAndTime.

@Test
public void testBreakoutAllCompletedAndTime() throws InterruptedException, ExecutionException {
    count = new AtomicInteger(0);
    List<Integer> result = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3).then(it -> it * 100).then(it -> {
        sleep(it);
        return it;
    }).capture(e -> count.incrementAndGet()).block(status -> status.getAllCompleted() > 1 && status.getElapsedMillis() > 20);
    assertThat(result.size(), is(2));
    assertThat(count.get(), is(0));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) SimpleReactStream(com.oath.cyclops.types.futurestream.SimpleReactStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SimpleReact(cyclops.futurestream.SimpleReact) Set(java.util.Set) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SimpleReact(cyclops.futurestream.SimpleReact) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 42 with SimpleReact

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

the class BlockingTest method testBlockStreamsSeparateExecutors.

@Test
public void testBlockStreamsSeparateExecutors() throws InterruptedException, ExecutionException {
    Integer result = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3).then(it -> it * 200).block().parallelStream().filter(f -> f > 300).map(m -> m - 5).reduce(0, (acc, next) -> acc + next);
    assertThat(result, is(990));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) SimpleReactStream(com.oath.cyclops.types.futurestream.SimpleReactStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SimpleReact(cyclops.futurestream.SimpleReact) Set(java.util.Set) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SimpleReact(cyclops.futurestream.SimpleReact) Test(org.junit.Test)

Example 43 with SimpleReact

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

the class BlockingTest method testBreakoutAllCompletedStrings.

@Test
public void testBreakoutAllCompletedStrings() throws InterruptedException, ExecutionException {
    count = new AtomicInteger(0);
    List<String> strings = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3).then(it -> it * 100).then(it -> {
        if (it == 100)
            throw new RuntimeException("boo!");
        else
            sleep(it);
        return it;
    }).then(it -> "*" + it).capture(e -> count.incrementAndGet()).block(status -> status.getAllCompleted() > 0);
    assertThat(strings.size(), is(0));
    assertThat(count.get(), is(1));
}
Also used : Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) SimpleReactStream(com.oath.cyclops.types.futurestream.SimpleReactStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SimpleReact(cyclops.futurestream.SimpleReact) Set(java.util.Set) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SimpleReact(cyclops.futurestream.SimpleReact) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 44 with SimpleReact

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

the class BlockingTest method testTypeInferencingThenPredicate.

@Test
public void testTypeInferencingThenPredicate() {
    List<String> result = new SimpleReact().ofAsync(() -> "World", () -> "Hello").then(in -> "hello").block(state -> state.getCompleted() > 3);
    assertThat(result.size(), is(2));
}
Also used : Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) SimpleReactStream(com.oath.cyclops.types.futurestream.SimpleReactStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SimpleReact(cyclops.futurestream.SimpleReact) Set(java.util.Set) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SimpleReact(cyclops.futurestream.SimpleReact) Test(org.junit.Test)

Example 45 with SimpleReact

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

the class ResultCollectionTest method testBreakoutExceptionTimes.

@Test
public void testBreakoutExceptionTimes() throws InterruptedException, ExecutionException {
    count = 0;
    List<String> strings = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3).then(it -> it * 100).<String>then(it -> {
        throw new RuntimeException("boo!");
    }).capture(e -> count++).block(status -> status.getCompleted() >= 1);
    assertThat(strings.size(), is(0));
    assertThat(count, is(3));
}
Also used : Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) SimpleReact(cyclops.futurestream.SimpleReact) Set(java.util.Set) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SimpleReact(cyclops.futurestream.SimpleReact) Test(org.junit.Test)

Aggregations

SimpleReact (cyclops.futurestream.SimpleReact)71 Test (org.junit.Test)70 Assert.assertThat (org.junit.Assert.assertThat)54 Matchers.is (org.hamcrest.Matchers.is)52 List (java.util.List)50 ExecutionException (java.util.concurrent.ExecutionException)46 Collectors (java.util.stream.Collectors)36 Set (java.util.Set)33 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)31 Matchers.hasItem (org.hamcrest.Matchers.hasItem)30 Matchers.greaterThan (org.hamcrest.Matchers.greaterThan)25 Arrays (java.util.Arrays)24 CompletableFuture (java.util.concurrent.CompletableFuture)24 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)21 Stream (java.util.stream.Stream)21 LazyReact (cyclops.futurestream.LazyReact)20 BaseSimpleReactStream (com.oath.cyclops.types.futurestream.BaseSimpleReactStream)17 ArrayList (java.util.ArrayList)16 ForkJoinPool (java.util.concurrent.ForkJoinPool)16 Ignore (org.junit.Ignore)14