Search in sources :

Example 16 with FastFuture

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

the class BatchingCollectorTest method testAcceptMock495.

@Test
public void testAcceptMock495() {
    collector = new BatchingCollector(new MaxActive(500, 5), 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 17 with FastFuture

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

the class BatchingCollectorTest method testBatchingCollectorMaxActive.

@Test
public void testBatchingCollectorMaxActive() {
    collector = new BatchingCollector(new MaxActive(10, 5), LazyReact.sequentialBuilder().of(1)).withResults(new HashSet<>());
    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(990)).isDone();
}
Also used : FastFuture(com.oath.cyclops.internal.react.async.future.FastFuture) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with FastFuture

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

the class EmptyCollectorTest method testAcceptMock50.

@Test
public void testAcceptMock50() {
    collector = new EmptyCollector<>(new MaxActive(500, 450), cf -> cf.join());
    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 : FastFuture(com.oath.cyclops.internal.react.async.future.FastFuture) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) EmptyCollector(com.oath.cyclops.react.collectors.lazy.EmptyCollector) Mockito.verify(org.mockito.Mockito.verify) Assert.assertThat(org.junit.Assert.assertThat) BDDMockito(org.mockito.BDDMockito) Mockito(org.mockito.Mockito) BDDMockito.given(org.mockito.BDDMockito.given) Matchers.is(org.hamcrest.Matchers.is) Mockito.mock(org.mockito.Mockito.mock) Before(org.junit.Before) FastFuture(com.oath.cyclops.internal.react.async.future.FastFuture) Test(org.junit.Test)

Example 19 with FastFuture

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

the class EmptyCollectorTest 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 20 with FastFuture

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

the class Runner method runContinuations.

public Continuation runContinuations(final LazyStreamWrapper lastActive, final EmptyCollector collector, boolean blocking) {
    final Iterator<FastFuture> it = lastActive.injectFutures().iterator();
    final Continuation[] cont = new Continuation[1];
    final Continuation finish = new Continuation(() -> {
        collector.afterResults(() -> {
            runnable.run();
            throw new ClosedQueueException();
        });
        return Continuation.empty();
    });
    final Continuation blockingFinish = new Continuation(() -> {
        collector.getResults();
        runnable.run();
        throw new ClosedQueueException();
    });
    final Continuation finishNoCollect = new Continuation(() -> {
        runnable.run();
        throw new ClosedQueueException();
    });
    cont[0] = new Continuation(() -> {
        try {
            if (it.hasNext()) {
                final FastFuture f = it.next();
                // if FastFuture has been filtered out, we need to move to the next one instead
                handleFilter(cont, f);
                collector.accept(f);
            }
            if (it.hasNext())
                return cont[0];
            else {
                return blocking ? blockingFinish.proceed() : finish.proceed();
            }
        } catch (final SimpleReactProcessingException e) {
        } catch (final java.util.concurrent.CompletionException e) {
        } catch (final Throwable e) {
            collector.getSafeJoin().apply(FastFuture.failedFuture(e));
        }
        return finishNoCollect;
    });
    return cont[0];
}
Also used : Continuation(com.oath.cyclops.types.futurestream.Continuation) FastFuture(com.oath.cyclops.internal.react.async.future.FastFuture) SimpleReactProcessingException(com.oath.cyclops.internal.react.exceptions.SimpleReactProcessingException) ClosedQueueException(com.oath.cyclops.async.adapters.Queue.ClosedQueueException)

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