use of org.infinispan.commons.test.ExceptionRunnable in project infinispan by infinispan.
the class JdbcStringBasedStoreTxFunctionalTest method testWithPassivation.
public void testWithPassivation(Method m) throws Exception {
ConfigurationBuilder base = getDefaultCacheConfiguration();
base.persistence().passivation(true);
ExceptionRunnable runnable = () -> TestingUtil.defineConfiguration(cacheManager, m.getName(), configureCacheLoader(base, m.getName(), false).build());
// transactional and shared don't mix with passivation
if (transactionalConfig || sharedConfig) {
Exceptions.expectException(CacheConfigurationException.class, runnable);
} else {
runnable.run();
}
}
use of org.infinispan.commons.test.ExceptionRunnable in project infinispan by infinispan.
the class AbstractInfinispanTest method getTestThreadFactory.
/**
* This should normally not be used, use the {@code fork(Runnable|Callable|ExceptionRunnable)}
* method when an executor is required.
*
* Although if you want a limited set of threads this could still be useful for something like
* {@link java.util.concurrent.Executors#newFixedThreadPool(int, java.util.concurrent.ThreadFactory)} or
* {@link java.util.concurrent.Executors#newSingleThreadExecutor(java.util.concurrent.ThreadFactory)}
*
* @param prefix The prefix starting for the thread factory
* @return A thread factory that will use the same naming schema as the other methods
*/
protected ThreadFactory getTestThreadFactory(final String prefix) {
final String className = getClass().getSimpleName();
return new ThreadFactory() {
private final AtomicInteger counter = new AtomicInteger(0);
@Override
public Thread newThread(Runnable r) {
String threadName = prefix + "-" + counter.incrementAndGet() + "," + className;
Thread thread = new Thread(r, threadName);
TestResourceTracker.addResource(AbstractInfinispanTest.this.getTestName(), new ThreadCleaner(thread));
return thread;
}
};
}
use of org.infinispan.commons.test.ExceptionRunnable in project infinispan by infinispan.
the class AbstractInfinispanTest method runConcurrently.
/**
* This will run two or more tasks concurrently.
*
* It synchronizes before starting at approximately the same time by ensuring they all start before
* allowing the tasks to proceed.
*
* @param tasks The tasks to run
* @throws InterruptedException Thrown if this thread is interrupted
* @throws ExecutionException Thrown if one of the callables throws any kind of Throwable. The
* thrown Throwable will be wrapped by this exception
* @throws TimeoutException If one of the tasks doesn't complete within the timeout
*/
protected void runConcurrently(long timeout, TimeUnit timeUnit, ExceptionRunnable... tasks) throws Exception {
if (tasks == null || tasks.length < 2) {
throw new IllegalArgumentException("Need at least 2 tasks to run concurrently");
}
long deadlineNanos = System.nanoTime() + TimeUnit.NANOSECONDS.convert(timeout, timeUnit);
List<Future<Void>> futures = new ArrayList<>(tasks.length);
CyclicBarrier barrier = new CyclicBarrier(tasks.length);
for (ExceptionRunnable task : tasks) {
futures.add(testExecutor.submit(new ConcurrentCallable(task, barrier)));
}
List<Exception> exceptions = new ArrayList<>();
for (Future<Void> future : futures) {
try {
future.get(deadlineNanos - System.nanoTime(), TimeUnit.NANOSECONDS);
} catch (Exception e) {
futures.forEach(f -> f.cancel(true));
exceptions.add(e);
}
}
if (!exceptions.isEmpty()) {
Exception exception = exceptions.remove(0);
for (Exception e : exceptions) {
exception.addSuppressed(e);
}
throw exception;
}
}
use of org.infinispan.commons.test.ExceptionRunnable in project infinispan by infinispan.
the class JdbcStringBasedStoreTxFunctionalTest method testWithPurgeOnStartup.
public void testWithPurgeOnStartup(Method m) throws Exception {
ConfigurationBuilder base = getDefaultCacheConfiguration();
ExceptionRunnable runnable = () -> TestingUtil.defineConfiguration(cacheManager, m.getName(), configureCacheLoader(base, m.getName(), true).build());
// shared doesn't mix with purgeOnStartup
if (sharedConfig) {
Exceptions.expectException(CacheConfigurationException.class, runnable);
} else {
runnable.run();
}
}
Aggregations