use of org.infinispan.util.function.SerializableFunction in project infinispan by infinispan.
the class AllClusterExecutorTest method testExecutorTriConsumerTimeoutException.
public void testExecutorTriConsumerTimeoutException() {
withCacheManagers(new MultiCacheManagerCallable(TestCacheManagerFactory.createCacheManager(CacheMode.DIST_SYNC, false), TestCacheManagerFactory.createCacheManager(CacheMode.DIST_SYNC, false)) {
@Override
public void call() throws InterruptedException, ExecutionException, TimeoutException {
EmbeddedCacheManager cm1 = cms[0];
TestClassLocal<CheckPoint> checkPoint = AllClusterExecutorTest.this.checkPoint;
SerializableFunction<EmbeddedCacheManager, Object> blockingFunction = m -> {
try {
checkPoint.get().trigger("block_execution");
checkPoint.get().awaitStrict("resume_execution", 10, TimeUnit.SECONDS);
checkPoint.get().trigger("complete");
} catch (InterruptedException | TimeoutException e) {
throw new TestException(e);
}
return null;
};
CompletableFuture<Void> futureRemote = executor(cm1).filterTargets(a -> !a.equals(cm1.getAddress())).timeout(1, TimeUnit.MILLISECONDS).submitConsumer(blockingFunction, (a, i, t) -> {
log.tracef("Consumer invoked with %s, %s, %s", a, i, t);
});
Exceptions.expectExecutionException(org.infinispan.util.concurrent.TimeoutException.class, futureRemote);
checkPoint.get().awaitStrict("block_execution", 10, TimeUnit.SECONDS);
checkPoint.get().trigger("resume_execution");
// Have to wait for callback to complete - otherwise a different thread could find the "resume_execution"
// checkpoint reached incorrectly
checkPoint.get().awaitStrict("complete", 10, TimeUnit.SECONDS);
CompletableFuture<Void> futureLocal = executor(cm1).filterTargets(a -> a.equals(cm1.getAddress())).timeout(1, TimeUnit.MILLISECONDS).submitConsumer(blockingFunction, (a, i, t) -> {
log.tracef("Consumer invoked with %s, %s, %s", a, i, t);
});
Exceptions.expectExecutionException(org.infinispan.util.concurrent.TimeoutException.class, futureLocal);
checkPoint.get().awaitStrict("block_execution", 10, TimeUnit.SECONDS);
checkPoint.get().trigger("resume_execution");
checkPoint.get().awaitStrict("complete", 10, TimeUnit.SECONDS);
}
});
}
use of org.infinispan.util.function.SerializableFunction in project infinispan by infinispan.
the class BaseClusteredExtendedStatisticTest method testComputeIfAbsent.
public void testComputeIfAbsent(Method method) throws InterruptedException {
final String key1 = k(method, 1);
final String key2 = k(method, 2);
assertEmpty(key1);
assertEmpty(key2);
put(1, key1, VALUE_1);
assertCacheValue(key1, VALUE_1);
SerializableFunction computeFunction = v -> VALUE_3 + v;
// failed operation is not added to the transaction
cache(0).computeIfAbsent(key1, computeFunction);
assertCacheValue(key1, VALUE_1);
SerializableFunction computeFunction2 = v -> VALUE_2;
computeIfAbsent(1, key2, computeFunction2);
assertCacheValue(key2, VALUE_2);
assertNoTransactions();
assertNoTxStats();
}
Aggregations