Search in sources :

Example 31 with FastFuture

use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.

the class FastFutureTest method onComplete_alreadyCompleted.

@Test
public void onComplete_alreadyCompleted() {
    called = false;
    FastFuture f = future.<Integer, Integer>thenApply(i -> i + 2).build();
    f.set(10);
    assertTrue(f.isDone());
    f.onComplete(event -> called = true);
    assertTrue(called);
}
Also used : FastFuture(com.oath.cyclops.internal.react.async.future.FastFuture) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) FinalPipeline(com.oath.cyclops.internal.react.async.future.FinalPipeline) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) ForkJoinPool(java.util.concurrent.ForkJoinPool) Matchers.equalTo(org.hamcrest.Matchers.equalTo) PipelineBuilder(com.oath.cyclops.internal.react.async.future.PipelineBuilder) Before(org.junit.Before) FastFuture(com.oath.cyclops.internal.react.async.future.FastFuture) Test(org.junit.Test)

Example 32 with FastFuture

use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.

the class FastFutureTest method essentialReversed_notCompleted_race.

@Test
public void essentialReversed_notCompleted_race() throws InterruptedException {
    for (int i = 0; i < TIMES; i++) {
        System.out.println(i);
        CountDownLatch race = new CountDownLatch(1);
        CountDownLatch init = new CountDownLatch(1);
        called = false;
        FastFuture f = future.<Integer, Integer>thenApply(x -> x + 2).build();
        Thread t1 = new Thread(() -> {
            init.countDown();
            try {
                race.await();
            } catch (Exception e) {
                e.printStackTrace();
            }
            f.set(10);
        });
        t1.start();
        race.countDown();
        f.essential(event -> called = true);
        t1.join();
        assertTrue(f.isDone());
        assertTrue(called);
    }
}
Also used : FastFuture(com.oath.cyclops.internal.react.async.future.FastFuture) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) FinalPipeline(com.oath.cyclops.internal.react.async.future.FinalPipeline) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) ForkJoinPool(java.util.concurrent.ForkJoinPool) Matchers.equalTo(org.hamcrest.Matchers.equalTo) PipelineBuilder(com.oath.cyclops.internal.react.async.future.PipelineBuilder) Before(org.junit.Before) FastFuture(com.oath.cyclops.internal.react.async.future.FastFuture) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test)

Example 33 with FastFuture

use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.

the class BatchingCollectorTest method testAcceptMock.

@Test
public void testAcceptMock() {
    FastFuture cf = Mockito.mock(FastFuture.class);
    BDDMockito.given(cf.isDone()).willReturn(true);
    for (int i = 0; i < 1000; i++) {
        collector.accept(cf);
    }
    Mockito.verify(cf, Mockito.atLeastOnce()).isDone();
}
Also used : FastFuture(com.oath.cyclops.internal.react.async.future.FastFuture) Test(org.junit.Test)

Example 34 with FastFuture

use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.

the class BatchingCollectorTest method testAcceptMock50.

@Test
public void testAcceptMock50() {
    collector = new BatchingCollector(new MaxActive(500, 450), LazyReact.sequentialBuilder().of(1)).withResults(new ArrayList<>());
    FastFuture cf = Mockito.mock(FastFuture.class);
    BDDMockito.given(cf.isDone()).willReturn(true);
    for (int i = 0; i < 1000; i++) {
        collector.accept(cf);
    }
    Mockito.verify(cf, Mockito.times(501)).isDone();
}
Also used : ArrayList(java.util.ArrayList) FastFuture(com.oath.cyclops.internal.react.async.future.FastFuture) Test(org.junit.Test)

Example 35 with FastFuture

use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.

the class LazyStream method runThread.

default void runThread(final Runnable r) {
    final Function<FastFuture, U> safeJoin = (final FastFuture cf) -> (U) BlockingStreamHelper.getSafe(cf, getErrorHandler());
    new Thread(() -> new Runner(r).run(getLastActive(), new EmptyCollector(getMaxActive(), safeJoin))).start();
}
Also used : Runner(com.oath.cyclops.internal.react.stream.Runner) EmptyCollector(com.oath.cyclops.react.collectors.lazy.EmptyCollector) FastFuture(com.oath.cyclops.internal.react.async.future.FastFuture)

Aggregations

FastFuture (com.oath.cyclops.internal.react.async.future.FastFuture)35 Test (org.junit.Test)30 FileNotFoundException (java.io.FileNotFoundException)21 IOException (java.io.IOException)21 CountDownLatch (java.util.concurrent.CountDownLatch)21 ArrayList (java.util.ArrayList)19 Assert.assertThat (org.junit.Assert.assertThat)18 Assert.assertTrue (org.junit.Assert.assertTrue)18 Before (org.junit.Before)18 FinalPipeline (com.oath.cyclops.internal.react.async.future.FinalPipeline)17 PipelineBuilder (com.oath.cyclops.internal.react.async.future.PipelineBuilder)17 List (java.util.List)17 ForkJoinPool (java.util.concurrent.ForkJoinPool)16 Matchers.equalTo (org.hamcrest.Matchers.equalTo)16 Assert.assertFalse (org.junit.Assert.assertFalse)16 Assert.assertNotNull (org.junit.Assert.assertNotNull)16 Assert.assertNull (org.junit.Assert.assertNull)16 EmptyCollector (com.oath.cyclops.react.collectors.lazy.EmptyCollector)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 Function (java.util.function.Function)2