Repository: ignite Updated Branches: refs/heads/master cc31cbde5 -> f76422600
IGNITE-10773 Migrate examples testsuites from Junit 3 to 4 - Fixes #5726. 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/f7642260 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f7642260 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f7642260 Branch: refs/heads/master Commit: f764226007a522f8693f0f36943a314d89f556a8 Parents: cc31cbd Author: Oleg Ignatenko <oignate...@gridgain.com> Authored: Thu Dec 27 19:36:47 2018 +0300 Committer: Dmitriy Govorukhin <dmitriy.govoruk...@gmail.com> Committed: Thu Dec 27 19:36:47 2018 +0300 ---------------------------------------------------------------------- .../IgniteLgplExamplesSelfTestSuite.java | 37 ++++---- .../testsuites/IgniteExamplesMLTestSuite.java | 79 +++++++++-------- .../testsuites/IgniteExamplesSelfTestSuite.java | 92 +++++++++----------- .../IgniteExamplesSparkSelfTestSuite.java | 27 +++--- .../ConfigVariationsTestSuiteBuilder.java | 2 - 5 files changed, 111 insertions(+), 126 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/f7642260/examples/src/test/java-lgpl/org/apache/ignite/testsuites/IgniteLgplExamplesSelfTestSuite.java ---------------------------------------------------------------------- diff --git a/examples/src/test/java-lgpl/org/apache/ignite/testsuites/IgniteLgplExamplesSelfTestSuite.java b/examples/src/test/java-lgpl/org/apache/ignite/testsuites/IgniteLgplExamplesSelfTestSuite.java index 91ea736..f7be880 100644 --- a/examples/src/test/java-lgpl/org/apache/ignite/testsuites/IgniteLgplExamplesSelfTestSuite.java +++ b/examples/src/test/java-lgpl/org/apache/ignite/testsuites/IgniteLgplExamplesSelfTestSuite.java @@ -17,8 +17,6 @@ package org.apache.ignite.testsuites; -import junit.framework.JUnit4TestAdapter; -import junit.framework.TestSuite; import org.apache.ignite.examples.ComputeScheduleExampleMultiNodeSelfTest; import org.apache.ignite.examples.ComputeScheduleExampleSelfTest; import org.apache.ignite.examples.HibernateL2CacheExampleMultiNodeSelfTest; @@ -26,34 +24,31 @@ import org.apache.ignite.examples.HibernateL2CacheExampleSelfTest; import org.apache.ignite.examples.SpatialQueryExampleMultiNodeSelfTest; import org.apache.ignite.examples.SpatialQueryExampleSelfTest; import org.apache.ignite.testframework.GridTestUtils; +import org.junit.BeforeClass; import org.junit.runner.RunWith; -import org.junit.runners.AllTests; +import org.junit.runners.Suite; import static org.apache.ignite.IgniteSystemProperties.IGNITE_OVERRIDE_MCAST_GRP; /** * Examples test suite. <p> Contains only Spring ignite examples tests. */ -@RunWith(AllTests.class) +@RunWith(Suite.class) +@Suite.SuiteClasses({ + HibernateL2CacheExampleSelfTest.class, + SpatialQueryExampleSelfTest.class, + ComputeScheduleExampleSelfTest.class, + + // Multi-node. + HibernateL2CacheExampleMultiNodeSelfTest.class, + SpatialQueryExampleMultiNodeSelfTest.class, + ComputeScheduleExampleMultiNodeSelfTest.class, +}) public class IgniteLgplExamplesSelfTestSuite { - /** - * @return Suite. - */ - public static TestSuite suite() { + /** */ + @BeforeClass + public static void init() { System.setProperty(IGNITE_OVERRIDE_MCAST_GRP, GridTestUtils.getNextMulticastGroup(IgniteLgplExamplesSelfTestSuite.class)); - - TestSuite suite = new TestSuite("Ignite Examples Test Suite"); - - suite.addTest(new JUnit4TestAdapter(HibernateL2CacheExampleSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(SpatialQueryExampleSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(ComputeScheduleExampleSelfTest.class)); - - // Multi-node. - suite.addTest(new JUnit4TestAdapter(HibernateL2CacheExampleMultiNodeSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(SpatialQueryExampleMultiNodeSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(ComputeScheduleExampleMultiNodeSelfTest.class)); - - return suite; } } http://git-wip-us.apache.org/repos/asf/ignite/blob/f7642260/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesMLTestSuite.java ---------------------------------------------------------------------- diff --git a/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesMLTestSuite.java b/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesMLTestSuite.java index 8551460..5b04a1a 100644 --- a/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesMLTestSuite.java +++ b/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesMLTestSuite.java @@ -23,25 +23,23 @@ import java.net.URL; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; -import javassist.CannotCompileException; +import java.util.stream.Collectors; import javassist.ClassClassPath; import javassist.ClassPool; import javassist.CtClass; import javassist.CtMethod; import javassist.CtNewMethod; -import javassist.NotFoundException; import javassist.bytecode.AnnotationsAttribute; import javassist.bytecode.ClassFile; import javassist.bytecode.ConstPool; import javassist.bytecode.annotation.Annotation; -import junit.framework.JUnit4TestAdapter; -import junit.framework.TestSuite; import org.apache.ignite.examples.ml.util.MLExamplesCommonArgs; import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.junits.common.GridAbstractExamplesTest; import org.junit.BeforeClass; import org.junit.runner.RunWith; -import org.junit.runners.AllTests; +import org.junit.runners.Suite; +import org.junit.runners.model.InitializationError; import static org.apache.ignite.IgniteSystemProperties.IGNITE_OVERRIDE_MCAST_GRP; @@ -50,7 +48,7 @@ import static org.apache.ignite.IgniteSystemProperties.IGNITE_OVERRIDE_MCAST_GRP * <p> * Contains only ML Grid Ignite examples tests.</p> */ -@RunWith(AllTests.class) +@RunWith(IgniteExamplesMLTestSuite.DynamicSuite.class) public class IgniteExamplesMLTestSuite { /** Base package to create test classes in. */ private static final String basePkgForTests = "org.apache.ignite.examples.ml"; @@ -66,18 +64,17 @@ public class IgniteExamplesMLTestSuite { } /** - * Creates test suite for Ignite ML examples. + * Creates list of test classes for Ignite ML examples. * - * @return Created suite. - * @throws Exception If failed. + * @return Created list. + * @throws IOException, ClassNotFoundException If failed. */ - public static TestSuite suite() throws Exception { - TestSuite suite = new TestSuite("Ignite ML Examples Test Suite"); - - for (Class clazz : getClasses(basePkgForTests)) - suite.addTest(new JUnit4TestAdapter(makeTestClass(clazz))); - - return suite; + public static Class<?>[] suite() throws IOException, ClassNotFoundException { + return getClasses(basePkgForTests) + .stream() + .map(IgniteExamplesMLTestSuite::makeTestClass) + .collect(Collectors.toList()) + .toArray(new Class[] {null}); } /** @@ -85,35 +82,39 @@ public class IgniteExamplesMLTestSuite { * * @param exampleCls Class of the example to be tested. * @return Test class. - * @throws NotFoundException If class not found. - * @throws CannotCompileException If test class cannot be compiled. */ - private static Class makeTestClass(Class<?> exampleCls) - throws NotFoundException, CannotCompileException { + private static Class<?> makeTestClass(Class<?> exampleCls) { ClassPool cp = ClassPool.getDefault(); cp.insertClassPath(new ClassClassPath(IgniteExamplesMLTestSuite.class)); CtClass cl = cp.makeClass(basePkgForTests + "." + exampleCls.getSimpleName() + "SelfTest"); - cl.setSuperclass(cp.get(GridAbstractExamplesTest.class.getName())); + try { + cl.setSuperclass(cp.get(GridAbstractExamplesTest.class.getName())); + + CtMethod mtd = CtNewMethod.make("public void testExample() { " + + exampleCls.getCanonicalName() + + ".main(" + + MLExamplesCommonArgs.class.getName() + + ".EMPTY_ARGS_ML); }", cl); + + // Create and add annotation. + ClassFile ccFile = cl.getClassFile(); + ConstPool constpool = ccFile.getConstPool(); - CtMethod mtd = CtNewMethod.make("public void testExample() { " - + exampleCls.getCanonicalName() - + ".main(" - + MLExamplesCommonArgs.class.getName() - + ".EMPTY_ARGS_ML); }", cl); + AnnotationsAttribute attr = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag); + Annotation annot = new Annotation("org.junit.Test", constpool); - // Create and add annotation. - ClassFile ccFile = cl.getClassFile(); - ConstPool constpool = ccFile.getConstPool(); - AnnotationsAttribute attr = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag); - Annotation annot = new Annotation("org.junit.Test", constpool); - attr.addAnnotation(annot); - mtd.getMethodInfo().addAttribute(attr); + attr.addAnnotation(annot); + mtd.getMethodInfo().addAttribute(attr); - cl.addMethod(mtd); + cl.addMethod(mtd); - return cl.toClass(); + return cl.toClass(); + } + catch (Exception e) { + throw new RuntimeException(e); + } } /** @@ -172,4 +173,12 @@ public class IgniteExamplesMLTestSuite { return classes; } + + /** */ + public static class DynamicSuite extends Suite { + /** */ + public DynamicSuite(Class<?> cls) throws InitializationError, IOException, ClassNotFoundException { + super(cls, suite()); + } + } } http://git-wip-us.apache.org/repos/asf/ignite/blob/f7642260/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java ---------------------------------------------------------------------- diff --git a/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java b/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java index 31e9a6c..a92d490 100644 --- a/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java +++ b/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java @@ -17,8 +17,6 @@ package org.apache.ignite.testsuites; -import junit.framework.JUnit4TestAdapter; -import junit.framework.TestSuite; import org.apache.ignite.examples.BasicExamplesMultiNodeSelfTest; import org.apache.ignite.examples.BasicExamplesSelfTest; import org.apache.ignite.examples.CacheClientBinaryExampleTest; @@ -50,64 +48,54 @@ import org.apache.ignite.examples.SqlExamplesSelfTest; import org.apache.ignite.examples.TaskExamplesMultiNodeSelfTest; import org.apache.ignite.examples.TaskExamplesSelfTest; import org.junit.runner.RunWith; -import org.junit.runners.AllTests; +import org.junit.runners.Suite; /** * Examples test suite. * <p> * Contains all Ignite examples tests.</p> */ -@RunWith(AllTests.class) -public class IgniteExamplesSelfTestSuite { - /** - * @return Suite. - */ - public static TestSuite suite() { -// System.setProperty(IGNITE_OVERRIDE_MCAST_GRP, -// GridTestUtils.getNextMulticastGroup(IgniteExamplesSelfTestSuite.class)); - - TestSuite suite = new TestSuite("Ignite Examples Test Suite"); - - suite.addTest(new JUnit4TestAdapter(CacheExamplesSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(SqlExamplesSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(BasicExamplesSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(ContinuationExamplesSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(ContinuousMapperExamplesSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(DeploymentExamplesSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(EventsExamplesSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(LifecycleExamplesSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(MessagingExamplesSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(MemcacheRestExamplesSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(MonteCarloExamplesSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(TaskExamplesSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(SpringBeanExamplesSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(SpringDataExampleSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(IgfsExamplesSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(CheckpointExamplesSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(ClusterGroupExampleSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(CacheContinuousQueryExamplesSelfTest.class)); +@RunWith(Suite.class) +@Suite.SuiteClasses({ + CacheExamplesSelfTest.class, + SqlExamplesSelfTest.class, + BasicExamplesSelfTest.class, + ContinuationExamplesSelfTest.class, + ContinuousMapperExamplesSelfTest.class, + DeploymentExamplesSelfTest.class, + EventsExamplesSelfTest.class, + LifecycleExamplesSelfTest.class, + MessagingExamplesSelfTest.class, + MemcacheRestExamplesSelfTest.class, + MonteCarloExamplesSelfTest.class, + TaskExamplesSelfTest.class, + SpringBeanExamplesSelfTest.class, + SpringDataExampleSelfTest.class, + IgfsExamplesSelfTest.class, + CheckpointExamplesSelfTest.class, + ClusterGroupExampleSelfTest.class, + CacheContinuousQueryExamplesSelfTest.class, - // Multi-node. - suite.addTest(new JUnit4TestAdapter(CacheExamplesMultiNodeSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(BasicExamplesMultiNodeSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(ContinuationExamplesMultiNodeSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(ContinuousMapperExamplesMultiNodeSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(DeploymentExamplesMultiNodeSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(EventsExamplesMultiNodeSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(TaskExamplesMultiNodeSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(MemcacheRestExamplesMultiNodeSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(MonteCarloExamplesMultiNodeSelfTest.class)); + // Multi-node. + CacheExamplesMultiNodeSelfTest.class, + BasicExamplesMultiNodeSelfTest.class, + ContinuationExamplesMultiNodeSelfTest.class, + ContinuousMapperExamplesMultiNodeSelfTest.class, + DeploymentExamplesMultiNodeSelfTest.class, + EventsExamplesMultiNodeSelfTest.class, + TaskExamplesMultiNodeSelfTest.class, + MemcacheRestExamplesMultiNodeSelfTest.class, + MonteCarloExamplesMultiNodeSelfTest.class, - // Binary. - suite.addTest(new JUnit4TestAdapter(CacheClientBinaryExampleTest.class)); - suite.addTest(new JUnit4TestAdapter(ComputeClientBinaryExampleTest.class)); + // Binary. + CacheClientBinaryExampleTest.class, + ComputeClientBinaryExampleTest.class, - // ML Grid. - suite.addTest(new JUnit4TestAdapter(IgniteExamplesMLTestSuite.class)); + // ML Grid. + IgniteExamplesMLTestSuite.class, - // Encryption. - suite.addTest(new JUnit4TestAdapter(EncryptedCacheExampleSelfTest.class)); - - return suite; - } + // Encryption. + EncryptedCacheExampleSelfTest.class, +}) +public class IgniteExamplesSelfTestSuite { } http://git-wip-us.apache.org/repos/asf/ignite/blob/f7642260/examples/src/test/spark/org/apache/ignite/spark/testsuites/IgniteExamplesSparkSelfTestSuite.java ---------------------------------------------------------------------- diff --git a/examples/src/test/spark/org/apache/ignite/spark/testsuites/IgniteExamplesSparkSelfTestSuite.java b/examples/src/test/spark/org/apache/ignite/spark/testsuites/IgniteExamplesSparkSelfTestSuite.java index 43a1198..5b75bb1 100644 --- a/examples/src/test/spark/org/apache/ignite/spark/testsuites/IgniteExamplesSparkSelfTestSuite.java +++ b/examples/src/test/spark/org/apache/ignite/spark/testsuites/IgniteExamplesSparkSelfTestSuite.java @@ -17,14 +17,13 @@ package org.apache.ignite.spark.testsuites; -import junit.framework.JUnit4TestAdapter; -import junit.framework.TestSuite; import org.apache.ignite.spark.examples.IgniteDataFrameSelfTest; import org.apache.ignite.spark.examples.JavaIgniteDataFrameSelfTest; import org.apache.ignite.spark.examples.SharedRDDExampleSelfTest; import org.apache.ignite.testframework.GridTestUtils; +import org.junit.BeforeClass; import org.junit.runner.RunWith; -import org.junit.runners.AllTests; +import org.junit.runners.Suite; import static org.apache.ignite.IgniteSystemProperties.IGNITE_OVERRIDE_MCAST_GRP; @@ -33,21 +32,17 @@ import static org.apache.ignite.IgniteSystemProperties.IGNITE_OVERRIDE_MCAST_GRP * <p> * Contains only Spring ignite examples tests. */ -@RunWith(AllTests.class) +@RunWith(Suite.class) +@Suite.SuiteClasses({ + SharedRDDExampleSelfTest.class, + IgniteDataFrameSelfTest.class, + JavaIgniteDataFrameSelfTest.class, +}) public class IgniteExamplesSparkSelfTestSuite { - /** - * @return Suite. - */ - public static TestSuite suite() { + /** */ + @BeforeClass + public static void init() { System.setProperty(IGNITE_OVERRIDE_MCAST_GRP, GridTestUtils.getNextMulticastGroup(IgniteExamplesSparkSelfTestSuite.class)); - - TestSuite suite = new TestSuite("Ignite Spark Examples Test Suite"); - - suite.addTest(new JUnit4TestAdapter(SharedRDDExampleSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(IgniteDataFrameSelfTest.class)); - suite.addTest(new JUnit4TestAdapter(JavaIgniteDataFrameSelfTest.class)); - - return suite; } } http://git-wip-us.apache.org/repos/asf/ignite/blob/f7642260/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 8441b0c..594dfd9 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,8 +18,6 @@ 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;