This is an automated email from the ASF dual-hosted git repository. ctubbsii pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push: new 09ae8477e6 Convert accumulo-start module to use JUnit5 (#2608) 09ae8477e6 is described below commit 09ae8477e6a8b141626045f34215b81caa98586c Author: AlbertWhitlock <albertwhitlo...@gmail.com> AuthorDate: Tue Apr 12 17:59:59 2022 -0400 Convert accumulo-start module to use JUnit5 (#2608) * Convert all tests to JUnit5 Jupiter engine, except for AccumuloVFSClassLoaderTest * Leave AccumuloVFSClassLoaderTest using the vintage engine because it uses PowerMock and cannot be converted until PowerMock works with JUnit5 --- start/pom.xml | 5 ++ .../classloader/vfs/AccumuloClasspathTest.java | 14 +++--- .../vfs/AccumuloReloadingVFSClassLoaderTest.java | 58 +++++++++++----------- .../start/classloader/vfs/ContextManagerTest.java | 35 ++++++------- .../start/classloader/vfs/WithTestNames.java | 42 ++++++++++++++++ .../vfs/providers/VfsClassLoaderTest.java | 14 +++--- .../accumulo/start/test/AccumuloDFSBase.java | 8 +-- 7 files changed, 111 insertions(+), 65 deletions(-) diff --git a/start/pom.xml b/start/pom.xml index a959f4ecdf..6f413d822d 100644 --- a/start/pom.xml +++ b/start/pom.xml @@ -74,6 +74,11 @@ <artifactId>log4j-slf4j-impl</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-api</artifactId> + <scope>test</scope> + </dependency> <dependency> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> diff --git a/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloClasspathTest.java b/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloClasspathTest.java index f2ff3ec3e8..04b3ec378b 100644 --- a/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloClasspathTest.java +++ b/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloClasspathTest.java @@ -18,22 +18,22 @@ */ package org.apache.accumulo.start.classloader.vfs; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.regex.Pattern; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class AccumuloClasspathTest { private static void assertPattern(String output, Pattern pattern, boolean shouldMatch) { if (shouldMatch) { - assertTrue("Pattern " + pattern + " did not match output: " + output, - pattern.matcher(output).matches()); + assertTrue(pattern.matcher(output).matches(), + "Pattern " + pattern + " did not match output: " + output); } else { - assertFalse("Pattern " + pattern + " should not match output: " + output, - pattern.matcher(output).matches()); + assertFalse(pattern.matcher(output).matches(), + "Pattern " + pattern + " should not match output: " + output); } } diff --git a/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloReloadingVFSClassLoaderTest.java b/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloReloadingVFSClassLoaderTest.java index 50206f32d2..13bfa549a8 100644 --- a/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloReloadingVFSClassLoaderTest.java +++ b/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloReloadingVFSClassLoaderTest.java @@ -18,44 +18,46 @@ */ package org.apache.accumulo.start.classloader.vfs; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; +import java.util.Objects; import org.apache.commons.io.FileUtils; import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileSystemManager; import org.apache.commons.vfs2.impl.VFSClassLoader; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @Deprecated @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "paths not set by user input") -public class AccumuloReloadingVFSClassLoaderTest { +public class AccumuloReloadingVFSClassLoaderTest extends WithTestNames { + + @TempDir + private static File folder1; + + private File tmpDir; - @Rule - public TemporaryFolder folder1 = - new TemporaryFolder(new File(System.getProperty("user.dir") + "/target")); String folderPath; private FileSystemManager vfs; - @Before + @BeforeEach public void setup() throws Exception { - vfs = ContextManagerTest.getVFS(); + tmpDir = new File(folder1, testName()); - folderPath = folder1.getRoot().toURI() + ".*"; - - FileUtils.copyURLToFile(this.getClass().getResource("/HelloWorld.jar"), - folder1.newFile("HelloWorld.jar")); + vfs = ContextManagerTest.getVFS(); + folderPath = tmpDir.toURI() + "/.*"; + FileUtils.copyURLToFile(Objects.requireNonNull(this.getClass().getResource("/HelloWorld.jar")), + new File(tmpDir, "HelloWorld.jar")); } FileObject[] createFileSystems(FileObject[] fos) throws FileSystemException { @@ -73,7 +75,7 @@ public class AccumuloReloadingVFSClassLoaderTest { @Test public void testConstructor() throws Exception { - FileObject testDir = vfs.resolveFile(folder1.getRoot().toURI().toString()); + FileObject testDir = vfs.resolveFile(tmpDir.toURI().toString()); FileObject[] dirContents = testDir.getChildren(); AccumuloReloadingVFSClassLoader arvcl = new AccumuloReloadingVFSClassLoader(folderPath, vfs, @@ -89,7 +91,7 @@ public class AccumuloReloadingVFSClassLoaderTest { @Test public void testReloading() throws Exception { - FileObject testDir = vfs.resolveFile(folder1.getRoot().toURI().toString()); + FileObject testDir = vfs.resolveFile(tmpDir.toURI().toString()); FileObject[] dirContents = testDir.getChildren(); AccumuloReloadingVFSClassLoader arvcl = new AccumuloReloadingVFSClassLoader(folderPath, vfs, @@ -109,14 +111,14 @@ public class AccumuloReloadingVFSClassLoaderTest { Class<?> clazz1_5 = arvcl.getClassLoader().loadClass("test.HelloWorld"); assertEquals(clazz1, clazz1_5); - assertTrue(new File(folder1.getRoot(), "HelloWorld.jar").delete()); + assertTrue(new File(tmpDir, "HelloWorld.jar").delete()); // VFS-487 significantly wait to avoid failure Thread.sleep(7000); // Update the class - FileUtils.copyURLToFile(this.getClass().getResource("/HelloWorld.jar"), - folder1.newFile("HelloWorld2.jar")); + FileUtils.copyURLToFile(Objects.requireNonNull(this.getClass().getResource("/HelloWorld.jar")), + new File(tmpDir, "HelloWorld2.jar")); // Wait for the monitor to notice // VFS-487 significantly wait to avoid failure @@ -135,7 +137,7 @@ public class AccumuloReloadingVFSClassLoaderTest { @Test public void testReloadingWithLongerTimeout() throws Exception { - FileObject testDir = vfs.resolveFile(folder1.getRoot().toURI().toString()); + FileObject testDir = vfs.resolveFile(tmpDir.toURI().toString()); FileObject[] dirContents = testDir.getChildren(); AccumuloReloadingVFSClassLoader arvcl = new AccumuloReloadingVFSClassLoader(folderPath, vfs, @@ -155,14 +157,14 @@ public class AccumuloReloadingVFSClassLoaderTest { Class<?> clazz1_5 = arvcl.getClassLoader().loadClass("test.HelloWorld"); assertEquals(clazz1, clazz1_5); - assertTrue(new File(folder1.getRoot(), "HelloWorld.jar").delete()); + assertTrue(new File(tmpDir, "HelloWorld.jar").delete()); // VFS-487 significantly wait to avoid failure Thread.sleep(7000); // Update the class - FileUtils.copyURLToFile(this.getClass().getResource("/HelloWorld.jar"), - folder1.newFile("HelloWorld2.jar")); + FileUtils.copyURLToFile(Objects.requireNonNull(this.getClass().getResource("/HelloWorld.jar")), + new File(tmpDir, "HelloWorld2.jar")); // Wait for the monitor to notice // VFS-487 significantly wait to avoid failure diff --git a/start/src/test/java/org/apache/accumulo/start/classloader/vfs/ContextManagerTest.java b/start/src/test/java/org/apache/accumulo/start/classloader/vfs/ContextManagerTest.java index 636a16c65c..ee8243dddc 100644 --- a/start/src/test/java/org/apache/accumulo/start/classloader/vfs/ContextManagerTest.java +++ b/start/src/test/java/org/apache/accumulo/start/classloader/vfs/ContextManagerTest.java @@ -18,34 +18,32 @@ */ package org.apache.accumulo.start.classloader.vfs; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; import java.io.File; import java.util.HashSet; +import java.util.Objects; import org.apache.commons.io.FileUtils; import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileSystemManager; import org.apache.commons.vfs2.impl.VFSClassLoader; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @Deprecated @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "paths not set by user input") public class ContextManagerTest { - - @Rule - public TemporaryFolder tempFolder = - new TemporaryFolder(new File(System.getProperty("user.dir") + "/target")); + @TempDir + private static File tempFolder; private FileSystemManager vfs; private File folder1; @@ -61,16 +59,15 @@ public class ContextManagerTest { } } - @Before + @BeforeEach public void setup() throws Exception { - vfs = getVFS(); - folder1 = tempFolder.newFolder(); - folder2 = tempFolder.newFolder(); + folder1 = new File(tempFolder, "folder1"); + folder2 = new File(tempFolder, "folder2"); - FileUtils.copyURLToFile(this.getClass().getResource("/HelloWorld.jar"), + FileUtils.copyURLToFile(Objects.requireNonNull(this.getClass().getResource("/HelloWorld.jar")), new File(folder1, "HelloWorld.jar")); - FileUtils.copyURLToFile(this.getClass().getResource("/HelloWorld.jar"), + FileUtils.copyURLToFile(Objects.requireNonNull(this.getClass().getResource("/HelloWorld.jar")), new File(folder2, "HelloWorld.jar")); uri1 = new File(folder1, "HelloWorld.jar").toURI().toString(); diff --git a/start/src/test/java/org/apache/accumulo/start/classloader/vfs/WithTestNames.java b/start/src/test/java/org/apache/accumulo/start/classloader/vfs/WithTestNames.java new file mode 100644 index 0000000000..bee3ca35f5 --- /dev/null +++ b/start/src/test/java/org/apache/accumulo/start/classloader/vfs/WithTestNames.java @@ -0,0 +1,42 @@ +/* + * 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.accumulo.start.classloader.vfs; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.TestInfo; + +// This is only for the unit tests and integration tests in this module +// It must be copied for use in other modules, because tests in one module +// don't have dependencies on other modules, and we can't put this in a +// regular, non-test jar, because we don't want to add a dependency on +// JUnit in a non-test jar +public class WithTestNames { + + private String testName; + + @BeforeEach + public void setTestName(TestInfo info) { + testName = info.getTestMethod().get().getName(); + } + + protected String testName() { + return testName; + } + +} diff --git a/start/src/test/java/org/apache/accumulo/start/classloader/vfs/providers/VfsClassLoaderTest.java b/start/src/test/java/org/apache/accumulo/start/classloader/vfs/providers/VfsClassLoaderTest.java index 2d687c5a4c..18dff46d76 100644 --- a/start/src/test/java/org/apache/accumulo/start/classloader/vfs/providers/VfsClassLoaderTest.java +++ b/start/src/test/java/org/apache/accumulo/start/classloader/vfs/providers/VfsClassLoaderTest.java @@ -18,8 +18,8 @@ */ package org.apache.accumulo.start.classloader.vfs.providers; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.net.URL; @@ -31,9 +31,9 @@ import org.apache.commons.vfs2.impl.DefaultFileMonitor; import org.apache.commons.vfs2.impl.VFSClassLoader; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class VfsClassLoaderTest extends AccumuloDFSBase { @@ -42,7 +42,7 @@ public class VfsClassLoaderTest extends AccumuloDFSBase { private FileSystem hdfs = null; private VFSClassLoader cl = null; - @Before + @BeforeEach public void setup() throws Exception { this.hdfs = cluster.getFileSystem(); @@ -106,7 +106,7 @@ public class VfsClassLoaderTest extends AccumuloDFSBase { } - @After + @AfterEach public void tearDown() throws Exception { this.hdfs.delete(TEST_DIR, true); } diff --git a/start/src/test/java/org/apache/accumulo/start/test/AccumuloDFSBase.java b/start/src/test/java/org/apache/accumulo/start/test/AccumuloDFSBase.java index 127e69c470..f070badd8e 100644 --- a/start/src/test/java/org/apache/accumulo/start/test/AccumuloDFSBase.java +++ b/start/src/test/java/org/apache/accumulo/start/test/AccumuloDFSBase.java @@ -34,8 +34,8 @@ import org.apache.commons.vfs2.provider.hdfs.HdfsFileProvider; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.MiniDFSCluster; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -52,7 +52,7 @@ public class AccumuloDFSBase { return HDFS_URI; } - @BeforeClass + @BeforeAll public static void miniDfsClusterSetup() { System.setProperty("java.io.tmpdir", System.getProperty("user.dir") + "/target"); // System.setProperty("org.apache.commons.logging.Log", @@ -127,7 +127,7 @@ public class AccumuloDFSBase { } - @AfterClass + @AfterAll public static void tearDownMiniDfsCluster() { if (null != cluster) { cluster.shutdown();