Search in sources :

Example 1 with SimpleReact

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

the class SimpleReactTest method testLargeChain.

@Test
public void testLargeChain() {
    BaseSimpleReactStream builder = new SimpleReact().ofAsync(() -> "Hello", () -> "World");
    for (int i = 0; i < 1000; i++) {
        builder = builder.then(input -> input + " " + counter++);
    }
    List<String> results = builder.block();
    assertThat(results.get(0).length(), greaterThan(100));
}
Also used : BaseSimpleReactStream(com.oath.cyclops.types.futurestream.BaseSimpleReactStream) 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 2 with SimpleReact

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

the class SimpleReactTest method testEagetParameters.

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

Example 3 with SimpleReact

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

the class SimpleReactTest method testMultithreading.

@Test
public void testMultithreading() throws InterruptedException, ExecutionException {
    Set<Long> threads = new SimpleReact(new ForkJoinPool(10)).<Integer>ofAsync(() -> 1, () -> 2, () -> 3, () -> 3, () -> 3, () -> 3, () -> 3).peek(it -> sleep(50l)).then(it -> Thread.currentThread().getId()).block(Collectors.toSet());
    assertThat(threads.size(), is(greaterThan(1)));
}
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) ForkJoinPool(java.util.concurrent.ForkJoinPool) Test(org.junit.Test)

Example 4 with SimpleReact

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

the class SimpleReactTest method testGenericExtract.

@Test
public void testGenericExtract() throws InterruptedException, ExecutionException {
    Set<Integer> result = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3, () -> 5).then(it -> it * 100).<Set<Integer>, Set<Integer>>allOf(Collectors.toSet(), (Set<Integer> it) -> {
        assertThat(it, instanceOf(Set.class));
        return it;
    }).capture(e -> e.printStackTrace()).block(status -> false).takeRight(1).get(0);
    assertThat(result.size(), is(4));
}
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) Set(java.util.Set) SimpleReact(cyclops.futurestream.SimpleReact) Test(org.junit.Test)

Example 5 with SimpleReact

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

the class SimpleReactTest method testCustomExecutor.

@Test
public void testCustomExecutor() {
    ExecutorService executor = Mockito.mock(ExecutorService.class);
    Mockito.doAnswer((invocation) -> {
        ((Runnable) invocation.getArguments()[0]).run();
        return null;
    }).when(executor).execute(Matchers.any(Runnable.class));
    new SimpleReact(executor).ofAsync(() -> "Hello", () -> "World").block();
    Mockito.verify(executor, Mockito.times(2)).execute(Matchers.any(Runnable.class));
}
Also used : SimpleReact(cyclops.futurestream.SimpleReact) ExecutorService(java.util.concurrent.ExecutorService) 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