IGNITE-10739 get rid of using JUnit 3 API in IgniteConfigVariationsAbstractTes - design cleanup per review comments -- verified with diffs overview and rebuild - Fixes #5715.
Signed-off-by: Dmitriy Govorukhin <dmitriy.govoruk...@gmail.com> Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/9f40da5a Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/9f40da5a Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/9f40da5a Branch: refs/heads/ignite-601 Commit: 9f40da5a1e8bf3cff0227306e7de1de44b3bffcc Parents: 2b23d46 Author: Oleg Ignatenko <oignate...@gridgain.com> Authored: Tue Dec 25 12:11:17 2018 +0300 Committer: Dmitriy Govorukhin <dmitriy.govoruk...@gmail.com> Committed: Tue Dec 25 12:11:17 2018 +0300 ---------------------------------------------------------------------- ...ridCacheReplicatedMultiNodeLockSelfTest.java | 9 +- .../GridCacheReplicatedMultiNodeSelfTest.java | 9 +- .../CheckpointReadLockFailureTest.java | 2 + .../db/wal/WalCompactionSwitchOnTest.java | 2 + .../ConfigVariationsTestSuiteBuilder.java | 22 ++- .../IgniteConfigVariationsTestSuite.java | 50 ------- .../configvariations/VariationsTestsConfig.java | 4 +- .../testframework/junits/GridAbstractTest.java | 65 +-------- .../IgniteConfigVariationsAbstractTest.java | 51 +++---- .../junits/JUnit3TestLegacySupport.java | 134 +++++++++++++++++++ .../junits/LegacyConfigVariationsSupport.java | 47 ------- .../testframework/junits/LegacySupport.java | 94 ------------- .../ConfigVariationsTestSuiteBuilderTest.java | 31 ++--- modules/twitter/pom.xml | 2 +- .../twitter/IgniteTwitterStreamerTest.java | 46 ++----- .../yarn/IgniteApplicationMasterSelfTest.java | 4 +- 16 files changed, 213 insertions(+), 359 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/9f40da5a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedMultiNodeLockSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedMultiNodeLockSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedMultiNodeLockSelfTest.java index a340244..42fa698 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedMultiNodeLockSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedMultiNodeLockSelfTest.java @@ -19,19 +19,16 @@ package org.apache.ignite.internal.processors.cache.distributed.replicated; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.internal.processors.cache.distributed.GridCacheMultiNodeLockAbstractTest; +import org.junit.Ignore; import static org.apache.ignite.cache.CacheMode.REPLICATED; /** * Test cases for multi-threaded tests. */ +@Ignore("https://issues.apache.org/jira/browse/IGNITE-601") public class GridCacheReplicatedMultiNodeLockSelfTest extends GridCacheMultiNodeLockAbstractTest { /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - fail("https://issues.apache.org/jira/browse/IGNITE-601"); - } - - /** {@inheritDoc} */ @Override protected CacheConfiguration cacheConfiguration() { CacheConfiguration cacheCfg = defaultCacheConfiguration(); @@ -39,4 +36,4 @@ public class GridCacheReplicatedMultiNodeLockSelfTest extends GridCacheMultiNode return cacheCfg; } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9f40da5a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedMultiNodeSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedMultiNodeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedMultiNodeSelfTest.java index f1eed3a..6fe1eba 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedMultiNodeSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedMultiNodeSelfTest.java @@ -20,19 +20,16 @@ package org.apache.ignite.internal.processors.cache.distributed.replicated; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.processors.cache.distributed.GridCacheMultiNodeAbstractTest; +import org.junit.Ignore; import static org.apache.ignite.cache.CacheMode.REPLICATED; /** * Test cases for multi-threaded tests. */ +@Ignore("https://issues.apache.org/jira/browse/IGNITE-601") public class GridCacheReplicatedMultiNodeSelfTest extends GridCacheMultiNodeAbstractTest { /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - fail("https://issues.apache.org/jira/browse/IGNITE-601"); - } - - /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); @@ -44,4 +41,4 @@ public class GridCacheReplicatedMultiNodeSelfTest extends GridCacheMultiNodeAbst return cfg; } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9f40da5a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/CheckpointReadLockFailureTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/CheckpointReadLockFailureTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/CheckpointReadLockFailureTest.java index 2ec5c2d..b3fede0 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/CheckpointReadLockFailureTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/CheckpointReadLockFailureTest.java @@ -32,6 +32,7 @@ import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Test; /** * Tests critical failure handling on checkpoint read lock acquisition errors. @@ -85,6 +86,7 @@ public class CheckpointReadLockFailureTest extends GridCommonAbstractTest { /** * @throws Exception If failed. */ + @Test public void testFailureTypeOnTimeout() throws Exception { hndLatch = new CountDownLatch(1); http://git-wip-us.apache.org/repos/asf/ignite/blob/9f40da5a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/WalCompactionSwitchOnTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/WalCompactionSwitchOnTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/WalCompactionSwitchOnTest.java index 64a937c..70183ae 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/WalCompactionSwitchOnTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/WalCompactionSwitchOnTest.java @@ -31,6 +31,7 @@ import org.apache.ignite.internal.util.lang.GridAbsPredicate; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Test; /** * Load without compaction -> Stop -> Enable WAL Compaction -> Start. @@ -65,6 +66,7 @@ public class WalCompactionSwitchOnTest extends GridCommonAbstractTest { * * @throws Exception On exception. */ + @Test public void testWalCompactionSwitch() throws Exception { IgniteEx ex = startGrid(0); http://git-wip-us.apache.org/repos/asf/ignite/blob/9f40da5a/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/ConfigVariationsTestSuiteBuilder.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/ConfigVariationsTestSuiteBuilder.java b/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/ConfigVariationsTestSuiteBuilder.java index a322ca1..8441b0c 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/ConfigVariationsTestSuiteBuilder.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/ConfigVariationsTestSuiteBuilder.java @@ -18,6 +18,8 @@ package org.apache.ignite.testframework.configvariations; import java.util.Arrays; +import junit.framework.JUnit4TestAdapter; +import junit.framework.TestResult; import junit.framework.TestSuite; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; @@ -198,7 +200,7 @@ public class ConfigVariationsTestSuiteBuilder { addedSuite = createMultiNodeTestSuite((Class<? extends IgniteCacheConfigVariationsAbstractTest>)cls, testCfg, testedNodeCnt, withClients, skipWaitPartMapExchange); else - addedSuite = new IgniteConfigVariationsTestSuite(cls, testCfg); + addedSuite = makeTestSuite(cls, testCfg); return addedSuite; } @@ -225,12 +227,28 @@ public class ConfigVariationsTestSuiteBuilder { stopNodes, startCache, stopCache, cfg.cacheStartMode(), cfg.gridCount(), i, withClients, !skipWaitParMapExchange); - suite.addTest(new IgniteConfigVariationsTestSuite(cls, cfg0)); + suite.addTest(makeTestSuite(cls, cfg0)); } return suite; } + /** */ + private static TestSuite makeTestSuite(Class<? extends IgniteConfigVariationsAbstractTest> cls, + VariationsTestsConfig cfg) { + TestSuite res = new TestSuite(cls.getSimpleName()); + + res.addTest(new JUnit4TestAdapter(cls) { + @Override public void run(TestResult tr) { + IgniteConfigVariationsAbstractTest.injectTestsConfiguration(cfg); + + super.run(tr); + } + }); + + return res; + } + /** * @return {@code this} for chaining. */ http://git-wip-us.apache.org/repos/asf/ignite/blob/9f40da5a/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/IgniteConfigVariationsTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/IgniteConfigVariationsTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/IgniteConfigVariationsTestSuite.java deleted file mode 100644 index d953c27..0000000 --- a/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/IgniteConfigVariationsTestSuite.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.configvariations; - -import junit.framework.Test; -import junit.framework.TestResult; -import junit.framework.TestSuite; -import org.apache.ignite.testframework.junits.IgniteConfigVariationsAbstractTest; - -/** - * Configuration variations test suite. - */ -public class IgniteConfigVariationsTestSuite extends TestSuite { - /** */ - protected final VariationsTestsConfig cfg; - - /** - * @param cls Test class. - * @param cfg Configuration. - */ - public IgniteConfigVariationsTestSuite(Class<? extends IgniteConfigVariationsAbstractTest> cls, - VariationsTestsConfig cfg) { - super(cls); - - this.cfg = cfg; - } - - /** {@inheritDoc} */ - @Override public void runTest(Test test, TestResult res) { - if (test instanceof IgniteConfigVariationsAbstractTest) - ((IgniteConfigVariationsAbstractTest)test).setTestsConfiguration(cfg); - - super.runTest(test, res); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/9f40da5a/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/VariationsTestsConfig.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/VariationsTestsConfig.java b/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/VariationsTestsConfig.java index 91c6c93..633333e 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/VariationsTestsConfig.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/VariationsTestsConfig.java @@ -48,7 +48,7 @@ public class VariationsTestsConfig { private boolean stopCache; /** */ - private boolean awaitPartMapExchange = true; + private boolean awaitPartMapExchange; /** */ private boolean withClients; @@ -88,7 +88,7 @@ public class VariationsTestsConfig { boolean withClients, boolean awaitPartMapExchange ) { - A.ensure(gridCnt >= 1, "Grids count cannot be less then 1."); + A.ensure(gridCnt >= 1, "Grids count cannot be less than 1."); this.factory = factory; this.desc = desc; http://git-wip-us.apache.org/repos/asf/ignite/blob/9f40da5a/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 af443be..600985c 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 @@ -127,8 +127,6 @@ import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestRule; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; import org.junit.runners.model.Statement; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; @@ -151,8 +149,7 @@ import static org.apache.ignite.testframework.config.GridTestProperties.IGNITE_C "ProhibitedExceptionDeclared", "JUnitTestCaseWithNonTrivialConstructors" }) -@RunWith(JUnit4.class) -public abstract class GridAbstractTest extends LegacySupport { +public abstract class GridAbstractTest extends JUnit3TestLegacySupport { /************************************************************** * DO NOT REMOVE TRANSIENT - THIS OBJECT MIGHT BE TRANSFERRED * * TO ANOTHER NODE. * @@ -180,7 +177,7 @@ public abstract class GridAbstractTest extends LegacySupport { /** */ protected static final String DEFAULT_CACHE_NAME = "default"; - /** Lock to maintain integrity of {@link TestCounters}. */ + /** Lock to maintain integrity of {@link TestCounters} and of {@link IgniteConfigVariationsAbstractTest}. */ private final Lock runSerializer = new ReentrantLock(); /** Manages test execution and reporting. */ @@ -555,66 +552,14 @@ public abstract class GridAbstractTest extends LegacySupport { } /** - * 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. - * @deprecated This method is deprecated. Instead of invoking or overriding it, it is recommended to make your own - * method with {@code @Before} annotation. - */ - @Deprecated - 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. - * @deprecated This method is deprecated. Instead of invoking or overriding it, it is recommended to make your own - * method with {@code @After} annotation. + * Will clean and re-create marshaller directory from scratch. */ - @Deprecated - 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. - * @deprecated This method is deprecated. Instead of invoking or overriding it, it is recommended to make your own - * method with {@code @BeforeClass} annotation. - */ - @Deprecated - protected void beforeTestsStarted() throws Exception { - // Will clean and re-create marshaller directory from scratch. + private void resolveWorkDirectory() throws Exception { U.resolveWorkDirectory(U.defaultWorkDirectory(), "marshaller", true); U.resolveWorkDirectory(U.defaultWorkDirectory(), "binary_meta", true); } /** - * 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. - * @deprecated This method is deprecated. Instead of invoking or overriding it, it is recommended to make your own - * method with {@code @AfterClass} annotation. - */ - @Deprecated - protected void afterTestsStopped() throws Exception { - // No-op. - } - - /** * {@inheritDoc} * <p> * Do not annotate with Before in overriding methods.</p> @@ -671,6 +616,8 @@ public abstract class GridAbstractTest extends LegacySupport { if (!jvmIds.isEmpty()) log.info("Next processes of IgniteNodeRunner were killed: " + jvmIds); + resolveWorkDirectory(); + beforeTestsStarted(); } catch (Exception | Error t) { http://git-wip-us.apache.org/repos/asf/ignite/blob/9f40da5a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteConfigVariationsAbstractTest.java ---------------------------------------------------------------------- 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 146e145..2bbead2 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 @@ -25,7 +25,6 @@ import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.io.Serializable; -import junit.framework.TestResult; import org.apache.commons.io.FileUtils; import org.apache.ignite.Ignition; import org.apache.ignite.binary.BinaryObjectException; @@ -39,16 +38,11 @@ import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.marshaller.jdk.JdkMarshaller; import org.apache.ignite.testframework.configvariations.VariationsTestsConfig; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.runners.model.Statement; /** * Common abstract test for Ignite tests based on configurations variations. - * TODO IGNITE-10739 redesign this and related classes to get rid of JUnit 3 features. - * - * @deprecated This class uses obsolete methods of JUnit 3 framework and because of that you need to use JUnit 3 - * naming convention for test cases in classes extending it. Also, Junit 4 annotations like {@code Before} - * and {@code Ignore} may not work. It is expected to be reworked per IGNITE-10739. */ -@Deprecated public abstract class IgniteConfigVariationsAbstractTest extends GridCommonAbstractTest { /** */ protected static final int SERVER_NODE_IDX = 0; @@ -62,47 +56,34 @@ public abstract class IgniteConfigVariationsAbstractTest extends GridCommonAbstr /** */ private static final File workDir = new File(U.getIgniteHome() + File.separator + "workOfConfigVariationsTests"); - /** */ - protected VariationsTestsConfig testsCfg; + /** Dummy initial stub to just let people launch test classes not from suite. */ + protected VariationsTestsConfig testsCfg = new VariationsTestsConfig(null, "Dummy config", false, null, 1, false); /** */ protected volatile DataMode dataMode = DataMode.PLANE_OBJECT; - /** - * @param testsCfg Tests configuration. - */ - public void setTestsConfiguration(VariationsTestsConfig testsCfg) { - assert this.testsCfg == null : "Test config must be set only once [oldTestCfg=" + this.testsCfg - + ", newTestCfg=" + testsCfg + "]"; - - this.testsCfg = testsCfg; - } + /** See {@link IgniteConfigVariationsAbstractTest#injectTestsConfiguration} */ + private static VariationsTestsConfig testsCfgInjected; /** - * {@inheritDoc} - * <p> - * Fallback to TestCase functionality.</p> + * @param testsCfgInjected Tests configuration. */ - @Override public int countTestCases() { - return countTestCasesFallback(); + public static void injectTestsConfiguration(VariationsTestsConfig testsCfgInjected) { + IgniteConfigVariationsAbstractTest.testsCfgInjected = testsCfgInjected; } /** * {@inheritDoc} * <p> - * Fallback to TestCase functionality.</p> + * IMPL NOTE when this override was introduced, alternative was to replace multiple usages of instance member + * {@code testsCfg} splattered all over the project with those of static one {@code testsCfgInjected} - kind + * of cumbersome, risky and potentially redundant change given the chance of later migration to JUnit 5 and + * further rework to use dynamic test parameters that would likely cause removal of the static member.</p> */ - @Override public void run(TestResult res) { - runFallback(res); - } + @Override protected void runTestCase(Statement testRoutine) throws Throwable { + testsCfg = testsCfgInjected; - /** - * {@inheritDoc} - * <p> - * Fallback to TestCase functionality.</p> - */ - @Override public String getName() { - return getNameFallback(); + super.runTestCase(testRoutine); } /** {@inheritDoc} */ @@ -191,6 +172,8 @@ public abstract class IgniteConfigVariationsAbstractTest extends GridCommonAbstr /** {@inheritDoc} */ @Override protected String testDescription() { + assert testsCfg != null: "Tests should be run using test suite."; + return super.testDescription() + '-' + testsCfg.description() + '-' + testsCfg.gridCount() + "-node(s)"; } http://git-wip-us.apache.org/repos/asf/ignite/blob/9f40da5a/modules/core/src/test/java/org/apache/ignite/testframework/junits/JUnit3TestLegacySupport.java ---------------------------------------------------------------------- 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 new file mode 100644 index 0000000..709b39c --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/JUnit3TestLegacySupport.java @@ -0,0 +1,134 @@ +/* + * 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 junit.framework.Assert; // IMPL NOTE some old tests expect inherited deprecated assertions. +import org.junit.Rule; +import org.junit.rules.TestName; +import org.junit.runners.model.Statement; + +/** + * Supports compatibility with old tests that expect specific threading behavior of JUnit 3 TestCase class, + * inherited deprecated assertions and specific old interface for GridTestUtils. + */ +@SuppressWarnings({"TransientFieldInNonSerializableClass", "ExtendsUtilityClass", "deprecation"}) +public abstract class JUnit3TestLegacySupport extends Assert { + /** + * 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(); + } + + /** This method is called before a test is executed. */ + abstract void setUp() throws Exception; + + /** Runs test code in between {@code setUp} and {@code tearDown}. */ + abstract void runTest(Statement testRoutine) throws Throwable; + + /** This method is called after a test is executed. */ + abstract void tearDown() throws Exception; + + /** + * Runs the bare test sequence like in JUnit 3 class TestCase. + * + * @throws Throwable if any exception is thrown + */ + protected void runTestCase(Statement testRoutine) throws Throwable { + Throwable e = null; + setUp(); + try { + runTest(testRoutine); + } catch (Throwable running) { + e = running; + } finally { + try { + tearDown(); + } catch (Throwable tearingDown) { + if (e == null) e = tearingDown; + } + } + if (e != null) throw e; + } + + /** + * 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. + * @deprecated This method is deprecated. Instead of invoking or overriding it, it is recommended to make your own + * method with {@code @Before} annotation. + */ + @Deprecated + 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. + * @deprecated This method is deprecated. Instead of invoking or overriding it, it is recommended to make your own + * method with {@code @After} annotation. + */ + @Deprecated + 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. + * @deprecated This method is deprecated. Instead of invoking or overriding it, it is recommended to make your own + * method with {@code @BeforeClass} annotation. + */ + @Deprecated + 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. + * @deprecated This method is deprecated. Instead of invoking or overriding it, it is recommended to make your own + * method with {@code @AfterClass} annotation. + */ + @Deprecated + protected void afterTestsStopped() throws Exception { + // No-op. + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9f40da5a/modules/core/src/test/java/org/apache/ignite/testframework/junits/LegacyConfigVariationsSupport.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/LegacyConfigVariationsSupport.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/LegacyConfigVariationsSupport.java deleted file mode 100644 index 843f677..0000000 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/LegacyConfigVariationsSupport.java +++ /dev/null @@ -1,47 +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 junit.framework.TestCase; // IMPL NOTE some old tests expect inherited deprecated assertions. -import junit.framework.TestResult; - -/** - * Supports compatibility with old tests based on configurations variations. - */ -abstract class LegacyConfigVariationsSupport extends TestCase { - /** - * Fallback to superclass. - */ - protected int countTestCasesFallback() { - return super.countTestCases(); - } - - /** - * Fallback to superclass. - */ - protected void runFallback(TestResult res) { - super.run(res); - } - - /** - * Fallback to superclass. - */ - protected String getNameFallback() { - return super.getName(); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/9f40da5a/modules/core/src/test/java/org/apache/ignite/testframework/junits/LegacySupport.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/LegacySupport.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/LegacySupport.java deleted file mode 100644 index 09e1ecd..0000000 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/LegacySupport.java +++ /dev/null @@ -1,94 +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 junit.framework.TestResult; -import org.junit.Rule; -import org.junit.rules.TestName; -import org.junit.runners.model.Statement; - -/** - * Supports compatibility with old tests that expect specific threading behavior of JUnit 3 TestCase class, - * inherited deprecated assertions and specific old interface for GridTestUtils. - */ -@SuppressWarnings({"TransientFieldInNonSerializableClass"}) -public abstract class LegacySupport extends LegacyConfigVariationsSupport { - /** - * 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. - */ - @Override public String getName() { - return nameRule.getMethodName(); - } - - /** Runs test code in between {@code setUp} and {@code tearDown}. */ - abstract void runTest(Statement testRoutine) throws Throwable; - - /** - * Runs the bare test sequence like in JUnit 3 class TestCase. - * - * @throws Throwable if any exception is thrown - */ - final void runTestCase(Statement testRoutine) throws Throwable { - Throwable e = null; - setUp(); - try { - runTest(testRoutine); - } catch (Throwable running) { - e = running; - } finally { - try { - tearDown(); - } catch (Throwable tearingDown) { - if (e == null) e = tearingDown; - } - } - if (e != null) throw e; - } - - /** - * {@inheritDoc} - * <p> - * This method is here only for subclass to pretend implementing particular interface expected by some utility - * methods in GridTestUtils.</p> - * - * @return Nothing. - */ - @Override public int countTestCases() { - throw new UnsupportedOperationException("This method is not expected to be invoked: countTestCases() at test: " - + getName()); - } - - /** - * {@inheritDoc} - * <p> - * This method is here only for subclass to pretend implementing particular interface expected by some utility - * methods in GridTestUtils.</p> - */ - @Override public void run(TestResult res) { - throw new UnsupportedOperationException("This method is not intended to be invoked: run(TestResult) at test: " - + getName()); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/9f40da5a/modules/core/src/test/java/org/apache/ignite/testframework/test/ConfigVariationsTestSuiteBuilderTest.java ---------------------------------------------------------------------- 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 50301e4..631f033 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 @@ -32,11 +32,9 @@ import static org.junit.Assert.assertEquals; * */ public class ConfigVariationsTestSuiteBuilderTest { - /** - * @throws Exception If failed. - */ + /** */ @Test - public void testDefaults() throws Exception { + public void testDefaults() { TestSuite dfltSuite = new ConfigVariationsTestSuiteBuilder("testSuite", NoopTest.class).build(); assertEquals(4, dfltSuite.countTestCases()); @@ -58,12 +56,10 @@ public class ConfigVariationsTestSuiteBuilderTest { assertEquals(4 * 4 * 2 * 3, dfltCacheSuite.countTestCases()); } - /** - * @throws Exception If failed. - */ + /** */ @SuppressWarnings("serial") @Test - public void testIgniteConfigFilter() throws Exception { + public void testIgniteConfigFilter() { TestSuite dfltSuite = new ConfigVariationsTestSuiteBuilder("testSuite", NoopTest.class).build(); final AtomicInteger cnt = new AtomicInteger(); @@ -79,12 +75,10 @@ public class ConfigVariationsTestSuiteBuilderTest { assertEquals(dfltSuite.countTestCases() / 2, filteredSuite.countTestCases()); } - /** - * @throws Exception If failed. - */ + /** */ @SuppressWarnings("serial") @Test - public void testCacheConfigFilter() throws Exception { + public void testCacheConfigFilter() { TestSuite dfltSuite = new ConfigVariationsTestSuiteBuilder("testSuite", NoopTest.class) .withBasicCacheParams() .build(); @@ -103,14 +97,11 @@ public class ConfigVariationsTestSuiteBuilderTest { assertEquals(dfltSuite.countTestCases() / 2, filteredSuite.countTestCases()); } - /** - * - */ - private static class NoopTest extends IgniteConfigVariationsAbstractTest { - /** - * @throws Exception If failed. - */ - public void test1() throws Exception { + /** */ + public static class NoopTest extends IgniteConfigVariationsAbstractTest { + /** */ + @Test + public void test1() { // No-op. } } http://git-wip-us.apache.org/repos/asf/ignite/blob/9f40da5a/modules/twitter/pom.xml ---------------------------------------------------------------------- diff --git a/modules/twitter/pom.xml b/modules/twitter/pom.xml index 017e43e..6d98eb2 100644 --- a/modules/twitter/pom.xml +++ b/modules/twitter/pom.xml @@ -71,7 +71,7 @@ <dependency> <groupId>com.github.tomakehurst</groupId> <artifactId>wiremock</artifactId> - <version>1.57</version> + <version>1.58</version> <classifier>standalone</classifier> <exclusions> <exclusion> http://git-wip-us.apache.org/repos/asf/ignite/blob/9f40da5a/modules/twitter/src/test/java/org/apache/ignite/stream/twitter/IgniteTwitterStreamerTest.java ---------------------------------------------------------------------- diff --git a/modules/twitter/src/test/java/org/apache/ignite/stream/twitter/IgniteTwitterStreamerTest.java b/modules/twitter/src/test/java/org/apache/ignite/stream/twitter/IgniteTwitterStreamerTest.java index c607f55..9b56478 100644 --- a/modules/twitter/src/test/java/org/apache/ignite/stream/twitter/IgniteTwitterStreamerTest.java +++ b/modules/twitter/src/test/java/org/apache/ignite/stream/twitter/IgniteTwitterStreamerTest.java @@ -24,7 +24,6 @@ import com.twitter.hbc.core.HttpHosts; import java.util.HashMap; import java.util.Map; import java.util.concurrent.CountDownLatch; -import junit.framework.TestResult; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteDataStreamer; @@ -35,8 +34,6 @@ import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; -import org.junit.internal.runners.JUnit38ClassRunner; -import org.junit.runner.RunWith; import twitter4j.Status; import twitter4j.TwitterException; import twitter4j.TwitterObjectFactory; @@ -50,7 +47,6 @@ import static org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_PUT; /** * Test for {@link TwitterStreamer}. Tests Public Status streaming API https://dev.twitter.com/streaming/public. */ -@RunWith(JUnit38ClassRunner.class) // TODO IGNITE-10739 migrate to JUnit 4. public class IgniteTwitterStreamerTest extends GridCommonAbstractTest { /** Cache entries count. */ private static final int CACHE_ENTRY_COUNT = 100; @@ -66,7 +62,9 @@ public class IgniteTwitterStreamerTest extends GridCommonAbstractTest { super(true); } - /** See <a href="http://wiremock.org/docs/junit-rule/">The JUnit 4.x Rule </a> */ + /** + * See <a href="http://wiremock.org/docs/junit-rule/">The JUnit 4.x Rule</a>. + */ @ClassRule public static WireMockClassRule wireMockClsRule = new WireMockClassRule(WireMockConfiguration.DYNAMIC_PORT); @@ -77,40 +75,13 @@ public class IgniteTwitterStreamerTest extends GridCommonAbstractTest { /** Embedded mock HTTP server for Twitter API. */ public final WireMockServer mockSrv = new WireMockServer(); //Starts server on 8080 port. - /** - * {@inheritDoc} - * <p> - * Fallback to TestCase functionality.</p> - */ - @Override public int countTestCases() { - return countTestCasesFallback(); - } - - /** - * {@inheritDoc} - * <p> - * Fallback to TestCase functionality.</p> - */ - @Override public void run(TestResult res) { - runFallback(res); - } - - /** - * {@inheritDoc} - * <p> - * Fallback to TestCase functionality.</p> - */ - @Override public String getName() { - return getNameFallback(); - } - /** {@inheritDoc} */ @Override protected long getTestTimeout() { return 10_000; } - /** {@inheritDoc} */ - @Override public void beforeTest() { + /** */ + private void init() { grid().getOrCreateCache(defaultCacheConfiguration()); mockSrv.start(); @@ -119,8 +90,8 @@ public class IgniteTwitterStreamerTest extends GridCommonAbstractTest { withHeader("Content-Type", "text/plain").withBody(tweet.length() + "\n" + tweet))); } - /** {@inheritDoc} */ - @Override public void afterTest() { + /** */ + private void cleanup() { stopAllGrids(); mockSrv.stop(); @@ -131,6 +102,7 @@ public class IgniteTwitterStreamerTest extends GridCommonAbstractTest { */ @Test public void testStatusesFilterEndpointOAuth1() throws Exception { + init(); try (IgniteDataStreamer<Long, String> dataStreamer = grid().dataStreamer(DEFAULT_CACHE_NAME)) { TwitterStreamerImpl streamer = newStreamerInstance(dataStreamer); @@ -145,6 +117,8 @@ public class IgniteTwitterStreamerTest extends GridCommonAbstractTest { streamer.setThreadsCount(8); executeStreamer(streamer); + } finally { + cleanup(); } } http://git-wip-us.apache.org/repos/asf/ignite/blob/9f40da5a/modules/yarn/src/test/java/org/apache/ignite/yarn/IgniteApplicationMasterSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/yarn/src/test/java/org/apache/ignite/yarn/IgniteApplicationMasterSelfTest.java b/modules/yarn/src/test/java/org/apache/ignite/yarn/IgniteApplicationMasterSelfTest.java index ffd60f8..575ef42 100644 --- a/modules/yarn/src/test/java/org/apache/ignite/yarn/IgniteApplicationMasterSelfTest.java +++ b/modules/yarn/src/test/java/org/apache/ignite/yarn/IgniteApplicationMasterSelfTest.java @@ -144,8 +144,8 @@ public class IgniteApplicationMasterSelfTest { * * @throws Exception If failed. */ - @Test - public void testMemoryOverHeadPreventAllocation() throws Exception { + @Test + public void testMemoryOverHeadPreventAllocation() throws Exception { rmMock.availableRes(new MockResource(1024, 2)); appMaster.setRmClient(rmMock); appMaster.setNmClient(new NMMock());