use of org.apache.felix.dm.impl.SerialExecutor in project felix by apache.
the class SerialExecutorTest method testSerialExecutor.
@Test
public void testSerialExecutor() {
info("Testing serial executor");
int cores = Math.max(10, Runtime.getRuntime().availableProcessors());
ExecutorService threadPool = null;
try {
threadPool = Executors.newFixedThreadPool(cores);
final SerialExecutor serial = new SerialExecutor(new Logger(null));
long timeStamp = System.currentTimeMillis();
for (int i = 0; i < TESTS; i++) {
final CountDownLatch latch = new CountDownLatch(cores * 2);
final SerialTask task = new SerialTask(serial, latch);
for (int j = 0; j < cores; j++) {
threadPool.execute(new Runnable() {
public void run() {
serial.execute(task);
}
});
}
Assert.assertTrue("Test " + i + " did not terminate timely", latch.await(20000, TimeUnit.MILLISECONDS));
}
long now = System.currentTimeMillis();
System.out.println("Performed " + TESTS + " tests in " + (now - timeStamp) + " ms.");
timeStamp = now;
} catch (Throwable t) {
t.printStackTrace();
Assert.fail("Test failed: " + t.getMessage());
} finally {
if (threadPool != null) {
shutdown(threadPool);
}
}
}
Aggregations