Search in sources :

Example 61 with SimpleReact

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

the class PeekTest method testPeekFirst.

@Test
public void testPeekFirst() throws InterruptedException, ExecutionException {
    Queue<Integer> peeked = new ConcurrentLinkedQueue<Integer>();
    List<String> strings = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3).peek(it -> peeked.add(it)).then(it -> it * 100).then(it -> "*" + it).block();
    assertThat(peeked.size(), is(strings.size()));
}
Also used : Assert.assertThat(org.junit.Assert.assertThat) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) SimpleReact(cyclops.futurestream.SimpleReact) Matchers.is(org.hamcrest.Matchers.is) Test(org.junit.Test) Queue(java.util.Queue) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) SimpleReact(cyclops.futurestream.SimpleReact) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Test(org.junit.Test)

Example 62 with SimpleReact

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

the class PeekTest method testPeek.

@Test
public void testPeek() throws InterruptedException, ExecutionException {
    Queue<String> peeked = new ConcurrentLinkedQueue<String>();
    List<String> strings = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3).then(it -> it * 100).<String>then(it -> "*" + it).peek((String it) -> peeked.add(it)).block();
    assertThat(peeked.size(), is(strings.size()));
    assertThat(strings, hasItem(peeked.peek()));
}
Also used : Assert.assertThat(org.junit.Assert.assertThat) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) SimpleReact(cyclops.futurestream.SimpleReact) Matchers.is(org.hamcrest.Matchers.is) Test(org.junit.Test) Queue(java.util.Queue) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) SimpleReact(cyclops.futurestream.SimpleReact) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Test(org.junit.Test)

Example 63 with SimpleReact

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

the class SimpleReactTest method testCaptureNull.

@Test
public void testCaptureNull() throws InterruptedException, ExecutionException {
    Throwable[] error = { null };
    List<String> strings = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3).then((it) -> it * 100).then((it) -> {
        if (it == 100)
            throw new RuntimeException("boo!");
        return it;
    }).onFail(e -> 1).then((it) -> "*" + it).capture(e -> error[0] = e).block();
    boolean[] foundOne = { false };
    strings.forEach((string) -> {
        assertThat(string, is(containsString("*")));
        if (Integer.valueOf(string.substring(1)) == 1)
            foundOne[0] = true;
    });
    assertThat(foundOne[0], is(true));
    assertThat(error[0], is(nullValue()));
}
Also used : Arrays(java.util.Arrays) LazyReact(cyclops.futurestream.LazyReact) Matchers(org.mockito.Matchers) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) BaseSimpleReactStream(com.oath.cyclops.types.futurestream.BaseSimpleReactStream) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) ExecutorService(java.util.concurrent.ExecutorService) Iterator(java.util.Iterator) Set(java.util.Set) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Matchers.any(org.mockito.Matchers.any) ExecutionException(java.util.concurrent.ExecutionException) CountDownLatch(java.util.concurrent.CountDownLatch) Mockito(org.mockito.Mockito) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Stream(java.util.stream.Stream) ForkJoinPool(java.util.concurrent.ForkJoinPool) SimpleReact(cyclops.futurestream.SimpleReact) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.mock(org.mockito.Mockito.mock) SimpleReact(cyclops.futurestream.SimpleReact) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 64 with SimpleReact

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

the class SimpleReactTest method testReactMixedTypes.

@Test
public void testReactMixedTypes() {
    List list = new ArrayList();
    List<Object> result = new SimpleReact().ofAsync(() -> "Hello", () -> list).block();
    assertThat(result.size(), is(2));
    assertThat(result, hasItem("Hello"));
    assertThat(result, hasItem(list));
}
Also used : SimpleReact(cyclops.futurestream.SimpleReact) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 65 with SimpleReact

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

the class SimpleReactTest method testThenPrimitive.

@Test
public void testThenPrimitive() {
    List<Boolean> result = new SimpleReact().ofAsync(() -> 1, () -> 1).then(it -> true).block();
    assertThat(result.size(), is(2));
    assertThat(result.get(0), is(true));
}
Also used : Arrays(java.util.Arrays) LazyReact(cyclops.futurestream.LazyReact) Matchers(org.mockito.Matchers) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) BaseSimpleReactStream(com.oath.cyclops.types.futurestream.BaseSimpleReactStream) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) ExecutorService(java.util.concurrent.ExecutorService) Iterator(java.util.Iterator) Set(java.util.Set) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Matchers.any(org.mockito.Matchers.any) ExecutionException(java.util.concurrent.ExecutionException) CountDownLatch(java.util.concurrent.CountDownLatch) Mockito(org.mockito.Mockito) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Stream(java.util.stream.Stream) ForkJoinPool(java.util.concurrent.ForkJoinPool) SimpleReact(cyclops.futurestream.SimpleReact) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.mock(org.mockito.Mockito.mock) SimpleReact(cyclops.futurestream.SimpleReact) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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