use of org.apache.ignite.internal.util.lang.IgniteThrowableFunction in project ignite by apache.
the class IgniteUtilsSelfTest method runTask.
/**
* @param executorService Executor service.
*/
private void runTask(ExecutorService executorService) {
List<Integer> data = asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
long threadId = Thread.currentThread().getId();
AtomicInteger curThreadCnt = new AtomicInteger();
Collection<Integer> res;
// Future for avoiding fast execution in only executor threads.
// Here we try to pass a number of tasks more that executor size,
// but there is a case when all task will be completed after last submit return control and
// current thread can not steal task because all task will be already finished.
GridFutureAdapter fut = new GridFutureAdapter();
try {
res = U.doInParallel(10, executorService, data, new IgniteThrowableFunction<Integer, Integer>() {
@Override
public Integer apply(Integer cnt) {
if (Thread.currentThread().getId() == threadId) {
fut.onDone();
curThreadCnt.incrementAndGet();
} else {
try {
fut.get();
} catch (IgniteCheckedException e) {
throw U.convertException(e);
}
}
return -cnt;
}
});
} catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
Assert.assertTrue(curThreadCnt.get() > 0);
Assert.assertEquals(asList(0, -1, -2, -3, -4, -5, -6, -7, -8, -9), res);
}
Aggregations