use of org.teiid.dqp.internal.process.FutureWork in project teiid by teiid.
the class TestThreadReuseExecutor method testPriorities.
@Test
public void testPriorities() throws Exception {
// $NON-NLS-1$
pool = new ThreadReuseExecutor("test", 1);
FutureWork<Boolean> work1 = new FutureWork<Boolean>(new Callable<Boolean>() {
public Boolean call() throws Exception {
synchronized (pool) {
while (pool.getSubmittedCount() < 4) {
pool.wait();
}
}
return true;
}
}, 0);
final ConcurrentLinkedQueue<Integer> order = new ConcurrentLinkedQueue<Integer>();
FutureWork<Boolean> work2 = new FutureWork<Boolean>(new Callable<Boolean>() {
public Boolean call() throws Exception {
order.add(2);
return true;
}
}, 2);
FutureWork<Boolean> work3 = new FutureWork<Boolean>(new Callable<Boolean>() {
public Boolean call() throws Exception {
order.add(3);
return false;
}
}, 1);
// ensure a later timestamp
Thread.sleep(20);
FutureWork<Boolean> work4 = new FutureWork<Boolean>(new Callable<Boolean>() {
public Boolean call() throws Exception {
order.add(4);
return false;
}
}, 2);
pool.execute(work1);
pool.execute(work2);
pool.execute(work3);
pool.execute(work4);
synchronized (pool) {
pool.notifyAll();
}
work1.get();
work2.get();
work3.get();
work4.get();
assertEquals(Integer.valueOf(3), order.remove());
assertEquals(Integer.valueOf(2), order.remove());
assertEquals(Integer.valueOf(4), order.remove());
}
Aggregations