ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject ignite git commit: ignite-2757 Test fixed
Date Fri, 04 Mar 2016 13:12:33 GMT
Repository: ignite
Updated Branches:
  refs/heads/master e82660db5 -> acc5ffab1


ignite-2757 Test fixed


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/acc5ffab
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/acc5ffab
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/acc5ffab

Branch: refs/heads/master
Commit: acc5ffab154bff1800d59b93007e58faa7080909
Parents: e82660d
Author: agura <agura@gridgain.com>
Authored: Thu Mar 3 20:54:18 2016 +0300
Committer: agura <agura@gridgain.com>
Committed: Fri Mar 4 16:11:35 2016 +0300

----------------------------------------------------------------------
 .../GridTaskCancelSingleNodeSelfTest.java       | 37 ++++++++++++++------
 1 file changed, 27 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/acc5ffab/modules/core/src/test/java/org/apache/ignite/internal/GridTaskCancelSingleNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridTaskCancelSingleNodeSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/GridTaskCancelSingleNodeSelfTest.java
index 7af987c..0557e04 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridTaskCancelSingleNodeSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/GridTaskCancelSingleNodeSelfTest.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal;
 
 import java.util.Collection;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCompute;
@@ -42,6 +43,7 @@ import org.jetbrains.annotations.Nullable;
 import static org.apache.ignite.events.EventType.EVT_JOB_CANCELLED;
 import static org.apache.ignite.events.EventType.EVT_JOB_FINISHED;
 import static org.apache.ignite.events.EventType.EVT_JOB_REJECTED;
+import static org.apache.ignite.events.EventType.EVT_JOB_STARTED;
 
 /**
  * Test for task cancellation issue.
@@ -81,11 +83,18 @@ public class GridTaskCancelSingleNodeSelfTest extends GridCommonAbstractTest
{
         final AtomicInteger cancelled = new AtomicInteger();
         final AtomicInteger rejected = new AtomicInteger();
 
+        final AtomicBoolean jobStarted = new AtomicBoolean();
+
         grid().events().localListen(new IgnitePredicate<Event>() {
             @Override public boolean apply(Event evt) {
                 info("Received event: " + evt);
 
                 switch (evt.type()) {
+                    case EVT_JOB_STARTED:
+                        jobStarted.set(true);
+
+                        break;
+
                     case EVT_JOB_FINISHED:
                         finished.incrementAndGet();
 
@@ -107,7 +116,7 @@ public class GridTaskCancelSingleNodeSelfTest extends GridCommonAbstractTest
{
 
                 return true;
             }
-        }, EVT_JOB_FINISHED, EVT_JOB_CANCELLED, EVT_JOB_REJECTED);
+        }, EVT_JOB_STARTED, EVT_JOB_FINISHED, EVT_JOB_CANCELLED, EVT_JOB_REJECTED);
 
         IgniteCompute comp = grid().compute().withAsync();
 
@@ -122,14 +131,22 @@ public class GridTaskCancelSingleNodeSelfTest extends GridCommonAbstractTest
{
 
         for (int i = 0; i < 3; i++) {
             try {
-            if (timeoutBeforeCancel == 0L)
-                assert (finished.get() == 0 && cancelled.get() == 0 && rejected.get()
== 0) :
-                    "Failed on iteration [i=" + i + ", finished=" + finished.get() +
-                    ", cancelled=" + cancelled.get() + ", rejected=" + rejected.get() + ']';
-            else
-                assert (finished.get() == 1 && cancelled.get() == 1 && rejected.get()
== 0) :
-                    "Failed on iteration [i=" + i + ", finished=" + finished.get() +
-                        ", cancelled=" + cancelled.get() + ", rejected=" + rejected.get()
+ ']';
+                if (timeoutBeforeCancel == 0L) {
+                    if (jobStarted.get())
+                        assertTrue("Failed on iteration [i=" + i + ", finished=" + finished.get()
+
+                            ", cancelled=" + cancelled.get() + ", rejected=" + rejected.get()
+ ']',
+                            finished.get() == 1 && cancelled.get() == 1 &&
rejected.get() == 0);
+                    else {
+                        // job can be rejected if was concurrently cancelled before started
+                        assertTrue("Failed on iteration [i=" + i + ", finished=" + finished.get()
+
+                                ", cancelled=" + cancelled.get() + ", rejected=" + rejected.get()
+ ']',
+                            finished.get() == 0 && cancelled.get() == 0 &&
rejected.get() <= 1);
+                    }
+                }
+                else
+                    assertTrue("Failed on iteration [i=" + i + ", finished=" + finished.get()
+
+                        ", cancelled=" + cancelled.get() + ", rejected=" + rejected.get()
+ ']',
+                        finished.get() == 1 && cancelled.get() == 1 && rejected.get()
== 0);
             }
             catch (AssertionError e) {
                 info("Check failed: " + e.getMessage());
@@ -145,7 +162,7 @@ public class GridTaskCancelSingleNodeSelfTest extends GridCommonAbstractTest
{
         try {
             fut.get();
 
-            assert false;
+            fail();
         }
         catch (IgniteFutureCancelledException e) {
             info("Caught expected exception: " + e);


Mime
View raw message