You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by il...@apache.org on 2019/03/20 10:27:11 UTC

[ignite] branch master updated: IGNITE-11356 Test framework: Remove custom assumption exceptions handling - Fixes #6288.

This is an automated email from the ASF dual-hosted git repository.

ilyak pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new a63f9bf  IGNITE-11356 Test framework: Remove custom assumption exceptions handling - Fixes #6288.
a63f9bf is described below

commit a63f9bfb16c07e45dd655dc0fa6d6b68b714bd43
Author: ipavlukhin <vo...@gmail.com>
AuthorDate: Wed Mar 20 13:25:22 2019 +0300

    IGNITE-11356 Test framework: Remove custom assumption exceptions handling - Fixes #6288.
    
    Signed-off-by: Ilya Kasnacheev <il...@gmail.com>
---
 .../testframework/junits/GridAbstractTest.java     | 81 +++++++++-------------
 .../junits/GridAbstractTestWithAssumption.java     | 50 -------------
 2 files changed, 33 insertions(+), 98 deletions(-)

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 69d5245..9244fd0 100755
--- 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
@@ -39,12 +39,9 @@ import java.util.UUID;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
 import javax.cache.configuration.Factory;
 import javax.cache.configuration.FactoryBuilder;
 import org.apache.ignite.Ignite;
@@ -177,19 +174,15 @@ public abstract class GridAbstractTest extends JUnit3TestLegacySupport {
     /** */
     protected static final String DEFAULT_CACHE_NAME = "default";
 
-    /** Manages first and last test execution. */
-    @ClassRule public static final TestRule firstLastTestRule = new TestRule() {
-        @Override public Statement apply(Statement base, Description desc) {
-            return ClassRuleWrapper.evaluate(base, desc.getTestClass(), 60);
-        }
-    };
+    /** Sustains {@link #beforeTestsStarted()} and {@link #afterTestsStopped()} methods execution.*/
+    @ClassRule public static final TestRule firstLastTestRule = new BeforeFirstAndAfterLastTestRule();
 
     /** Manages test execution and reporting. */
-    @Rule public transient TestRule runRule = (base, description) -> new Statement() {
+    @Rule public transient TestRule runRule = (base, desc) -> new Statement() {
         @Override public void evaluate() throws Throwable {
             assert getName() != null : "getName returned null";
 
-            GridAbstractTestWithAssumption.handleAssumption(() -> runTestCase(base), log());
+            runTestCase(base);
         }
     };
 
@@ -262,30 +255,6 @@ public abstract class GridAbstractTest extends JUnit3TestLegacySupport {
         GridAbstractTest.startGrid = startGrid;
     }
 
-    /** */
-    private void clsRule(Statement base) throws Throwable {
-        GridAbstractTestWithAssumption src = () ->
-        {
-            try {
-                setSystemPropertiesBeforeClass();
-
-                try {
-                    beforeFirstTest();
-
-                    base.evaluate();
-                }
-                finally {
-                    afterLastTest();
-                }
-            }
-            finally {
-                clearSystemPropertiesAfterClass();
-            }
-        };
-
-        GridAbstractTestWithAssumption.handleAssumption(src, log());
-    }
-
     /**
      * @param cls Class to create.
      * @return Instance of class.
@@ -2575,30 +2544,46 @@ public abstract class GridAbstractTest extends JUnit3TestLegacySupport {
     }
 
     /**
-     *  Runs test classes sequentionally, in order to prevent corruption of static members of {@link GridAbstractTest}.
+     *  Calls {@link #beforeFirstTest()} and {@link #afterLastTest()} methods
+     *  in order to support {@link #beforeTestsStarted()} and {@link #afterTestsStopped()}.
+     *  <p>
+     *  Processes {@link WithSystemProperty} annotations as well.
      */
-    private static class ClassRuleWrapper {
-        /** */
-        private static final Lock runSerializer = new ReentrantLock();
-
-        /** */
-        static Statement evaluate(Statement base, Class<?> cls, long timeoutMnutes) {
+    private static class BeforeFirstAndAfterLastTestRule implements TestRule {
+        /** {@inheritDoc} */
+        @Override public Statement apply(Statement base, Description desc) {
             return new Statement() {
                 @Override public void evaluate() throws Throwable {
-                    apply(base, cls, timeoutMnutes);
+                    GridAbstractTest fixtureInstance = (GridAbstractTest)desc.getTestClass().newInstance();
+
+                    fixtureInstance.evaluateInsideFixture(base);
                 }
             };
         }
+    }
+
+    /**
+     * Executes a statement inside a fixture calling GridAbstractTest specific methods which
+     * should be executed before and after a test class execution.
+     *
+     * @param stmt Statement to execute.
+     * @throws Throwable In case of failure.
+     */
+    private void evaluateInsideFixture(Statement stmt) throws Throwable {
+        try {
+            setSystemPropertiesBeforeClass();
 
-        /** */
-        private static void apply(Statement base, Class<?> cls, long timeoutMnutes) throws Throwable {
             try {
-                runSerializer.tryLock(timeoutMnutes, TimeUnit.MINUTES);
-                ((GridAbstractTest)cls.newInstance()).clsRule(base);
+                beforeFirstTest();
+
+                stmt.evaluate();
             }
             finally {
-                runSerializer.unlock();
+                afterLastTest();
             }
         }
+        finally {
+            clearSystemPropertiesAfterClass();
+        }
     }
 }
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTestWithAssumption.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTestWithAssumption.java
deleted file mode 100644
index cd63258..0000000
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTestWithAssumption.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.testframework.junits;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.function.BiConsumer;
-import org.apache.ignite.IgniteLogger;
-import org.junit.internal.AssumptionViolatedException;
-
-/** */
-@FunctionalInterface
-interface GridAbstractTestWithAssumption {
-    /** */
-    public void evaluateInvocation() throws Throwable;
-
-    /** */
-    public static void handleAssumption(GridAbstractTestWithAssumption src, IgniteLogger log) throws Throwable {
-        BiConsumer<Throwable, IgniteLogger> report
-            = (t, logger) -> logger.warning("Test skipped by assumption: " + t.getMessage(), t);
-
-        try {
-            src.evaluateInvocation();
-        } catch (AssumptionViolatedException e) {
-            report.accept(e, log);
-        } catch (InvocationTargetException e) {
-            Throwable actual = e.getTargetException();
-            if (actual instanceof AssumptionViolatedException) {
-                report.accept(e, log);
-
-                return;
-            }
-            throw e;
-        }
-    }
-}