ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [1/2] ignite git commit: Usability and safety improvements.
Date Wed, 14 Sep 2016 12:47:20 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-3661 71fbcad8a -> 36c817038


Usability and safety improvements.


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

Branch: refs/heads/ignite-3661
Commit: bca08147e22f39ccceda8199c4b66d11d7d648e6
Parents: 71fbcad
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Wed Sep 14 15:44:22 2016 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Wed Sep 14 15:44:22 2016 +0300

----------------------------------------------------------------------
 .../ignite/testframework/IgniteTestSuite.java   | 63 +++++++++++++++++++-
 .../testframework/junits/GridAbstractTest.java  | 22 ++++++-
 .../apache/ignite/testsuites/IgniteIgnore.java  |  9 ++-
 .../internal/websession/WebSessionSelfTest.java |  2 +-
 .../WebSessionTransactionalSelfTest.java        | 12 ++--
 5 files changed, 95 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/bca08147/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 e2802aa..73610c2 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
@@ -20,6 +20,8 @@ package org.apache.ignite.testframework;
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.testframework.junits.GridAbstractTest;
 import org.apache.ignite.testsuites.IgniteIgnore;
 import org.jetbrains.annotations.Nullable;
 import org.junit.internal.MethodSorter;
@@ -123,6 +125,7 @@ public class IgniteTestSuite extends TestSuite {
 
             for(List<String> names = new ArrayList<>(); Test.class.isAssignableFrom(superCls);
                 superCls = superCls.getSuperclass()) {
+
                 Method[] methods = MethodSorter.getDeclaredMethods(superCls);
 
                 for (Method each : methods) {
@@ -159,10 +162,38 @@ public class IgniteTestSuite extends TestSuite {
 
         names.add(name);
 
-        if (m.isAnnotationPresent(IgniteIgnore.class) == ignoredOnly) {
-            addTest(createTest(theClass, name));
+        boolean hasIgnore = m.isAnnotationPresent(IgniteIgnore.class);
+
+        if (ignoredOnly) {
+            if (hasIgnore) {
+                IgniteIgnore ignore = m.getAnnotation(IgniteIgnore.class);
+
+                String ticket = ignore.jira();
+
+                if (F.isEmpty(ticket))
+                    throw new IllegalArgumentException("JIRA ticket is not set for ignored
test [class=" +
+                        theClass.getName() + ", method=" + name + ']');
+
+                Test test = createTest(theClass, name);
+
+                if (ignore.forceFailure()) {
+                    if (test instanceof GridAbstractTest)
+                        ((GridAbstractTest)test).forceFailure(ignore.jira());
+                    else
+                        test = new ForcedFailure(name, ignore.jira());
+                }
+
+                addTest(test);
+
+                return true;
+            }
+        }
+        else {
+            if (!hasIgnore) {
+                addTest(createTest(theClass, name));
 
-            return true;
+                return true;
+            }
         }
 
         return false;
@@ -189,4 +220,30 @@ public class IgniteTestSuite extends TestSuite {
     private static boolean isPublicTestMethod(Method m) {
         return isTestMethod(m) && Modifier.isPublic(m.getModifiers());
     }
+
+    /**
+     * Test case simulating failure.
+     */
+    private static class ForcedFailure extends TestCase {
+        /** Message. */
+        private final String msg;
+
+        /**
+         * Constructor.
+         *
+         * @param name Name.
+         * @param msg  Message.
+         */
+        private ForcedFailure(String name, String msg) {
+            super(name);
+
+            this.msg = msg;
+        }
+
+        /** {@inheritDoc} */
+        @Override protected void runTest() {
+            fail("Forced failure: " + msg + " (extend " + GridAbstractTest.class.getSimpleName()
+
+                " for better output).");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/bca08147/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 3910ce4..8d6fd07 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
@@ -155,6 +155,12 @@ public abstract class GridAbstractTest extends TestCase {
     /** Starting grid name. */
     protected static final ThreadLocal<String> startingGrid = new ThreadLocal<>();
 
+    /** Force failure flag. */
+    private boolean forceFailure;
+
+    /** Force failure message. */
+    private String forceFailureMsg;
+
     /**
      *
      */
@@ -1753,11 +1759,25 @@ public abstract class GridAbstractTest extends TestCase {
     }
 
     /**
+     * Force test failure.
+     *
+     * @param msg Message.
+     */
+    public void forceFailure(@Nullable String msg) {
+        forceFailure = true;
+
+        forceFailureMsg = msg;
+    }
+
+    /**
      * @throws Throwable If failed.
      */
     @SuppressWarnings({"ProhibitedExceptionDeclared"})
     private void runTestInternal() throws Throwable {
-        super.runTest();
+        if (forceFailure)
+            fail("Forced failure: " + forceFailureMsg);
+        else
+            super.runTest();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/bca08147/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteIgnore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteIgnore.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteIgnore.java
index ac9a885..b98202e 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteIgnore.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteIgnore.java
@@ -29,7 +29,12 @@ import java.lang.annotation.Target;
 @Target({ElementType.METHOD, ElementType.TYPE})
 public @interface IgniteIgnore {
     /**
-     * The optional reason why the test is ignored.
+     * JIRA ticket URL for this failure.
      */
-    String value() default "";
+    String jira();
+
+    /**
+     * Whether tests should be failed immediately. Useful when test hangs or consumes a lot
of time.
+     */
+    boolean forceFailure() default false;
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/bca08147/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionSelfTest.java
b/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionSelfTest.java
index 5138e3a..1c3d23c 100644
--- a/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionSelfTest.java
+++ b/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionSelfTest.java
@@ -89,7 +89,7 @@ public class WebSessionSelfTest extends GridCommonAbstractTest {
     /**
      * @throws Exception If failed.
      */
-    @IgniteIgnore("https://issues.apache.org/jira/browse/IGNITE-3663")
+    @IgniteIgnore(jira = "https://issues.apache.org/jira/browse/IGNITE-3663")
     public void testSessionRenewalDuringLogin() throws Exception {
         testSessionRenewalDuringLogin("/modules/core/src/test/config/websession/example-cache.xml");
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/bca08147/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionTransactionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionTransactionalSelfTest.java
b/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionTransactionalSelfTest.java
index 7a9179b..80fa445 100644
--- a/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionTransactionalSelfTest.java
+++ b/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionTransactionalSelfTest.java
@@ -29,20 +29,20 @@ public class WebSessionTransactionalSelfTest extends WebSessionSelfTest
{
     }
 
     /** {@inheritDoc} */
-    @IgniteIgnore("https://issues.apache.org/jira/browse/IGNITE-810")
+    @IgniteIgnore(jira = "https://issues.apache.org/jira/browse/IGNITE-810", forceFailure
= true)
     @Override public void testRestarts() throws Exception {
-        fail("https://issues.apache.org/jira/browse/IGNITE-810");
+        // No-op.
     }
 
     /** {@inheritDoc} */
-    @IgniteIgnore("https://issues.apache.org/jira/browse/IGNITE-810")
+    @IgniteIgnore(jira = "https://issues.apache.org/jira/browse/IGNITE-810", forceFailure
= true)
     @Override public void testInvalidatedSession() throws Exception {
-        fail("https://issues.apache.org/jira/browse/IGNITE-810");
+        // No-op.
     }
 
     /** {@inheritDoc} */
-    @IgniteIgnore("https://issues.apache.org/jira/browse/IGNITE-810")
+    @IgniteIgnore(jira = "https://issues.apache.org/jira/browse/IGNITE-810", forceFailure
= true)
     @Override public void testClientReconnectRequest() throws Exception {
-        fail("https://issues.apache.org/jira/browse/IGNITE-810");
+        // No-op.
     }
 }


Mime
View raw message