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 ccc0a7a Convert tserver module tests from JUnit4 to JUnit5 (#2565) ccc0a7a is described below commit ccc0a7a815394fb958f09e143e02b194de2eadc4 Author: Dom G <dominic.gargu...@gmail.com> AuthorDate: Tue Mar 15 13:07:38 2022 -0400 Convert tserver module tests from JUnit4 to JUnit5 (#2565) --- server/tserver/pom.xml | 4 +- .../accumulo/tserver/AssignmentWatcherTest.java | 6 +- .../accumulo/tserver/BusiestTrackerTest.java | 6 +- .../accumulo/tserver/CheckTabletMetadataTest.java | 8 +-- .../accumulo/tserver/CountingIteratorTest.java | 4 +- .../apache/accumulo/tserver/InMemoryMapTest.java | 83 ++++++++++++---------- .../org/apache/accumulo/tserver/MemValueTest.java | 4 +- .../tserver/TabletResourceManagerTest.java | 8 +-- .../tserver/TabletServerSyncCheckTest.java | 4 +- .../accumulo/tserver/TservConstraintEnvTest.java | 6 +- .../accumulo/tserver/WalRemovalOrderTest.java | 4 +- .../{MemValueTest.java => WithTestNames.java} | 28 +++++--- .../tserver/compaction/CompactableUtilsTest.java | 4 +- .../tserver/compaction/CompactionPlanTest.java | 4 +- .../compaction/DefaultCompactionStrategyTest.java | 6 +- .../SizeLimitCompactionStrategyTest.java | 8 +-- .../tserver/compaction/SizeWindowTest.java | 6 +- .../strategies/BasicCompactionStrategyTest.java | 14 ++-- .../ConfigurableCompactionStrategyTest.java | 6 +- .../tserver/constraints/ConstraintCheckerTest.java | 10 +-- .../apache/accumulo/tserver/log/DfsLoggerTest.java | 4 +- .../apache/accumulo/tserver/log/LogEventsTest.java | 4 +- .../accumulo/tserver/log/LogFileKeyTest.java | 10 +-- .../tserver/log/RecoveryLogsIteratorTest.java | 53 +++++++------- .../tserver/log/SortedLogRecoveryTest.java | 31 ++++---- .../tserver/log/TestUpgradePathForWALogs.java | 46 ++++++------ .../accumulo/tserver/logger/LogFileTest.java | 6 +- .../memory/LargestFirstMemoryManagerTest.java | 14 ++-- .../replication/AccumuloReplicaSystemTest.java | 12 ++-- .../BatchWriterReplicationReplayerTest.java | 10 +-- .../replication/ReplicationProcessorTest.java | 6 +- .../tablet/CompactableImplFileManagerTest.java | 10 +-- .../tserver/tablet/CompactableImplTest.java | 6 +- .../tablet/TabletMutationPrepAttemptTest.java | 10 +-- .../apache/accumulo/tserver/tablet/TabletTest.java | 4 +- 35 files changed, 232 insertions(+), 217 deletions(-) diff --git a/server/tserver/pom.xml b/server/tserver/pom.xml index be5747f..2f62cad 100644 --- a/server/tserver/pom.xml +++ b/server/tserver/pom.xml @@ -120,8 +120,8 @@ <scope>test</scope> </dependency> <dependency> - <groupId>org.junit.vintage</groupId> - <artifactId>junit-vintage-engine</artifactId> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-api</artifactId> <scope>test</scope> </dependency> </dependencies> diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/AssignmentWatcherTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/AssignmentWatcherTest.java index bf55357..2680868 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/AssignmentWatcherTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/AssignmentWatcherTest.java @@ -30,8 +30,8 @@ import org.apache.accumulo.core.dataImpl.KeyExtent; import org.apache.accumulo.server.ServerContext; import org.apache.accumulo.tserver.TabletServerResourceManager.AssignmentWatcher; import org.easymock.EasyMock; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class AssignmentWatcherTest { @@ -40,7 +40,7 @@ public class AssignmentWatcherTest { private AccumuloConfiguration conf; private AssignmentWatcher watcher; - @Before + @BeforeEach public void setup() { assignments = new HashMap<>(); context = EasyMock.createMock(ServerContext.class); diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/BusiestTrackerTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/BusiestTrackerTest.java index 2404c54..26e04e3 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/BusiestTrackerTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/BusiestTrackerTest.java @@ -21,8 +21,8 @@ package org.apache.accumulo.tserver; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; -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.util.ArrayList; import java.util.Collection; @@ -34,7 +34,7 @@ import org.apache.accumulo.core.data.TableId; import org.apache.accumulo.core.dataImpl.KeyExtent; import org.apache.accumulo.core.util.ComparablePair; import org.apache.accumulo.tserver.tablet.Tablet; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.google.common.base.Preconditions; diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/CheckTabletMetadataTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/CheckTabletMetadataTest.java index 4bc8f89..1acc509 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/CheckTabletMetadataTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/CheckTabletMetadataTest.java @@ -19,9 +19,9 @@ package org.apache.accumulo.tserver; import static org.apache.accumulo.tserver.AssignmentHandler.checkTabletMetadata; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.EnumSet; import java.util.TreeMap; @@ -39,7 +39,7 @@ import org.apache.accumulo.core.metadata.schema.TabletMetadata; import org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType; import org.apache.accumulo.core.util.ColumnFQ; import org.apache.hadoop.io.Text; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CheckTabletMetadataTest { diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/CountingIteratorTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/CountingIteratorTest.java index 6594e91..a799ff7 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/CountingIteratorTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/CountingIteratorTest.java @@ -18,7 +18,7 @@ */ package org.apache.accumulo.tserver; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.util.HashSet; @@ -30,7 +30,7 @@ import org.apache.accumulo.core.data.Range; import org.apache.accumulo.core.data.Value; import org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator; import org.apache.accumulo.server.compaction.CountingIterator; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CountingIteratorTest { diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/InMemoryMapTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/InMemoryMapTest.java index 61956ca..8e91271 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/InMemoryMapTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/InMemoryMapTest.java @@ -18,10 +18,10 @@ */ package org.apache.accumulo.tserver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; @@ -57,20 +57,18 @@ import org.apache.accumulo.core.iteratorsImpl.system.IterationInterruptedExcepti import org.apache.accumulo.core.sample.impl.SamplerConfigurationImpl; import org.apache.accumulo.core.sample.impl.SamplerFactory; import org.apache.accumulo.core.util.LocalityGroupUtil; -import org.apache.accumulo.core.util.LocalityGroupUtil.LocalityGroupConfigurationError; import org.apache.accumulo.server.ServerContext; import org.apache.accumulo.tserver.InMemoryMap.MemoryIterator; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.io.Text; import org.easymock.EasyMock; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "paths not set by user input") -public class InMemoryMapTest { +public class InMemoryMapTest extends WithTestNames { private static class SampleIE implements IteratorEnvironment { @@ -107,9 +105,8 @@ public class InMemoryMapTest { return context; } - @Rule - public TemporaryFolder tempFolder = - new TemporaryFolder(new File(System.getProperty("user.dir") + "/target")); + @TempDir + private static File tempDir; public void mutate(InMemoryMap imm, String row, String column, long ts, String value) { Mutation m = new Mutation(new Text(row)); @@ -164,8 +161,7 @@ public class InMemoryMapTest { return config; } - static InMemoryMap newInMemoryMap(boolean useNative, String memDumpDir) - throws LocalityGroupConfigurationError { + static InMemoryMap newInMemoryMap(boolean useNative, String memDumpDir) { ConfigurationCopy config = new ConfigurationCopy(DefaultConfiguration.getInstance()); config.set(Property.TSERV_NATIVEMAP_ENABLED, "" + useNative); config.set(Property.TSERV_MEMDUMP_DIR, memDumpDir); @@ -174,7 +170,7 @@ public class InMemoryMapTest { @Test public void test2() throws Exception { - InMemoryMap imm = newInMemoryMap(false, tempFolder.newFolder().getAbsolutePath()); + InMemoryMap imm = newInMemoryMap(false, uniqueDirPaths(1)[0]); MemoryIterator ski1 = imm.skvIterator(null); mutate(imm, "r1", "foo:cq1", 3, "bar1"); @@ -192,7 +188,7 @@ public class InMemoryMapTest { @Test public void test3() throws Exception { - InMemoryMap imm = newInMemoryMap(false, tempFolder.newFolder().getAbsolutePath()); + InMemoryMap imm = newInMemoryMap(false, uniqueDirPaths(1)[0]); mutate(imm, "r1", "foo:cq1", 3, "bar1"); mutate(imm, "r1", "foo:cq1", 3, "bar2"); @@ -218,7 +214,7 @@ public class InMemoryMapTest { @Test public void test4() throws Exception { - InMemoryMap imm = newInMemoryMap(false, tempFolder.newFolder().getAbsolutePath()); + InMemoryMap imm = newInMemoryMap(false, uniqueDirPaths(1)[0]); mutate(imm, "r1", "foo:cq1", 3, "bar1"); mutate(imm, "r1", "foo:cq1", 3, "bar2"); @@ -251,7 +247,7 @@ public class InMemoryMapTest { @Test public void testDecodeValueModification() throws Exception { // This test case is the fix for ACCUMULO-4483 - InMemoryMap imm = newInMemoryMap(false, tempFolder.newFolder().getAbsolutePath()); + InMemoryMap imm = newInMemoryMap(false, uniqueDirPaths(1)[0]); mutate(imm, "r1", "foo:cq1", 3, ""); MemoryIterator ski1 = imm.skvIterator(null); @@ -269,7 +265,8 @@ public class InMemoryMapTest { @Test public void test5() throws Exception { - InMemoryMap imm = newInMemoryMap(false, tempFolder.newFolder().getAbsolutePath()); + String[] newFolders = uniqueDirPaths(2); + InMemoryMap imm = newInMemoryMap(false, newFolders[0]); mutate(imm, "r1", "foo:cq1", 3, "bar1"); mutate(imm, "r1", "foo:cq1", 3, "bar2"); @@ -287,7 +284,7 @@ public class InMemoryMapTest { ski1.close(); - imm = newInMemoryMap(false, tempFolder.newFolder().getAbsolutePath()); + imm = newInMemoryMap(false, newFolders[1]); mutate(imm, "r1", "foo:cq1", 3, "bar1"); mutate(imm, "r1", "foo:cq2", 3, "bar2"); @@ -308,7 +305,7 @@ public class InMemoryMapTest { @Test public void test6() throws Exception { - InMemoryMap imm = newInMemoryMap(false, tempFolder.newFolder().getAbsolutePath()); + InMemoryMap imm = newInMemoryMap(false, uniqueDirPaths(1)[0]); mutate(imm, "r1", "foo:cq1", 3, "bar1"); mutate(imm, "r1", "foo:cq2", 3, "bar2"); @@ -354,7 +351,7 @@ public class InMemoryMapTest { private void deepCopyAndDelete(int interleaving, boolean interrupt) throws Exception { // interleaving == 0 intentionally omitted, this runs the test w/o deleting in mem map - InMemoryMap imm = newInMemoryMap(false, tempFolder.newFolder().getAbsolutePath()); + InMemoryMap imm = newInMemoryMap(false, uniqueDirPaths(1)[0]); mutate(imm, "r1", "foo:cq1", 3, "bar1"); mutate(imm, "r1", "foo:cq2", 3, "bar2"); @@ -420,14 +417,14 @@ public class InMemoryMapTest { for (int i = 1; i <= 4; i++) { final int finalI = i; - assertThrows("i = " + finalI, IterationInterruptedException.class, - () -> deepCopyAndDelete(finalI, true)); + assertThrows(IterationInterruptedException.class, () -> deepCopyAndDelete(finalI, true), + "i = " + finalI); } } @Test public void testBug1() throws Exception { - InMemoryMap imm = newInMemoryMap(false, tempFolder.newFolder().getAbsolutePath()); + InMemoryMap imm = newInMemoryMap(false, uniqueDirPaths(1)[0]); for (int i = 0; i < 20; i++) { mutate(imm, "r1", "foo:cq" + i, 3, "bar" + i); @@ -455,7 +452,7 @@ public class InMemoryMapTest { @Test public void testSeekBackWards() throws Exception { - InMemoryMap imm = newInMemoryMap(false, tempFolder.newFolder().getAbsolutePath()); + InMemoryMap imm = newInMemoryMap(false, uniqueDirPaths(1)[0]); mutate(imm, "r1", "foo:cq1", 3, "bar1"); mutate(imm, "r1", "foo:cq2", 3, "bar2"); @@ -474,7 +471,7 @@ public class InMemoryMapTest { @Test public void testDuplicateKey() throws Exception { - InMemoryMap imm = newInMemoryMap(false, tempFolder.newFolder().getAbsolutePath()); + InMemoryMap imm = newInMemoryMap(false, uniqueDirPaths(1)[0]); Mutation m = new Mutation(new Text("r1")); m.put(new Text("foo"), new Text("cq"), 3, new Value("v1")); @@ -489,7 +486,7 @@ public class InMemoryMapTest { @Test public void testLocalityGroups() throws Exception { - ConfigurationCopy config = newConfig(tempFolder.newFolder().getAbsolutePath()); + ConfigurationCopy config = newConfig(uniqueDirPaths(1)[0]); config.set(Property.TABLE_LOCALITY_GROUP_PREFIX + "lg1", LocalityGroupUtil.encodeColumnFamilies(toTextSet("cf1", "cf2"))); config.set(Property.TABLE_LOCALITY_GROUP_PREFIX + "lg2", @@ -543,13 +540,13 @@ public class InMemoryMapTest { SamplerConfigurationImpl sampleConfig = new SamplerConfigurationImpl(RowSampler.class.getName(), Map.of("hasher", "murmur3_32", "modulus", "7")); Sampler sampler = SamplerFactory.newSampler(sampleConfig, DefaultConfiguration.getInstance()); - - ConfigurationCopy config1 = newConfig(tempFolder.newFolder().getAbsolutePath()); + String[] newFolders = uniqueDirPaths(2); + ConfigurationCopy config1 = newConfig(newFolders[0]); for (Entry<String,String> entry : sampleConfig.toTablePropertiesMap().entrySet()) { config1.set(entry.getKey(), entry.getValue()); } - ConfigurationCopy config2 = newConfig(tempFolder.newFolder().getAbsolutePath()); + ConfigurationCopy config2 = newConfig(newFolders[1]); config2.set(Property.TABLE_LOCALITY_GROUP_PREFIX + "lg1", LocalityGroupUtil.encodeColumnFamilies(toTextSet("cf2"))); config2.set(Property.TABLE_LOCALITY_GROUPS.getKey(), "lg1"); @@ -639,7 +636,7 @@ public class InMemoryMapTest { RowSampler.class.getName(), Map.of("hasher", "murmur3_32", "modulus", "2")); Sampler sampler = SamplerFactory.newSampler(sampleConfig1, DefaultConfiguration.getInstance()); - ConfigurationCopy config1 = newConfig(tempFolder.newFolder().getAbsolutePath()); + ConfigurationCopy config1 = newConfig(uniqueDirPaths(1)[0]); for (Entry<String,String> entry : sampleConfig1.toTablePropertiesMap().entrySet()) { config1.set(entry.getKey(), entry.getValue()); } @@ -693,11 +690,11 @@ public class InMemoryMapTest { } @Test - public void testDifferentSampleConfig() throws Exception { + public void testDifferentSampleConfig() { SamplerConfigurationImpl sampleConfig = new SamplerConfigurationImpl(RowSampler.class.getName(), Map.of("hasher", "murmur3_32", "modulus", "7")); - ConfigurationCopy config1 = newConfig(tempFolder.newFolder().getAbsolutePath()); + ConfigurationCopy config1 = newConfig(uniqueDirPaths(1)[0]); for (Entry<String,String> entry : sampleConfig.toTablePropertiesMap().entrySet()) { config1.set(entry.getKey(), entry.getValue()); } @@ -713,8 +710,8 @@ public class InMemoryMapTest { } @Test - public void testNoSampleConfig() throws Exception { - InMemoryMap imm = newInMemoryMap(false, tempFolder.newFolder().getAbsolutePath()); + public void testNoSampleConfig() { + InMemoryMap imm = newInMemoryMap(false, uniqueDirPaths(1)[0]); mutate(imm, "r", "cf:cq", 5, "b"); @@ -726,7 +723,7 @@ public class InMemoryMapTest { @Test public void testEmptyNoSampleConfig() throws Exception { - InMemoryMap imm = newInMemoryMap(false, tempFolder.newFolder().getAbsolutePath()); + InMemoryMap imm = newInMemoryMap(false, uniqueDirPaths(1)[0]); SamplerConfigurationImpl sampleConfig2 = new SamplerConfigurationImpl( RowSampler.class.getName(), Map.of("hasher", "murmur3_32", "modulus", "9")); @@ -742,7 +739,7 @@ public class InMemoryMapTest { SamplerConfigurationImpl sampleConfig1 = new SamplerConfigurationImpl( RowSampler.class.getName(), Map.of("hasher", "murmur3_32", "modulus", "9")); - ConfigurationCopy config1 = newConfig(tempFolder.newFolder().getAbsolutePath()); + ConfigurationCopy config1 = newConfig(uniqueDirPaths(1)[0]); for (Entry<String,String> entry : sampleConfig1.toTablePropertiesMap().entrySet()) { config1.set(entry.getKey(), entry.getValue()); } @@ -781,6 +778,16 @@ public class InMemoryMapTest { () -> finalIter.seek(new Range(), Set.of(), false)); } + private String[] uniqueDirPaths(int numOfDirs) { + String[] newDirs = new String[numOfDirs]; + for (int i = 0; i < newDirs.length; i++) { + File newDir = new File(tempDir, testName() + i); + assertTrue(newDir.isDirectory() || newDir.mkdir(), "Failed to create directory: " + newDir); + newDirs[i] = newDir.getAbsolutePath(); + } + return newDirs; + } + private TreeMap<Key,Value> readAll(SortedKeyValueIterator<Key,Value> iter) throws IOException { iter.seek(new Range(), Set.of(), false); diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/MemValueTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/MemValueTest.java index c6e7a56..a6d5d7e 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/MemValueTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/MemValueTest.java @@ -18,10 +18,10 @@ */ package org.apache.accumulo.tserver; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.apache.accumulo.core.data.Value; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MemValueTest { diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/TabletResourceManagerTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/TabletResourceManagerTest.java index b02db75..d66a1bb 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/TabletResourceManagerTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/TabletResourceManagerTest.java @@ -19,13 +19,13 @@ package org.apache.accumulo.tserver; import static org.easymock.EasyMock.createMock; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.apache.accumulo.core.dataImpl.KeyExtent; import org.apache.accumulo.server.conf.TableConfiguration; import org.apache.accumulo.tserver.TabletServerResourceManager.TabletResourceManager; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class TabletResourceManagerTest { private TabletServerResourceManager tsrm; @@ -33,7 +33,7 @@ public class TabletResourceManagerTest { private KeyExtent extent; private TableConfiguration conf; - @Before + @BeforeEach public void setUp() { tsrm = createMock(TabletServerResourceManager.class); extent = createMock(KeyExtent.class); diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/TabletServerSyncCheckTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/TabletServerSyncCheckTest.java index 473fbee..86fdc63 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/TabletServerSyncCheckTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/TabletServerSyncCheckTest.java @@ -18,7 +18,7 @@ */ package org.apache.accumulo.tserver; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.Collections; import java.util.Map; @@ -36,7 +36,7 @@ import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hdfs.DistributedFileSystem; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TabletServerSyncCheckTest { private static final String DFS_SUPPORT_APPEND = "dfs.support.append"; diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/TservConstraintEnvTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/TservConstraintEnvTest.java index f5d54ef..877a6d7 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/TservConstraintEnvTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/TservConstraintEnvTest.java @@ -21,8 +21,8 @@ package org.apache.accumulo.tserver; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; -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.nio.ByteBuffer; import java.util.Collections; @@ -32,7 +32,7 @@ import org.apache.accumulo.core.data.ArrayByteSequence; import org.apache.accumulo.core.data.ByteSequence; import org.apache.accumulo.core.securityImpl.thrift.TCredentials; import org.apache.accumulo.server.security.SecurityOperation; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TservConstraintEnvTest { diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/WalRemovalOrderTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/WalRemovalOrderTest.java index c9b86c4..ef8dac1 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/WalRemovalOrderTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/WalRemovalOrderTest.java @@ -18,7 +18,7 @@ */ package org.apache.accumulo.tserver; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Collections; import java.util.LinkedHashSet; @@ -31,7 +31,7 @@ import org.apache.accumulo.server.fs.VolumeManager; import org.apache.accumulo.tserver.TabletServer.ReferencedRemover; import org.apache.accumulo.tserver.log.DfsLogger; import org.apache.accumulo.tserver.log.DfsLogger.ServerResources; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.google.common.collect.Sets; diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/MemValueTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/WithTestNames.java similarity index 57% copy from server/tserver/src/test/java/org/apache/accumulo/tserver/MemValueTest.java copy to server/tserver/src/test/java/org/apache/accumulo/tserver/WithTestNames.java index c6e7a56..04dcc17 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/MemValueTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/WithTestNames.java @@ -18,19 +18,25 @@ */ package org.apache.accumulo.tserver; -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.TestInfo; -import org.apache.accumulo.core.data.Value; -import org.junit.Test; +// 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 { -public class MemValueTest { + private String testName; - @Test - public void testDecodeDoesntModifyInputValue() { - Value v = new Value("2.0"); - Value encodedValue = MemValue.encode(v, 3); - MemValue m1 = MemValue.decode(encodedValue); - MemValue m2 = MemValue.decode(encodedValue); - assertEquals(m1.kvCount, m2.kvCount); + @BeforeEach + public void setTestName(TestInfo info) { + testName = info.getTestMethod().get().getName(); } + + protected String testName() { + return testName; + } + } diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/CompactableUtilsTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/CompactableUtilsTest.java index d77b2c4..897d393 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/CompactableUtilsTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/CompactableUtilsTest.java @@ -18,12 +18,12 @@ */ package org.apache.accumulo.tserver.compaction; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.apache.accumulo.core.metadata.TabletFile; import org.apache.accumulo.tserver.tablet.CompactableUtils; import org.apache.hadoop.fs.Path; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CompactableUtilsTest { diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/CompactionPlanTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/CompactionPlanTest.java index 9df184a..52c8eab 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/CompactionPlanTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/CompactionPlanTest.java @@ -18,12 +18,12 @@ */ package org.apache.accumulo.tserver.compaction; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.Set; import org.apache.accumulo.core.metadata.StoredTabletFile; -import org.junit.Test; +import org.junit.jupiter.api.Test; @SuppressWarnings("removal") public class CompactionPlanTest { diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/DefaultCompactionStrategyTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/DefaultCompactionStrategyTest.java index 07728a3..fdd4540 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/DefaultCompactionStrategyTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/DefaultCompactionStrategyTest.java @@ -18,8 +18,8 @@ */ package org.apache.accumulo.tserver.compaction; -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.io.DataInputStream; import java.util.ArrayList; @@ -57,7 +57,7 @@ import org.apache.accumulo.core.util.Pair; import org.apache.accumulo.server.ServerContext; import org.apache.hadoop.io.Text; import org.easymock.EasyMock; -import org.junit.Test; +import org.junit.jupiter.api.Test; @SuppressWarnings("removal") public class DefaultCompactionStrategyTest { diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/SizeLimitCompactionStrategyTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/SizeLimitCompactionStrategyTest.java index f9c81dd..476ab52 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/SizeLimitCompactionStrategyTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/SizeLimitCompactionStrategyTest.java @@ -19,9 +19,9 @@ package org.apache.accumulo.tserver.compaction; import static org.apache.accumulo.tserver.compaction.DefaultCompactionStrategyTest.getServerContext; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +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 java.io.IOException; import java.util.HashMap; @@ -34,7 +34,7 @@ import org.apache.accumulo.core.data.TableId; import org.apache.accumulo.core.dataImpl.KeyExtent; import org.apache.accumulo.core.metadata.StoredTabletFile; import org.apache.accumulo.core.metadata.schema.DataFileValue; -import org.junit.Test; +import org.junit.jupiter.api.Test; @SuppressWarnings("removal") public class SizeLimitCompactionStrategyTest { diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/SizeWindowTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/SizeWindowTest.java index 4b9e0fb..aeab0f4 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/SizeWindowTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/SizeWindowTest.java @@ -18,8 +18,8 @@ */ package org.apache.accumulo.tserver.compaction; -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.util.Collection; import java.util.HashMap; @@ -30,7 +30,7 @@ import org.apache.accumulo.core.metadata.StoredTabletFile; import org.apache.accumulo.core.metadata.TabletFile; import org.apache.accumulo.core.metadata.schema.DataFileValue; import org.apache.accumulo.tserver.compaction.DefaultCompactionStrategy.SizeWindow; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SizeWindowTest { diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/strategies/BasicCompactionStrategyTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/strategies/BasicCompactionStrategyTest.java index 4120cd9..4c047e2 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/strategies/BasicCompactionStrategyTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/strategies/BasicCompactionStrategyTest.java @@ -19,10 +19,10 @@ package org.apache.accumulo.tserver.compaction.strategies; import static org.apache.accumulo.tserver.compaction.DefaultCompactionStrategyTest.getServerContext; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.HashMap; @@ -41,8 +41,8 @@ import org.apache.accumulo.tserver.InMemoryMapTest; import org.apache.accumulo.tserver.compaction.MajorCompactionReason; import org.apache.accumulo.tserver.compaction.MajorCompactionRequest; import org.apache.accumulo.tserver.compaction.SizeLimitCompactionStrategyTest; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests org.apache.accumulo.tserver.compaction.BasicCompactionStrategy @@ -66,7 +66,7 @@ public class BasicCompactionStrategyTest { return ret; } - @Before + @BeforeEach public void setup() { opts.put(BasicCompactionStrategy.LARGE_FILE_COMPRESSION_TYPE, largeCompressionType); opts.put(BasicCompactionStrategy.LARGE_FILE_COMPRESSION_THRESHOLD, "500M"); diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/strategies/ConfigurableCompactionStrategyTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/strategies/ConfigurableCompactionStrategyTest.java index ca3537f..0c2176f 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/strategies/ConfigurableCompactionStrategyTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/compaction/strategies/ConfigurableCompactionStrategyTest.java @@ -19,8 +19,8 @@ package org.apache.accumulo.tserver.compaction.strategies; import static org.apache.accumulo.core.conf.ConfigurationTypeHelper.getFixedMemoryAsBytes; -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.URI; import java.net.URISyntaxException; @@ -36,7 +36,7 @@ import org.apache.accumulo.core.client.admin.compaction.CompactionConfigurer.Ove import org.apache.accumulo.core.compaction.CompactionSettings; import org.apache.accumulo.core.conf.Property; import org.apache.accumulo.core.data.TableId; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ConfigurableCompactionStrategyTest { diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/constraints/ConstraintCheckerTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/constraints/ConstraintCheckerTest.java index e6f9c82..9d206f3 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/constraints/ConstraintCheckerTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/constraints/ConstraintCheckerTest.java @@ -23,8 +23,8 @@ import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.createMockBuilder; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; -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 java.util.ArrayList; import java.util.HashSet; @@ -37,8 +37,8 @@ import org.apache.accumulo.core.data.TabletId; import org.apache.accumulo.core.data.constraints.Constraint; import org.apache.accumulo.core.data.constraints.Constraint.Environment; 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 com.google.common.collect.Iterables; @@ -51,7 +51,7 @@ public class ConstraintCheckerTest { private Mutation m; private Mutation m2; - @Before + @BeforeEach public void setup() throws SecurityException { cc = createMockBuilder(ConstraintChecker.class).addMockedMethod("getConstraints").createMock(); constraints = new ArrayList<>(); diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/log/DfsLoggerTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/log/DfsLoggerTest.java index 2b79fd0..d12c227 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/log/DfsLoggerTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/log/DfsLoggerTest.java @@ -18,7 +18,7 @@ */ package org.apache.accumulo.tserver.log; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.ArrayList; import java.util.Collection; @@ -29,7 +29,7 @@ import org.apache.accumulo.core.client.Durability; import org.apache.accumulo.tserver.TabletMutations; import org.apache.accumulo.tserver.tablet.CommitSession; import org.easymock.EasyMock; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class DfsLoggerTest { diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/log/LogEventsTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/log/LogEventsTest.java index 5673069..4e847af 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/log/LogEventsTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/log/LogEventsTest.java @@ -18,10 +18,10 @@ */ package org.apache.accumulo.tserver.log; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.apache.accumulo.tserver.logger.LogEvents; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class LogEventsTest { @Test diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/log/LogFileKeyTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/log/LogFileKeyTest.java index 03bf876..436b9eb 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/log/LogFileKeyTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/log/LogFileKeyTest.java @@ -18,8 +18,8 @@ */ package org.apache.accumulo.tserver.log; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; import java.util.ArrayList; @@ -32,7 +32,7 @@ import org.apache.accumulo.core.dataImpl.KeyExtent; import org.apache.accumulo.tserver.logger.LogEvents; import org.apache.accumulo.tserver.logger.LogFileKey; import org.apache.hadoop.io.Text; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class LogFileKeyTest { @@ -111,8 +111,8 @@ public class LogFileKeyTest { Key k = logFileKey.toKey(); var converted = LogFileKey.fromKey(k); - assertEquals("Failed to convert tabletId = " + tabletId + " seq = " + seq, logFileKey, - converted); + assertEquals(logFileKey, converted, + "Failed to convert tabletId = " + tabletId + " seq = " + seq); } @Test diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/log/RecoveryLogsIteratorTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/log/RecoveryLogsIteratorTest.java index d6a013e..c8905bf 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/log/RecoveryLogsIteratorTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/log/RecoveryLogsIteratorTest.java @@ -23,10 +23,9 @@ import static org.apache.accumulo.tserver.logger.LogEvents.OPEN; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.File; import java.io.IOException; @@ -47,20 +46,20 @@ import org.apache.accumulo.server.ServerContext; import org.apache.accumulo.server.fs.VolumeManager; import org.apache.accumulo.server.fs.VolumeManagerImpl; import org.apache.accumulo.server.log.SortedLogState; +import org.apache.accumulo.tserver.WithTestNames; import org.apache.accumulo.tserver.logger.LogFileKey; import org.apache.accumulo.tserver.logger.LogFileValue; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterEach; +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; @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "paths not set by user input") -public class RecoveryLogsIteratorTest { +public class RecoveryLogsIteratorTest extends WithTestNames { private VolumeManager fs; private File workDir; @@ -68,18 +67,16 @@ public class RecoveryLogsIteratorTest { static ServerContext context; static LogSorter logSorter; - @Rule - public TemporaryFolder tempFolder = - new TemporaryFolder(new File(System.getProperty("user.dir") + "/target")); + @TempDir + private static File tempDir; - @Before + @BeforeEach public void setUp() throws Exception { context = createMock(ServerContext.class); logSorter = new LogSorter(context, DefaultConfiguration.getInstance()); - workDir = tempFolder.newFolder(); + workDir = new File(tempDir, testName()); String path = workDir.getAbsolutePath(); - assertTrue(workDir.delete()); fs = VolumeManagerImpl.getLocalForTesting(path); expect(context.getVolumeManager()).andReturn(fs).anyTimes(); expect(context.getCryptoService()).andReturn(CryptoServiceFactory.newDefaultInstance()) @@ -88,7 +85,7 @@ public class RecoveryLogsIteratorTest { replay(context); } - @After + @AfterEach public void tearDown() throws Exception { fs.close(); } @@ -138,8 +135,8 @@ public class RecoveryLogsIteratorTest { try (RecoveryLogsIterator rli = new RecoveryLogsIterator(context, dirs, null, null, false)) { while (rli.hasNext()) { Entry<LogFileKey,LogFileValue> entry = rli.next(); - assertEquals("TabletId does not match", 1, entry.getKey().tabletId); - assertEquals("Event does not match", DEFINE_TABLET, entry.getKey().event); + assertEquals(1, entry.getKey().tabletId, "TabletId does not match"); + assertEquals(DEFINE_TABLET, entry.getKey().event, "Event does not match"); } } } @@ -161,8 +158,9 @@ public class RecoveryLogsIteratorTest { createRecoveryDir(logs, dirs, false); - assertThrows("Finish marker should not be found", IOException.class, - () -> new RecoveryLogsIterator(context, dirs, null, null, false)); + assertThrows(IOException.class, + () -> new RecoveryLogsIterator(context, dirs, null, null, false), + "Finish marker should not be found"); } @Test @@ -170,9 +168,10 @@ public class RecoveryLogsIteratorTest { String destPath = workDir + "/test.rf"; fs.create(new Path(destPath)); - assertThrows("Finish marker should not be found for a single file.", IOException.class, - () -> new RecoveryLogsIterator(context, Collections.singletonList(new Path(destPath)), null, - null, false)); + assertThrows( + IOException.class, () -> new RecoveryLogsIterator(context, + Collections.singletonList(new Path(destPath)), null, null, false), + "Finish marker should not be found for a single file."); } @Test @@ -192,9 +191,9 @@ public class RecoveryLogsIteratorTest { createRecoveryDir(logs, dirs, true); - assertThrows("First log entry is not OPEN so exception should be thrown.", - IllegalStateException.class, - () -> new RecoveryLogsIterator(context, dirs, null, null, true)); + assertThrows(IllegalStateException.class, + () -> new RecoveryLogsIterator(context, dirs, null, null, true), + "First log entry is not OPEN so exception should be thrown."); } @Test diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/log/SortedLogRecoveryTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/log/SortedLogRecoveryTest.java index 415b7ed..e0671a5 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/log/SortedLogRecoveryTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/log/SortedLogRecoveryTest.java @@ -27,9 +27,9 @@ import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.reset; import static org.easymock.EasyMock.verify; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; @@ -61,6 +61,7 @@ import org.apache.accumulo.server.ServerContext; import org.apache.accumulo.server.data.ServerMutation; import org.apache.accumulo.server.fs.VolumeManagerImpl; import org.apache.accumulo.server.log.SortedLogState; +import org.apache.accumulo.tserver.WithTestNames; import org.apache.accumulo.tserver.logger.LogEvents; import org.apache.accumulo.tserver.logger.LogFileKey; import org.apache.accumulo.tserver.logger.LogFileValue; @@ -69,15 +70,14 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.Text; import org.easymock.EasyMock; -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; @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "paths not set by user input") -public class SortedLogRecoveryTest { +public class SortedLogRecoveryTest extends WithTestNames { static final int bufferSize = 5; static final KeyExtent extent = new KeyExtent(TableId.of("table"), null, null); @@ -87,11 +87,10 @@ public class SortedLogRecoveryTest { static ServerContext context; static LogSorter logSorter; - @Rule - public TemporaryFolder tempFolder = - new TemporaryFolder(new File(System.getProperty("user.dir") + "/target")); + @TempDir + private static File tempDir; - @Before + @BeforeEach public void setup() { context = EasyMock.createMock(ServerContext.class); logSorter = new LogSorter(context, DefaultConfiguration.getInstance()); @@ -166,7 +165,7 @@ public class SortedLogRecoveryTest { private List<Mutation> recover(Map<String,KeyValue[]> logs, Set<String> files, KeyExtent extent, int bufferSize) throws IOException { - final String workdir = tempFolder.newFolder().getAbsolutePath(); + final String workdir = new File(tempDir, testName()).getAbsolutePath(); try (var fs = VolumeManagerImpl.getLocalForTesting(workdir)) { expect(context.getVolumeManager()).andReturn(fs).anyTimes(); expect(context.getCryptoService()).andReturn(CryptoServiceFactory.newDefaultInstance()) @@ -1074,8 +1073,8 @@ public class SortedLogRecoveryTest { // test all the possible properties for tserver.sort.file. prefix String prop = Property.TSERV_WAL_SORT_FILE_PREFIX + "invalid"; testConfig.set(prop, "snappy"); - assertThrows("Did not throw IllegalArgumentException for " + prop, - IllegalArgumentException.class, () -> new LogSorter(context, testConfig)); + assertThrows(IllegalArgumentException.class, () -> new LogSorter(context, testConfig), + "Did not throw IllegalArgumentException for " + prop); } @Test @@ -1095,7 +1094,7 @@ public class SortedLogRecoveryTest { testConfig.set(prefix + "replication", "3"); LogSorter sorter = new LogSorter(context, testConfig); - final String workdir = tempFolder.newFolder().getAbsolutePath(); + final String workdir = new File(tempDir, testName()).getAbsolutePath(); try (var vm = VolumeManagerImpl.getLocalForTesting(workdir)) { expect(context.getVolumeManager()).andReturn(vm).anyTimes(); diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/log/TestUpgradePathForWALogs.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/log/TestUpgradePathForWALogs.java index 23614bd..b030560 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/log/TestUpgradePathForWALogs.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/log/TestUpgradePathForWALogs.java @@ -23,9 +23,9 @@ import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.FileOutputStream; @@ -39,19 +39,19 @@ import org.apache.accumulo.core.crypto.CryptoServiceFactory; import org.apache.accumulo.server.ServerContext; import org.apache.accumulo.server.fs.VolumeManager; import org.apache.accumulo.server.fs.VolumeManagerImpl; +import org.apache.accumulo.tserver.WithTestNames; import org.apache.commons.io.IOUtils; import org.apache.hadoop.fs.Path; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterEach; +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; @SuppressFBWarnings(value = {"PATH_TRAVERSAL_IN", "PATH_TRAVERSAL_OUT"}, justification = "paths not set by user input") -public class TestUpgradePathForWALogs { +public class TestUpgradePathForWALogs extends WithTestNames { // older logs no longer compatible private static final String WALOG_FROM_15 = "/walog-from-15.walog"; @@ -63,16 +63,22 @@ public class TestUpgradePathForWALogs { private static final AccumuloConfiguration config = DefaultConfiguration.getInstance(); private ServerContext context; - @Rule - public TemporaryFolder tempFolder = - new TemporaryFolder(new File(System.getProperty("user.dir"), "target")); + @TempDir + private static File tempDir; - @Before + private static File perTestTempSubDir; + + @BeforeEach public void setUp() throws Exception { context = createMock(ServerContext.class); - File workDir = tempFolder.newFolder(); - String path = workDir.getAbsolutePath(); - assertTrue(workDir.delete()); + + // Create a new subdirectory for each test + perTestTempSubDir = new File(tempDir, testName()); + assertTrue(perTestTempSubDir.isDirectory() || perTestTempSubDir.mkdir(), + "Failed to create folder: " + perTestTempSubDir); + + String path = perTestTempSubDir.getAbsolutePath(); + VolumeManager fs = VolumeManagerImpl.getLocalForTesting(path); expect(context.getCryptoService()).andReturn(CryptoServiceFactory.newDefaultInstance()) .anyTimes(); @@ -80,7 +86,7 @@ public class TestUpgradePathForWALogs { replay(context); } - @After + @AfterEach public void tearDown() { verify(context); } @@ -91,7 +97,7 @@ public class TestUpgradePathForWALogs { @Test public void testUpgradeOf15WALog() throws IOException { String walogToTest = WALOG_FROM_15; - String testPath = tempFolder.getRoot().getAbsolutePath(); + String testPath = perTestTempSubDir.getAbsolutePath(); try (InputStream walogStream = getClass().getResourceAsStream(walogToTest); OutputStream walogInHDFStream = new FileOutputStream(testPath + walogToTest)) { @@ -111,7 +117,7 @@ public class TestUpgradePathForWALogs { @Test public void testBasic16WALogRead() throws IOException { String walogToTest = WALOG_FROM_16; - String testPath = tempFolder.getRoot().getAbsolutePath(); + String testPath = perTestTempSubDir.getAbsolutePath(); String destPath = "file://" + testPath + "/manyMaps"; try (InputStream walogStream = getClass().getResourceAsStream(walogToTest); @@ -135,7 +141,7 @@ public class TestUpgradePathForWALogs { @Test public void testBasic20WALogRead() throws IOException { String walogToTest = WALOG_FROM_20; - String testPath = tempFolder.getRoot().getAbsolutePath(); + String testPath = perTestTempSubDir.getAbsolutePath(); String destPath = "file://" + testPath + "/manyMaps"; try (InputStream walogStream = getClass().getResourceAsStream(walogToTest); diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/logger/LogFileTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/logger/LogFileTest.java index dcc2196..c21eaa4 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/logger/LogFileTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/logger/LogFileTest.java @@ -24,8 +24,8 @@ import static org.apache.accumulo.tserver.logger.LogEvents.DEFINE_TABLET; import static org.apache.accumulo.tserver.logger.LogEvents.MANY_MUTATIONS; import static org.apache.accumulo.tserver.logger.LogEvents.MUTATION; import static org.apache.accumulo.tserver.logger.LogEvents.OPEN; -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.io.IOException; import java.util.Arrays; @@ -39,7 +39,7 @@ import org.apache.accumulo.server.data.ServerMutation; import org.apache.hadoop.io.DataInputBuffer; import org.apache.hadoop.io.DataOutputBuffer; import org.apache.hadoop.io.Text; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class LogFileTest { diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/memory/LargestFirstMemoryManagerTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/memory/LargestFirstMemoryManagerTest.java index 2d839a3..906179e 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/memory/LargestFirstMemoryManagerTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/memory/LargestFirstMemoryManagerTest.java @@ -22,7 +22,7 @@ import static java.util.concurrent.TimeUnit.MINUTES; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Arrays; import java.util.List; @@ -34,14 +34,12 @@ import org.apache.accumulo.core.data.TableId; import org.apache.accumulo.core.dataImpl.KeyExtent; import org.apache.accumulo.server.ServerContext; import org.apache.hadoop.io.Text; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.Timeout; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; +@Timeout(60) public class LargestFirstMemoryManagerTest { - @Rule - public Timeout timeout = Timeout.seconds(60); private static final long ZERO = LargestFirstMemoryManager.ZERO_TIME; private static final long LATER = ZERO + MINUTES.toMillis(20); @@ -52,7 +50,7 @@ public class LargestFirstMemoryManagerTest { private ServerContext context; - @Before + @BeforeEach public void mockServerInfo() { context = createMock(ServerContext.class); AccumuloConfiguration conf = createMock(AccumuloConfiguration.class); diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/replication/AccumuloReplicaSystemTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/replication/AccumuloReplicaSystemTest.java index d65102a..73e0e61 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/replication/AccumuloReplicaSystemTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/replication/AccumuloReplicaSystemTest.java @@ -22,9 +22,9 @@ import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -57,7 +57,7 @@ import org.apache.accumulo.tserver.logger.LogFileKey; import org.apache.accumulo.tserver.logger.LogFileValue; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.Text; -import org.junit.Test; +import org.junit.jupiter.api.Test; @Deprecated public class AccumuloReplicaSystemTest { @@ -321,8 +321,8 @@ public class AccumuloReplicaSystemTest { assertEquals("row", new String(m.getRow())); assertEquals(1, m.getReplicationSources().size()); - assertTrue("Expected source cluster to be listed in mutation replication source", - m.getReplicationSources().contains("source")); + assertTrue(m.getReplicationSources().contains("source"), + "Expected source cluster to be listed in mutation replication source"); } @Test diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/replication/BatchWriterReplicationReplayerTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/replication/BatchWriterReplicationReplayerTest.java index e659962..2267bfa 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/replication/BatchWriterReplicationReplayerTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/replication/BatchWriterReplicationReplayerTest.java @@ -39,9 +39,9 @@ import org.apache.accumulo.core.replication.thrift.WalEdits; import org.apache.accumulo.server.data.ServerMutation; import org.apache.accumulo.tserver.logger.LogEvents; import org.apache.accumulo.tserver.logger.LogFileKey; -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.Lists; @@ -52,7 +52,7 @@ public class BatchWriterReplicationReplayerTest { private AccumuloConfiguration conf; private BatchWriter bw; - @Before + @BeforeEach public void setUpContext() { conf = createMock(AccumuloConfiguration.class); bw = createMock(BatchWriter.class); @@ -60,7 +60,7 @@ public class BatchWriterReplicationReplayerTest { expect(context.getConfiguration()).andReturn(conf).anyTimes(); } - @After + @AfterEach public void verifyMock() { verify(context, conf, bw); } diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/replication/ReplicationProcessorTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/replication/ReplicationProcessorTest.java index 95c9626..a9c379a 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/replication/ReplicationProcessorTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/replication/ReplicationProcessorTest.java @@ -24,8 +24,8 @@ import static org.easymock.EasyMock.createMockBuilder; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.Map; @@ -39,7 +39,7 @@ import org.apache.accumulo.server.replication.ReplicaSystem; import org.apache.accumulo.server.replication.ReplicaSystemHelper; import org.apache.accumulo.server.replication.proto.Replication.Status; import org.apache.hadoop.fs.Path; -import org.junit.Test; +import org.junit.jupiter.api.Test; @Deprecated public class ReplicationProcessorTest { diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/tablet/CompactableImplFileManagerTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/tablet/CompactableImplFileManagerTest.java index 059e828..b6825ed 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/tablet/CompactableImplFileManagerTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/tablet/CompactableImplFileManagerTest.java @@ -23,10 +23,10 @@ import static org.apache.accumulo.core.spi.compaction.CompactionKind.SELECTOR; import static org.apache.accumulo.core.spi.compaction.CompactionKind.SYSTEM; import static org.apache.accumulo.core.spi.compaction.CompactionKind.USER; import static org.apache.accumulo.tserver.tablet.CompactableImplFileManagerTest.TestFileManager.SELECTION_EXPIRATION; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.Duration; import java.util.Arrays; @@ -47,7 +47,7 @@ import org.apache.accumulo.core.spi.compaction.CompactionKind; import org.apache.accumulo.tserver.tablet.CompactableImpl.ChopSelectionStatus; import org.apache.accumulo.tserver.tablet.CompactableImpl.FileManager.ChopSelector; import org.apache.accumulo.tserver.tablet.CompactableImpl.FileSelectionStatus; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.google.common.collect.Sets; diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/tablet/CompactableImplTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/tablet/CompactableImplTest.java index 983145a..c492f6a 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/tablet/CompactableImplTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/tablet/CompactableImplTest.java @@ -20,8 +20,8 @@ package org.apache.accumulo.tserver.tablet; import static org.apache.accumulo.tserver.tablet.CompactableImplFileManagerTest.newFile; import static org.apache.accumulo.tserver.tablet.CompactableImplFileManagerTest.newFiles; -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.util.HashMap; import java.util.Map; @@ -36,7 +36,7 @@ import org.apache.accumulo.core.metadata.schema.ExternalCompactionMetadata; import org.apache.accumulo.core.spi.compaction.CompactionExecutorId; import org.apache.accumulo.core.spi.compaction.CompactionKind; import org.apache.accumulo.core.util.compaction.CompactionExecutorIdImpl; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CompactableImplTest { private static ExternalCompactionMetadata newECM(Set<StoredTabletFile> jobFiles, diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/tablet/TabletMutationPrepAttemptTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/tablet/TabletMutationPrepAttemptTest.java index 70a4451..60dee7b 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/tablet/TabletMutationPrepAttemptTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/tablet/TabletMutationPrepAttemptTest.java @@ -19,10 +19,10 @@ package org.apache.accumulo.tserver.tablet; import static org.easymock.EasyMock.mock; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; import java.util.HashSet; @@ -31,7 +31,7 @@ import java.util.Set; import org.apache.accumulo.core.constraints.Violations; import org.apache.accumulo.core.data.Mutation; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TabletMutationPrepAttemptTest { diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/tablet/TabletTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/tablet/TabletTest.java index dcc9caa..3233f06 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/tablet/TabletTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/tablet/TabletTest.java @@ -18,7 +18,7 @@ */ package org.apache.accumulo.tserver.tablet; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Map; @@ -26,7 +26,7 @@ import org.apache.accumulo.core.conf.Property; import org.apache.accumulo.tserver.compaction.CompactionPlan; import org.apache.accumulo.tserver.compaction.WriteParameters; import org.easymock.EasyMock; -import org.junit.Test; +import org.junit.jupiter.api.Test; @SuppressWarnings("removal") public class TabletTest {