IGNITE-10907 Fix IgniteUtilsSelfTest.testDoInParallelWithStealingJobRunTaskInExecutor...
authorDmitriy Govorukhin <dmitriy.govorukhin@gmail.com>
Tue, 25 Dec 2018 11:01:50 +0000 (14:01 +0300)
committerDmitriy Govorukhin <dmitriy.govorukhin@gmail.com>
Fri, 11 Jan 2019 20:47:10 +0000 (23:47 +0300)
modules/core/src/test/java/org/apache/ignite/internal/util/IgniteUtilsSelfTest.java

index 93b7586..757e40a 100644 (file)
@@ -62,6 +62,7 @@ import org.apache.ignite.compute.ComputeJob;
 import org.apache.ignite.compute.ComputeJobAdapter;
 import org.apache.ignite.internal.IgniteInterruptedCheckedException;
 import org.apache.ignite.internal.processors.igfs.IgfsUtils;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
 import org.apache.ignite.internal.util.lang.GridPeerDeployAware;
 import org.apache.ignite.internal.util.lang.IgniteThrowableConsumer;
 import org.apache.ignite.internal.util.typedef.F;
@@ -1095,14 +1096,31 @@ public class IgniteUtilsSelfTest extends GridCommonAbstractTest {
 
         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 IgniteThrowableConsumer<Integer, Integer>() {
                     @Override public Integer accept(Integer cnt) {
-                        if (Thread.currentThread().getId() == threadId)
+                        if (Thread.currentThread().getId() == threadId) {
+                            fut.onDone();
+
                             curThreadCnt.incrementAndGet();
+                        }
+                        else {
+                            try {
+                                fut.get();
+                            }
+                            catch (IgniteCheckedException e) {
+                                throw U.convertException(e);
+                            }
+                        }
 
                         return -cnt;
                     }