ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [12/34] ignite git commit: Fixed incorrect test count calculation leading to afterTestsStopped() not being called.
Date Mon, 10 Oct 2016 16:00:39 GMT
Fixed incorrect test count calculation leading to afterTestsStopped() not being called.


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

Branch: refs/heads/ignite-comm-opts2
Commit: 78144c4c9d6200ceef8b666a186039685f053381
Parents: 33d3494
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Wed Sep 28 16:52:13 2016 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Wed Sep 28 16:52:13 2016 +0300

----------------------------------------------------------------------
 .../ignite/testframework/IgniteTestSuite.java   | 79 +++++++++++++++++---
 .../testframework/junits/GridAbstractTest.java  | 31 +++++++-
 2 files changed, 94 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/78144c4c/modules/core/src/test/java/org/apache/ignite/testframework/IgniteTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/IgniteTestSuite.java
b/modules/core/src/test/java/org/apache/ignite/testframework/IgniteTestSuite.java
index 7db9664..1cf69ae 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/IgniteTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/IgniteTestSuite.java
@@ -29,6 +29,7 @@ import org.junit.internal.MethodSorter;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
+import java.util.LinkedList;
 import java.util.List;
 
 /**
@@ -134,7 +135,9 @@ public class IgniteTestSuite extends TestSuite {
             Class superCls = theClass;
 
             int testAdded = 0;
-            int testIgnored = 0;
+            int testSkipped = 0;
+
+            LinkedList<Test> addedTests = new LinkedList<>();
 
             for(List<String> names = new ArrayList<>(); Test.class.isAssignableFrom(superCls);
                 superCls = superCls.getSuperclass()) {
@@ -142,15 +145,29 @@ public class IgniteTestSuite extends TestSuite {
                 Method[] methods = MethodSorter.getDeclaredMethods(superCls);
 
                 for (Method each : methods) {
-                    if (addTestMethod(each, names, theClass, clsIgnore))
+                    AddResult res = addTestMethod(each, names, theClass, clsIgnore);
+
+                    if (res.added()) {
                         testAdded++;
+
+                        addedTests.add(res.test());
+                    }
                     else
-                        testIgnored++;
+                        testSkipped++;
                 }
             }
 
-            if(testAdded == 0 && testIgnored == 0)
+            if(testAdded == 0 && testSkipped == 0)
                 addTest(warning("No tests found in " + theClass.getName()));
+
+            // Populate tests count.
+            for (Test test : addedTests) {
+                if (test instanceof GridAbstractTest) {
+                    GridAbstractTest test0 = (GridAbstractTest)test;
+
+                    test0.forceTestCount(addedTests.size());
+                }
+            }
         }
     }
 
@@ -161,20 +178,20 @@ public class IgniteTestSuite extends TestSuite {
      * @param names Test name list.
      * @param theClass Test class.
      * @param clsIgnore Class ignore descriptor (if any).
-     * @return Whether test method was added.
+     * @return Result.
      */
-    private boolean addTestMethod(Method m, List<String> names, Class<?> theClass,
+    private AddResult addTestMethod(Method m, List<String> names, Class<?> theClass,
         @Nullable IgnoreDescriptor clsIgnore) {
         String name = m.getName();
 
         if (names.contains(name))
-            return false;
+            return new AddResult(false, null);
 
         if (!isPublicTestMethod(m)) {
             if (isTestMethod(m))
                 addTest(warning("Test method isn't public: " + m.getName() + "(" + theClass.getCanonicalName()
+ ")"));
 
-            return false;
+            return new AddResult(false, null);
         }
 
         names.add(name);
@@ -197,18 +214,20 @@ public class IgniteTestSuite extends TestSuite {
 
                 addTest(test);
 
-                return true;
+                return new AddResult(true, test);
             }
         }
         else {
             if (ignore == null) {
-                addTest(createTest(theClass, name));
+                Test test = createTest(theClass, name);
+
+                addTest(test);
 
-                return true;
+                return new AddResult(true, test);
             }
         }
 
-        return false;
+        return new AddResult(false, null);
     }
 
     /**
@@ -337,6 +356,42 @@ public class IgniteTestSuite extends TestSuite {
     }
 
     /**
+     * Test add result.
+     */
+    private static class AddResult {
+        /** Result. */
+        private final boolean added;
+
+        /** Test */
+        private final Test test;
+
+        /**
+         * Constructor.
+         *
+         * @param added Result.
+         * @param test Test.
+         */
+        public AddResult(boolean added, Test test) {
+            this.added = added;
+            this.test = test;
+        }
+
+        /**
+         * @return Result.
+         */
+        public boolean added() {
+            return added;
+        }
+
+        /**
+         * @return Test.
+         */
+        public Test test() {
+            return test;
+        }
+    }
+
+    /**
      * Test case simulating failure.
      */
     private static class ForcedFailure extends TestCase {

http://git-wip-us.apache.org/repos/asf/ignite/blob/78144c4c/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
index 8d6fd07..aa90af0 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
@@ -161,6 +161,12 @@ public abstract class GridAbstractTest extends TestCase {
     /** Force failure message. */
     private String forceFailureMsg;
 
+    /** Whether test count is known is advance. */
+    private boolean forceTestCnt;
+
+    /** Number of tests. */
+    private int testCnt;
+
     /**
      *
      */
@@ -1770,6 +1776,15 @@ public abstract class GridAbstractTest extends TestCase {
     }
 
     /**
+     * Set test count.
+     */
+    public void forceTestCount(int cnt) {
+        testCnt = cnt;
+
+        forceTestCnt = true;
+    }
+
+    /**
      * @throws Throwable If failed.
      */
     @SuppressWarnings({"ProhibitedExceptionDeclared"})
@@ -2076,11 +2091,19 @@ public abstract class GridAbstractTest extends TestCase {
          */
         public int getNumberOfTests() {
             if (numOfTests == -1) {
-                int cnt = 0;
+                GridAbstractTest this0 = GridAbstractTest.this;
+
+                int cnt;
 
-                for (Method m : GridAbstractTest.this.getClass().getMethods())
-                    if (m.getName().startsWith("test") && Modifier.isPublic(m.getModifiers()))
-                        cnt++;
+                if (this0.forceTestCnt)
+                    cnt = this0.testCnt;
+                else {
+                    cnt = 0;
+
+                    for (Method m : this0.getClass().getMethods())
+                        if (m.getName().startsWith("test") && Modifier.isPublic(m.getModifiers()))
+                            cnt++;
+                }
 
                 numOfTests = cnt;
             }


Mime
View raw message