Search in sources :

Example 36 with SimpleReact

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

the class BlockingTest method testLast.

@Test
public void testLast() throws InterruptedException, ExecutionException {
    Integer result = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3, () -> 5).then(it -> it * 100).then(it -> sleep(it)).block().takeRight(1).get(0);
    assertThat(result, is(500));
}
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 37 with SimpleReact

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

the class BlockingTest method testBreakoutExceptionTimes.

@Test
public void testBreakoutExceptionTimes() throws InterruptedException, ExecutionException {
    count = new AtomicInteger(0);
    List<Integer> results = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3).then(it -> it * 100).<Integer>then(it -> {
        throw new RuntimeException("boo!");
    }).capture(e -> count.incrementAndGet()).block(status -> status.getCompleted() >= 1);
    assertThat(results.size(), is(0));
    assertThat(count.get(), is(3));
}
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 38 with SimpleReact

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

the class BlockingTest method testBreakoutException.

@Test
public void testBreakoutException() throws InterruptedException, ExecutionException {
    Throwable[] error = { null };
    List<Integer> results = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3).then(it -> it * 100).<Integer>then(it -> {
        throw new RuntimeException("boo!");
    }).capture(e -> error[0] = e.getCause()).block(status -> status.getCompleted() >= 1);
    assertThat(results.size(), is(0));
    assertThat(error[0], instanceOf(RuntimeException.class));
}
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 39 with SimpleReact

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

the class BlockingTest method testFirstSimple.

@Test
public void testFirstSimple() throws InterruptedException, ExecutionException {
    SimpleReactStream<Integer> stage = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3, () -> 5).then(it -> it * 100).then(it -> sleep(it));
    int result = stage.block().firstValue(null);
    assertThat(result, is(100));
    stage.block();
}
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 40 with SimpleReact

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

the class BlockingTest method testTypeInferencingThen.

@Test
public void testTypeInferencingThen() {
    List<String> result = new SimpleReact().ofAsync(() -> "World", () -> "Hello").then(in -> "hello").block();
    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)

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