From bf88eb15601fc6317616e8a252fce702d74c3b7a Mon Sep 17 00:00:00 2001 From: domgarguilo Date: Thu, 24 Mar 2022 12:39:23 -0400 Subject: [PATCH] Migrate all tests to JUnit5 --- pom.xml | 12 ++-- .../apache/accumulo/examples/ExamplesIT.java | 42 ++++++------- .../AlphaNumKeyConstraintTest.java | 6 +- .../NumericValueConstraintTest.java | 6 +- .../accumulo/examples/dirlist/CountIT.java | 14 ++--- .../examples/filedata/ChunkCombinerTest.java | 60 +++++++++---------- .../examples/filedata/ChunkInputFormatIT.java | 27 ++++----- .../examples/filedata/ChunkInputStreamIT.java | 16 ++--- .../filedata/ChunkInputStreamTest.java | 12 ++-- .../examples/filedata/KeyUtilTest.java | 8 ++- .../examples/mapreduce/MapReduceIT.java | 4 +- 11 files changed, 103 insertions(+), 104 deletions(-) diff --git a/pom.xml b/pom.xml index 6f85a88..f5f385a 100644 --- a/pom.xml +++ b/pom.xml @@ -107,12 +107,6 @@ org.apache.zookeeper zookeeper - - - junit - junit - test - org.apache.accumulo accumulo-minicluster @@ -123,6 +117,12 @@ accumulo-test test + + + org.junit.jupiter + junit-jupiter-api + test + ${project.artifactId} diff --git a/src/test/java/org/apache/accumulo/examples/ExamplesIT.java b/src/test/java/org/apache/accumulo/examples/ExamplesIT.java index 11fcb9c..2840881 100644 --- a/src/test/java/org/apache/accumulo/examples/ExamplesIT.java +++ b/src/test/java/org/apache/accumulo/examples/ExamplesIT.java @@ -18,10 +18,11 @@ import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.BufferedWriter; import java.io.File; @@ -75,10 +76,9 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.junit.After; -import org.junit.Assert; -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; import com.google.common.collect.Iterators; @@ -100,7 +100,7 @@ public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration hadoo cfg.setProperty(Property.TSERV_NATIVEMAP_ENABLED, "false"); } - @Before + @BeforeEach public void setupTest() throws Exception { c = Accumulo.newClient().from(getClientProps()).build(); String user = c.whoami(); @@ -111,7 +111,7 @@ public void setupTest() throws Exception { String passwd = new String(((PasswordToken) getAdminToken()).getPassword(), UTF_8); writeClientPropsFile(getClientPropsFile(), instance, keepers, user, passwd); } else { - Assert.fail("Unknown token type: " + token); + fail("Unknown token type: " + token); } fs = getCluster().getFileSystem(); dir = new Path(cluster.getTemporaryPath(), getClass().getName()).toString(); @@ -120,7 +120,7 @@ public void setupTest() throws Exception { c.securityOperations().changeUserAuthorizations(user, new Authorizations(auths.split(","))); } - @After + @AfterEach public void teardownTest() throws Exception { if (null != origAuths) { c.securityOperations().changeUserAuthorizations(getAdminPrincipal(), origAuths); @@ -186,10 +186,10 @@ public void testStatsCombiner() throws Exception { bw.flush(); Iterator> iter = c.createScanner(table, Authorizations.EMPTY).iterator(); - assertTrue("Iterator had no results", iter.hasNext()); + assertTrue(iter.hasNext(), "Iterator had no results"); Entry e = iter.next(); - assertEquals("Results ", "1,3,4,2", e.getValue().toString()); - assertFalse("Iterator had additional results", iter.hasNext()); + assertEquals("1,3,4,2", e.getValue().toString(), "Results "); + assertFalse(iter.hasNext(), "Iterator had additional results"); m = new Mutation("foo"); m.put("a", "b", "0,20,20,2"); @@ -197,10 +197,10 @@ public void testStatsCombiner() throws Exception { bw.close(); iter = c.createScanner(table, Authorizations.EMPTY).iterator(); - assertTrue("Iterator had no results", iter.hasNext()); + assertTrue(iter.hasNext(), "Iterator had no results"); e = iter.next(); - assertEquals("Results ", "0,20,24,4", e.getValue().toString()); - assertFalse("Iterator had additional results", iter.hasNext()); + assertEquals("0,20,24,4", e.getValue().toString(), "Results "); + assertFalse(iter.hasNext(), "Iterator had additional results"); } @Test @@ -220,8 +220,10 @@ public void testShardedIndex() throws Exception { // should find ourselves boolean thisFile = false; for (String file : found) { - if (file.endsWith("/ExamplesIT.java")) + if (file.endsWith("/ExamplesIT.java")) { thisFile = true; + break; + } } assertTrue(thisFile); @@ -280,7 +282,7 @@ public void testWordCount() throws Exception { assumeTrue(getAdminToken() instanceof PasswordToken); Path readme = new Path(new Path(System.getProperty("user.dir")), "README.md"); if (!new File(readme.toString()).exists()) { - Assert.fail("README.md does not exist!"); + fail("README.md does not exist!"); } fs.copyFromLocalFile(readme, new Path(dir + "/tmp/wc/README.md")); String[] args = new String[] {"-c", getClientPropsFile(), "-i", dir + "/tmp/wc", "-t", @@ -333,6 +335,6 @@ private void goodExec(Class theClass, String... args) throws IOException { // We're already slurping stdout into memory (not redirecting to file). Might as well add it // to error message. pair = getClusterControl().execWithStdout(theClass, args); - Assert.assertEquals("stdout=" + pair.getValue(), 0, pair.getKey().intValue()); + assertEquals(0, pair.getKey().intValue(), "stdout=" + pair.getValue()); } } diff --git a/src/test/java/org/apache/accumulo/examples/constraints/AlphaNumKeyConstraintTest.java b/src/test/java/org/apache/accumulo/examples/constraints/AlphaNumKeyConstraintTest.java index dc2cece..a114ed9 100644 --- a/src/test/java/org/apache/accumulo/examples/constraints/AlphaNumKeyConstraintTest.java +++ b/src/test/java/org/apache/accumulo/examples/constraints/AlphaNumKeyConstraintTest.java @@ -16,13 +16,13 @@ */ package org.apache.accumulo.examples.constraints; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import org.apache.accumulo.core.data.Mutation; import org.apache.accumulo.core.data.Value; import org.apache.hadoop.io.Text; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.google.common.collect.ImmutableList; diff --git a/src/test/java/org/apache/accumulo/examples/constraints/NumericValueConstraintTest.java b/src/test/java/org/apache/accumulo/examples/constraints/NumericValueConstraintTest.java index 8e89545..1b0c72e 100644 --- a/src/test/java/org/apache/accumulo/examples/constraints/NumericValueConstraintTest.java +++ b/src/test/java/org/apache/accumulo/examples/constraints/NumericValueConstraintTest.java @@ -16,13 +16,13 @@ */ package org.apache.accumulo.examples.constraints; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import org.apache.accumulo.core.data.Mutation; import org.apache.accumulo.core.data.Value; import org.apache.hadoop.io.Text; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.google.common.collect.Iterables; diff --git a/src/test/java/org/apache/accumulo/examples/dirlist/CountIT.java b/src/test/java/org/apache/accumulo/examples/dirlist/CountIT.java index 950b295..51f6f9a 100644 --- a/src/test/java/org/apache/accumulo/examples/dirlist/CountIT.java +++ b/src/test/java/org/apache/accumulo/examples/dirlist/CountIT.java @@ -16,8 +16,8 @@ */ package org.apache.accumulo.examples.dirlist; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.util.ArrayList; import java.util.Map.Entry; @@ -39,9 +39,9 @@ import org.apache.accumulo.test.functional.ConfigurableMacBase; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.io.Text; -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 CountIT extends ConfigurableMacBase { @@ -53,7 +53,7 @@ protected void configure(MiniAccumuloConfigImpl cfg, Configuration hadoopCoreSit cfg.setProperty(Property.TSERV_NATIVEMAP_ENABLED, "false"); } - @Before + @BeforeEach public void setupInstance() throws Exception { tableName = getUniqueNames(1)[0]; client = Accumulo.newClient().from(getClientProperties()).build(); @@ -75,7 +75,7 @@ public void setupInstance() throws Exception { bw.close(); } - @After + @AfterEach public void teardown() { client.close(); } diff --git a/src/test/java/org/apache/accumulo/examples/filedata/ChunkCombinerTest.java b/src/test/java/org/apache/accumulo/examples/filedata/ChunkCombinerTest.java index e64f5fa..300637a 100644 --- a/src/test/java/org/apache/accumulo/examples/filedata/ChunkCombinerTest.java +++ b/src/test/java/org/apache/accumulo/examples/filedata/ChunkCombinerTest.java @@ -16,6 +16,11 @@ */ package org.apache.accumulo.examples.filedata; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + import java.io.IOException; import java.util.Collection; import java.util.Collections; @@ -33,10 +38,10 @@ import org.apache.accumulo.core.data.Value; import org.apache.accumulo.core.iterators.IteratorEnvironment; import org.apache.accumulo.core.iterators.SortedKeyValueIterator; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; - -public class ChunkCombinerTest extends TestCase { +public class ChunkCombinerTest { public static class MapIterator implements SortedKeyValueIterator { private Iterator> iter; @@ -76,7 +81,7 @@ public boolean hasTop() { } @Override - public void next() throws IOException { + public void next() { entry = null; while (iter.hasNext()) { entry = iter.next(); @@ -92,8 +97,7 @@ public void next() throws IOException { } @Override - public void seek(Range range, Collection columnFamilies, boolean inclusive) - throws IOException { + public void seek(Range range, Collection columnFamilies, boolean inclusive) { if (!inclusive) { throw new IllegalArgumentException("can only do inclusive colf filtering"); } @@ -114,43 +118,34 @@ public void seek(Range range, Collection columnFamilies, boolean i @Override public void init(SortedKeyValueIterator source, Map options, - IteratorEnvironment env) throws IOException { + IteratorEnvironment env) { throw new UnsupportedOperationException(); } } - private TreeMap row1; - private TreeMap row2; - private TreeMap row3; - private TreeMap allRows; + private static TreeMap allRows; - private TreeMap cRow1; - private TreeMap cRow2; - private TreeMap cRow3; - private TreeMap allCRows; + private static TreeMap allCRows; - private TreeMap cOnlyRow1; - private TreeMap cOnlyRow2; - private TreeMap cOnlyRow3; - private TreeMap allCOnlyRows; + private static TreeMap allCOnlyRows; - private TreeMap badrow; + private static TreeMap badrow; - @Override - protected void setUp() { - row1 = new TreeMap<>(); - row2 = new TreeMap<>(); - row3 = new TreeMap<>(); + @BeforeAll + protected static void setUp() { + TreeMap row1 = new TreeMap<>(); + TreeMap row2 = new TreeMap<>(); + TreeMap row3 = new TreeMap<>(); allRows = new TreeMap<>(); - cRow1 = new TreeMap<>(); - cRow2 = new TreeMap<>(); - cRow3 = new TreeMap<>(); + TreeMap cRow1 = new TreeMap<>(); + TreeMap cRow2 = new TreeMap<>(); + TreeMap cRow3 = new TreeMap<>(); allCRows = new TreeMap<>(); - cOnlyRow1 = new TreeMap<>(); - cOnlyRow2 = new TreeMap<>(); - cOnlyRow3 = new TreeMap<>(); + TreeMap cOnlyRow1 = new TreeMap<>(); + TreeMap cOnlyRow2 = new TreeMap<>(); + TreeMap cOnlyRow3 = new TreeMap<>(); allCOnlyRows = new TreeMap<>(); badrow = new TreeMap<>(); @@ -225,6 +220,7 @@ protected void setUp() { private static final Collection emptyColfs = new HashSet<>(); + @Test public void test1() throws IOException { runTest(false, allRows, allCRows, emptyColfs); runTest(true, allRows, allCRows, emptyColfs); @@ -250,7 +246,7 @@ private void runTest(boolean reseek, TreeMap source, TreeMap seen = new TreeMap<>(); while (iter.hasTop()) { - assertFalse("already contains " + iter.getTopKey(), seen.containsKey(iter.getTopKey())); + assertFalse(seen.containsKey(iter.getTopKey()), "already contains " + iter.getTopKey()); seen.put(new Key(iter.getTopKey()), new Value(iter.getTopValue())); if (reseek) diff --git a/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputFormatIT.java b/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputFormatIT.java index ee0900a..f24aa15 100644 --- a/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputFormatIT.java +++ b/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputFormatIT.java @@ -17,10 +17,10 @@ package org.apache.accumulo.examples.filedata; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; import java.io.File; import java.io.IOException; @@ -48,10 +48,10 @@ import org.apache.hadoop.mapreduce.lib.output.NullOutputFormat; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; @@ -75,19 +75,19 @@ public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration hadoo private AccumuloClient client; private String tableName; - @Before + @BeforeEach public void setupInstance() throws Exception { client = Accumulo.newClient().from(getClientProps()).build(); tableName = getUniqueNames(1)[0]; client.securityOperations().changeUserAuthorizations(client.whoami(), AUTHS); } - @After + @AfterEach public void teardown() { client.close(); } - @BeforeClass + @BeforeAll public static void setupClass() { System.setProperty("hadoop.tmp.dir", System.getProperty("user.dir") + "/target/hadoop-tmp"); @@ -154,7 +154,7 @@ protected void map(List> key, InputStream value, Context contex } @Override - protected void cleanup(Context context) throws IOException, InterruptedException { + protected void cleanup(Context context) { String table = context.getConfiguration().get("MRTester_tableName"); assertNotNull(table); @@ -203,8 +203,7 @@ protected void map(List> key, InputStream value, Context contex public static class TestBadData extends Mapper>,InputStream,List>,InputStream> { @Override - protected void map(List> key, InputStream value, Context context) - throws IOException, InterruptedException { + protected void map(List> key, InputStream value, Context context) { String table = context.getConfiguration().get("MRTester_tableName"); assertNotNull(table); diff --git a/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamIT.java b/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamIT.java index cf28d1d..66cb18c 100644 --- a/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamIT.java +++ b/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamIT.java @@ -17,8 +17,8 @@ package org.apache.accumulo.examples.filedata; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.io.IOException; import java.util.ArrayList; @@ -45,9 +45,9 @@ import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.io.Text; -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; import com.google.common.collect.Iterators; import com.google.common.collect.PeekingIterator; @@ -67,19 +67,19 @@ public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration hadoo private List> baddata; private List> multidata; - @Before + @BeforeEach public void setupInstance() throws Exception { client = Accumulo.newClient().from(getClientProps()).build(); tableName = getUniqueNames(1)[0]; client.securityOperations().changeUserAuthorizations(client.whoami(), AUTHS); } - @After + @AfterEach public void teardown() { client.close(); } - @Before + @BeforeEach public void setupData() { data = new ArrayList<>(); addData(data, "a", "refs", "id\0ext", "A&B", "ext"); diff --git a/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamTest.java b/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamTest.java index 2ff9892..e0bc356 100644 --- a/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamTest.java +++ b/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamTest.java @@ -16,9 +16,9 @@ */ package org.apache.accumulo.examples.filedata; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.util.ArrayList; @@ -29,8 +29,8 @@ import org.apache.accumulo.core.data.KeyValue; import org.apache.accumulo.core.data.Value; import org.apache.hadoop.io.Text; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,7 +43,7 @@ public class ChunkInputStreamTest { private List> baddata; private List> multidata; - @Before + @BeforeEach public void setupData() { data = new ArrayList<>(); addData(data, "a", "refs", "id\0ext", "A&B", "ext"); diff --git a/src/test/java/org/apache/accumulo/examples/filedata/KeyUtilTest.java b/src/test/java/org/apache/accumulo/examples/filedata/KeyUtilTest.java index 7f28882..245220a 100644 --- a/src/test/java/org/apache/accumulo/examples/filedata/KeyUtilTest.java +++ b/src/test/java/org/apache/accumulo/examples/filedata/KeyUtilTest.java @@ -16,11 +16,12 @@ */ package org.apache.accumulo.examples.filedata; -import org.apache.hadoop.io.Text; +import static org.junit.jupiter.api.Assertions.assertEquals; -import junit.framework.TestCase; +import org.apache.hadoop.io.Text; +import org.junit.jupiter.api.Test; -public class KeyUtilTest extends TestCase { +public class KeyUtilTest { public static void checkSeps(String... s) { Text t = KeyUtil.buildNullSepText(s); String[] rets = KeyUtil.splitNullSepText(t); @@ -34,6 +35,7 @@ public static void checkSeps(String... s) { assertEquals(s[i], rets[i]); } + @Test public void testNullSep() { checkSeps("abc", "d", "", "efgh"); checkSeps("ab", ""); diff --git a/src/test/java/org/apache/accumulo/examples/mapreduce/MapReduceIT.java b/src/test/java/org/apache/accumulo/examples/mapreduce/MapReduceIT.java index b77ae9e..1133195 100644 --- a/src/test/java/org/apache/accumulo/examples/mapreduce/MapReduceIT.java +++ b/src/test/java/org/apache/accumulo/examples/mapreduce/MapReduceIT.java @@ -16,7 +16,7 @@ */ package org.apache.accumulo.examples.mapreduce; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.security.MessageDigest; import java.util.Base64; @@ -40,7 +40,7 @@ import org.apache.accumulo.test.functional.ConfigurableMacBase; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.io.Text; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MapReduceIT extends ConfigurableMacBase {