Search in sources :

Example 6 with FastFuture

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

the class FastFutureTest method essential_alreadyCompleted.

@Test
public void essential_alreadyCompleted() {
    called = false;
    FastFuture f = future.<Integer, Integer>thenApply(i -> i + 2).build();
    f.set(10);
    assertTrue(f.isDone());
    f.essential(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 7 with FastFuture

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

the class FastFutureTest method testAllOf.

@Test
public void testAllOf() throws InterruptedException {
    for (int i = 0; i < TIMES; i++) {
        complete = false;
        FastFuture f1 = new FastFuture(FinalPipeline.empty(), a -> {
        });
        FastFuture f2 = new FastFuture(FinalPipeline.empty(), a -> {
        });
        CountDownLatch race = new CountDownLatch(1);
        FastFuture allOf = FastFuture.allOf(() -> complete = true, f1, f2);
        new Thread(() -> {
            race.countDown();
            f1.set("done");
            f2.set("with");
        }).start();
        try {
            race.await();
        } catch (Exception e) {
            e.printStackTrace();
        }
        race.await();
        while (!complete) {
        }
    }
}
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)

Example 8 with FastFuture

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

the class FastFutureTest method essential_notCompleted.

@Test
public void essential_notCompleted() {
    called = false;
    FastFuture f = future.<Integer, Integer>thenApply(i -> i + 2).build();
    f.essential(event -> called = true);
    f.set(10);
    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) Test(org.junit.Test)

Example 9 with FastFuture

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

the class FastFutureTest method testXOf.

@Test
public void testXOf() {
    for (int i = 0; i < TIMES; i++) {
        complete = false;
        FastFuture f1 = new FastFuture(FinalPipeline.empty(), a -> {
        });
        FastFuture f2 = new FastFuture(FinalPipeline.empty(), a -> {
        });
        CountDownLatch race = new CountDownLatch(1);
        FastFuture xOf = FastFuture.xOf(2, () -> complete = true, f1, f2);
        new Thread(() -> {
            race.countDown();
            f1.set("done");
            f2.set("with");
        }).start();
        try {
            race.await();
        } catch (Exception e) {
            e.printStackTrace();
        }
        while (!complete) {
        }
    }
}
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)

Example 10 with FastFuture

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

the class FastFutureTest method onFail.

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

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