You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ip...@apache.org on 2019/04/23 12:58:12 UTC

[ignite] branch master updated: IGNITE-11412 Actualize JUnit3TestLegacySupport class - Fixes #6267 - Fixes #6267.

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

ipavlukhin 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 5dacccb  IGNITE-11412 Actualize JUnit3TestLegacySupport class - Fixes #6267 - Fixes #6267.
5dacccb is described below

commit 5dacccb6fd1cff821c69f1ba00cd9951c7f29f64
Author: Fedotov <va...@gmail.com>
AuthorDate: Tue Apr 23 15:57:26 2019 +0300

    IGNITE-11412 Actualize JUnit3TestLegacySupport class - Fixes #6267 - Fixes #6267.
    
    Signed-off-by: ipavlukhin <vo...@gmail.com>
---
 .../testframework/junits/GridAbstractTest.java     | 145 ++++++++++++++++-----
 .../junits/IgniteConfigVariationsAbstractTest.java |   2 +-
 .../junits/JUnit3TestLegacySupport.java            |  91 -------------
 .../test/ConfigVariationsTestSuiteBuilderTest.java |   2 +
 4 files changed, 113 insertions(+), 127 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 2e4f820..d30a2d6 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
@@ -123,9 +123,13 @@ import org.apache.log4j.RollingFileAppender;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.ClassRule;
 import org.junit.Rule;
+import org.junit.rules.RuleChain;
+import org.junit.rules.TestName;
 import org.junit.rules.TestRule;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
@@ -146,10 +150,11 @@ import static org.apache.ignite.testframework.config.GridTestProperties.IGNITE_C
  * Common abstract test for Ignite tests.
  */
 @SuppressWarnings({
-    "TransientFieldInNonSerializableClass",
-    "ProhibitedExceptionDeclared"
+    "ExtendsUtilityClass",
+    "ProhibitedExceptionDeclared",
+    "TransientFieldInNonSerializableClass"
 })
-public abstract class GridAbstractTest extends JUnit3TestLegacySupport {
+public abstract class GridAbstractTest extends JUnitAssertAware {
     /**************************************************************
      * DO NOT REMOVE TRANSIENT - THIS OBJECT MIGHT BE TRANSFERRED *
      *                  TO ANOTHER NODE.                          *
@@ -178,7 +183,7 @@ public abstract class GridAbstractTest extends JUnit3TestLegacySupport {
     @ClassRule public static final TestRule firstLastTestRule = new BeforeFirstAndAfterLastTestRule();
 
     /** Manages test execution and reporting. */
-    @Rule public transient TestRule runRule = (base, desc) -> new Statement() {
+    private transient TestRule runRule = (base, desc) -> new Statement() {
         @Override public void evaluate() throws Throwable {
             assert getName() != null : "getName returned null";
 
@@ -186,6 +191,29 @@ public abstract class GridAbstractTest extends JUnit3TestLegacySupport {
         }
     };
 
+    /**
+     * Supports obtaining test name for JUnit4 framework in a way that makes it available for methods invoked
+     * from {@code runTest(Statement)}.
+     */
+    private transient TestName nameRule = new TestName();
+
+    /**
+     * Gets the name of the currently executed test case.
+     *
+     * @return Name of the currently executed test case.
+     */
+    public String getName() {
+        return nameRule.getMethodName();
+    }
+
+    /**
+     * Provides the order of JUnit TestRules. Because of JUnit framework specifics {@link #nameRule} must be invoked
+     * first.
+     */
+    @Rule public transient RuleChain nameAndRunRulesChain = RuleChain
+        .outerRule(nameRule)
+        .around(runRule);
+
     /** */
     private static transient boolean startGrid;
 
@@ -256,6 +284,52 @@ public abstract class GridAbstractTest extends JUnit3TestLegacySupport {
     }
 
     /**
+     * Called before execution of every test method in class.
+     * <p>
+     * Do not annotate with {@link Before} in overriding methods.</p>
+     *
+     * @throws Exception If failed. {@link #afterTest()} will be called anyway.
+     */
+    protected void beforeTest() throws Exception {
+        // No-op.
+    }
+
+    /**
+     * Called after execution of every test method in class or if {@link #beforeTest()} failed without test method
+     * execution.
+     * <p>
+     * Do not annotate with {@link After} in overriding methods.</p>
+     *
+     * @throws Exception If failed.
+     */
+    protected void afterTest() throws Exception {
+        // No-op.
+    }
+
+    /**
+     * Called before execution of all test methods in class.
+     * <p>
+     * Do not annotate with {@link BeforeClass} in overriding methods.</p>
+     *
+     * @throws Exception If failed. {@link #afterTestsStopped()} will be called in this case.
+     */
+    protected void beforeTestsStarted() throws Exception {
+        // No-op.
+    }
+
+    /**
+     * Called after execution of all test methods in class or if {@link #beforeTestsStarted()} failed without
+     * execution of any test methods.
+     * <p>
+     * Do not annotate with {@link AfterClass} in overriding methods.</p>
+     *
+     * @throws Exception If failed.
+     */
+    protected void afterTestsStopped() throws Exception {
+        // No-op.
+    }
+
+    /**
      * @param cls Class to create.
      * @return Instance of class.
      * @throws Exception If failed.
@@ -570,7 +644,7 @@ public abstract class GridAbstractTest extends JUnit3TestLegacySupport {
             t.printStackTrace();
 
             try {
-                tearDown();
+                cleanUpTestEnviroment();
             }
             catch (Exception e) {
                 log.error("Failed to tear down test after exception was thrown in beforeTestsStarted (will " +
@@ -581,6 +655,31 @@ public abstract class GridAbstractTest extends JUnit3TestLegacySupport {
         }
     }
 
+    /**
+     * Runs after each test. Is responsible for clean up test enviroment in accordance with {@link #afterTest()}
+     * method overriding.
+     *
+     * @throws Exception If failed.
+     */
+    private void cleanUpTestEnviroment() throws Exception {
+        long dur = System.currentTimeMillis() - ts;
+
+        info(">>> Stopping test: " + testDescription() + " in " + dur + " ms <<<");
+
+        try {
+            afterTest();
+        }
+        finally {
+            serializedObj.clear();
+
+            Thread.currentThread().setContextClassLoader(clsLdr);
+
+            clsLdr = null;
+
+            cleanReferences();
+        }
+    }
+
     /** */
     private void setSystemPropertiesBeforeClass() {
         List<WithSystemProperty[]> allProps = new LinkedList<>();
@@ -2034,7 +2133,7 @@ public abstract class GridAbstractTest extends JUnit3TestLegacySupport {
 
     /** Runs test with the provided scenario. */
     private void runTest(Statement testRoutine) throws Throwable {
-        setUp();
+        prepareTestEnviroment();
         
         try {
             final AtomicReference<Throwable> ex = new AtomicReference<>();
@@ -2092,7 +2191,7 @@ public abstract class GridAbstractTest extends JUnit3TestLegacySupport {
         }
         finally {
             try {
-                tearDown();
+                cleanUpTestEnviroment();
             }
             catch (Exception e) {
                 log.error("Failed to execute tear down after test (will ignore)", e);
@@ -2101,11 +2200,12 @@ public abstract class GridAbstractTest extends JUnit3TestLegacySupport {
     }
 
     /**
-     * Runs before each test.
+     * Runs before each test. Is responsible for prepare test enviroment in accordance with {@link #beforeTest()}
+     * method overriding.
      *
      * @throws Exception If failed.
      */
-    private void setUp() throws Exception {
+    private void prepareTestEnviroment() throws Exception {
         stopGridErr = false;
 
         clsLdr = Thread.currentThread().getContextClassLoader();
@@ -2123,7 +2223,7 @@ public abstract class GridAbstractTest extends JUnit3TestLegacySupport {
         }
         catch (Exception | Error t) {
             try {
-                tearDown();
+                cleanUpTestEnviroment();
             }
             catch (Exception e) {
                 log.error("Failed to tear down test after exception was thrown in beforeTest (will ignore)", e);
@@ -2136,31 +2236,6 @@ public abstract class GridAbstractTest extends JUnit3TestLegacySupport {
     }
 
     /**
-     * Runs after each test.
-     *
-     * @throws Exception If failed.
-     */
-    private void tearDown() throws Exception {
-        long dur = System.currentTimeMillis() - ts;
-
-        info(">>> Stopping test: " + testDescription() + " in " + dur + " ms <<<");
-
-        try {
-            afterTest();
-        }
-        finally {
-            if (!keepSerializedObjects())
-                serializedObj.clear();
-
-            Thread.currentThread().setContextClassLoader(clsLdr);
-
-            clsLdr = null;
-
-            cleanReferences();
-        }
-    }
-
-    /**
      * @return If {@code true} serialized objects placed to {@link #serializedObj}
      * are not cleared after each test execution.
      *
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteConfigVariationsAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteConfigVariationsAbstractTest.java
index 44aa797..6ab78fb 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteConfigVariationsAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteConfigVariationsAbstractTest.java
@@ -60,7 +60,7 @@ public abstract class IgniteConfigVariationsAbstractTest extends GridCommonAbstr
 
     /** Manages first and last test execution. */
     @Rule public RuleChain runRule
-        = RuleChain.outerRule(rulePrivate).around(super.runRule);
+        = RuleChain.outerRule(rulePrivate).around(super.nameAndRunRulesChain);
 
     /** */
     protected static final int SERVER_NODE_IDX = 0;
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/JUnit3TestLegacySupport.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/JUnit3TestLegacySupport.java
deleted file mode 100644
index be3d9bf..0000000
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/JUnit3TestLegacySupport.java
+++ /dev/null
@@ -1,91 +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 org.junit.Rule;
-import org.junit.rules.TestName;
-
-/**
- * Supports compatibility with old tests that expect specific threading behavior of JUnit 3 TestCase class,
- * inherited assertions and specific old interface for GridTestUtils.
- * @deprecated and should be removed once all tests will be refactored to use proper API.
- */
-@SuppressWarnings({"TransientFieldInNonSerializableClass", "ExtendsUtilityClass"})
-@Deprecated
-public class JUnit3TestLegacySupport extends JUnitAssertAware {
-    /**
-     * Supports obtaining test name for JUnit4 framework in a way that makes it available for legacy methods invoked
-     * from {@code runTest(Statement)}.
-     */
-    @Rule public transient TestName nameRule = new TestName();
-
-    /**
-     * Gets the name of the currently executed test case.
-     *
-     * @return Name of the currently executed test case.
-     */
-    public String getName() {
-        return nameRule.getMethodName();
-    }
-
-    /**
-     * Called before execution of every test method in class.
-     * <p>
-     * Do not annotate with Before in overriding methods.</p>
-     *
-     * @throws Exception If failed. {@link #afterTest()} will be called in this case.
-     */
-    protected void beforeTest() throws Exception {
-        // No-op.
-    }
-
-    /**
-     * Called after execution of every test method in class or if {@link #beforeTest()} failed without test method
-     * execution.
-     * <p>
-     * Do not annotate with After in overriding methods.</p>
-     *
-     * @throws Exception If failed.
-     */
-    protected void afterTest() throws Exception {
-        // No-op.
-    }
-
-    /**
-     * Called before execution of all test methods in class.
-     * <p>
-     * Do not annotate with BeforeClass in overriding methods.</p>
-     *
-     * @throws Exception If failed. {@link #afterTestsStopped()} will be called in this case.
-     */
-    protected void beforeTestsStarted() throws Exception {
-        // No-op.
-    }
-
-    /**
-     * Called after execution of all test methods in class or
-     * if {@link #beforeTestsStarted()} failed without execution of any test methods.
-     * <p>
-     * Do not annotate with AfterClass in overriding methods.</p>
-     *
-     * @throws Exception If failed.
-     */
-    protected void afterTestsStopped() throws Exception {
-        // No-op.
-    }
-}
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/test/ConfigVariationsTestSuiteBuilderTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/test/ConfigVariationsTestSuiteBuilderTest.java
index 0c6b291..0178315 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/test/ConfigVariationsTestSuiteBuilderTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/test/ConfigVariationsTestSuiteBuilderTest.java
@@ -428,6 +428,7 @@ public class ConfigVariationsTestSuiteBuilderTest {
         }
 
         /** */
+        @Ignore("https://issues.apache.org/jira/browse/IGNITE-11708")
         @Test
         public void test1() {
             processStage("test1", 2, 3);
@@ -435,6 +436,7 @@ public class ConfigVariationsTestSuiteBuilderTest {
         }
 
         /** */
+        @Ignore("https://issues.apache.org/jira/browse/IGNITE-11708")
         @Test
         public void test2() {
             processStage("test2", 2, 3);