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();
}
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();
}
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();
}
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();
}
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];
}
Aggregations