Search in sources :

Example 1 with FastFuture

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

the class FastFutureTest method onFailRecovered.

@Test
public void onFailRecovered() {
    FastFuture f = future.onFail(t -> failed = t).exceptionally(e -> "hello world").thenApply(v -> {
        throw new RuntimeException();
    }).build();
    f.set("boo!");
    assertThat(f.join(), equalTo("hello world"));
}
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 2 with FastFuture

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

the class FastFutureTest method onComplete_notCompleted_race.

@Test
public void onComplete_notCompleted_race() throws InterruptedException {
    for (int i = 0; i < TIMES; 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.onComplete(event -> called = true);
        });
        t1.start();
        race.countDown();
        f.set(10);
        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 3 with FastFuture

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

the class FastFutureTest method essential_notCompleted_race.

@Test
public void essential_notCompleted_race() throws InterruptedException {
    for (int i = 0; i < TIMES; 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.essential(event -> called = true);
        });
        t1.start();
        init.await();
        race.countDown();
        f.set(10);
        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 4 with FastFuture

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

the class FastFutureTest method onFailNull.

@Test
public void onFailNull() {
    FastFuture f = future.thenApply(v -> {
        throw new RuntimeException();
    }).build();
    f.set("boo!");
    assertNull(failed);
}
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 5 with FastFuture

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

the class FastFutureTest method essential_withNoPipeline_notCompleted_race.

@Test
public void essential_withNoPipeline_notCompleted_race() throws InterruptedException {
    for (int i = 0; i < TIMES; i++) {
        CountDownLatch race = new CountDownLatch(1);
        CountDownLatch init = new CountDownLatch(1);
        called = false;
        FastFuture f = future.build();
        Thread t1 = new Thread(() -> {
            init.countDown();
            try {
                race.await();
            } catch (Exception e) {
                e.printStackTrace();
            }
            f.essential(event -> called = true);
        });
        t1.start();
        race.countDown();
        f.set(10);
        t1.join();
        assertTrue(f.isDone());
        assertTrue(called);
    }
}
Also used : 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)

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