Search in sources :

Example 56 with SimpleReact

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

the class AnyOfTest method testAnyOfCompletableFilterNoError.

// unreliable with filter, as filtered records count as completed.
@Test
// unreliable with filter, as filtered records count as completed.
@Ignore
public void testAnyOfCompletableFilterNoError() {
    String result = new SimpleReact().of("hello", "world", "2").onFail(it -> "hello").filter(it -> !"2".equals(it)).peek(it -> System.out.println(it)).anyOf(data -> {
        System.out.println(data);
        return data;
    }).block().firstValue(null);
    assertThat(result, is(notNullValue()));
}
Also used : Assert.assertThat(org.junit.Assert.assertThat) ExecutionException(java.util.concurrent.ExecutionException) Arrays(java.util.Arrays) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Ignore(org.junit.Ignore) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) SimpleReact(cyclops.futurestream.SimpleReact) Matchers.is(org.hamcrest.Matchers.is) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test) SimpleReact(cyclops.futurestream.SimpleReact) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 57 with SimpleReact

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

the class AnyOfTest method testAnyOfCompletableFutureOnFailRecovers.

@Test
public void testAnyOfCompletableFutureOnFailRecovers() {
    List<String> urls = Arrays.asList("hello", "world", "2");
    List<String> result = new SimpleReact().fromStream(urls.stream().<CompletableFuture<String>>map(it -> handle(it))).capture(e -> e.printStackTrace()).onFail(e -> "woot!").anyOf(data -> {
        System.out.println(data);
        return data;
    }).block();
    assertThat(result.size(), is(1));
}
Also used : Assert.assertThat(org.junit.Assert.assertThat) ExecutionException(java.util.concurrent.ExecutionException) Arrays(java.util.Arrays) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Ignore(org.junit.Ignore) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) SimpleReact(cyclops.futurestream.SimpleReact) Matchers.is(org.hamcrest.Matchers.is) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test) SimpleReact(cyclops.futurestream.SimpleReact) Test(org.junit.Test)

Example 58 with SimpleReact

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

the class CaptureTest method capture.

@Test
public void capture() throws InterruptedException {
    t = null;
    new SimpleReact().of("hello", "world").capture(e -> t = e).peek(System.out::println).then(this::exception).peek(System.out::println).then(s -> "hello" + s).run();
    Thread.sleep(500);
    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) SimpleReact(cyclops.futurestream.SimpleReact) SimpleReactFailedStageException(com.oath.cyclops.react.SimpleReactFailedStageException) Test(org.junit.Test)

Example 59 with SimpleReact

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

the class CaptureTest method captureLast.

@Test
public void captureLast() throws InterruptedException {
    t = null;
    new SimpleReact().of("hello", "world").capture(e -> t = e).peek(System.out::println).peek(System.out::println).then(s -> "hello" + s).then(this::exception).run();
    Thread.sleep(500);
    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) SimpleReact(cyclops.futurestream.SimpleReact) SimpleReactFailedStageException(com.oath.cyclops.react.SimpleReactFailedStageException) Test(org.junit.Test)

Example 60 with SimpleReact

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

the class MergeTest method testMergeTypes.

@Test
public void testMergeTypes() throws InterruptedException, ExecutionException {
    SimpleReactStream<Integer> stage1 = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3);
    SimpleReactStream<String> stage2 = new SimpleReact().<Integer>ofAsync(() -> 4, () -> 5, () -> 6).then(it -> "*" + it);
    List<Object> result = SimpleReactStream.<Object>merge(stage1, stage2).block();
    assertThat(result.size(), is(6));
}
Also used : 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