You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by li...@apache.org on 2026/04/26 06:22:46 UTC
(hbase) branch branch-2.5 updated: HBASE-30066 Upgrade hbase-server to use junit5 Part9 (#8135)
This is an automated email from the ASF dual-hosted git repository.
liuxiaocs7 pushed a commit to branch branch-2.5
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2.5 by this push:
new bd698926383 HBASE-30066 Upgrade hbase-server to use junit5 Part9 (#8135)
bd698926383 is described below
commit bd698926383003dda12ba4b7cbc56ef42b5ded2c
Author: Xiao Liu <li...@apache.org>
AuthorDate: Sun Apr 26 14:22:41 2026 +0800
HBASE-30066 Upgrade hbase-server to use junit5 Part9 (#8135)
Signed-off-by: Duo Zhang <zh...@apache.org>
(cherry picked from commit b5f648b6d8d5449740112590b8d49d33f5c5ce5d)
(cherry picked from commit e36a1baff66d95a164889fc435b4da9f45b22ff6)
---
.../hadoop/hbase/backup/TestHFileArchiving.java | 130 +++++++-------
.../example/TestZooKeeperTableArchiveClient.java | 62 ++++---
.../hadoop/hbase/codec/CodecPerformance.java | 4 +-
.../hadoop/hbase/codec/TestCellMessageCodec.java | 19 +--
.../hadoop/hbase/constraint/TestConstraint.java | 32 ++--
.../hadoop/hbase/constraint/TestConstraints.java | 54 +++---
.../hbase/coprocessor/SimpleRegionObserver.java | 8 +-
.../hbase/coprocessor/TestAppendTimeRange.java | 43 +++--
.../coprocessor/TestCoprocessorConfiguration.java | 55 +++---
.../hbase/coprocessor/TestCoprocessorHost.java | 31 ++--
.../coprocessor/TestCoprocessorInterface.java | 47 +++--
.../hbase/coprocessor/TestCoprocessorMetrics.java | 64 ++++---
.../TestCoprocessorShortCircuitRPC.java | 27 +--
.../hbase/coprocessor/TestCoprocessorStop.java | 27 ++-
.../coprocessor/TestCoreMasterCoprocessor.java | 30 ++--
.../coprocessor/TestCoreRegionCoprocessor.java | 38 ++---
.../TestCoreRegionServerCoprocessor.java | 38 ++---
.../TestIncrementAndAppendWithNullResult.java | 31 ++--
.../hbase/coprocessor/TestIncrementTimeRange.java | 35 ++--
.../TestMasterCoprocessorExceptionWithAbort.java | 43 +++--
.../TestMasterCoprocessorExceptionWithRemove.java | 33 ++--
.../hbase/coprocessor/TestMasterObserver.java | 190 ++++++++++-----------
.../TestMasterObserverToModifyTableSchema.java | 28 +--
.../hbase/coprocessor/TestMetaTableMetrics.java | 27 ++-
...estNegativeMemStoreSizeWithSlowCoprocessor.java | 28 ++-
.../coprocessor/TestOpenTableInCoprocessor.java | 33 ++--
.../TestPostIncrementAndAppendBeforeWAL.java | 47 +++--
.../coprocessor/TestReadOnlyConfiguration.java | 18 +-
.../coprocessor/TestRegionCoprocessorHost.java | 49 +++---
.../coprocessor/TestRegionObserverBypass.java | 31 ++--
...ObserverForAddingMutationsFromCoprocessors.java | 39 ++---
.../coprocessor/TestRegionObserverInterface.java | 106 ++++++------
.../TestRegionObserverPreFlushAndPreCompact.java | 28 ++-
.../TestRegionObserverScannerOpenHook.java | 57 +++----
.../coprocessor/TestRegionObserverStacking.java | 15 +-
...tRegionServerCoprocessorExceptionWithAbort.java | 19 +--
...RegionServerCoprocessorExceptionWithRemove.java | 29 ++--
.../hadoop/hbase/coprocessor/TestWALObserver.java | 62 +++----
.../TestForeignExceptionDispatcher.java | 21 +--
.../TestForeignExceptionSerialization.java | 32 ++--
.../TestTimeoutExceptionInjector.java | 15 +-
.../hadoop/hbase/executor/TestExecutorService.java | 20 +--
.../apache/hadoop/hbase/fs/TestBlockReorder.java | 71 ++++----
.../hbase/fs/TestBlockReorderBlockLocation.java | 58 +++----
.../hbase/fs/TestBlockReorderMultiBlocks.java | 51 +++---
.../hadoop/hbase/http/TestInfoServersACL.java | 65 +++----
.../TestMemoryBoundedLogMessageBuffer.java | 25 ++-
.../hadoop/hbase/monitoring/TestTaskMonitor.java | 37 ++--
.../hbase/snapshot/MobSnapshotTestingUtils.java | 6 +-
.../hbase/snapshot/SnapshotTestingUtils.java | 45 ++---
.../TestConcurrentFlushSnapshotFromClient.java | 17 +-
.../snapshot/TestFlushSnapshotFromClient.java | 39 +++--
.../snapshot/TestMobFlushSnapshotFromClient.java | 17 +-
.../TestMobRestoreFlushSnapshotFromClient.java | 15 +-
.../snapshot/TestMobRestoreSnapshotHelper.java | 10 +-
.../hbase/snapshot/TestRegionSnapshotTask.java | 27 ++-
.../TestRestoreFlushSnapshotFromClient.java | 44 ++---
.../hbase/snapshot/TestRestoreSnapshotHelper.java | 49 +++---
.../hbase/snapshot/TestSnapshotClientRetries.java | 49 +++---
.../snapshot/TestSnapshotDescriptionUtils.java | 32 ++--
.../hbase/snapshot/TestSnapshotManifest.java | 23 +--
.../hbase/snapshot/TestSnapshotStoreFileSize.java | 26 ++-
.../snapshot/TestSnapshotWhenChoreCleaning.java | 37 ++--
63 files changed, 1085 insertions(+), 1403 deletions(-)
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestHFileArchiving.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestHFileArchiving.java
index 00cfebbe7b2..e459c4bf517 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestHFileArchiving.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestHFileArchiving.java
@@ -17,10 +17,12 @@
*/
package org.apache.hadoop.hbase.backup;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -42,7 +44,6 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.PathFilter;
import org.apache.hadoop.hbase.ChoreService;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.Stoppable;
@@ -66,15 +67,12 @@ import org.apache.hadoop.hbase.util.HFileArchiveTestingUtil;
import org.apache.hadoop.hbase.util.HFileArchiveUtil;
import org.apache.hadoop.hbase.util.StoppableImplementation;
import org.apache.hadoop.security.UserGroupInformation;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.mockito.ArgumentCaptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -83,25 +81,24 @@ import org.slf4j.LoggerFactory;
* Test that the {@link HFileArchiver} correctly removes all the parts of a region when cleaning up
* a region
*/
-@Category({ LargeTests.class, MiscTests.class })
+@Tag(LargeTests.TAG)
+@Tag(MiscTests.TAG)
public class TestHFileArchiving {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestHFileArchiving.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestHFileArchiving.class);
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
private static final byte[] TEST_FAM = Bytes.toBytes("fam");
private static DirScanPool POOL;
- @Rule
- public TestName name = new TestName();
+
+ private String testMethodName(TestInfo testInfo) {
+ return testInfo.getTestMethod().get().getName();
+ }
/**
* Setup the config for the cluster
*/
- @BeforeClass
+ @BeforeAll
public static void setupCluster() throws Exception {
setupConf(UTIL.getConfiguration());
UTIL.startMiniCluster();
@@ -125,13 +122,13 @@ public class TestHFileArchiving {
ConstantSizeRegionSplitPolicy.class.getName());
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
// cleanup the archive directory
clearArchiveDirectory();
}
- @AfterClass
+ @AfterAll
public static void cleanupTest() throws Exception {
UTIL.shutdownMiniCluster();
POOL.shutdownNow();
@@ -171,11 +168,11 @@ public class TestHFileArchiving {
HFileArchiver::archiveStoreFiles);
}
- @Test(expected = IOException.class)
+ @Test
public void testArchiveStoreFilesDifferentFileSystemsArchiveFileMismatch() throws Exception {
String baseDir = CommonFSUtils.getRootDir(UTIL.getConfiguration()).toString() + "/";
- testArchiveStoreFilesDifferentFileSystems("/hbase/wals/", baseDir, true, true, true,
- HFileArchiver::archiveStoreFiles);
+ assertThrows(IOException.class, () -> testArchiveStoreFilesDifferentFileSystems("/hbase/wals/",
+ baseDir, true, true, true, HFileArchiver::archiveStoreFiles));
}
private void testArchiveStoreFilesDifferentFileSystems(String walDir, String expectedBase,
@@ -275,14 +272,15 @@ public class TestHFileArchiving {
}
}
- @Test(expected = IOException.class)
+ @Test
public void testArchiveRecoveredEditsWrongFS() throws Exception {
String baseDir = CommonFSUtils.getRootDir(UTIL.getConfiguration()).toString() + "/";
// Internally, testArchiveStoreFilesDifferentFileSystems will pass a "mockedFS"
// to HFileArchiver.archiveRecoveredEdits, but since wal-dir is supposedly on same FS
// as root dir it would lead to conflicting FSes and an IOException is expected.
- testArchiveStoreFilesDifferentFileSystems("/wal-dir", baseDir, (conf, fs, region, dir, family,
- list) -> HFileArchiver.archiveRecoveredEdits(conf, fs, region, family, list));
+ assertThrows(IOException.class,
+ () -> testArchiveStoreFilesDifferentFileSystems("/wal-dir", baseDir, (conf, fs, region, dir,
+ family, list) -> HFileArchiver.archiveRecoveredEdits(conf, fs, region, family, list)));
}
@Test
@@ -293,8 +291,8 @@ public class TestHFileArchiving {
}
@Test
- public void testRemoveRegionDirOnArchive() throws Exception {
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ public void testRemoveRegionDirOnArchive(TestInfo testInfo) throws Exception {
+ final TableName tableName = TableName.valueOf(testMethodName(testInfo));
UTIL.createTable(tableName, TEST_FAM);
final Admin admin = UTIL.getAdmin();
@@ -350,8 +348,8 @@ public class TestHFileArchiving {
* still has hidden files.
*/
@Test
- public void testDeleteRegionWithNoStoreFiles() throws Exception {
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ public void testDeleteRegionWithNoStoreFiles(TestInfo testInfo) throws IOException {
+ final TableName tableName = TableName.valueOf(testMethodName(testInfo));
UTIL.createTable(tableName, TEST_FAM);
// get the current store files for the region
@@ -366,7 +364,7 @@ public class TestHFileArchiving {
Path rootDir = CommonFSUtils.getRootDir(fs.getConf());
Path regionDir = FSUtils.getRegionDirFromRootDir(rootDir, region.getRegionInfo());
FileStatus[] regionFiles = CommonFSUtils.listStatus(fs, regionDir, null);
- Assert.assertNotNull("No files in the region directory", regionFiles);
+ assertNotNull(regionFiles, "No files in the region directory");
if (LOG.isDebugEnabled()) {
List<Path> files = new ArrayList<>();
for (FileStatus file : regionFiles) {
@@ -392,7 +390,7 @@ public class TestHFileArchiving {
HFileArchiver.archiveRegion(UTIL.getConfiguration(), fs, region.getRegionInfo());
// and check to make sure the region directoy got deleted
- assertFalse("Region directory (" + regionDir + "), still exists.", fs.exists(regionDir));
+ assertFalse(fs.exists(regionDir), "Region directory (" + regionDir + "), still exists.");
UTIL.deleteTable(tableName);
}
@@ -420,8 +418,8 @@ public class TestHFileArchiving {
}
@Test
- public void testArchiveRegions() throws Exception {
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ public void testArchiveRegions(TestInfo testInfo) throws Exception {
+ final TableName tableName = TableName.valueOf(testMethodName(testInfo));
List<HRegion> regions = initTableForArchivingRegions(tableName);
FileSystem fs = UTIL.getTestFileSystem();
@@ -459,9 +457,9 @@ public class TestHFileArchiving {
UTIL.deleteTable(tableName);
}
- @Test(expected = IOException.class)
- public void testArchiveRegionsWhenPermissionDenied() throws Exception {
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ @Test
+ public void testArchiveRegionsWhenPermissionDenied(TestInfo testInfo) throws Exception {
+ final TableName tableName = TableName.valueOf(testMethodName(testInfo));
List<HRegion> regions = initTableForArchivingRegions(tableName);
// now attempt to depose the regions
@@ -476,22 +474,22 @@ public class TestHFileArchiving {
UserGroupInformation.createUserForTesting("foo1234", new String[] { "group1" });
try {
- ugi.doAs((PrivilegedExceptionAction<Void>) () -> {
- FileSystem fs = UTIL.getTestFileSystem();
- HFileArchiver.archiveRegions(UTIL.getConfiguration(), fs, rootDir, tableDir, regionDirList);
- return null;
- });
- } catch (IOException e) {
+ IOException e =
+ assertThrows(IOException.class, () -> ugi.doAs((PrivilegedExceptionAction<Void>) () -> {
+ FileSystem fs = UTIL.getTestFileSystem();
+ HFileArchiver.archiveRegions(UTIL.getConfiguration(), fs, rootDir, tableDir,
+ regionDirList);
+ return null;
+ }));
assertTrue(e.getCause().getMessage().contains("Permission denied"));
- throw e;
} finally {
UTIL.deleteTable(tableName);
}
}
@Test
- public void testArchiveOnTableDelete() throws Exception {
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ public void testArchiveOnTableDelete(TestInfo testInfo) throws Exception {
+ final TableName tableName = TableName.valueOf(testMethodName(testInfo));
UTIL.createTable(tableName, TEST_FAM);
List<HRegion> servingRegions = UTIL.getHBaseCluster().getRegions(tableName);
@@ -509,7 +507,7 @@ public class TestHFileArchiving {
// get the hfiles in the region
List<HRegion> regions = hrs.getRegions(tableName);
- assertEquals("More that 1 region for test table.", 1, regions.size());
+ assertEquals(1, regions.size(), "More that 1 region for test table.");
region = regions.get(0);
// wait for all the compactions to complete
@@ -561,16 +559,17 @@ public class TestHFileArchiving {
LOG.debug(i + " - " + archivedFiles.get(i));
}
- assertTrue("Archived files are missing some of the store files!",
- archivedFiles.containsAll(storeFiles));
+ assertTrue(archivedFiles.containsAll(storeFiles),
+ "Archived files are missing some of the store files!");
}
/**
* Test that the store files are archived when a column family is removed.
*/
@Test
- public void testArchiveOnTableFamilyDelete() throws Exception {
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ public void testArchiveOnTableFamilyDelete(TestInfo testInfo)
+ throws IOException, InterruptedException {
+ final TableName tableName = TableName.valueOf(testMethodName(testInfo));
UTIL.createTable(tableName, new byte[][] { TEST_FAM, Bytes.toBytes("fam2") });
List<HRegion> servingRegions = UTIL.getHBaseCluster().getRegions(tableName);
@@ -588,7 +587,7 @@ public class TestHFileArchiving {
// get the hfiles in the region
List<HRegion> regions = hrs.getRegions(tableName);
- assertEquals("More that 1 region for test table.", 1, regions.size());
+ assertEquals(1, regions.size(), "More that 1 region for test table.");
region = regions.get(0);
// wait for all the compactions to complete
@@ -617,7 +616,7 @@ public class TestHFileArchiving {
* Test HFileArchiver.resolveAndArchive() race condition HBASE-7643
*/
@Test
- public void testCleaningRace() throws Exception {
+ public void testCleaningRace(TestInfo testInfo) throws Exception {
final long TEST_TIME = 20 * 1000;
final ChoreService choreService = new ChoreService("TEST_SERVER_NAME");
@@ -627,7 +626,8 @@ public class TestHFileArchiving {
Path archiveDir = new Path(rootDir, HConstants.HFILE_ARCHIVE_DIRECTORY);
Path regionDir = new Path(
- CommonFSUtils.getTableDir(new Path("./"), TableName.valueOf(name.getMethodName())), "abcdef");
+ CommonFSUtils.getTableDir(new Path("./"), TableName.valueOf(testMethodName(testInfo))),
+ "abcdef");
Path familyDir = new Path(regionDir, "cf");
Path sourceRegionDir = new Path(rootDir, regionDir);
@@ -639,7 +639,6 @@ public class TestHFileArchiving {
HFileCleaner cleaner = new HFileCleaner(1, stoppable, conf, fs, archiveDir, POOL);
try {
choreService.scheduleChore(cleaner);
-
// Keep creating/archiving new files while the cleaner is running in the other thread
long startTime = EnvironmentEdgeManager.currentTime();
for (long fid = 0; (EnvironmentEdgeManager.currentTime() - startTime) < TEST_TIME; ++fid) {
@@ -689,10 +688,11 @@ public class TestHFileArchiving {
}
@Test
- public void testArchiveRegionWithTableDirNull() throws IOException {
+ public void testArchiveRegionWithTableDirNull(TestInfo testInfo) throws IOException {
Configuration conf = UTIL.getMiniHBaseCluster().getMaster().getConfiguration();
Path regionDir = new Path(
- CommonFSUtils.getTableDir(new Path("./"), TableName.valueOf(name.getMethodName())), "xyzabc");
+ CommonFSUtils.getTableDir(new Path("./"), TableName.valueOf(testMethodName(testInfo))),
+ "xyzabc");
Path familyDir = new Path(regionDir, "rd");
Path rootDir = UTIL.getDataTestDirOnTestFS("testCleaningRace");
Path file = new Path(familyDir, "1");
@@ -707,11 +707,11 @@ public class TestHFileArchiving {
}
@Test
- public void testArchiveRegionWithRegionDirNull() throws IOException {
+ public void testArchiveRegionWithRegionDirNull(TestInfo testInfo) throws IOException {
Configuration conf = UTIL.getMiniHBaseCluster().getMaster().getConfiguration();
- Path regionDir =
- new Path(CommonFSUtils.getTableDir(new Path("./"), TableName.valueOf(name.getMethodName())),
- "elgn4nf");
+ Path regionDir = new Path(
+ CommonFSUtils.getTableDir(new Path("./"), TableName.valueOf(testMethodName(testInfo))),
+ "elgn4nf");
Path familyDir = new Path(regionDir, "rdar");
Path rootDir = UTIL.getDataTestDirOnTestFS("testCleaningRace");
Path file = new Path(familyDir, "2");
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/backup/example/TestZooKeeperTableArchiveClient.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/backup/example/TestZooKeeperTableArchiveClient.java
index f4f3145f79f..e96a035434a 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/backup/example/TestZooKeeperTableArchiveClient.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/backup/example/TestZooKeeperTableArchiveClient.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.backup.example;
-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 static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.mock;
@@ -32,7 +32,6 @@ import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.ChoreService;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.Stoppable;
@@ -57,12 +56,11 @@ import org.apache.hadoop.hbase.util.StoppableImplementation;
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.apache.zookeeper.KeeperException;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -73,13 +71,10 @@ import org.slf4j.LoggerFactory;
* Spin up a small cluster and check that the hfiles of region are properly long-term archived as
* specified via the {@link ZKTableArchiveClient}.
*/
-@Category({ MiscTests.class, MediumTests.class })
+@Tag(MiscTests.TAG)
+@Tag(MediumTests.TAG)
public class TestZooKeeperTableArchiveClient {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestZooKeeperTableArchiveClient.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestZooKeeperTableArchiveClient.class);
private static final HBaseTestingUtility UTIL = HBaseTestingUtility.createLocalHTU();
private static final String STRING_TABLE_NAME = "test";
@@ -94,7 +89,7 @@ public class TestZooKeeperTableArchiveClient {
/**
* Setup the config for the cluster
*/
- @BeforeClass
+ @BeforeAll
public static void setupCluster() throws Exception {
setupConf(UTIL.getConfiguration());
UTIL.startMiniZKCluster();
@@ -113,7 +108,7 @@ public class TestZooKeeperTableArchiveClient {
conf.setInt("hbase.hstore.compaction.min", 3);
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
try {
FileSystem fs = UTIL.getTestFileSystem();
@@ -131,7 +126,7 @@ public class TestZooKeeperTableArchiveClient {
archivingClient.disableHFileBackup();
}
- @AfterClass
+ @AfterAll
public static void cleanupTest() throws Exception {
if (CONNECTION != null) {
CONNECTION.close();
@@ -150,20 +145,21 @@ public class TestZooKeeperTableArchiveClient {
// 1. turn on hfile backups
LOG.debug("----Starting archiving");
archivingClient.enableHFileBackupAsync(TABLE_NAME);
- assertTrue("Archving didn't get turned on", archivingClient.getArchivingEnabled(TABLE_NAME));
+ assertTrue(archivingClient.getArchivingEnabled(TABLE_NAME), "Archiving didn't get turned on");
// 2. Turn off archiving and make sure its off
archivingClient.disableHFileBackup();
- assertFalse("Archving didn't get turned off.", archivingClient.getArchivingEnabled(TABLE_NAME));
+ assertFalse(archivingClient.getArchivingEnabled(TABLE_NAME),
+ "Archiving didn't get turned off.");
// 3. Check enable/disable on a single table
archivingClient.enableHFileBackupAsync(TABLE_NAME);
- assertTrue("Archving didn't get turned on", archivingClient.getArchivingEnabled(TABLE_NAME));
+ assertTrue(archivingClient.getArchivingEnabled(TABLE_NAME), "Archiving didn't get turned on");
// 4. Turn off archiving and make sure its off
archivingClient.disableHFileBackup(TABLE_NAME);
- assertFalse("Archving didn't get turned off for " + STRING_TABLE_NAME,
- archivingClient.getArchivingEnabled(TABLE_NAME));
+ assertFalse(archivingClient.getArchivingEnabled(TABLE_NAME),
+ "Archiving didn't get turned off for " + STRING_TABLE_NAME);
}
@Test
@@ -204,7 +200,7 @@ public class TestZooKeeperTableArchiveClient {
// know the cleaner ran, so now check all the files again to make sure they are still there
List<Path> archivedFiles = getAllFiles(fs, archiveDir);
- assertEquals("Archived files changed after running archive cleaner.", files, archivedFiles);
+ assertEquals(files, archivedFiles, "Archived files changed after running archive cleaner.");
// but we still have the archive directory
assertTrue(fs.exists(HFileArchiveUtil.getArchivePath(UTIL.getConfiguration())));
@@ -276,8 +272,8 @@ public class TestZooKeeperTableArchiveClient {
}
}
- assertTrue("Didn't archive files for:" + STRING_TABLE_NAME, initialCountForPrimary > 0);
- assertTrue("Didn't archive files for:" + otherTable, initialCountForOtherTable > 0);
+ assertTrue(initialCountForPrimary > 0, "Didn't archive files for:" + STRING_TABLE_NAME);
+ assertTrue(initialCountForOtherTable > 0, "Didn't archive files for:" + otherTable);
// run the cleaners, checking for each of the directories + files (both should be deleted and
// need to be checked) in 'otherTable' and the files (which should be retained) in the 'table'
@@ -295,17 +291,17 @@ public class TestZooKeeperTableArchiveClient {
for (Path file : archivedFiles) {
String tableName = file.getParent().getParent().getParent().getName();
// ensure we don't have files from the non-archived table
- assertFalse("Have a file from the non-archived table: " + file, tableName.equals(otherTable));
+ assertFalse(tableName.equals(otherTable), "Have a file from the non-archived table: " + file);
if (tableName.equals(STRING_TABLE_NAME)) {
archivedForPrimary++;
}
}
- assertEquals("Not all archived files for the primary table were retained.",
- initialCountForPrimary, archivedForPrimary);
+ assertEquals(initialCountForPrimary, archivedForPrimary,
+ "Not all archived files for the primary table were retained.");
// but we still have the archive directory
- assertTrue("Archive directory was deleted via archiver", fs.exists(archiveDir));
+ assertTrue(fs.exists(archiveDir), "Archive directory was deleted via archiver");
}
private void createArchiveDirectory() throws IOException {
@@ -346,7 +342,7 @@ public class TestZooKeeperTableArchiveClient {
// turn on hfile retention
LOG.debug("----Starting archiving for table:" + tableName);
archivingClient.enableHFileBackupAsync(Bytes.toBytes(tableName));
- assertTrue("Archving didn't get turned on", archivingClient.getArchivingEnabled(tableName));
+ assertTrue(archivingClient.getArchivingEnabled(tableName), "Archiving didn't get turned on");
// wait for the archiver to get the notification
List<BaseHFileCleanerDelegate> cleaners = cleaner.getDelegatesForTesting();
@@ -426,8 +422,8 @@ public class TestZooKeeperTableArchiveClient {
HStore s = region.getStore(family);
int count = s.getStorefilesCount();
- assertTrue("Don't have the expected store files, wanted >= 2 store files, but was:" + count,
- count >= 2);
+ assertTrue(count >= 2,
+ "Don't have the expected store files, wanted >= 2 store files, but was:" + count);
// compact the two files into one file to get files in the archive
LOG.debug("Compacting stores");
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/codec/CodecPerformance.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/codec/CodecPerformance.java
index 272bf1c4609..c19ef182b36 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/codec/CodecPerformance.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/codec/CodecPerformance.java
@@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.codec;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/codec/TestCellMessageCodec.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/codec/TestCellMessageCodec.java
index d580c3d7ff1..d6f8f271096 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/codec/TestCellMessageCodec.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/codec/TestCellMessageCodec.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.codec;
-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.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -28,27 +28,22 @@ import java.io.DataOutputStream;
import java.io.IOException;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hbase.thirdparty.com.google.common.io.CountingInputStream;
import org.apache.hbase.thirdparty.com.google.common.io.CountingOutputStream;
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestCellMessageCodec {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCellMessageCodec.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestCellMessageCodec.class);
@Test
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/constraint/TestConstraint.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/constraint/TestConstraint.java
index f8eb026b2ec..f73f7411506 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/constraint/TestConstraint.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/constraint/TestConstraint.java
@@ -17,11 +17,10 @@
*/
package org.apache.hadoop.hbase.constraint;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+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 org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
@@ -32,25 +31,21 @@ import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Do the complex testing of constraints against a minicluster
*/
-@Category({ MiscTests.class, MediumTests.class })
+@Tag(MiscTests.TAG)
+@Tag(MediumTests.TAG)
public class TestConstraint {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestConstraint.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestConstraint.class);
private static HBaseTestingUtility util;
@@ -59,7 +54,7 @@ public class TestConstraint {
private static final byte[] row1 = Bytes.toBytes("r1");
private static final byte[] test = Bytes.toBytes("test");
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() throws Exception {
util = new HBaseTestingUtility();
util.getConfiguration().setBoolean(CoprocessorHost.ABORT_ON_ERROR_KEY, false);
@@ -102,7 +97,6 @@ public class TestConstraint {
@SuppressWarnings("unchecked")
@Test
public void testConstraintFails() throws Exception {
-
// create the table
// it would be nice if this was also a method on the util
HTableDescriptor desc = new HTableDescriptor(tableName);
@@ -236,7 +230,7 @@ public class TestConstraint {
table.close();
}
- @After
+ @AfterEach
public void cleanup() throws Exception {
// cleanup
CheckWasRunConstraint.wasRun = false;
@@ -244,7 +238,7 @@ public class TestConstraint {
util.getAdmin().deleteTable(tableName);
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
util.shutdownMiniCluster();
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/constraint/TestConstraints.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/constraint/TestConstraints.java
index a772ee3dab1..09a25001d42 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/constraint/TestConstraints.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/constraint/TestConstraints.java
@@ -17,14 +17,13 @@
*/
package org.apache.hadoop.hbase.constraint;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-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.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.util.List;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Put;
@@ -33,29 +32,25 @@ import org.apache.hadoop.hbase.constraint.WorksConstraint.NameConstraint;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Pair;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
/**
* Test reading/writing the constraints into the {@link HTableDescriptor}
*/
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestConstraints {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestConstraints.class);
-
- @Rule
- public TestName name = new TestName();
+ private TableName getTableName(TestInfo testInfo) {
+ return TableName.valueOf(testInfo.getTestMethod().get().getName());
+ }
@SuppressWarnings("unchecked")
@Test
- public void testSimpleReadWrite() throws Throwable {
- HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
+ public void testSimpleReadWrite(TestInfo testInfo) throws Throwable {
+ HTableDescriptor desc = new HTableDescriptor(getTableName(testInfo));
Constraints.add(desc, WorksConstraint.class);
List<? extends Constraint> constraints =
@@ -78,8 +73,8 @@ public class TestConstraints {
@SuppressWarnings("unchecked")
@Test
- public void testReadWriteWithConf() throws Throwable {
- HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
+ public void testReadWriteWithConf(TestInfo testInfo) throws Throwable {
+ HTableDescriptor desc = new HTableDescriptor(getTableName(testInfo));
Constraints.add(desc, new Pair<>(CheckConfigurationConstraint.class,
CheckConfigurationConstraint.getConfiguration()));
@@ -105,8 +100,8 @@ public class TestConstraints {
*/
@SuppressWarnings("unchecked")
@Test
- public void testEnableDisableRemove() throws Exception {
- HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
+ public void testEnableDisableRemove(TestInfo testInfo) throws Exception {
+ HTableDescriptor desc = new HTableDescriptor(getTableName(testInfo));
// check general enabling/disabling of constraints
// first add a constraint
Constraints.add(desc, AllPassConstraint.class);
@@ -139,8 +134,8 @@ public class TestConstraints {
*/
@SuppressWarnings("unchecked")
@Test
- public void testUpdateConstraint() throws Exception {
- HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
+ public void testUpdateConstraint(TestInfo testInfo) throws Exception {
+ HTableDescriptor desc = new HTableDescriptor(getTableName(testInfo));
Constraints.add(desc, CheckConfigurationConstraint.class, CheckWasRunConstraint.class);
Constraints.setConfiguration(desc, CheckConfigurationConstraint.class,
CheckConfigurationConstraint.getConfiguration());
@@ -160,18 +155,18 @@ public class TestConstraints {
* it. on failure.
*/
@Test
- public void testRemoveUnsetConstraint() throws Throwable {
- HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
+ public void testRemoveUnsetConstraint(TestInfo testInfo) throws Throwable {
+ HTableDescriptor desc = new HTableDescriptor(getTableName(testInfo));
Constraints.remove(desc);
Constraints.remove(desc, AlsoWorks.class);
}
@Test
- public void testConfigurationPreserved() throws Throwable {
+ public void testConfigurationPreserved(TestInfo testInfo) throws Throwable {
Configuration conf = new Configuration();
conf.setBoolean("_ENABLED", false);
conf.setLong("_PRIORITY", 10);
- HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
+ HTableDescriptor desc = new HTableDescriptor(getTableName(testInfo));
Constraints.add(desc, AlsoWorks.class, conf);
Constraints.add(desc, WorksConstraint.class);
assertFalse(Constraints.enabled(desc, AlsoWorks.class));
@@ -184,7 +179,6 @@ public class TestConstraints {
else assertEquals(2, storedConf.getLong("_PRIORITY", -1));
}
-
}
// ---------- Constraints just used for testing
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/SimpleRegionObserver.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/SimpleRegionObserver.java
index be54f320ef7..ac5c11e59e1 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/SimpleRegionObserver.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/SimpleRegionObserver.java
@@ -17,10 +17,10 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.HashMap;
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestAppendTimeRange.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestAppendTimeRange.java
index 34570afe9f7..295a75a8065 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestAppendTimeRange.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestAppendTimeRange.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-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.assertTrue;
import java.io.IOException;
import java.util.Arrays;
@@ -28,7 +28,6 @@ import java.util.Map;
import java.util.NavigableMap;
import java.util.Optional;
import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Append;
@@ -44,23 +43,18 @@ import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.ManualEnvironmentEdge;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
-
-@Category({ CoprocessorTests.class, MediumTests.class })
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+
+@Tag(CoprocessorTests.TAG)
+@Tag(MediumTests.TAG)
public class TestAppendTimeRange {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestAppendTimeRange.class);
-
- @Rule
- public TestName name = new TestName();
+ private String currentTestName;
private static final HBaseTestingUtility util = new HBaseTestingUtility();
private static final ManualEnvironmentEdge mee = new ManualEnvironmentEdge();
@@ -73,7 +67,7 @@ public class TestAppendTimeRange {
private static final byte[] VALUE = Bytes.toBytes("1");
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() throws Exception {
util.getConfiguration().set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
MyObserver.class.getName());
@@ -84,11 +78,16 @@ public class TestAppendTimeRange {
EnvironmentEdgeManager.injectEdge(mee);
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
util.shutdownMiniCluster();
}
+ @BeforeEach
+ public void setUp(TestInfo testInfo) {
+ currentTestName = testInfo.getTestMethod().get().getName();
+ }
+
public static class MyObserver implements RegionCoprocessor, RegionObserver {
private static TimeRange tr10 = null;
private static TimeRange tr2 = null;
@@ -119,7 +118,7 @@ public class TestAppendTimeRange {
@Test
public void testHTableInterfaceMethods() throws Exception {
- try (Table table = util.createTable(TableName.valueOf(name.getMethodName()), TEST_FAMILY)) {
+ try (Table table = util.createTable(TableName.valueOf(currentTestName), TEST_FAMILY)) {
table.put(new Put(ROW).addColumn(TEST_FAMILY, QUAL, VALUE));
long time = EnvironmentEdgeManager.currentTime();
mee.setValue(time);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorConfiguration.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorConfiguration.java
index 4e5f92628d6..efd3131f29a 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorConfiguration.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorConfiguration.java
@@ -17,9 +17,10 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -27,7 +28,6 @@ import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CoprocessorEnvironment;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HTableDescriptor;
@@ -40,25 +40,16 @@ import org.apache.hadoop.hbase.regionserver.RegionServerCoprocessorHost;
import org.apache.hadoop.hbase.regionserver.RegionServerServices;
import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
/**
* Tests for global coprocessor loading configuration
*/
-@Category({ CoprocessorTests.class, SmallTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(SmallTests.TAG)
public class TestCoprocessorConfiguration {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCoprocessorConfiguration.class);
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
private static final Configuration CONF = HBaseConfiguration.create();
static {
CONF.setStrings(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, SystemCoprocessor.class.getName());
@@ -115,12 +106,12 @@ public class TestCoprocessorConfiguration {
systemCoprocessorLoaded.set(false);
tableCoprocessorLoaded.set(false);
new RegionCoprocessorHost(region, rsServices, conf);
- assertEquals("System coprocessors loading default was not honored",
- CoprocessorHost.DEFAULT_COPROCESSORS_ENABLED, systemCoprocessorLoaded.get());
- assertEquals("Table coprocessors loading default was not honored",
+ assertEquals(CoprocessorHost.DEFAULT_COPROCESSORS_ENABLED, systemCoprocessorLoaded.get(),
+ "System coprocessors loading default was not honored");
+ assertEquals(
CoprocessorHost.DEFAULT_COPROCESSORS_ENABLED
&& CoprocessorHost.DEFAULT_USER_COPROCESSORS_ENABLED,
- tableCoprocessorLoaded.get());
+ tableCoprocessorLoaded.get(), "Table coprocessors loading default was not honored");
}
@Test
@@ -129,8 +120,8 @@ public class TestCoprocessorConfiguration {
RegionServerServices rsServices = mock(RegionServerServices.class);
systemCoprocessorLoaded.set(false);
new RegionServerCoprocessorHost(rsServices, conf);
- assertEquals("System coprocessors loading default was not honored",
- CoprocessorHost.DEFAULT_COPROCESSORS_ENABLED, systemCoprocessorLoaded.get());
+ assertEquals(CoprocessorHost.DEFAULT_COPROCESSORS_ENABLED, systemCoprocessorLoaded.get(),
+ "System coprocessors loading default was not honored");
}
@Test
@@ -139,8 +130,8 @@ public class TestCoprocessorConfiguration {
MasterServices masterServices = mock(MasterServices.class);
systemCoprocessorLoaded.set(false);
new MasterCoprocessorHost(masterServices, conf);
- assertEquals("System coprocessors loading default was not honored",
- CoprocessorHost.DEFAULT_COPROCESSORS_ENABLED, systemCoprocessorLoaded.get());
+ assertEquals(CoprocessorHost.DEFAULT_COPROCESSORS_ENABLED, systemCoprocessorLoaded.get(),
+ "System coprocessors loading default was not honored");
}
@Test
@@ -154,8 +145,8 @@ public class TestCoprocessorConfiguration {
systemCoprocessorLoaded.set(false);
tableCoprocessorLoaded.set(false);
new RegionCoprocessorHost(region, rsServices, conf);
- assertFalse("System coprocessors should not have been loaded", systemCoprocessorLoaded.get());
- assertFalse("Table coprocessors should not have been loaded", tableCoprocessorLoaded.get());
+ assertFalse(systemCoprocessorLoaded.get(), "System coprocessors should not have been loaded");
+ assertFalse(tableCoprocessorLoaded.get(), "Table coprocessors should not have been loaded");
}
@Test
@@ -170,8 +161,8 @@ public class TestCoprocessorConfiguration {
systemCoprocessorLoaded.set(false);
tableCoprocessorLoaded.set(false);
new RegionCoprocessorHost(region, rsServices, conf);
- assertTrue("System coprocessors should have been loaded", systemCoprocessorLoaded.get());
- assertFalse("Table coprocessors should not have been loaded", tableCoprocessorLoaded.get());
+ assertTrue(systemCoprocessorLoaded.get(), "System coprocessors should have been loaded");
+ assertFalse(tableCoprocessorLoaded.get(), "Table coprocessors should not have been loaded");
}
/**
@@ -193,9 +184,9 @@ public class TestCoprocessorConfiguration {
found = true;
}
Configuration c = cpenv.getConfiguration();
- thrown.expect(UnsupportedOperationException.class);
- c.set("one.two.three", "four.five.six");
+ assertThrows(UnsupportedOperationException.class,
+ () -> c.set("one.two.three", "four.five.six"));
}
- assertTrue("Should be at least one CP found", found);
+ assertTrue(found, "Should be at least one CP found");
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorHost.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorHost.java
index 9ba0830ddde..7b0d5f9c18a 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorHost.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorHost.java
@@ -17,8 +17,10 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+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 static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
@@ -26,23 +28,16 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Abortable;
import org.apache.hadoop.hbase.Coprocessor;
import org.apache.hadoop.hbase.CoprocessorEnvironment;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.ClassLoaderTestHelper;
-import org.junit.Assert;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category({ SmallTests.class })
+@Tag(SmallTests.TAG)
public class TestCoprocessorHost {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCoprocessorHost.class);
-
private static final HBaseCommonTestingUtility TEST_UTIL = new HBaseCommonTestingUtility();
/**
@@ -54,7 +49,7 @@ public class TestCoprocessorHost {
@Override
public void abort(String why, Throwable e) {
this.aborted = true;
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
@Override
@@ -82,7 +77,7 @@ public class TestCoprocessorHost {
// Three coprocessors(SimpleRegionObserver, SimpleRegionObserverV2,
// SimpleRegionObserverV3) loaded
- Assert.assertEquals(3, host.coprocEnvironments.size());
+ assertEquals(3, host.coprocEnvironments.size());
// Check the priority value
CoprocessorEnvironment<?> simpleEnv =
@@ -164,7 +159,7 @@ public class TestCoprocessorHost {
}
}
- @Test(expected = AssertionError.class)
+ @Test
public void testLoadSystemCoprocessorWithPathDoesNotExist() throws Exception {
Configuration conf = TEST_UTIL.getConfiguration();
final String key = "KEY";
@@ -179,10 +174,10 @@ public class TestCoprocessorHost {
// Try and load a system coprocessors
conf.setStrings(key, coprocessorWithPath);
// when loading non-exist with CoprocessorHostForTest host, it aborts with AssertionError
- host.loadSystemCoprocessors(conf, key);
+ assertThrows(AssertionError.class, () -> host.loadSystemCoprocessors(conf, key));
}
- @Test(expected = AssertionError.class)
+ @Test
public void testLoadSystemCoprocessorWithPathDoesNotExistAndPriority() throws Exception {
Configuration conf = TEST_UTIL.getConfiguration();
final String key = "KEY";
@@ -199,7 +194,7 @@ public class TestCoprocessorHost {
// Try and load a system coprocessors
conf.setStrings(key, coprocessor);
// when loading non-exist coprocessor, it aborts with AssertionError
- host.loadSystemCoprocessors(conf, key);
+ assertThrows(AssertionError.class, () -> host.loadSystemCoprocessors(conf, key));
}
public static class SimpleRegionObserverV2 extends SimpleRegionObserver {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorInterface.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorInterface.java
index ee858ac5e68..a2cffac6c84 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorInterface.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorInterface.java
@@ -20,11 +20,11 @@ package org.apache.hadoop.hbase.coprocessor;
import static org.apache.hadoop.hbase.HBaseTestingUtility.fam1;
import static org.apache.hadoop.hbase.HBaseTestingUtility.fam2;
import static org.apache.hadoop.hbase.HBaseTestingUtility.fam3;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+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 static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
import java.util.ArrayList;
@@ -37,7 +37,6 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.Coprocessor;
import org.apache.hadoop.hbase.CoprocessorEnvironment;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
@@ -64,24 +63,24 @@ import org.apache.hadoop.hbase.regionserver.compactions.CompactionLifeCycleTrack
import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequest;
import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.mockito.Mockito;
-@Category({ CoprocessorTests.class, MediumTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(MediumTests.TAG)
public class TestCoprocessorInterface {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCoprocessorInterface.class);
-
- @Rule
- public TestName name = new TestName();
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
static final Path DIR = TEST_UTIL.getDataTestDir();
+ private String currentTestName;
+
+ @BeforeEach
+ public void setUp(TestInfo testInfo) {
+ currentTestName = testInfo.getTestMethod().get().getName();
+ }
private static class CustomScanner implements RegionScanner {
@@ -293,11 +292,11 @@ public class TestCoprocessorInterface {
@Test
public void testSharedData() throws IOException {
- TableName tableName = TableName.valueOf(name.getMethodName());
+ TableName tableName = TableName.valueOf(currentTestName);
byte[][] families = { fam1, fam2, fam3 };
Configuration hc = initConfig();
- HRegion region = initHRegion(tableName, name.getMethodName(), hc, new Class<?>[] {}, families);
+ HRegion region = initHRegion(tableName, currentTestName, hc, new Class<?>[] {}, families);
for (int i = 0; i < 3; i++) {
HTestConst.addContent(region, fam3);
@@ -355,11 +354,11 @@ public class TestCoprocessorInterface {
@Test
public void testCoprocessorInterface() throws IOException {
- TableName tableName = TableName.valueOf(name.getMethodName());
+ TableName tableName = TableName.valueOf(currentTestName);
byte[][] families = { fam1, fam2, fam3 };
Configuration hc = initConfig();
- HRegion region = initHRegion(tableName, name.getMethodName(), hc,
+ HRegion region = initHRegion(tableName, currentTestName, hc,
new Class<?>[] { CoprocessorImpl.class }, families);
for (int i = 0; i < 3; i++) {
HTestConst.addContent(region, fam3);
@@ -378,8 +377,8 @@ public class TestCoprocessorInterface {
HBaseTestingUtility.closeRegionAndWAL(region);
Coprocessor c = region.getCoprocessorHost().findCoprocessor(CoprocessorImpl.class);
- assertTrue("Coprocessor not started", ((CoprocessorImpl) c).wasStarted());
- assertTrue("Coprocessor not stopped", ((CoprocessorImpl) c).wasStopped());
+ assertTrue(((CoprocessorImpl) c).wasStarted(), "Coprocessor not started");
+ assertTrue(((CoprocessorImpl) c).wasStopped(), "Coprocessor not stopped");
assertTrue(((CoprocessorImpl) c).wasOpened());
assertTrue(((CoprocessorImpl) c).wasClosed());
assertTrue(((CoprocessorImpl) c).wasFlushed());
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorMetrics.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorMetrics.java
index f69a2fef661..5b7470acb0b 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorMetrics.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorMetrics.java
@@ -17,11 +17,11 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNull;
-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.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.protobuf.RpcCallback;
import com.google.protobuf.RpcController;
@@ -32,7 +32,6 @@ import java.util.Optional;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CoprocessorEnvironment;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HRegionLocation;
@@ -67,14 +66,12 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.wal.WALEdit;
import org.apache.hadoop.hbase.wal.WALKey;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -83,21 +80,17 @@ import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
/**
* Testing of coprocessor metrics end-to-end.
*/
-@Category({ CoprocessorTests.class, MediumTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(MediumTests.TAG)
public class TestCoprocessorMetrics {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCoprocessorMetrics.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestCoprocessorMetrics.class);
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
private static final byte[] foo = Bytes.toBytes("foo");
private static final byte[] bar = Bytes.toBytes("bar");
- @Rule
- public TestName name = new TestName();
+ private String currentTestName;
/**
* MasterObserver that has a Timer metric for create table operation.
@@ -264,7 +257,7 @@ public class TestCoprocessorMetrics {
}
}
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() throws Exception {
Configuration conf = UTIL.getConfiguration();
// inject master, regionserver and WAL coprocessors
@@ -276,13 +269,14 @@ public class TestCoprocessorMetrics {
UTIL.startMiniCluster();
}
- @AfterClass
+ @AfterAll
public static void teardownAfterClass() throws Exception {
UTIL.shutdownMiniCluster();
}
- @Before
- public void setup() throws IOException {
+ @BeforeEach
+ public void setup(TestInfo testInfo) throws IOException {
+ currentTestName = testInfo.getTestMethod().get().getName();
try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
Admin admin = connection.getAdmin()) {
for (HTableDescriptor htd : admin.listTables()) {
@@ -308,7 +302,7 @@ public class TestCoprocessorMetrics {
Timer createTableTimer = (Timer) metric.get();
long prevCount = createTableTimer.getHistogram().getCount();
LOG.info("Creating table");
- admin.createTable(new HTableDescriptor(TableName.valueOf(name.getMethodName()))
+ admin.createTable(new HTableDescriptor(TableName.valueOf(currentTestName))
.addFamily(new HColumnDescriptor("foo")));
assertEquals(1, createTableTimer.getHistogram().getCount() - prevCount);
@@ -351,14 +345,14 @@ public class TestCoprocessorMetrics {
try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
Admin admin = connection.getAdmin()) {
- admin.createTable(new HTableDescriptor(TableName.valueOf(name.getMethodName()))
+ admin.createTable(new HTableDescriptor(TableName.valueOf(currentTestName))
.addFamily(new HColumnDescriptor("foo")));
Counter rollWalRequests = (Counter) metric.get();
long prevCount = rollWalRequests.getCount();
assertTrue(prevCount > 0);
- try (Table table = connection.getTable(TableName.valueOf(name.getMethodName()))) {
+ try (Table table = connection.getTable(TableName.valueOf(currentTestName))) {
table.put(new Put(foo).addColumn(foo, foo, foo));
}
@@ -386,7 +380,7 @@ public class TestCoprocessorMetrics {
@Test
public void testRegionObserverSingleRegion() throws IOException {
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ final TableName tableName = TableName.valueOf(currentTestName);
try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
Admin admin = connection.getAdmin()) {
admin.createTable(new HTableDescriptor(tableName).addFamily(new HColumnDescriptor(foo))
@@ -403,7 +397,7 @@ public class TestCoprocessorMetrics {
@Test
public void testRegionObserverMultiRegion() throws IOException {
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ final TableName tableName = TableName.valueOf(currentTestName);
try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
Admin admin = connection.getAdmin()) {
admin.createTable(new HTableDescriptor(tableName).addFamily(new HColumnDescriptor(foo))
@@ -425,8 +419,8 @@ public class TestCoprocessorMetrics {
@Test
public void testRegionObserverMultiTable() throws IOException {
- final TableName tableName1 = TableName.valueOf(name.getMethodName() + "1");
- final TableName tableName2 = TableName.valueOf(name.getMethodName() + "2");
+ final TableName tableName1 = TableName.valueOf(currentTestName + "1");
+ final TableName tableName2 = TableName.valueOf(currentTestName + "2");
try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
Admin admin = connection.getAdmin()) {
admin.createTable(new HTableDescriptor(tableName1).addFamily(new HColumnDescriptor(foo))
@@ -446,7 +440,7 @@ public class TestCoprocessorMetrics {
@Test
public void testRegionObserverMultiCoprocessor() throws IOException {
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ final TableName tableName = TableName.valueOf(currentTestName);
try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
Admin admin = connection.getAdmin()) {
admin.createTable(new HTableDescriptor(tableName).addFamily(new HColumnDescriptor(foo))
@@ -466,7 +460,7 @@ public class TestCoprocessorMetrics {
@Test
public void testRegionObserverAfterRegionClosed() throws IOException {
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ final TableName tableName = TableName.valueOf(currentTestName);
try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
Admin admin = connection.getAdmin()) {
admin.createTable(new HTableDescriptor(tableName).addFamily(new HColumnDescriptor(foo))
@@ -508,7 +502,7 @@ public class TestCoprocessorMetrics {
@Test
public void testRegionObserverEndpoint() throws IOException, ServiceException {
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ final TableName tableName = TableName.valueOf(currentTestName);
try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
Admin admin = connection.getAdmin()) {
admin.createTable(new HTableDescriptor(tableName).addFamily(new HColumnDescriptor(foo))
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorShortCircuitRPC.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorShortCircuitRPC.java
index bf1dc240cb6..2a0478fde65 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorShortCircuitRPC.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorShortCircuitRPC.java
@@ -17,45 +17,36 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CoprocessorEnvironment;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.SharedConnection;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ServerConnectionUtils;
import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
/**
* Ensure Coprocessors get ShortCircuit Connections when they get a Connection from their
* CoprocessorEnvironment.
*/
-@Category({ CoprocessorTests.class, MediumTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(MediumTests.TAG)
public class TestCoprocessorShortCircuitRPC {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCoprocessorShortCircuitRPC.class);
-
- @Rule
- public TestName name = new TestName();
private static final HBaseTestingUtility HTU = HBaseTestingUtility.createLocalHTU();
/**
* Start up a mini cluster with my three CPs loaded.
*/
- @BeforeClass
+ @BeforeAll
public static void beforeClass() throws Exception {
// Set my test Coprocessors into the Configuration before we start up the cluster.
Configuration conf = HTU.getConfiguration();
@@ -68,7 +59,7 @@ public class TestCoprocessorShortCircuitRPC {
HTU.startMiniCluster();
}
- @AfterClass
+ @AfterAll
public static void afterClass() throws Exception {
HTU.shutdownMiniCluster();
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorStop.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorStop.java
index 62778ff3aca..d37c10f6730 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorStop.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorStop.java
@@ -17,37 +17,32 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.CoprocessorEnvironment;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.MiniHBaseCluster;
import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Tests for master and regionserver coprocessor stop method
*/
-@Category({ CoprocessorTests.class, MediumTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(MediumTests.TAG)
public class TestCoprocessorStop {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCoprocessorStop.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestCoprocessorStop.class);
private static HBaseTestingUtility UTIL = new HBaseTestingUtility();
private static final String MASTER_FILE = "master" + EnvironmentEdgeManager.currentTime();
@@ -92,7 +87,7 @@ public class TestCoprocessorStop {
}
}
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() throws Exception {
Configuration conf = UTIL.getConfiguration();
@@ -102,7 +97,7 @@ public class TestCoprocessorStop {
UTIL.startMiniCluster();
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
UTIL.shutdownMiniCluster();
}
@@ -120,9 +115,9 @@ public class TestCoprocessorStop {
FileSystem fs = FileSystem.get(conf);
Path resultFile = new Path(UTIL.getDataTestDirOnTestFS(), MASTER_FILE);
- assertTrue("Master flag file should have been created", fs.exists(resultFile));
+ assertTrue(fs.exists(resultFile), "Master flag file should have been created");
resultFile = new Path(UTIL.getDataTestDirOnTestFS(), REGIONSERVER_FILE);
- assertTrue("RegionServer flag file should have been created", fs.exists(resultFile));
+ assertTrue(fs.exists(resultFile), "RegionServer flag file should have been created");
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreMasterCoprocessor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreMasterCoprocessor.java
index 051875c5942..9c83292936e 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreMasterCoprocessor.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreMasterCoprocessor.java
@@ -17,50 +17,42 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-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 org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.master.MasterCoprocessorHost;
import org.apache.hadoop.hbase.master.MasterServices;
import org.apache.hadoop.hbase.master.assignment.MockMasterServices;
import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
/**
* Test CoreCoprocessor Annotation works giving access to facility not usually available. Test
* MasterCoprocessor.
*/
-@Category({ CoprocessorTests.class, SmallTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(SmallTests.TAG)
public class TestCoreMasterCoprocessor {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCoreMasterCoprocessor.class);
- @Rule
- public TestName name = new TestName();
private static final HBaseTestingUtility HTU = HBaseTestingUtility.createLocalHTU();
private MasterServices ms;
private MasterCoprocessorHost mch;
- @Before
+ @BeforeEach
public void before() throws Exception {
this.ms = new MockMasterServices(HTU.getConfiguration());
this.mch = new MasterCoprocessorHost(this.ms, HTU.getConfiguration());
this.mch.preMasterInitialization();
}
- @After
+ @AfterEach
public void after() throws IOException {
this.mch.preStopMaster();
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreRegionCoprocessor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreRegionCoprocessor.java
index fb28b802147..1c6e9fe4cb1 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreRegionCoprocessor.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreRegionCoprocessor.java
@@ -17,12 +17,11 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-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 org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.MockRegionServerServices;
import org.apache.hadoop.hbase.TableName;
@@ -40,34 +39,29 @@ import org.apache.hadoop.hbase.regionserver.RegionServerServices;
import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
/**
* Test CoreCoprocessor Annotation works giving access to facility not usually available. Test
* RegionCoprocessor.
*/
-@Category({ CoprocessorTests.class, SmallTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(SmallTests.TAG)
public class TestCoreRegionCoprocessor {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCoreRegionCoprocessor.class);
-
- @Rule
- public TestName name = new TestName();
HBaseTestingUtility HTU = HBaseTestingUtility.createLocalHTU();
private HRegion region = null;
private RegionServerServices rss;
+ private String currentTestName;
- @Before
- public void before() throws IOException {
- String methodName = this.name.getMethodName();
+ @BeforeEach
+ public void before(TestInfo testInfo) throws IOException {
+ currentTestName = testInfo.getTestMethod().get().getName();
+ String methodName = this.currentTestName;
TableName tn = TableName.valueOf(methodName);
ColumnFamilyDescriptor cfd =
ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(methodName)).build();
@@ -80,7 +74,7 @@ public class TestCoreRegionCoprocessor {
this.region = HRegion.openHRegion(ri, td, null, HTU.getConfiguration(), this.rss, null);
}
- @After
+ @AfterEach
public void after() throws IOException {
this.region.close();
HTU.cleanupTestDir();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreRegionServerCoprocessor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreRegionServerCoprocessor.java
index 4a97b8261c7..abf1eae1288 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreRegionServerCoprocessor.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreRegionServerCoprocessor.java
@@ -17,51 +17,45 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-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 org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.MockRegionServerServices;
import org.apache.hadoop.hbase.regionserver.RegionServerCoprocessorHost;
import org.apache.hadoop.hbase.regionserver.RegionServerServices;
import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
/**
* Test CoreCoprocessor Annotation works giving access to facility not usually available. Test
* RegionServerCoprocessor.
*/
-@Category({ CoprocessorTests.class, SmallTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(SmallTests.TAG)
public class TestCoreRegionServerCoprocessor {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCoreRegionServerCoprocessor.class);
-
- @Rule
- public TestName name = new TestName();
private static final HBaseTestingUtility HTU = HBaseTestingUtility.createLocalHTU();
private RegionServerServices rss;
private RegionServerCoprocessorHost rsch;
+ private String currentTestName;
- @Before
- public void before() throws IOException {
- String methodName = this.name.getMethodName();
+ @BeforeEach
+ public void before(TestInfo testInfo) throws IOException {
+ currentTestName = testInfo.getTestMethod().get().getName();
+ String methodName = this.currentTestName;
this.rss = new MockRegionServerServices(HTU.getConfiguration());
this.rsch = new RegionServerCoprocessorHost(this.rss, HTU.getConfiguration());
}
- @After
+ @AfterEach
public void after() throws IOException {
this.rsch.preStop("Stopping", null);
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestIncrementAndAppendWithNullResult.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestIncrementAndAppendWithNullResult.java
index 815b7498bf8..442ddbd49d3 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestIncrementAndAppendWithNullResult.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestIncrementAndAppendWithNullResult.java
@@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.Arrays;
@@ -27,7 +27,6 @@ import java.util.Optional;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellBuilderFactory;
import org.apache.hadoop.hbase.CellBuilderType;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName;
@@ -39,19 +38,15 @@ import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category({ CoprocessorTests.class, MediumTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(MediumTests.TAG)
public class TestIncrementAndAppendWithNullResult {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestIncrementAndAppendWithNullResult.class);
-
private static final HBaseTestingUtility util = new HBaseTestingUtility();
private static final TableName TEST_TABLE = TableName.valueOf("test");
private static final byte[] TEST_FAMILY = Bytes.toBytes("f1");
@@ -59,7 +54,7 @@ public class TestIncrementAndAppendWithNullResult {
private static final byte[] qualifierCol1 = Bytes.toBytes("col1");
private static Table table;
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() throws Exception {
util.getConfiguration().set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
MyObserver.class.getName());
@@ -69,7 +64,7 @@ public class TestIncrementAndAppendWithNullResult {
table = util.createTable(TEST_TABLE, TEST_FAMILY);
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
util.shutdownMiniCluster();
}
@@ -147,9 +142,9 @@ public class TestIncrementAndAppendWithNullResult {
private static void checkResult(Object[] results) {
for (int i = 0; i != results.length; ++i) {
- assertNotNull("The result[" + i + "] should not be null", results[i]);
- assertTrue("The result[" + i + "] should be Result type", results[i] instanceof Result);
- assertTrue("The result[" + i + "] shuold be empty", ((Result) results[i]).isEmpty());
+ assertNotNull(results[i], "The result[" + i + "] should not be null");
+ assertTrue(results[i] instanceof Result, "The result[" + i + "] should be Result type");
+ assertTrue(((Result) results[i]).isEmpty(), "The result[" + i + "] should be empty");
}
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestIncrementTimeRange.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestIncrementTimeRange.java
index a74422b8b7e..c5779417607 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestIncrementTimeRange.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestIncrementTimeRange.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-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.assertTrue;
import java.io.IOException;
import java.util.Arrays;
@@ -27,7 +27,6 @@ import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Get;
@@ -43,26 +42,22 @@ import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.ManualEnvironmentEdge;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
/**
* This test runs batch mutation with Increments which have custom TimeRange. Custom Observer
* records the TimeRange. We then verify that the recorded TimeRange has same bounds as the initial
* TimeRange. See HBASE-15698
*/
-@Category({ CoprocessorTests.class, MediumTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(MediumTests.TAG)
public class TestIncrementTimeRange {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestIncrementTimeRange.class);
-
private static final HBaseTestingUtility util = new HBaseTestingUtility();
private static ManualEnvironmentEdge mee = new ManualEnvironmentEdge();
@@ -82,7 +77,7 @@ public class TestIncrementTimeRange {
private Table hTableInterface;
private Table table;
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() throws Exception {
util.getConfiguration().set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
MyObserver.class.getName());
@@ -93,12 +88,12 @@ public class TestIncrementTimeRange {
EnvironmentEdgeManager.injectEdge(mee);
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
util.shutdownMiniCluster();
}
- @Before
+ @BeforeEach
public void before() throws Exception {
table = util.createTable(TEST_TABLE, TEST_FAMILY);
@@ -115,7 +110,7 @@ public class TestIncrementTimeRange {
table.put(putc);
}
- @After
+ @AfterEach
public void after() throws Exception {
try {
if (table != null) {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterCoprocessorExceptionWithAbort.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterCoprocessorExceptionWithAbort.java
index 01762f71499..7b5ef29003f 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterCoprocessorExceptionWithAbort.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterCoprocessorExceptionWithAbort.java
@@ -17,17 +17,16 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-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.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
import java.util.Optional;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Abortable;
import org.apache.hadoop.hbase.CoprocessorEnvironment;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
@@ -44,24 +43,20 @@ import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.zookeeper.ZKNodeTracker;
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
/**
* Tests unhandled exceptions thrown by coprocessors running on master. Expected result is that the
* master will abort with an informative error message describing the set of its loaded coprocessors
* for crash diagnosis. (HBASE-4014).
*/
-@Category({ CoprocessorTests.class, MediumTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(MediumTests.TAG)
public class TestMasterCoprocessorExceptionWithAbort {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestMasterCoprocessorExceptionWithAbort.class);
-
public static class MasterTracker extends ZKNodeTracker {
public boolean masterZKNodeWasDeleted = false;
@@ -95,8 +90,8 @@ public class TestMasterCoprocessorExceptionWithAbort {
admin.createTable(htd);
fail("BuggyMasterObserver failed to throw an exception.");
} catch (IOException e) {
- assertEquals("HBaseAdmin threw an interrupted IOException as expected.",
- "java.io.InterruptedIOException", e.getClass().getName());
+ assertEquals("java.io.InterruptedIOException", e.getClass().getName(),
+ "HBaseAdmin threw an interrupted IOException as expected.");
}
}
}
@@ -150,7 +145,7 @@ public class TestMasterCoprocessorExceptionWithAbort {
private static byte[] TEST_TABLE = Bytes.toBytes("observed_table");
private static byte[] TEST_FAMILY = Bytes.toBytes("fam1");
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() throws Exception {
Configuration conf = UTIL.getConfiguration();
conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, BuggyMasterObserver.class.getName());
@@ -159,7 +154,7 @@ public class TestMasterCoprocessorExceptionWithAbort {
UTIL.startMiniCluster();
}
- @AfterClass
+ @AfterAll
public static void teardownAfterClass() throws Exception {
UTIL.shutdownMiniCluster();
}
@@ -171,7 +166,7 @@ public class TestMasterCoprocessorExceptionWithAbort {
HMaster master = cluster.getMaster();
MasterCoprocessorHost host = master.getMasterCoprocessorHost();
BuggyMasterObserver cp = host.findCoprocessor(BuggyMasterObserver.class);
- assertFalse("No table created yet", cp.wasCreateTableCalled());
+ assertFalse(cp.wasCreateTableCalled(), "No table created yet");
// set a watch on the zookeeper /hbase/master node. If the master dies,
// the node will be deleted.
@@ -227,15 +222,15 @@ public class TestMasterCoprocessorExceptionWithAbort {
}
}
- assertTrue("Master aborted on coprocessor exception, as expected.",
- masterTracker.masterZKNodeWasDeleted);
+ assertTrue(masterTracker.masterZKNodeWasDeleted,
+ "Master aborted on coprocessor exception, as expected.");
createTableThread.interrupt();
try {
createTableThread.join(1000);
} catch (InterruptedException e) {
- assertTrue("Ignoring InterruptedException while waiting for " + " createTableThread.join().",
- true);
+ assertTrue(true,
+ "Ignoring InterruptedException while waiting for " + " createTableThread.join().");
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterCoprocessorExceptionWithRemove.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterCoprocessorExceptionWithRemove.java
index 5da1f4f3bd7..89a6427c2e6 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterCoprocessorExceptionWithRemove.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterCoprocessorExceptionWithRemove.java
@@ -17,16 +17,15 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+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 java.io.IOException;
import java.util.Optional;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Abortable;
import org.apache.hadoop.hbase.CoprocessorEnvironment;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
@@ -42,24 +41,20 @@ import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.zookeeper.ZKNodeTracker;
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
/**
* Tests unhandled exceptions thrown by coprocessors running on master. Expected result is that the
* master will remove the buggy coprocessor from its set of coprocessors and throw a
* org.apache.hadoop.hbase.exceptions.DoNotRetryIOException back to the client. (HBASE-4014).
*/
-@Category({ CoprocessorTests.class, MediumTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(MediumTests.TAG)
public class TestMasterCoprocessorExceptionWithRemove {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestMasterCoprocessorExceptionWithRemove.class);
-
public static class MasterTracker extends ZKNodeTracker {
public boolean masterZKNodeWasDeleted = false;
@@ -130,7 +125,7 @@ public class TestMasterCoprocessorExceptionWithRemove {
private static byte[] TEST_TABLE2 = Bytes.toBytes("table2");
private static byte[] TEST_FAMILY2 = Bytes.toBytes("fam2");
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() throws Exception {
Configuration conf = UTIL.getConfiguration();
conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, BuggyMasterObserver.class.getName());
@@ -138,7 +133,7 @@ public class TestMasterCoprocessorExceptionWithRemove {
UTIL.startMiniCluster();
}
- @AfterClass
+ @AfterAll
public static void teardownAfterClass() throws Exception {
UTIL.shutdownMiniCluster();
}
@@ -150,7 +145,7 @@ public class TestMasterCoprocessorExceptionWithRemove {
HMaster master = cluster.getMaster();
MasterCoprocessorHost host = master.getMasterCoprocessorHost();
BuggyMasterObserver cp = host.findCoprocessor(BuggyMasterObserver.class);
- assertFalse("No table created yet", cp.wasCreateTableCalled());
+ assertFalse(cp.wasCreateTableCalled(), "No table created yet");
// Set a watch on the zookeeper /hbase/master node. If the master dies,
// the node will be deleted.
@@ -213,8 +208,8 @@ public class TestMasterCoprocessorExceptionWithRemove {
fail("InterruptedException while sleeping.");
}
- assertFalse("Master survived coprocessor NPE, as expected.",
- masterTracker.masterZKNodeWasDeleted);
+ assertFalse(masterTracker.masterZKNodeWasDeleted,
+ "Master survived coprocessor NPE, as expected.");
String loadedCoprocessors = HMaster.getLoadedCoprocessors();
assertTrue(loadedCoprocessors.contains(coprocessorName));
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java
index 61e671b7389..dead3c1d333 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-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.io.IOException;
import java.util.Arrays;
@@ -30,7 +30,6 @@ import java.util.Set;
import java.util.concurrent.CountDownLatch;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CoprocessorEnvironment;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HRegionLocation;
@@ -63,13 +62,12 @@ import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Threads;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -82,13 +80,10 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableNa
* Tests invocation of the {@link org.apache.hadoop.hbase.coprocessor.MasterObserver} interface
* hooks at all appropriate times during normal HMaster operations.
*/
-@Category({ CoprocessorTests.class, MediumTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(MediumTests.TAG)
public class TestMasterObserver {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestMasterObserver.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestMasterObserver.class);
public static CountDownLatch tableCreationLatch = new CountDownLatch(1);
@@ -1260,7 +1255,6 @@ public class TestMasterObserver {
final ObserverContext<MasterCoprocessorEnvironment> ctx, final RegionInfo[] regionsToMerge)
throws IOException {
}
-
}
private static HBaseTestingUtility UTIL = new HBaseTestingUtility();
@@ -1268,10 +1262,14 @@ public class TestMasterObserver {
private static TableName TEST_CLONE = TableName.valueOf("observed_clone");
private static byte[] TEST_FAMILY = Bytes.toBytes("fam1");
private static byte[] TEST_FAMILY2 = Bytes.toBytes("fam2");
- @Rule
- public TestName name = new TestName();
+ private String currentTestName;
+
+ @BeforeEach
+ public void setUp(TestInfo testInfo) {
+ currentTestName = testInfo.getTestMethod().get().getName();
+ }
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() throws Exception {
Configuration conf = UTIL.getConfiguration();
conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, CPMasterObserver.class.getName());
@@ -1279,7 +1277,7 @@ public class TestMasterObserver {
UTIL.startMiniCluster(2);
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
UTIL.shutdownMiniCluster();
}
@@ -1289,28 +1287,28 @@ public class TestMasterObserver {
MiniHBaseCluster cluster = UTIL.getHBaseCluster();
HMaster master = cluster.getMaster();
- assertTrue("Master should be active", master.isActiveMaster());
+ assertTrue(master.isActiveMaster(), "Master should be active");
MasterCoprocessorHost host = master.getMasterCoprocessorHost();
- assertNotNull("CoprocessorHost should not be null", host);
+ assertNotNull(host, "CoprocessorHost should not be null");
CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class);
- assertNotNull("CPMasterObserver coprocessor not found or not installed!", cp);
+ assertNotNull(cp, "CPMasterObserver coprocessor not found or not installed!");
// check basic lifecycle
- assertTrue("MasterObserver should have been started", cp.wasStarted());
- assertTrue("preMasterInitialization() hook should have been called",
- cp.wasMasterInitializationCalled());
- assertTrue("postStartMaster() hook should have been called", cp.wasStartMasterCalled());
+ assertTrue(cp.wasStarted(), "MasterObserver should have been started");
+ assertTrue(cp.wasMasterInitializationCalled(),
+ "preMasterInitialization() hook should have been called");
+ assertTrue(cp.wasStartMasterCalled(), "postStartMaster() hook should have been called");
}
@Test
public void testTableOperations() throws Exception {
MiniHBaseCluster cluster = UTIL.getHBaseCluster();
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ final TableName tableName = TableName.valueOf(currentTestName);
HMaster master = cluster.getMaster();
MasterCoprocessorHost host = master.getMasterCoprocessorHost();
CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class);
cp.resetStates();
- assertFalse("No table created yet", cp.wasCreateTableCalled());
+ assertFalse(cp.wasCreateTableCalled(), "No table created yet");
// create a table
HTableDescriptor htd = new HTableDescriptor(tableName);
@@ -1321,31 +1319,31 @@ public class TestMasterObserver {
admin.createTable(htd,
Arrays.copyOfRange(HBaseTestingUtility.KEYS, 1, HBaseTestingUtility.KEYS.length));
- assertTrue("Test table should be created", cp.wasCreateTableCalled());
+ assertTrue(cp.wasCreateTableCalled(), "Test table should be created");
tableCreationLatch.await();
- assertTrue("Table pre create handler called.", cp.wasPreCreateTableActionCalled());
- assertTrue("Table create handler should be called.", cp.wasCreateTableActionCalled());
+ assertTrue(cp.wasPreCreateTableActionCalled(), "Table pre create handler called.");
+ assertTrue(cp.wasCreateTableActionCalled(), "Table create handler should be called.");
RegionLocator regionLocator = connection.getRegionLocator(htd.getTableName());
List<HRegionLocation> regions = regionLocator.getAllRegionLocations();
admin.mergeRegionsAsync(regions.get(0).getRegionInfo().getEncodedNameAsBytes(),
regions.get(1).getRegionInfo().getEncodedNameAsBytes(), true);
- assertTrue("Coprocessor should have been called on region merge", cp.wasMergeRegionsCalled());
+ assertTrue(cp.wasMergeRegionsCalled(), "Coprocessor should have been called on region merge");
tableCreationLatch = new CountDownLatch(1);
admin.disableTable(tableName);
assertTrue(admin.isTableDisabled(tableName));
- assertTrue("Coprocessor should have been called on table disable",
- cp.wasDisableTableCalled());
- assertTrue("Disable table handler should be called.", cp.wasDisableTableActionCalled());
+ assertTrue(cp.wasDisableTableCalled(),
+ "Coprocessor should have been called on table disable");
+ assertTrue(cp.wasDisableTableActionCalled(), "Disable table handler should be called.");
// enable
assertFalse(cp.wasEnableTableCalled());
admin.enableTable(tableName);
assertTrue(admin.isTableEnabled(tableName));
- assertTrue("Coprocessor should have been called on table enable", cp.wasEnableTableCalled());
- assertTrue("Enable table handler should be called.", cp.wasEnableTableActionCalled());
+ assertTrue(cp.wasEnableTableCalled(), "Coprocessor should have been called on table enable");
+ assertTrue(cp.wasEnableTableActionCalled(), "Enable table handler should be called.");
admin.disableTable(tableName);
assertTrue(admin.isTableDisabled(tableName));
@@ -1353,7 +1351,7 @@ public class TestMasterObserver {
// modify table
htd.setMaxFileSize(512 * 1024 * 1024);
modifyTableSync(admin, tableName, htd);
- assertTrue("Test table should have been modified", cp.wasModifyTableCalled());
+ assertTrue(cp.wasModifyTableCalled(), "Test table should have been modified");
// truncate table
admin.truncateTable(tableName, false);
@@ -1362,58 +1360,58 @@ public class TestMasterObserver {
admin.disableTable(tableName);
assertTrue(admin.isTableDisabled(tableName));
deleteTable(admin, tableName);
- assertFalse("Test table should have been deleted", admin.tableExists(tableName));
- assertTrue("Coprocessor should have been called on table delete", cp.wasDeleteTableCalled());
- assertTrue("Delete table handler should be called.", cp.wasDeleteTableActionCalled());
+ assertFalse(admin.tableExists(tableName), "Test table should have been deleted");
+ assertTrue(cp.wasDeleteTableCalled(), "Coprocessor should have been called on table delete");
+ assertTrue(cp.wasDeleteTableActionCalled(), "Delete table handler should be called.");
// When bypass was supported, we'd turn off bypass and rerun tests. Leaving rerun in place.
cp.resetStates();
admin.createTable(htd);
- assertTrue("Test table should be created", cp.wasCreateTableCalled());
+ assertTrue(cp.wasCreateTableCalled(), "Test table should be created");
tableCreationLatch.await();
- assertTrue("Table pre create handler called.", cp.wasPreCreateTableActionCalled());
- assertTrue("Table create handler should be called.", cp.wasCreateTableActionCalled());
+ assertTrue(cp.wasPreCreateTableActionCalled(), "Table pre create handler called.");
+ assertTrue(cp.wasCreateTableActionCalled(), "Table create handler should be called.");
// disable
assertFalse(cp.wasDisableTableCalled());
assertFalse(cp.wasDisableTableActionCalled());
admin.disableTable(tableName);
assertTrue(admin.isTableDisabled(tableName));
- assertTrue("Coprocessor should have been called on table disable",
- cp.wasDisableTableCalled());
- assertTrue("Disable table handler should be called.", cp.wasDisableTableActionCalled());
+ assertTrue(cp.wasDisableTableCalled(),
+ "Coprocessor should have been called on table disable");
+ assertTrue(cp.wasDisableTableActionCalled(), "Disable table handler should be called.");
// modify table
htd.setMaxFileSize(512 * 1024 * 1024);
modifyTableSync(admin, tableName, htd);
- assertTrue("Test table should have been modified", cp.wasModifyTableCalled());
+ assertTrue(cp.wasModifyTableCalled(), "Test table should have been modified");
// enable
assertFalse(cp.wasEnableTableCalled());
assertFalse(cp.wasEnableTableActionCalled());
admin.enableTable(tableName);
assertTrue(admin.isTableEnabled(tableName));
- assertTrue("Coprocessor should have been called on table enable", cp.wasEnableTableCalled());
- assertTrue("Enable table handler should be called.", cp.wasEnableTableActionCalled());
+ assertTrue(cp.wasEnableTableCalled(), "Coprocessor should have been called on table enable");
+ assertTrue(cp.wasEnableTableActionCalled(), "Enable table handler should be called.");
// disable again
admin.disableTable(tableName);
assertTrue(admin.isTableDisabled(tableName));
// delete table
- assertFalse("No table deleted yet", cp.wasDeleteTableCalled());
- assertFalse("Delete table handler should not be called.", cp.wasDeleteTableActionCalled());
+ assertFalse(cp.wasDeleteTableCalled(), "No table deleted yet");
+ assertFalse(cp.wasDeleteTableActionCalled(), "Delete table handler should not be called.");
deleteTable(admin, tableName);
- assertFalse("Test table should have been deleted", admin.tableExists(tableName));
- assertTrue("Coprocessor should have been called on table delete", cp.wasDeleteTableCalled());
- assertTrue("Delete table handler should be called.", cp.wasDeleteTableActionCalled());
+ assertFalse(admin.tableExists(tableName), "Test table should have been deleted");
+ assertTrue(cp.wasDeleteTableCalled(), "Coprocessor should have been called on table delete");
+ assertTrue(cp.wasDeleteTableActionCalled(), "Delete table handler should be called.");
}
}
@Test
public void testSnapshotOperations() throws Exception {
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ final TableName tableName = TableName.valueOf(currentTestName);
MiniHBaseCluster cluster = UTIL.getHBaseCluster();
HMaster master = cluster.getMaster();
MasterCoprocessorHost host = master.getMasterCoprocessorHost();
@@ -1435,21 +1433,21 @@ public class TestMasterObserver {
try {
// Test snapshot operation
- assertFalse("Coprocessor should not have been called yet", cp.wasSnapshotCalled());
+ assertFalse(cp.wasSnapshotCalled(), "Coprocessor should not have been called yet");
admin.snapshot(TEST_SNAPSHOT, tableName);
- assertTrue("Coprocessor should have been called on snapshot", cp.wasSnapshotCalled());
+ assertTrue(cp.wasSnapshotCalled(), "Coprocessor should have been called on snapshot");
// Test list operation
admin.listSnapshots();
- assertTrue("Coprocessor should have been called on snapshot list",
- cp.wasListSnapshotCalled());
+ assertTrue(cp.wasListSnapshotCalled(),
+ "Coprocessor should have been called on snapshot list");
// Test clone operation
admin.cloneSnapshot(TEST_SNAPSHOT, TEST_CLONE);
- assertTrue("Coprocessor should have been called on snapshot clone",
- cp.wasCloneSnapshotCalled());
- assertFalse("Coprocessor restore should not have been called on snapshot clone",
- cp.wasRestoreSnapshotCalled());
+ assertTrue(cp.wasCloneSnapshotCalled(),
+ "Coprocessor should have been called on snapshot clone");
+ assertFalse(cp.wasRestoreSnapshotCalled(),
+ "Coprocessor restore should not have been called on snapshot clone");
admin.disableTable(TEST_CLONE);
assertTrue(admin.isTableDisabled(tableName));
deleteTable(admin, TEST_CLONE);
@@ -1457,14 +1455,14 @@ public class TestMasterObserver {
// Test restore operation
cp.resetStates();
admin.restoreSnapshot(TEST_SNAPSHOT);
- assertTrue("Coprocessor should have been called on snapshot restore",
- cp.wasRestoreSnapshotCalled());
- assertFalse("Coprocessor clone should not have been called on snapshot restore",
- cp.wasCloneSnapshotCalled());
+ assertTrue(cp.wasRestoreSnapshotCalled(),
+ "Coprocessor should have been called on snapshot restore");
+ assertFalse(cp.wasCloneSnapshotCalled(),
+ "Coprocessor clone should not have been called on snapshot restore");
admin.deleteSnapshot(TEST_SNAPSHOT);
- assertTrue("Coprocessor should have been called on snapshot delete",
- cp.wasDeleteSnapshotCalled());
+ assertTrue(cp.wasDeleteSnapshotCalled(),
+ "Coprocessor should have been called on snapshot delete");
} finally {
deleteTable(admin, tableName);
}
@@ -1482,15 +1480,15 @@ public class TestMasterObserver {
Admin admin = UTIL.getAdmin();
admin.listNamespaces();
- assertTrue("preListNamespaces should have been called", cp.preListNamespacesCalled);
- assertTrue("postListNamespaces should have been called", cp.postListNamespacesCalled);
+ assertTrue(cp.preListNamespacesCalled, "preListNamespaces should have been called");
+ assertTrue(cp.postListNamespacesCalled, "postListNamespaces should have been called");
admin.createNamespace(NamespaceDescriptor.create(testNamespace).build());
- assertTrue("Test namespace should be created", cp.wasCreateNamespaceCalled());
+ assertTrue(cp.wasCreateNamespaceCalled(), "Test namespace should be created");
assertNotNull(admin.getNamespaceDescriptor(testNamespace));
- assertTrue("Test namespace descriptor should have been called",
- cp.wasGetNamespaceDescriptorCalled());
+ assertTrue(cp.wasGetNamespaceDescriptorCalled(),
+ "Test namespace descriptor should have been called");
// This test used to do a bunch w/ bypass but bypass of these table and namespace stuff has
// been removed so the testing code was removed.
}
@@ -1510,7 +1508,7 @@ public class TestMasterObserver {
@Test
public void testRegionTransitionOperations() throws Exception {
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ final TableName tableName = TableName.valueOf(currentTestName);
MiniHBaseCluster cluster = UTIL.getHBaseCluster();
HMaster master = cluster.getMaster();
@@ -1531,7 +1529,7 @@ public class TestMasterObserver {
break;
}
}
- assertNotNull("Found a non-null entry", firstGoodPair);
+ assertNotNull(firstGoodPair, "Found a non-null entry");
LOG.info("Found " + firstGoodPair.toString());
// Try to force a move
Collection<ServerName> servers = master.getClusterMetrics().getLiveServerMetrics().keySet();
@@ -1551,16 +1549,16 @@ public class TestMasterObserver {
break;
}
}
- assertTrue("Found server", found);
+ assertTrue(found, "Found server");
LOG.info("Found " + destName);
master.getMasterRpcServices().moveRegion(null, RequestConverter.buildMoveRegionRequest(
firstGoodPair.getRegionInfo().getEncodedNameAsBytes(), ServerName.valueOf(destName)));
- assertTrue("Coprocessor should have been called on region move", cp.wasMoveCalled());
+ assertTrue(cp.wasMoveCalled(), "Coprocessor should have been called on region move");
// make sure balancer is on
master.balanceSwitch(true);
- assertTrue("Coprocessor should have been called on balance switch",
- cp.wasBalanceSwitchCalled());
+ assertTrue(cp.wasBalanceSwitchCalled(),
+ "Coprocessor should have been called on balance switch");
// turn balancer off
master.balanceSwitch(false);
@@ -1588,7 +1586,7 @@ public class TestMasterObserver {
// now trigger a balance
master.balanceSwitch(true);
master.balance();
- assertTrue("Coprocessor should be called on region rebalancing", cp.wasBalanceCalled());
+ assertTrue(cp.wasBalanceCalled(), "Coprocessor should be called on region rebalancing");
} finally {
Admin admin = UTIL.getAdmin();
admin.disableTable(tableName);
@@ -1609,8 +1607,8 @@ public class TestMasterObserver {
RequestConverter.buildGetTableDescriptorsRequest((List<TableName>) null);
master.getMasterRpcServices().getTableDescriptors(null, req);
- assertTrue("Coprocessor should be called on table descriptors request",
- cp.wasGetTableDescriptorsCalled());
+ assertTrue(cp.wasGetTableDescriptorsCalled(),
+ "Coprocessor should be called on table descriptors request");
}
@Test
@@ -1623,7 +1621,7 @@ public class TestMasterObserver {
cp.resetStates();
master.getMasterRpcServices().getTableNames(null, GetTableNamesRequest.newBuilder().build());
- assertTrue("Coprocessor should be called on table names request", cp.wasGetTableNamesCalled());
+ assertTrue(cp.wasGetTableNamesCalled(), "Coprocessor should be called on table names request");
}
@Test
@@ -1636,8 +1634,8 @@ public class TestMasterObserver {
cp.resetStates();
master.abortProcedure(1, true);
- assertTrue("Coprocessor should be called on abort procedure request",
- cp.wasAbortProcedureCalled());
+ assertTrue(cp.wasAbortProcedureCalled(),
+ "Coprocessor should be called on abort procedure request");
}
@Test
@@ -1650,8 +1648,8 @@ public class TestMasterObserver {
cp.resetStates();
master.getProcedures();
- assertTrue("Coprocessor should be called on get procedures request",
- cp.wasGetProceduresCalled());
+ assertTrue(cp.wasGetProceduresCalled(),
+ "Coprocessor should be called on get procedures request");
}
@Test
@@ -1664,7 +1662,7 @@ public class TestMasterObserver {
cp.resetStates();
master.getLocks();
- assertTrue("Coprocessor should be called on get locks request", cp.wasGetLocksCalled());
+ assertTrue(cp.wasGetLocksCalled(), "Coprocessor should be called on get locks request");
}
private void deleteTable(Admin admin, TableName tableName) throws Exception {
@@ -1699,15 +1697,15 @@ public class TestMasterObserver {
MasterCoprocessorHost host = master.getMasterCoprocessorHost();
CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class);
cp.resetStates();
- assertFalse("No master store flush call", cp.preMasterStoreFlushCalled);
- assertFalse("No master store flush call", cp.postMasterStoreFlushCalled);
+ assertFalse(cp.preMasterStoreFlushCalled, "No master store flush call");
+ assertFalse(cp.postMasterStoreFlushCalled, "No master store flush call");
try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
Admin admin = connection.getAdmin()) {
admin.flushMasterStore();
- assertTrue("Master store flush called", cp.preMasterStoreFlushCalled);
- assertTrue("Master store flush called", cp.postMasterStoreFlushCalled);
+ assertTrue(cp.preMasterStoreFlushCalled, "Master store flush called");
+ assertTrue(cp.postMasterStoreFlushCalled, "Master store flush called");
}
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserverToModifyTableSchema.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserverToModifyTableSchema.java
index dd7cecb5dc9..c916501f1e0 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserverToModifyTableSchema.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserverToModifyTableSchema.java
@@ -17,12 +17,11 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.util.Optional;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
@@ -33,28 +32,19 @@ import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category({ CoprocessorTests.class, MediumTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(MediumTests.TAG)
public class TestMasterObserverToModifyTableSchema {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestMasterObserverToModifyTableSchema.class);
-
private static HBaseTestingUtility UTIL = new HBaseTestingUtility();
private static TableName TABLENAME = TableName.valueOf("TestTable");
- @Rule
- public TestName name = new TestName();
-
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() throws Exception {
Configuration conf = UTIL.getConfiguration();
conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY,
@@ -62,7 +52,7 @@ public class TestMasterObserverToModifyTableSchema {
UTIL.startMiniCluster(1);
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
UTIL.shutdownMiniCluster();
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMetaTableMetrics.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMetaTableMetrics.java
index 18acf54a2cd..9a305d093a5 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMetaTableMetrics.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMetaTableMetrics.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
import java.util.ArrayList;
@@ -41,7 +41,6 @@ import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.JMXListener;
import org.apache.hadoop.hbase.TableName;
@@ -57,20 +56,16 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.hamcrest.CustomTypeSafeMatcher;
import org.hamcrest.Matcher;
import org.hamcrest.core.AllOf;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Category({ CoprocessorTests.class, LargeTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(LargeTests.TAG)
public class TestMetaTableMetrics {
-
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestMetaTableMetrics.class);
private static final Logger LOG = LoggerFactory.getLogger(TestMetaTableMetrics.class);
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
@@ -91,7 +86,7 @@ public class TestMetaTableMetrics {
private byte[] tablename;
private final int nthreads = 20;
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() throws Exception {
Configuration conf = UTIL.getConfiguration();
// Set system coprocessor so it can be applied to meta regions
@@ -120,7 +115,7 @@ public class TestMetaTableMetrics {
}
}
- @AfterClass
+ @AfterAll
public static void tearDown() throws Exception {
UTIL.shutdownMiniCluster();
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestNegativeMemStoreSizeWithSlowCoprocessor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestNegativeMemStoreSizeWithSlowCoprocessor.java
index c786ceab027..5bb9f96a756 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestNegativeMemStoreSizeWithSlowCoprocessor.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestNegativeMemStoreSizeWithSlowCoprocessor.java
@@ -17,9 +17,11 @@
*/
package org.apache.hadoop.hbase.coprocessor;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName;
@@ -30,12 +32,10 @@ import org.apache.hadoop.hbase.regionserver.HRegion;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.wal.WALEdit;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,13 +44,9 @@ import org.slf4j.LoggerFactory;
* slow/expensive and a flush is triggered at the same time the coprocessow is doing its work. To
* simulate this we call flush from the coprocessor itself
*/
-@Category(MediumTests.class)
+@Tag(MediumTests.TAG)
public class TestNegativeMemStoreSizeWithSlowCoprocessor {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestNegativeMemStoreSizeWithSlowCoprocessor.class);
-
static final Logger LOG =
LoggerFactory.getLogger(TestNegativeMemStoreSizeWithSlowCoprocessor.class);
@@ -59,7 +55,7 @@ public class TestNegativeMemStoreSizeWithSlowCoprocessor {
private static final byte[] family = Bytes.toBytes("f");
private static final byte[] qualifier = Bytes.toBytes("q");
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() throws Exception {
Configuration conf = TEST_UTIL.getConfiguration();
conf.setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
@@ -70,7 +66,7 @@ public class TestNegativeMemStoreSizeWithSlowCoprocessor {
TEST_UTIL.createTable(TableName.valueOf(tableName), family);
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
@@ -93,7 +89,7 @@ public class TestNegativeMemStoreSizeWithSlowCoprocessor {
} catch (IOException e) {
IOEthrown = true;
} finally {
- Assert.assertFalse("Shouldn't have thrown an exception", IOEthrown);
+ assertFalse(IOEthrown, "Shouldn't have thrown an exception");
if (table != null) {
table.close();
}
@@ -110,7 +106,7 @@ public class TestNegativeMemStoreSizeWithSlowCoprocessor {
if (Bytes.equals(put.getRow(), Bytes.toBytes("row2"))) {
region.flush(false);
- Assert.assertTrue(region.getMemStoreDataSize() >= 0);
+ assertTrue(region.getMemStoreDataSize() >= 0);
}
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestOpenTableInCoprocessor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestOpenTableInCoprocessor.java
index ccd7ff32b27..7f79e9b8066 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestOpenTableInCoprocessor.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestOpenTableInCoprocessor.java
@@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-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.Collections;
@@ -27,7 +27,6 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
@@ -43,25 +42,21 @@ import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Threads;
import org.apache.hadoop.hbase.wal.WALEdit;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.apache.hbase.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder;
/**
* Test that a coprocessor can open a connection and write to another table, inside a hook.
*/
-@Category({ CoprocessorTests.class, MediumTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(MediumTests.TAG)
public class TestOpenTableInCoprocessor {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestOpenTableInCoprocessor.class);
-
private static final TableName otherTable = TableName.valueOf("otherTable");
private static final TableName primaryTable = TableName.valueOf("primary");
private static final byte[] family = new byte[] { 'f' };
@@ -134,12 +129,12 @@ public class TestOpenTableInCoprocessor {
private static HBaseTestingUtility UTIL = new HBaseTestingUtility();
- @BeforeClass
+ @BeforeAll
public static void setupCluster() throws Exception {
UTIL.startMiniCluster();
}
- @After
+ @AfterEach
public void cleanupTestTable() throws Exception {
UTIL.getAdmin().disableTable(primaryTable);
UTIL.getAdmin().deleteTable(primaryTable);
@@ -149,7 +144,7 @@ public class TestOpenTableInCoprocessor {
}
- @AfterClass
+ @AfterAll
public static void teardownCluster() throws Exception {
UTIL.shutdownMiniCluster();
}
@@ -187,8 +182,8 @@ public class TestOpenTableInCoprocessor {
table.close();
Table target = UTIL.getConnection().getTable(otherTable);
- assertTrue("Didn't complete update to target table!", completeCheck[0]);
- assertEquals("Didn't find inserted row", 1, getKeyValueCount(target));
+ assertTrue(completeCheck[0], "Didn't complete update to target table!");
+ assertEquals(1, getKeyValueCount(target), "Didn't find inserted row");
target.close();
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestPostIncrementAndAppendBeforeWAL.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestPostIncrementAndAppendBeforeWAL.java
index 1f7cadc0ce3..d618d2af5d1 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestPostIncrementAndAppendBeforeWAL.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestPostIncrementAndAppendBeforeWAL.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
import java.util.Iterator;
@@ -31,7 +31,6 @@ import org.apache.hadoop.hbase.CellBuilderType;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.DoNotRetryIOException;
import org.apache.hadoop.hbase.ExtendedCellBuilderFactory;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.PrivateCellUtil;
import org.apache.hadoop.hbase.TableName;
@@ -56,13 +55,11 @@ import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -73,15 +70,11 @@ import org.slf4j.LoggerFactory;
* change the cells which will be applied to memstore and WAL. So add unit test for the case which
* change the cell's column family and tags.
*/
-@Category({ CoprocessorTests.class, MediumTests.class })
+@org.junit.jupiter.api.Tag(CoprocessorTests.TAG)
+@org.junit.jupiter.api.Tag(MediumTests.TAG)
public class TestPostIncrementAndAppendBeforeWAL {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestPostIncrementAndAppendBeforeWAL.class);
-
- @Rule
- public TestName name = new TestName();
+ private String currentTestName;
private static final Logger LOG = LoggerFactory.getLogger(TestFromClientSide.class);
@@ -99,18 +92,24 @@ public class TestPostIncrementAndAppendBeforeWAL {
private static final byte[] CQ1 = Bytes.toBytes("cq1");
private static final byte[] CQ2 = Bytes.toBytes("cq2");
private static final byte[] VALUE = Bytes.toBytes("value");
+
+ @BeforeEach
+ public void setUp(TestInfo testInfo) {
+ currentTestName = testInfo.getTestMethod().get().getName();
+ }
+
private static final byte[] VALUE2 = Bytes.toBytes("valuevalue");
private static final String USER = "User";
private static final Permission PERMS =
Permission.newBuilder().withActions(Permission.Action.READ).build();
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() throws Exception {
UTIL.startMiniCluster();
connection = UTIL.getConnection();
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
connection.close();
UTIL.shutdownMiniCluster();
@@ -127,7 +126,7 @@ public class TestPostIncrementAndAppendBeforeWAL {
@Test
public void testChangeCellWithDifferntColumnFamily() throws Exception {
- TableName tableName = TableName.valueOf(name.getMethodName());
+ TableName tableName = TableName.valueOf(currentTestName);
createTableWithCoprocessor(tableName,
ChangeCellWithDifferntColumnFamilyObserver.class.getName());
@@ -150,7 +149,7 @@ public class TestPostIncrementAndAppendBeforeWAL {
@Test
public void testChangeCellWithNotExistColumnFamily() throws Exception {
- TableName tableName = TableName.valueOf(name.getMethodName());
+ TableName tableName = TableName.valueOf(currentTestName);
createTableWithCoprocessor(tableName,
ChangeCellWithNotExistColumnFamilyObserver.class.getName());
@@ -174,7 +173,7 @@ public class TestPostIncrementAndAppendBeforeWAL {
@Test
public void testIncrementTTLWithACLTag() throws Exception {
- TableName tableName = TableName.valueOf(name.getMethodName());
+ TableName tableName = TableName.valueOf(currentTestName);
createTableWithCoprocessor(tableName, ChangeCellWithACLTagObserver.class.getName());
try (Table table = connection.getTable(tableName)) {
// Increment without TTL
@@ -212,7 +211,7 @@ public class TestPostIncrementAndAppendBeforeWAL {
@Test
public void testAppendTTLWithACLTag() throws Exception {
- TableName tableName = TableName.valueOf(name.getMethodName());
+ TableName tableName = TableName.valueOf(currentTestName);
createTableWithCoprocessor(tableName, ChangeCellWithACLTagObserver.class.getName());
try (Table table = connection.getTable(tableName)) {
// Append without TTL
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestReadOnlyConfiguration.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestReadOnlyConfiguration.java
index 91efc0d1f3f..ebf0f0e74b8 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestReadOnlyConfiguration.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestReadOnlyConfiguration.java
@@ -18,25 +18,15 @@
package org.apache.hadoop.hbase.coprocessor;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category({ RegionServerTests.class, SmallTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(SmallTests.TAG)
public class TestReadOnlyConfiguration {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestReadOnlyConfiguration.class);
-
- @Rule
- public TestName name = new TestName();
-
@Test
public void testAddDefaultResource() {
Configuration configuration = new Configuration();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionCoprocessorHost.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionCoprocessorHost.java
index e704ed4c9b4..1ecc0fba819 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionCoprocessorHost.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionCoprocessorHost.java
@@ -21,9 +21,9 @@ import static org.apache.hadoop.hbase.coprocessor.CoprocessorHost.COPROCESSORS_E
import static org.apache.hadoop.hbase.coprocessor.CoprocessorHost.REGION_COPROCESSOR_CONF_KEY;
import static org.apache.hadoop.hbase.coprocessor.CoprocessorHost.SKIP_LOAD_DUPLICATE_TABLE_COPROCESSOR;
import static org.apache.hadoop.hbase.coprocessor.CoprocessorHost.USER_COPROCESSORS_ENABLED_CONF_KEY;
-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 static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -31,7 +31,6 @@ import java.io.IOException;
import java.util.Optional;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CellComparator;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeepDeletedCells;
@@ -54,23 +53,16 @@ import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequest;
import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
-
-@Category({ SmallTests.class })
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+
+@Tag(SmallTests.TAG)
public class TestRegionCoprocessorHost {
private Configuration conf;
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestRegionCoprocessorHost.class);
-
- @Rule
- public final TestName name = new TestName();
+ private String currentTestName;
private RegionInfo regionInfo;
private HRegion region;
private RegionServerServices rsServices;
@@ -79,8 +71,9 @@ public class TestRegionCoprocessorHost {
public static final int TTL = 1000;
public static final int TIME_TO_PURGE_DELETES = 2000;
- @Before
- public void setup() throws IOException {
+ @BeforeEach
+ public void setup(TestInfo testInfo) throws IOException {
+ currentTestName = testInfo.getTestMethod().get().getName();
init(null);
}
@@ -88,7 +81,7 @@ public class TestRegionCoprocessorHost {
conf = HBaseConfiguration.create();
conf.setBoolean(COPROCESSORS_ENABLED_CONF_KEY, true);
conf.setBoolean(USER_COPROCESSORS_ENABLED_CONF_KEY, true);
- TableName tableName = TableName.valueOf(name.getMethodName());
+ TableName tableName = TableName.valueOf(currentTestName);
regionInfo = RegionInfoBuilder.newBuilder(tableName).build();
TableDescriptor tableDesc = null;
if (flag == null) {
@@ -132,7 +125,7 @@ public class TestRegionCoprocessorHost {
RegionCoprocessorHost host = new RegionCoprocessorHost(region, rsServices, conf);
Scan scan = new Scan();
scan.setTimeRange(TimeRange.INITIAL_MIN_TIMESTAMP, TimeRange.INITIAL_MAX_TIMESTAMP);
- assertTrue("Scan is not for all time", scan.getTimeRange().isAllTime());
+ assertTrue(scan.getTimeRange().isAllTime(), "Scan is not for all time");
// SimpleRegionObserver is set to update the ScanInfo parameters if the passed-in scan
// is for all time. this lets us exercise both that the Scan is wired up properly in the coproc
// and that we can customize the metadata
@@ -182,20 +175,20 @@ public class TestRegionCoprocessorHost {
// By default SimpleRegionObserver is set as region coprocessor which implements
// postScannerFilterRow
RegionCoprocessorHost host = new RegionCoprocessorHost(region, rsServices, conf);
- assertTrue("Region coprocessor implement postScannerFilterRow",
- host.hasCustomPostScannerFilterRow());
+ assertTrue(host.hasCustomPostScannerFilterRow(),
+ "Region coprocessor implement postScannerFilterRow");
// Set a region CP which doesn't implement postScannerFilterRow
init(true);
host = new RegionCoprocessorHost(region, rsServices, conf);
- assertFalse("Region coprocessor implement postScannerFilterRow",
- host.hasCustomPostScannerFilterRow());
+ assertFalse(host.hasCustomPostScannerFilterRow(),
+ "Region coprocessor implement postScannerFilterRow");
// Set multiple region CPs, in which one implements postScannerFilterRow
init(false);
host = new RegionCoprocessorHost(region, rsServices, conf);
- assertTrue("Region coprocessor doesn't implement postScannerFilterRow",
- host.hasCustomPostScannerFilterRow());
+ assertTrue(host.hasCustomPostScannerFilterRow(),
+ "Region coprocessor doesn't implement postScannerFilterRow");
}
private void verifyScanInfo(ScanInfo newScanInfo) {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverBypass.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverBypass.java
index ca0367c8a9c..058558af5dd 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverBypass.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverBypass.java
@@ -17,7 +17,7 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-import static junit.framework.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.util.ArrayList;
@@ -27,7 +27,6 @@ import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName;
@@ -45,20 +44,16 @@ import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManagerTestHelper;
import org.apache.hadoop.hbase.util.IncrementingEnvironmentEdge;
import org.apache.hadoop.hbase.wal.WALEdit;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category({ CoprocessorTests.class, MediumTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(MediumTests.TAG)
public class TestRegionObserverBypass {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestRegionObserverBypass.class);
-
private static HBaseTestingUtility util;
private static final TableName tableName = TableName.valueOf("test");
private static final byte[] dummy = Bytes.toBytes("dummy");
@@ -67,7 +62,7 @@ public class TestRegionObserverBypass {
private static final byte[] row3 = Bytes.toBytes("r3");
private static final byte[] test = Bytes.toBytes("test");
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() throws Exception {
// Stack up three coprocessors just so I can check bypass skips subsequent calls.
Configuration conf = HBaseConfiguration.create();
@@ -78,12 +73,12 @@ public class TestRegionObserverBypass {
util.startMiniCluster();
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
util.shutdownMiniCluster();
}
- @Before
+ @BeforeEach
public void setUp() throws Exception {
Admin admin = util.getAdmin();
if (admin.tableExists(tableName)) {
@@ -245,8 +240,8 @@ public class TestRegionObserverBypass {
// three coprocessors in the chain. So we should have:
// 3 invocations for first put + 1 invocation + 1 bypass for second put + 1 invocation +
// 1 bypass for the last put. Assert.
- assertEquals("Total CP invocation count", 5, TestCoprocessor.PREPUT_INVOCATIONS.get());
- assertEquals("Total CP bypasses", 2, TestCoprocessor.PREPUT_BYPASSES.get());
+ assertEquals(5, TestCoprocessor.PREPUT_INVOCATIONS.get(), "Total CP invocation count");
+ assertEquals(2, TestCoprocessor.PREPUT_BYPASSES.get(), "Total CP bypasses");
}
public static class TestCoprocessor implements RegionCoprocessor, RegionObserver {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverForAddingMutationsFromCoprocessors.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverForAddingMutationsFromCoprocessors.java
index 4d3146be0f8..db3970769ed 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverForAddingMutationsFromCoprocessors.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverForAddingMutationsFromCoprocessors.java
@@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.IOException;
import java.util.Arrays;
@@ -26,7 +26,6 @@ import java.util.List;
import java.util.Optional;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
@@ -45,26 +44,20 @@ import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.wal.WALEdit;
import org.apache.hadoop.hbase.wal.WALKey;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
-@Category(MediumTests.class)
+@Tag(MediumTests.TAG)
public class TestRegionObserverForAddingMutationsFromCoprocessors {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestRegionObserverForAddingMutationsFromCoprocessors.class);
-
private static final Logger LOG =
LoggerFactory.getLogger(TestRegionObserverForAddingMutationsFromCoprocessors.class);
@@ -75,11 +68,10 @@ public class TestRegionObserverForAddingMutationsFromCoprocessors {
private static final byte[] row3 = Bytes.toBytes("r3");
private static final byte[] test = Bytes.toBytes("test");
- @Rule
- public TestName name = new TestName();
+ private String currentTestName;
private TableName tableName;
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() throws Exception {
Configuration conf = HBaseConfiguration.create();
conf.set(CoprocessorHost.WAL_COPROCESSOR_CONF_KEY, TestWALObserver.class.getName());
@@ -87,14 +79,15 @@ public class TestRegionObserverForAddingMutationsFromCoprocessors {
util.startMiniCluster();
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
util.shutdownMiniCluster();
}
- @Before
- public void setUp() throws Exception {
- tableName = TableName.valueOf(name.getMethodName());
+ @BeforeEach
+ public void setUp(TestInfo testInfo) throws Exception {
+ currentTestName = testInfo.getTestMethod().get().getName();
+ tableName = TableName.valueOf(currentTestName);
}
private void createTable(String coprocessor) throws IOException {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverInterface.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverInterface.java
index 5940e8d7ef6..a20a503f624 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverInterface.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverInterface.java
@@ -17,10 +17,11 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-import static org.junit.Assert.assertArrayEquals;
-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.assertArrayEquals;
+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.assertTrue;
import java.io.IOException;
import java.lang.reflect.Method;
@@ -35,7 +36,6 @@ import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.CompareOperator;
import org.apache.hadoop.hbase.Coprocessor;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
@@ -89,27 +89,22 @@ import org.apache.hadoop.hbase.util.Threads;
import org.apache.hadoop.hbase.wal.WALEdit;
import org.apache.hadoop.hbase.wal.WALKey;
import org.apache.hadoop.hbase.wal.WALKeyImpl;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
-@Category({ CoprocessorTests.class, LargeTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(LargeTests.TAG)
public class TestRegionObserverInterface {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestRegionObserverInterface.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestRegionObserverInterface.class);
public static final TableName TEST_TABLE = TableName.valueOf("TestTable");
@@ -122,10 +117,14 @@ public class TestRegionObserverInterface {
private static HBaseTestingUtility util = new HBaseTestingUtility();
private static MiniHBaseCluster cluster = null;
- @Rule
- public TestName name = new TestName();
+ private String currentTestName;
+
+ @BeforeEach
+ public void setUp(TestInfo testInfo) {
+ currentTestName = testInfo.getTestMethod().get().getName();
+ }
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() throws Exception {
// set configure to indicate which cp should be loaded
Configuration conf = util.getConfiguration();
@@ -137,7 +136,7 @@ public class TestRegionObserverInterface {
cluster = util.getMiniHBaseCluster();
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
util.shutdownMiniCluster();
}
@@ -145,7 +144,7 @@ public class TestRegionObserverInterface {
@Test
public void testRegionObserver() throws IOException {
final TableName tableName =
- TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
+ TableName.valueOf(TEST_TABLE.getNameAsString() + "." + currentTestName);
// recreate table every time in order to reset the status of the
// coprocessor.
Table table = util.createTable(tableName, new byte[][] { A, B, C });
@@ -206,7 +205,7 @@ public class TestRegionObserverInterface {
@Test
public void testRowMutation() throws IOException {
final TableName tableName =
- TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
+ TableName.valueOf(TEST_TABLE.getNameAsString() + "." + currentTestName);
Table table = util.createTable(tableName, new byte[][] { A, B, C });
try {
verifyMethodResult(SimpleRegionObserver.class,
@@ -239,7 +238,7 @@ public class TestRegionObserverInterface {
@Test
public void testIncrementHook() throws IOException {
final TableName tableName =
- TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
+ TableName.valueOf(TEST_TABLE.getNameAsString() + "." + currentTestName);
Table table = util.createTable(tableName, new byte[][] { A, B, C });
try {
Increment inc = new Increment(Bytes.toBytes(0));
@@ -265,7 +264,7 @@ public class TestRegionObserverInterface {
@Test
public void testCheckAndPutHooks() throws IOException {
final TableName tableName =
- TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
+ TableName.valueOf(TEST_TABLE.getNameAsString() + "." + currentTestName);
try (Table table = util.createTable(tableName, new byte[][] { A, B, C })) {
Put p = new Put(Bytes.toBytes(0));
p.addColumn(A, A, A);
@@ -303,7 +302,7 @@ public class TestRegionObserverInterface {
@Test
public void testCheckAndDeleteHooks() throws IOException {
final TableName tableName =
- TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
+ TableName.valueOf(TEST_TABLE.getNameAsString() + "." + currentTestName);
Table table = util.createTable(tableName, new byte[][] { A, B, C });
try {
Put p = new Put(Bytes.toBytes(0));
@@ -343,7 +342,7 @@ public class TestRegionObserverInterface {
@Test
public void testCheckAndIncrementHooks() throws Exception {
final TableName tableName =
- TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
+ TableName.valueOf(TEST_TABLE.getNameAsString() + "." + currentTestName);
Table table = util.createTable(tableName, new byte[][] { A, B, C });
try {
byte[] row = Bytes.toBytes(0);
@@ -375,7 +374,7 @@ public class TestRegionObserverInterface {
@Test
public void testCheckAndAppendHooks() throws Exception {
final TableName tableName =
- TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
+ TableName.valueOf(TEST_TABLE.getNameAsString() + "." + currentTestName);
Table table = util.createTable(tableName, new byte[][] { A, B, C });
try {
byte[] row = Bytes.toBytes(0);
@@ -407,7 +406,7 @@ public class TestRegionObserverInterface {
@Test
public void testCheckAndRowMutationsHooks() throws Exception {
final TableName tableName =
- TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
+ TableName.valueOf(TEST_TABLE.getNameAsString() + "." + currentTestName);
Table table = util.createTable(tableName, new byte[][] { A, B, C });
try {
byte[] row = Bytes.toBytes(0);
@@ -446,7 +445,7 @@ public class TestRegionObserverInterface {
@Test
public void testAppendHook() throws IOException {
final TableName tableName =
- TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
+ TableName.valueOf(TEST_TABLE.getNameAsString() + "." + currentTestName);
Table table = util.createTable(tableName, new byte[][] { A, B, C });
try {
Append app = new Append(Bytes.toBytes(0));
@@ -472,7 +471,7 @@ public class TestRegionObserverInterface {
@Test
// HBase-3583
public void testHBase3583() throws IOException {
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ final TableName tableName = TableName.valueOf(currentTestName);
util.createTable(tableName, new byte[][] { A, B, C });
util.waitUntilAllRegionsAssigned(tableName);
@@ -514,7 +513,7 @@ public class TestRegionObserverInterface {
@Test
public void testHBASE14489() throws IOException {
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ final TableName tableName = TableName.valueOf(currentTestName);
Table table = util.createTable(tableName, new byte[][] { A });
Put put = new Put(ROW);
put.addColumn(A, A, A);
@@ -539,7 +538,7 @@ public class TestRegionObserverInterface {
@Test
// HBase-3758
public void testHBase3758() throws IOException {
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ final TableName tableName = TableName.valueOf(currentTestName);
util.createTable(tableName, new byte[][] { A, B, C });
verifyMethodResult(SimpleRegionObserver.class,
@@ -638,7 +637,7 @@ public class TestRegionObserverInterface {
*/
@Test
public void testCompactionOverride() throws Exception {
- final TableName compactTable = TableName.valueOf(name.getMethodName());
+ final TableName compactTable = TableName.valueOf(currentTestName);
Admin admin = util.getAdmin();
if (admin.tableExists(compactTable)) {
admin.disableTable(compactTable);
@@ -661,7 +660,7 @@ public class TestRegionObserverInterface {
HRegion firstRegion = cluster.getRegions(compactTable).get(0);
Coprocessor cp = firstRegion.getCoprocessorHost().findCoprocessor(EvenOnlyCompactor.class);
- assertNotNull("EvenOnlyCompactor coprocessor should be loaded", cp);
+ assertNotNull(cp, "EvenOnlyCompactor coprocessor should be loaded");
EvenOnlyCompactor compactor = (EvenOnlyCompactor) cp;
// force a compaction
@@ -674,7 +673,7 @@ public class TestRegionObserverInterface {
}
Thread.sleep(1000);
}
- assertTrue("Flush didn't complete", compactor.lastFlush >= ts);
+ assertTrue(compactor.lastFlush >= ts, "Flush didn't complete");
LOG.debug("Flush complete");
ts = compactor.lastFlush;
@@ -687,7 +686,7 @@ public class TestRegionObserverInterface {
Thread.sleep(1000);
}
LOG.debug("Last compaction was at " + compactor.lastCompaction);
- assertTrue("Compaction didn't complete", compactor.lastCompaction >= ts);
+ assertTrue(compactor.lastCompaction >= ts, "Compaction didn't complete");
// only even rows should remain
ResultScanner scanner = table.getScanner(new Scan());
@@ -697,8 +696,8 @@ public class TestRegionObserverInterface {
assertNotNull(r);
assertFalse(r.isEmpty());
byte[] iBytes = Bytes.toBytes(i);
- assertArrayEquals("Row should be " + i, r.getRow(), iBytes);
- assertArrayEquals("Value should be " + i, r.getValue(A, A), iBytes);
+ assertArrayEquals(r.getRow(), iBytes, "Row should be " + i);
+ assertArrayEquals(r.getValue(A, A), iBytes, "Value should be " + i);
}
} finally {
scanner.close();
@@ -708,10 +707,9 @@ public class TestRegionObserverInterface {
@Test
public void bulkLoadHFileTest() throws Exception {
- final String testName =
- TestRegionObserverInterface.class.getName() + "." + name.getMethodName();
+ final String testName = TestRegionObserverInterface.class.getName() + "." + currentTestName;
final TableName tableName =
- TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
+ TableName.valueOf(TEST_TABLE.getNameAsString() + "." + currentTestName);
Configuration conf = util.getConfiguration();
Table table = util.createTable(tableName, new byte[][] { A, B, C });
try (RegionLocator locator = util.getConnection().getRegionLocator(tableName)) {
@@ -739,9 +737,9 @@ public class TestRegionObserverInterface {
@Test
public void testRecovery() throws Exception {
- LOG.info(TestRegionObserverInterface.class.getName() + "." + name.getMethodName());
+ LOG.info(TestRegionObserverInterface.class.getName() + "." + currentTestName);
final TableName tableName =
- TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
+ TableName.valueOf(TEST_TABLE.getNameAsString() + "." + currentTestName);
Table table = util.createTable(tableName, new byte[][] { A, B, C });
try (RegionLocator locator = util.getConnection().getRegionLocator(tableName)) {
@@ -790,7 +788,7 @@ public class TestRegionObserverInterface {
@Test
public void testPreWALRestoreSkip() throws Exception {
- LOG.info(TestRegionObserverInterface.class.getName() + "." + name.getMethodName());
+ LOG.info(TestRegionObserverInterface.class.getName() + "." + currentTestName);
TableName tableName = TableName.valueOf(SimpleRegionObserver.TABLE_SKIPPED);
Table table = util.createTable(tableName, new byte[][] { A, B, C });
@@ -862,15 +860,15 @@ public class TestRegionObserverInterface {
new WALKeyImpl(Bytes.toBytes("region"), TEST_TABLE, EnvironmentEdgeManager.currentTime());
WALEdit edit = new WALEdit();
sro.preWALAppend(ctx, key, edit);
- Assert.assertEquals(1, key.getExtendedAttributes().size());
- Assert.assertArrayEquals(SimpleRegionObserver.WAL_EXTENDED_ATTRIBUTE_BYTES,
+ assertEquals(1, key.getExtendedAttributes().size());
+ assertArrayEquals(SimpleRegionObserver.WAL_EXTENDED_ATTRIBUTE_BYTES,
key.getExtendedAttribute(Integer.toString(sro.getCtPreWALAppend())));
}
@Test
public void testPreWALAppendIsWrittenToWAL() throws Exception {
final TableName tableName =
- TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
+ TableName.valueOf(TEST_TABLE.getNameAsString() + "." + currentTestName);
Table table = util.createTable(tableName, new byte[][] { A, B, C });
PreWALAppendWALActionsListener listener = new PreWALAppendWALActionsListener();
@@ -880,14 +878,14 @@ public class TestRegionObserverInterface {
region.getWAL().registerWALActionsListener(listener);
testPreWALAppendHook(table, tableName);
boolean[] expectedResults = { true, true, true, true };
- Assert.assertArrayEquals(expectedResults, listener.getWalKeysCorrectArray());
+ assertArrayEquals(expectedResults, listener.getWalKeysCorrectArray());
}
@Test
public void testPreWALAppendNotCalledOnMetaEdit() throws Exception {
final TableName tableName =
- TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
+ TableName.valueOf(TEST_TABLE.getNameAsString() + "." + currentTestName);
TableDescriptorBuilder tdBuilder = TableDescriptorBuilder.newBuilder(tableName);
ColumnFamilyDescriptorBuilder cfBuilder = ColumnFamilyDescriptorBuilder.newBuilder(FAMILY);
tdBuilder.setColumnFamily(cfBuilder.build());
@@ -934,9 +932,9 @@ public class TestRegionObserverInterface {
for (int i = 0; i < methodName.length; ++i) {
Method m = coprocessor.getMethod(methodName[i]);
Object o = m.invoke(cp);
- assertTrue("Result of " + coprocessor.getName() + "." + methodName[i]
- + " is expected to be " + value[i].toString() + ", while we get " + o.toString(),
- o.equals(value[i]));
+ assertTrue(o.equals(value[i]),
+ "Result of " + coprocessor.getName() + "." + methodName[i] + " is expected to be "
+ + value[i].toString() + ", while we get " + o.toString());
}
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverPreFlushAndPreCompact.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverPreFlushAndPreCompact.java
index a2700f94ffc..7f16e9e2bdf 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverPreFlushAndPreCompact.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverPreFlushAndPreCompact.java
@@ -18,11 +18,11 @@
package org.apache.hadoop.hbase.coprocessor;
import static org.apache.hadoop.hbase.coprocessor.CoprocessorHost.REGION_COPROCESSOR_CONF_KEY;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.IOException;
import java.util.Optional;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
@@ -39,11 +39,8 @@ import org.apache.hadoop.hbase.regionserver.compactions.CompactionLifeCycleTrack
import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequest;
import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
/**
@@ -53,16 +50,10 @@ import org.mockito.Mockito;
* {@link RegionObserver#preCompact(ObserverContext, Store, InternalScanner, ScanType, CompactionLifeCycleTracker, CompactionRequest)}
* @see <a href=https://issues.apache.org/jira/browse/HBASE-19122>HBASE-19122</a>
*/
-@Category({ CoprocessorTests.class, SmallTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(SmallTests.TAG)
public class TestRegionObserverPreFlushAndPreCompact {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestRegionObserverPreFlushAndPreCompact.class);
-
- @Rule
- public TestName name = new TestName();
-
/**
* Coprocessor that returns null when preCompact or preFlush is called.
*/
@@ -90,20 +81,21 @@ public class TestRegionObserverPreFlushAndPreCompact {
* Ensure we get expected exception when we try to return null from a preFlush call.
* @throws IOException We expect it to throw {@link CoprocessorException}
*/
- @Test(expected = CoprocessorException.class)
+ @Test
public void testPreFlushReturningNull() throws IOException {
RegionCoprocessorHost rch = getRegionCoprocessorHost();
- rch.preFlush(null, null, null);
+ assertThrows(CoprocessorException.class, () -> rch.preFlush(null, null, null));
}
/**
* Ensure we get expected exception when we try to return null from a preCompact call.
* @throws IOException We expect it to throw {@link CoprocessorException}
*/
- @Test(expected = CoprocessorException.class)
+ @Test
public void testPreCompactReturningNull() throws IOException {
RegionCoprocessorHost rch = getRegionCoprocessorHost();
- rch.preCompact(null, null, null, null, null, null);
+ assertThrows(CoprocessorException.class,
+ () -> rch.preCompact(null, null, null, null, null, null));
}
private RegionCoprocessorHost getRegionCoprocessorHost() {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverScannerOpenHook.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverScannerOpenHook.java
index f3a7d093df3..c069c9df2bb 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverScannerOpenHook.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverScannerOpenHook.java
@@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-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.io.IOException;
import java.util.List;
@@ -29,7 +29,6 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.Coprocessor;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
@@ -68,24 +67,24 @@ import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.wal.WAL;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
-@Category({ CoprocessorTests.class, MediumTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(MediumTests.TAG)
public class TestRegionObserverScannerOpenHook {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestRegionObserverScannerOpenHook.class);
-
private static HBaseTestingUtility UTIL = new HBaseTestingUtility();
static final Path DIR = UTIL.getDataTestDir();
- @Rule
- public TestName name = new TestName();
+ private String currentTestName;
+
+ @BeforeEach
+ public void setUp(TestInfo testInfo) {
+ currentTestName = testInfo.getTestMethod().get().getName();
+ }
public static class NoDataFilter extends FilterBase {
@@ -224,10 +223,8 @@ public class TestRegionObserverScannerOpenHook {
Get get = new Get(ROW);
Result r = region.get(get);
- assertNull(
- "Got an unexpected number of rows - "
- + "no data should be returned with the NoDataFromScan coprocessor. Found: " + r,
- r.listCells());
+ assertNull(r.listCells(), "Got an unexpected number of rows - "
+ + "no data should be returned with the NoDataFromScan coprocessor. Found: " + r);
HBaseTestingUtility.closeRegionAndWAL(region);
}
@@ -252,10 +249,8 @@ public class TestRegionObserverScannerOpenHook {
region.flush(true);
Get get = new Get(ROW);
Result r = region.get(get);
- assertNull(
- "Got an unexpected number of rows - "
- + "no data should be returned with the NoDataFromScan coprocessor. Found: " + r,
- r.listCells());
+ assertNull(r.listCells(), "Got an unexpected number of rows - "
+ + "no data should be returned with the NoDataFromScan coprocessor. Found: " + r);
HBaseTestingUtility.closeRegionAndWAL(region);
}
@@ -312,7 +307,7 @@ public class TestRegionObserverScannerOpenHook {
UTIL.startMiniCluster();
byte[] ROW = Bytes.toBytes("testRow");
byte[] A = Bytes.toBytes("A");
- HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
+ HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(currentTestName));
desc.addFamily(new HColumnDescriptor(A));
desc.addCoprocessor(EmptyRegionObsever.class.getName(), null, Coprocessor.PRIORITY_USER, null);
desc.addCoprocessor(NoDataFromCompaction.class.getName(), null, Coprocessor.PRIORITY_HIGHEST,
@@ -330,7 +325,7 @@ public class TestRegionObserverScannerOpenHook {
HRegionServer rs = UTIL.getRSForFirstRegionInTable(desc.getTableName());
List<HRegion> regions = rs.getRegions(desc.getTableName());
- assertEquals("More than 1 region serving test table with 1 row", 1, regions.size());
+ assertEquals(1, regions.size(), "More than 1 region serving test table with 1 row");
Region region = regions.get(0);
admin.flushRegion(region.getRegionInfo().getRegionName());
CountDownLatch latch =
@@ -348,17 +343,13 @@ public class TestRegionObserverScannerOpenHook {
// check both rows to ensure that they aren't there
Get get = new Get(ROW);
Result r = table.get(get);
- assertNull(
- "Got an unexpected number of rows - "
- + "no data should be returned with the NoDataFromScan coprocessor. Found: " + r,
- r.listCells());
+ assertNull(r.listCells(), "Got an unexpected number of rows - "
+ + "no data should be returned with the NoDataFromScan coprocessor. Found: " + r);
get = new Get(Bytes.toBytes("anotherrow"));
r = table.get(get);
- assertNull(
- "Got an unexpected number of rows - "
- + "no data should be returned with the NoDataFromScan coprocessor Found: " + r,
- r.listCells());
+ assertNull(r.listCells(), "Got an unexpected number of rows - "
+ + "no data should be returned with the NoDataFromScan coprocessor Found: " + r);
table.close();
UTIL.shutdownMiniCluster();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverStacking.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverStacking.java
index c2c75d5b117..9e28a3bff86 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverStacking.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverStacking.java
@@ -17,14 +17,13 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.Optional;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Coprocessor;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HRegionInfo;
@@ -43,18 +42,14 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.Threads;
import org.apache.hadoop.hbase.wal.WALEdit;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
-@Category({ CoprocessorTests.class, SmallTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(SmallTests.TAG)
public class TestRegionObserverStacking {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestRegionObserverStacking.class);
-
private static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
static final Path DIR = TEST_UTIL.getDataTestDir();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithAbort.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithAbort.java
index 004f9b3ceb5..f269cba203b 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithAbort.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithAbort.java
@@ -17,12 +17,12 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CoprocessorEnvironment;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.MiniHBaseCluster;
@@ -36,10 +36,8 @@ import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.wal.WALEdit;
-import org.junit.Assert;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -48,13 +46,10 @@ import org.slf4j.LoggerFactory;
* that the regionserver will abort with an informative error message describing the set of its
* loaded coprocessors for crash diagnosis. (HBASE-4014).
*/
-@Category({ CoprocessorTests.class, MediumTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(MediumTests.TAG)
public class TestRegionServerCoprocessorExceptionWithAbort {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestRegionServerCoprocessorExceptionWithAbort.class);
-
private static final Logger LOG =
LoggerFactory.getLogger(TestRegionServerCoprocessorExceptionWithAbort.class);
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
@@ -132,7 +127,7 @@ public class TestRegionServerCoprocessorExceptionWithAbort {
fail("InterruptedException while waiting for regionserver " + "zk node to be deleted.");
}
}
- Assert.assertTrue("The region server should have aborted", aborted);
+ assertTrue(aborted, "The region server should have aborted");
table.close();
} finally {
TEST_UTIL.shutdownMiniCluster();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithRemove.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithRemove.java
index 1231a1018ca..948a058064a 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithRemove.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionServerCoprocessorExceptionWithRemove.java
@@ -17,13 +17,12 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+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 java.io.IOException;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Durability;
@@ -34,24 +33,20 @@ import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.wal.WALEdit;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
/**
* Tests unhandled exceptions thrown by coprocessors running on regionserver. Expected result is
* that the region server will remove the buggy coprocessor from its set of coprocessors and throw a
* org.apache.hadoop.hbase.exceptions.DoNotRetryIOException back to the client. (HBASE-4014).
*/
-@Category({ CoprocessorTests.class, MediumTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(MediumTests.TAG)
public class TestRegionServerCoprocessorExceptionWithRemove {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestRegionServerCoprocessorExceptionWithRemove.class);
-
public static class BuggyRegionObserver extends SimpleRegionObserver {
@SuppressWarnings("null")
@Override
@@ -69,7 +64,7 @@ public class TestRegionServerCoprocessorExceptionWithRemove {
private static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() throws Exception {
// set configure to indicate which cp should be loaded
Configuration conf = TEST_UTIL.getConfiguration();
@@ -78,7 +73,7 @@ public class TestRegionServerCoprocessorExceptionWithRemove {
TEST_UTIL.startMiniCluster();
}
- @AfterClass
+ @AfterAll
public static void teardownAfterClass() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
@@ -113,7 +108,7 @@ public class TestRegionServerCoprocessorExceptionWithRemove {
} catch (IOException e) {
threwIOE = true;
} finally {
- assertTrue("The regionserver should have thrown an exception", threwIOE);
+ assertTrue(threwIOE, "The regionserver should have thrown an exception");
}
// Wait 10 seconds for the regionserver to abort: expected result is that
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestWALObserver.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestWALObserver.java
index fdc8378f0f9..4512c74fb54 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestWALObserver.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestWALObserver.java
@@ -17,10 +17,10 @@
*/
package org.apache.hadoop.hbase.coprocessor;
-import static org.junit.Assert.assertEquals;
-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.assertEquals;
+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.io.IOException;
import java.security.PrivilegedExceptionAction;
@@ -35,7 +35,6 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.Coprocessor;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
@@ -64,15 +63,13 @@ import org.apache.hadoop.hbase.wal.WALEdit;
import org.apache.hadoop.hbase.wal.WALFactory;
import org.apache.hadoop.hbase.wal.WALKeyImpl;
import org.apache.hadoop.hbase.wal.WALSplitter;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -80,13 +77,10 @@ import org.slf4j.LoggerFactory;
* Tests invocation of the {@link org.apache.hadoop.hbase.coprocessor.MasterObserver} interface
* hooks at all appropriate times during normal HMaster operations.
*/
-@Category({ CoprocessorTests.class, MediumTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(MediumTests.TAG)
public class TestWALObserver {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestWALObserver.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestWALObserver.class);
private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
@@ -99,8 +93,7 @@ public class TestWALObserver {
{ Bytes.toBytes("v1"), Bytes.toBytes("v2"), Bytes.toBytes("v3"), };
private static byte[] TEST_ROW = Bytes.toBytes("testRow");
- @Rule
- public TestName currentTest = new TestName();
+ private String currentTestName;
private Configuration conf;
private FileSystem fs;
@@ -110,7 +103,7 @@ public class TestWALObserver {
private Path logDir;
private WALFactory wals;
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() throws Exception {
Configuration conf = TEST_UTIL.getConfiguration();
conf.setStrings(CoprocessorHost.WAL_COPROCESSOR_CONF_KEY,
@@ -128,21 +121,22 @@ public class TestWALObserver {
CommonFSUtils.setWALRootDir(conf, hbaseWALRootDir);
}
- @AfterClass
+ @AfterAll
public static void teardownAfterClass() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ public void setUp(TestInfo testInfo) throws Exception {
+ currentTestName = testInfo.getTestMethod().get().getName();
this.conf = HBaseConfiguration.create(TEST_UTIL.getConfiguration());
// this.cluster = TEST_UTIL.getDFSCluster();
this.fs = TEST_UTIL.getDFSCluster().getFileSystem();
this.hbaseRootDir = CommonFSUtils.getRootDir(conf);
this.hbaseWALRootDir = CommonFSUtils.getWALRootDir(conf);
this.oldLogDir = new Path(this.hbaseWALRootDir, HConstants.HREGION_OLDLOGDIR_NAME);
- String serverName = ServerName
- .valueOf(currentTest.getMethodName(), 16010, EnvironmentEdgeManager.currentTime()).toString();
+ String serverName =
+ ServerName.valueOf(currentTestName, 16010, EnvironmentEdgeManager.currentTime()).toString();
this.logDir =
new Path(this.hbaseWALRootDir, AbstractFSWALProvider.getWALDirectoryName(serverName));
@@ -155,7 +149,7 @@ public class TestWALObserver {
this.wals = new WALFactory(conf, serverName);
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
try {
wals.shutdown();
@@ -290,8 +284,8 @@ public class TestWALObserver {
new WALEdit());
log.sync(txid);
- assertFalse("Empty WALEdit should skip coprocessor evaluation.", cp.isPreWALWriteCalled());
- assertFalse("Empty WALEdit should skip coprocessor evaluation.", cp.isPostWALWriteCalled());
+ assertFalse(cp.isPreWALWriteCalled(), "Empty WALEdit should skip coprocessor evaluation.");
+ assertFalse(cp.isPostWALWriteCalled(), "Empty WALEdit should skip coprocessor evaluation.");
} finally {
log.close();
}
@@ -304,7 +298,7 @@ public class TestWALObserver {
public void testWALCoprocessorReplay() throws Exception {
// WAL replay is handled at HRegion::replayRecoveredEdits(), which is
// ultimately called by HRegion::initialize()
- TableName tableName = TableName.valueOf(currentTest.getMethodName());
+ TableName tableName = TableName.valueOf(currentTestName);
TableDescriptor htd = getBasic3FamilyHTableDescriptor(tableName);
MultiVersionConcurrencyControl mvcc = new MultiVersionConcurrencyControl();
// final HRegionInfo hri =
@@ -345,10 +339,8 @@ public class TestWALObserver {
Path p = runWALSplit(newConf);
LOG.info("WALSplit path == " + p);
// Make a new wal for new region open.
- final WALFactory wals2 = new WALFactory(conf,
- ServerName
- .valueOf(currentTest.getMethodName() + "2", 16010, EnvironmentEdgeManager.currentTime())
- .toString());
+ final WALFactory wals2 = new WALFactory(conf, ServerName
+ .valueOf(currentTestName + "2", 16010, EnvironmentEdgeManager.currentTime()).toString());
WAL wal2 = wals2.getWAL(null);
HRegion region = HRegion.openHRegion(newConf, FileSystem.get(newConf), hbaseRootDir, hri,
htd, wal2, TEST_UTIL.getHBaseCluster().getRegionServer(0), null);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/errorhandling/TestForeignExceptionDispatcher.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/errorhandling/TestForeignExceptionDispatcher.java
index aabfa0ed3e2..e733a137263 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/errorhandling/TestForeignExceptionDispatcher.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/errorhandling/TestForeignExceptionDispatcher.java
@@ -17,15 +17,13 @@
*/
package org.apache.hadoop.hbase.errorhandling;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MasterTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,13 +32,10 @@ import org.slf4j.LoggerFactory;
* Test that we propagate errors through an dispatcher exactly once via different failure injection
* mechanisms.
*/
-@Category({ MasterTests.class, SmallTests.class })
+@Tag(MasterTests.TAG)
+@Tag(SmallTests.TAG)
public class TestForeignExceptionDispatcher {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestForeignExceptionDispatcher.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestForeignExceptionDispatcher.class);
/**
@@ -77,7 +72,7 @@ public class TestForeignExceptionDispatcher {
dispatcher.rethrowException();
fail("Monitor should have thrown an exception after getting error.");
} catch (ForeignException ex) {
- assertTrue("Got an unexpected exception:" + ex, ex.getCause() == EXTEXN.getCause());
+ assertTrue(ex.getCause() == EXTEXN.getCause(), "Got an unexpected exception:" + ex);
LOG.debug("Got the testing exception!");
}
@@ -102,7 +97,7 @@ public class TestForeignExceptionDispatcher {
timer.start();
timer.trigger();
- assertTrue("Monitor didn't get timeout", monitor.hasException());
+ assertTrue(monitor.hasException(), "Monitor didn't get timeout");
// verify that that we propagated the error
Mockito.verify(listener1).receive(Mockito.any());
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/errorhandling/TestForeignExceptionSerialization.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/errorhandling/TestForeignExceptionSerialization.java
index 817fcdf6349..6746d268118 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/errorhandling/TestForeignExceptionSerialization.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/errorhandling/TestForeignExceptionSerialization.java
@@ -17,29 +17,24 @@
*/
package org.apache.hadoop.hbase.errorhandling;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-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.assertTrue;
import java.io.IOException;
import java.util.Objects;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MasterTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
/**
* Test that we correctly serialize exceptions from a remote source
*/
-@Category({ MasterTests.class, SmallTests.class })
+@Tag(MasterTests.TAG)
+@Tag(SmallTests.TAG)
public class TestForeignExceptionSerialization {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestForeignExceptionSerialization.class);
-
private static final String srcName = "someNode";
/**
@@ -59,8 +54,8 @@ public class TestForeignExceptionSerialization {
e = ForeignException.deserialize(ForeignException.serialize(srcName, in));
assertNotNull(e);
- assertEquals("Stack trace got corrupted", elem, e.getCause().getStackTrace()[0]);
- assertEquals("Got an unexpectedly long stack trace", 1, e.getCause().getStackTrace().length);
+ assertEquals(elem, e.getCause().getStackTrace()[0], "Stack trace got corrupted");
+ assertEquals(1, e.getCause().getStackTrace().length, "Got an unexpectedly long stack trace");
}
/**
@@ -78,11 +73,12 @@ public class TestForeignExceptionSerialization {
// Workaround for java 11 - replaced assertArrayEquals with individual elements comparison
// using custom comparison helper method
- assertEquals("Stacktrace lengths don't match", generic.getStackTrace().length,
- e.getCause().getStackTrace().length);
+ assertEquals(generic.getStackTrace().length, e.getCause().getStackTrace().length,
+ "Stacktrace lengths don't match");
for (int i = 0; i < generic.getStackTrace().length; i++) {
- assertTrue("Local stack trace got corrupted at " + i + "th index",
- compareStackTraceElement(generic.getStackTrace()[i], e.getCause().getStackTrace()[i]));
+ assertTrue(
+ compareStackTraceElement(generic.getStackTrace()[i], e.getCause().getStackTrace()[i]),
+ "Local stack trace got corrupted at " + i + "th index");
}
e.printStackTrace(); // should have ForeignException and source node in it.
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/errorhandling/TestTimeoutExceptionInjector.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/errorhandling/TestTimeoutExceptionInjector.java
index 750e63090cd..a6d8569a30a 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/errorhandling/TestTimeoutExceptionInjector.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/errorhandling/TestTimeoutExceptionInjector.java
@@ -17,7 +17,7 @@
*/
package org.apache.hadoop.hbase.errorhandling;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -25,25 +25,20 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MasterTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Test the {@link TimeoutExceptionInjector} to ensure we fulfill contracts
*/
-@Category({ MasterTests.class, SmallTests.class })
+@Tag(MasterTests.TAG)
+@Tag(SmallTests.TAG)
public class TestTimeoutExceptionInjector {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestTimeoutExceptionInjector.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestTimeoutExceptionInjector.class);
/**
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/executor/TestExecutorService.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/executor/TestExecutorService.java
index dfea5343073..23de92a5b26 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/executor/TestExecutorService.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/executor/TestExecutorService.java
@@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.executor;
-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 static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
@@ -34,7 +34,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.Server;
import org.apache.hadoop.hbase.Waiter;
@@ -44,20 +43,15 @@ import org.apache.hadoop.hbase.executor.ExecutorService.ExecutorConfig;
import org.apache.hadoop.hbase.executor.ExecutorService.ExecutorStatus;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.Assert;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestExecutorService {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestExecutorService.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestExecutorService.class);
@Test
@@ -244,7 +238,7 @@ public class TestExecutorService {
waitForEventToStart.await(10, TimeUnit.SECONDS);
int activeCount = executorService.getExecutor(ExecutorType.MASTER_SNAPSHOT_OPERATIONS)
.getThreadPoolExecutor().getActiveCount();
- Assert.assertEquals(1, activeCount);
+ assertEquals(1, activeCount);
latch.countDown();
Waiter.waitFor(conf, 3000, () -> {
int count = executorService.getExecutor(ExecutorType.MASTER_SNAPSHOT_OPERATIONS)
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorder.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorder.java
index e1331ac3cba..4111b64367a 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorder.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorder.java
@@ -18,6 +18,8 @@
package org.apache.hadoop.hbase.fs;
import static org.apache.hadoop.hbase.util.LocatedBlockHelper.getLocatedBlockLocations;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -30,7 +32,6 @@ import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.testclassification.MiscTests;
@@ -41,14 +42,10 @@ import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
import org.apache.hadoop.hdfs.protocol.LocatedBlock;
import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
import org.apache.hadoop.hdfs.server.datanode.DataNode;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -58,13 +55,10 @@ import org.slf4j.LoggerFactory;
* cleared in hadoop's ShutdownHookManager in hadoop 3. This leads to 'Failed suppression of fs
* shutdown hook' error in region server.
*/
-@Category({ MiscTests.class, LargeTests.class })
+@Tag(MiscTests.TAG)
+@Tag(LargeTests.TAG)
public class TestBlockReorder {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestBlockReorder.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestBlockReorder.class);
private Configuration conf;
@@ -75,10 +69,7 @@ public class TestBlockReorder {
private static final String host2 = "host2";
private static final String host3 = "host3";
- @Rule
- public TestName name = new TestName();
-
- @Before
+ @BeforeEach
public void setUp() throws Exception {
htu = new HBaseTestingUtility();
htu.getConfiguration().setInt("dfs.blocksize", 1024);// For the test with multiple blocks
@@ -91,7 +82,7 @@ public class TestBlockReorder {
dfs = (DistributedFileSystem) FileSystem.get(conf);
}
- @After
+ @AfterEach
public void tearDownAfterClass() throws Exception {
htu.shutdownMiniCluster();
}
@@ -103,7 +94,7 @@ public class TestBlockReorder {
public void testBlockLocationReorder() throws Exception {
Path p = new Path("hello");
- Assert.assertTrue((short) cluster.getDataNodes().size() > 1);
+ assertTrue((short) cluster.getDataNodes().size() > 1);
final int repCount = 2;
// Let's write the file
@@ -115,11 +106,11 @@ public class TestBlockReorder {
// Let's check we can read it when everybody's there
long start = EnvironmentEdgeManager.currentTime();
FSDataInputStream fin = dfs.open(p);
- Assert.assertTrue(toWrite == fin.readDouble());
+ assertTrue(toWrite == fin.readDouble());
long end = EnvironmentEdgeManager.currentTime();
LOG.info("readtime= " + (end - start));
fin.close();
- Assert.assertTrue((end - start) < 30 * 1000);
+ assertTrue((end - start) < 30 * 1000);
// Let's kill the first location. But actually the fist location returned will change
// The first thing to do is to get the location, then the port
@@ -129,7 +120,7 @@ public class TestBlockReorder {
lbs = dfs.getFileBlockLocations(f, 0, 1);
} while (lbs.length != 1 && lbs[0].getLength() != repCount);
final String name = lbs[0].getNames()[0];
- Assert.assertTrue(name.indexOf(':') > 0);
+ assertTrue(name.indexOf(':') > 0);
String portS = name.substring(name.indexOf(':') + 1);
final int port = Integer.parseInt(portS);
LOG.info("port= " + port);
@@ -152,28 +143,26 @@ public class TestBlockReorder {
break;
}
}
- Assert.assertTrue("didn't find the server to kill, was looking for " + lookup + " found " + sb,
- ok);
+ assertTrue(ok, "didn't find the server to kill, was looking for " + lookup + " found " + sb);
LOG.info("ipc port= " + ipcPort);
// Add the hook, with an implementation checking that we don't use the port we've just killed.
- Assert
- .assertTrue(HFileSystem.addLocationsOrderInterceptor(conf, new HFileSystem.ReorderBlocks() {
- @Override
- public void reorderBlocks(Configuration c, LocatedBlocks lbs, String src) {
- for (LocatedBlock lb : lbs.getLocatedBlocks()) {
- if (getLocatedBlockLocations(lb).length > 1) {
- DatanodeInfo[] infos = getLocatedBlockLocations(lb);
- if (infos[0].getHostName().equals(lookup)) {
- LOG.info("HFileSystem bad host, inverting");
- DatanodeInfo tmp = infos[0];
- infos[0] = infos[1];
- infos[1] = tmp;
- }
+ assertTrue(HFileSystem.addLocationsOrderInterceptor(conf, new HFileSystem.ReorderBlocks() {
+ @Override
+ public void reorderBlocks(Configuration c, LocatedBlocks lbs, String src) {
+ for (LocatedBlock lb : lbs.getLocatedBlocks()) {
+ if (getLocatedBlockLocations(lb).length > 1) {
+ DatanodeInfo[] infos = getLocatedBlockLocations(lb);
+ if (infos[0].getHostName().equals(lookup)) {
+ LOG.info("HFileSystem bad host, inverting");
+ DatanodeInfo tmp = infos[0];
+ infos[0] = infos[1];
+ infos[1] = tmp;
}
}
}
- }));
+ }
+ }));
final int retries = 10;
ServerSocket ss = null;
@@ -196,11 +185,11 @@ public class TestBlockReorder {
for (int i = 0; i < retries; i++) {
start = EnvironmentEdgeManager.currentTime();
fin = dfs.open(p);
- Assert.assertTrue(toWrite == fin.readDouble());
+ assertTrue(toWrite == fin.readDouble());
fin.close();
end = EnvironmentEdgeManager.currentTime();
LOG.info("HFileSystem readtime= " + (end - start));
- Assert.assertFalse("We took too much time to read", (end - start) > 60000);
+ assertFalse((end - start) > 60000, "We took too much time to read");
}
ss.close();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorderBlockLocation.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorderBlockLocation.java
index 27f9e37e4d8..52d2da97fbd 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorderBlockLocation.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorderBlockLocation.java
@@ -18,13 +18,17 @@
package org.apache.hadoop.hbase.fs;
import static org.apache.hadoop.hbase.util.LocatedBlockHelper.getLocatedBlockLocations;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+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.assertTrue;
import java.lang.reflect.Field;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.MiniHBaseCluster;
@@ -37,14 +41,10 @@ import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.protocol.ClientProtocol;
import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
/**
* Tests for the hdfs fix from HBASE-6435. Please don't add new subtest which involves starting /
@@ -52,13 +52,10 @@ import org.junit.rules.TestName;
* cleared in hadoop's ShutdownHookManager in hadoop 3. This leads to 'Failed suppression of fs
* shutdown hook' error in region server.
*/
-@Category({ MiscTests.class, LargeTests.class })
+@Tag(MiscTests.TAG)
+@Tag(LargeTests.TAG)
public class TestBlockReorderBlockLocation {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestBlockReorderBlockLocation.class);
-
private Configuration conf;
private MiniDFSCluster cluster;
private HBaseTestingUtility htu;
@@ -67,10 +64,7 @@ public class TestBlockReorderBlockLocation {
private static final String host2 = "host2";
private static final String host3 = "host3";
- @Rule
- public TestName name = new TestName();
-
- @Before
+ @BeforeEach
public void setUp() throws Exception {
htu = new HBaseTestingUtility();
htu.getConfiguration().setInt("dfs.blocksize", 1024);// For the test with multiple blocks
@@ -83,7 +77,7 @@ public class TestBlockReorderBlockLocation {
dfs = (DistributedFileSystem) FileSystem.get(conf);
}
- @After
+ @AfterEach
public void tearDownAfterClass() throws Exception {
htu.shutdownMiniCluster();
}
@@ -109,7 +103,7 @@ public class TestBlockReorderBlockLocation {
Path p = new Path(fileName);
final int repCount = 3;
- Assert.assertTrue((short) cluster.getDataNodes().size() >= repCount);
+ assertTrue((short) cluster.getDataNodes().size() >= repCount);
// Let's write the file
FSDataOutputStream fop = dfs.create(p, (short) repCount);
@@ -123,36 +117,36 @@ public class TestBlockReorderBlockLocation {
final long max = EnvironmentEdgeManager.currentTime() + 10000;
do {
lbs = getNamenode(dfs.getClient()).getBlockLocations(fileName, 0, 1);
- Assert.assertNotNull(lbs.getLocatedBlocks());
- Assert.assertEquals(1, lbs.getLocatedBlocks().size());
- Assert.assertTrue(
- "Expecting " + repCount + " , got " + getLocatedBlockLocations(lbs.get(0)).length,
- EnvironmentEdgeManager.currentTime() < max);
+ assertNotNull(lbs.getLocatedBlocks());
+ assertEquals(1, lbs.getLocatedBlocks().size());
+ assertTrue(EnvironmentEdgeManager.currentTime() < max,
+ "Expecting " + repCount + " , got " + getLocatedBlockLocations(lbs.get(0)).length);
} while (getLocatedBlockLocations(lbs.get(0)).length != repCount);
// Should be filtered, the name is different => The order won't change
Object[] originalList = lbs.getLocatedBlocks().toArray();
HFileSystem.ReorderWALBlocks lrb = new HFileSystem.ReorderWALBlocks();
lrb.reorderBlocks(conf, lbs, fileName);
- Assert.assertArrayEquals(originalList, lbs.getLocatedBlocks().toArray());
+ assertArrayEquals(originalList, lbs.getLocatedBlocks().toArray());
// Should be reordered, as we pretend to be a file name with a compliant stuff
- Assert.assertNotNull(conf.get(HConstants.HBASE_DIR));
- Assert.assertFalse(conf.get(HConstants.HBASE_DIR).isEmpty());
+ assertNotNull(conf.get(HConstants.HBASE_DIR));
+ assertFalse(conf.get(HConstants.HBASE_DIR).isEmpty());
String pseudoLogFile = conf.get(HConstants.HBASE_DIR) + "/" + HConstants.HREGION_LOGDIR_NAME
+ "/" + host1 + ",6977,6576" + "/mylogfile";
// Check that it will be possible to extract a ServerName from our construction
- Assert.assertNotNull("log= " + pseudoLogFile,
- AbstractFSWALProvider.getServerNameFromWALDirectoryName(dfs.getConf(), pseudoLogFile));
+ assertNotNull(
+ AbstractFSWALProvider.getServerNameFromWALDirectoryName(dfs.getConf(), pseudoLogFile),
+ "log= " + pseudoLogFile);
// And check we're doing the right reorder.
lrb.reorderBlocks(conf, lbs, pseudoLogFile);
- Assert.assertEquals(host1, getLocatedBlockLocations(lbs.get(0))[2].getHostName());
+ assertEquals(host1, getLocatedBlockLocations(lbs.get(0))[2].getHostName());
// Check again, it should remain the same.
lrb.reorderBlocks(conf, lbs, pseudoLogFile);
- Assert.assertEquals(host1, getLocatedBlockLocations(lbs.get(0))[2].getHostName());
+ assertEquals(host1, getLocatedBlockLocations(lbs.get(0))[2].getHostName());
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorderMultiBlocks.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorderMultiBlocks.java
index a551911e3dd..c2763623687 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorderMultiBlocks.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorderMultiBlocks.java
@@ -18,6 +18,10 @@
package org.apache.hadoop.hbase.fs;
import static org.apache.hadoop.hbase.util.LocatedBlockHelper.getLocatedBlockLocations;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -29,7 +33,6 @@ import org.apache.hadoop.fs.BlockLocation;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.MiniHBaseCluster;
@@ -54,14 +57,11 @@ import org.apache.hadoop.hdfs.protocol.DirectoryListing;
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
import org.apache.hadoop.ipc.RemoteException;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -71,13 +71,10 @@ import org.slf4j.LoggerFactory;
* cleared in hadoop's ShutdownHookManager in hadoop 3. This leads to 'Failed suppression of fs
* shutdown hook' error in region server.
*/
-@Category({ MiscTests.class, LargeTests.class })
+@Tag(MiscTests.TAG)
+@Tag(LargeTests.TAG)
public class TestBlockReorderMultiBlocks {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestBlockReorderMultiBlocks.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestBlockReorderMultiBlocks.class);
private Configuration conf;
@@ -88,10 +85,7 @@ public class TestBlockReorderMultiBlocks {
private static final String host2 = "host2";
private static final String host3 = "host3";
- @Rule
- public TestName name = new TestName();
-
- @Before
+ @BeforeEach
public void setUp() throws Exception {
htu = new HBaseTestingUtility();
htu.getConfiguration().setInt("dfs.blocksize", 1024);// For the test with multiple blocks
@@ -104,7 +98,7 @@ public class TestBlockReorderMultiBlocks {
dfs = (DistributedFileSystem) FileSystem.get(conf);
}
- @After
+ @AfterEach
public void tearDownAfterClass() throws Exception {
htu.shutdownMiniCluster();
}
@@ -113,7 +107,7 @@ public class TestBlockReorderMultiBlocks {
* Test that the hook works within HBase, including when there are multiple blocks.
*/
@Test()
- public void testHBaseCluster() throws Exception {
+ public void testHBaseCluster(TestInfo testInfo) throws Exception {
byte[] sb = Bytes.toBytes("sb");
htu.startMiniZKCluster();
@@ -135,7 +129,7 @@ public class TestBlockReorderMultiBlocks {
// We use the regionserver file system & conf as we expect it to have the hook.
conf = targetRs.getConfiguration();
HFileSystem rfs = (HFileSystem) targetRs.getFileSystem();
- Table h = htu.createTable(TableName.valueOf(name.getMethodName()), sb);
+ Table h = htu.createTable(TableName.valueOf(testInfo.getTestMethod().get().getName()), sb);
// Now, we have 4 datanodes and a replication count of 3. So we don't know if the datanode
// with the same node will be used. We can't really stop an existing datanode, this would
@@ -191,7 +185,7 @@ public class TestBlockReorderMultiBlocks {
HdfsFileStatus[] hfs = dl.getPartialListing();
// As we wrote a put, we should have at least one log file.
- Assert.assertTrue(hfs.length >= 1);
+ assertTrue(hfs.length >= 1);
for (HdfsFileStatus hf : hfs) {
// Because this is a live cluster, log files might get archived while we're processing
try {
@@ -211,7 +205,7 @@ public class TestBlockReorderMultiBlocks {
LOG.info(bl.getHosts().length + " replicas for block 0 in " + logFile + " ");
for (int i = 0; i < bl.getHosts().length - 1; i++) {
LOG.info(bl.getHosts()[i] + " " + logFile);
- Assert.assertNotSame(bl.getHosts()[i], host4);
+ assertNotSame(bl.getHosts()[i], host4);
}
String last = bl.getHosts()[bl.getHosts().length - 1];
LOG.info(last + " " + logFile);
@@ -254,11 +248,11 @@ public class TestBlockReorderMultiBlocks {
final long max = EnvironmentEdgeManager.currentTime() + 10000;
boolean done;
do {
- Assert.assertTrue("Can't get enouth replica", EnvironmentEdgeManager.currentTime() < max);
+ assertTrue(EnvironmentEdgeManager.currentTime() < max, "Can't get enough replica");
lbs = getNamenode(dfs.getClient()).getBlockLocations(src, 0, 1);
- Assert.assertNotNull("Can't get block locations for " + src, lbs);
- Assert.assertNotNull(lbs.getLocatedBlocks());
- Assert.assertTrue(lbs.getLocatedBlocks().size() > 0);
+ assertNotNull(lbs, "Can't get block locations for " + src);
+ assertNotNull(lbs.getLocatedBlocks());
+ assertTrue(lbs.getLocatedBlocks().size() > 0);
done = true;
for (int y = 0; y < lbs.getLocatedBlocks().size() && done; y++) {
@@ -267,8 +261,7 @@ public class TestBlockReorderMultiBlocks {
} while (!done);
for (int y = 0; y < lbs.getLocatedBlocks().size() && done; y++) {
- Assert.assertEquals(localhost,
- getLocatedBlockLocations(lbs.get(y))[repCount - 1].getHostName());
+ assertEquals(localhost, getLocatedBlockLocations(lbs.get(y))[repCount - 1].getHostName());
}
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestInfoServersACL.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestInfoServersACL.java
index 209696573cb..adf3380a70a 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestInfoServersACL.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestInfoServersACL.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.http;
-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.File;
import java.lang.management.ManagementFactory;
@@ -30,7 +30,6 @@ import javax.management.ObjectName;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CommonConfigurationKeys;
import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.LocalHBaseCluster;
@@ -62,26 +61,20 @@ import org.ietf.jgss.GSSCredential;
import org.ietf.jgss.GSSManager;
import org.ietf.jgss.GSSName;
import org.ietf.jgss.Oid;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Testing info servers for admin acl.
*/
-@Category({ MiscTests.class, MediumTests.class })
+@Tag(MiscTests.TAG)
+@Tag(MediumTests.TAG)
public class TestInfoServersACL {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestInfoServersACL.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestInfoServersACL.class);
private final static HBaseTestingUtility UTIL = new HBaseTestingUtility();
private static Configuration conf;
@@ -94,16 +87,13 @@ public class TestInfoServersACL {
private static String PRINCIPAL;
private static String HTTP_PRINCIPAL;
- @Rule
- public TestName name = new TestName();
-
// user/group present in hbase.admin.acl
private static final String USER_ADMIN_STR = "admin";
// user with no permissions
private static final String USER_NONE_STR = "none";
- @BeforeClass
+ @BeforeAll
public static void beforeClass() throws Exception {
conf = UTIL.getConfiguration();
KDC = UTIL.setupMiniKdc(KEYTAB_FILE);
@@ -147,7 +137,7 @@ public class TestInfoServersACL {
/**
* Helper method to shut down the cluster (if running)
*/
- @AfterClass
+ @AfterAll
public static void shutDownMiniCluster() throws Exception {
if (CLUSTER != null) {
CLUSTER.shutdown();
@@ -170,8 +160,8 @@ public class TestInfoServersACL {
String expectedContent = "Get Log Level";
Pair<Integer, String> pair = getLogLevelPage();
assertEquals(HttpURLConnection.HTTP_OK, pair.getFirst().intValue());
- assertTrue("expected=" + expectedContent + ", content=" + pair.getSecond(),
- pair.getSecond().contains(expectedContent));
+ assertTrue(pair.getSecond().contains(expectedContent),
+ "expected=" + expectedContent + ", content=" + pair.getSecond());
return null;
}
});
@@ -202,8 +192,8 @@ public class TestInfoServersACL {
// Check the expected content is present in the http response
Pair<Integer, String> pair = getTablePage(TableName.META_TABLE_NAME);
assertEquals(HttpURLConnection.HTTP_OK, pair.getFirst().intValue());
- assertTrue("expected=" + expectedAuthorizedContent + ", content=" + pair.getSecond(),
- pair.getSecond().contains(expectedAuthorizedContent));
+ assertTrue(pair.getSecond().contains(expectedAuthorizedContent),
+ "expected=" + expectedAuthorizedContent + ", content=" + pair.getSecond());
return null;
}
});
@@ -215,9 +205,8 @@ public class TestInfoServersACL {
public Void run() throws Exception {
Pair<Integer, String> pair = getTablePage(TableName.META_TABLE_NAME);
assertEquals(HttpURLConnection.HTTP_OK, pair.getFirst().intValue());
- assertFalse(
- "should not find=" + expectedAuthorizedContent + ", content=" + pair.getSecond(),
- pair.getSecond().contains(expectedAuthorizedContent));
+ assertFalse(pair.getSecond().contains(expectedAuthorizedContent),
+ "should not find=" + expectedAuthorizedContent + ", content=" + pair.getSecond());
return null;
}
});
@@ -234,8 +223,8 @@ public class TestInfoServersACL {
// Check the expected content is present in the http response
Pair<Integer, String> pair = getLogsPage();
assertEquals(HttpURLConnection.HTTP_OK, pair.getFirst().intValue());
- assertTrue("expected=" + expectedAuthorizedContent + ", content=" + pair.getSecond(),
- pair.getSecond().contains(expectedAuthorizedContent));
+ assertTrue(pair.getSecond().contains(expectedAuthorizedContent),
+ "expected=" + expectedAuthorizedContent + ", content=" + pair.getSecond());
return null;
}
});
@@ -263,8 +252,8 @@ public class TestInfoServersACL {
// Check the expected content is present in the http response
Pair<Integer, String> pair = getMasterDumpPage();
assertEquals(HttpURLConnection.HTTP_OK, pair.getFirst().intValue());
- assertTrue("expected=" + expectedAuthorizedContent + ", content=" + pair.getSecond(),
- pair.getSecond().contains(expectedAuthorizedContent));
+ assertTrue(pair.getSecond().contains(expectedAuthorizedContent),
+ "expected=" + expectedAuthorizedContent + ", content=" + pair.getSecond());
return null;
}
});
@@ -292,8 +281,8 @@ public class TestInfoServersACL {
// Check the expected content is present in the http response
Pair<Integer, String> pair = getStacksPage();
assertEquals(HttpURLConnection.HTTP_OK, pair.getFirst().intValue());
- assertTrue("expected=" + expectedAuthorizedContent + ", content=" + pair.getSecond(),
- pair.getSecond().contains(expectedAuthorizedContent));
+ assertTrue(pair.getSecond().contains(expectedAuthorizedContent),
+ "expected=" + expectedAuthorizedContent + ", content=" + pair.getSecond());
return null;
}
});
@@ -334,8 +323,8 @@ public class TestInfoServersACL {
// Check the expected content is present in the http response
Pair<Integer, String> pair = getJmxPage();
assertEquals(HttpURLConnection.HTTP_OK, pair.getFirst().intValue());
- assertTrue("expected=" + expectedAuthorizedContent + ", content=" + pair.getSecond(),
- pair.getSecond().contains(expectedAuthorizedContent));
+ assertTrue(pair.getSecond().contains(expectedAuthorizedContent),
+ "expected=" + expectedAuthorizedContent + ", content=" + pair.getSecond());
return null;
}
});
@@ -369,8 +358,8 @@ public class TestInfoServersACL {
return null;
}
assertEquals(HttpURLConnection.HTTP_OK, pair.getFirst().intValue());
- assertTrue("expected=" + expectedAuthorizedContent + ", content=" + pair.getSecond(),
- pair.getSecond().contains(expectedAuthorizedContent));
+ assertTrue(pair.getSecond().contains(expectedAuthorizedContent),
+ "expected=" + expectedAuthorizedContent + ", content=" + pair.getSecond());
return null;
}
});
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/monitoring/TestMemoryBoundedLogMessageBuffer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/monitoring/TestMemoryBoundedLogMessageBuffer.java
index 8614b831cde..1672b4567ef 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/monitoring/TestMemoryBoundedLogMessageBuffer.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/monitoring/TestMemoryBoundedLogMessageBuffer.java
@@ -17,29 +17,24 @@
*/
package org.apache.hadoop.hbase.monitoring;
-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.io.PrintWriter;
import java.io.StringWriter;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
/**
* Test case for the MemoryBoundedLogMessageBuffer utility. Ensures that it uses no more memory than
* it's supposed to, and that it properly deals with multibyte encodings.
*/
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestMemoryBoundedLogMessageBuffer {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestMemoryBoundedLogMessageBuffer.class);
-
private static final long TEN_KB = 10 * 1024;
private static final String JP_TEXT = "こんにちは";
@@ -50,14 +45,14 @@ public class TestMemoryBoundedLogMessageBuffer {
for (int i = 0; i < 1000; i++) {
buf.add("hello " + i);
}
- assertTrue("Usage too big: " + buf.estimateHeapUsage(), buf.estimateHeapUsage() < TEN_KB);
- assertTrue("Too many retained: " + buf.getMessages().size(), buf.getMessages().size() < 100);
+ assertTrue(buf.estimateHeapUsage() < TEN_KB, "Usage too big: " + buf.estimateHeapUsage());
+ assertTrue(buf.getMessages().size() < 100, "Too many retained: " + buf.getMessages().size());
StringWriter sw = new StringWriter();
buf.dumpTo(new PrintWriter(sw));
String dump = sw.toString();
String eol = System.getProperty("line.separator");
- assertFalse("The early log messages should be evicted", dump.contains("hello 1" + eol));
- assertTrue("The late log messages should be retained", dump.contains("hello 999" + eol));
+ assertFalse(dump.contains("hello 1" + eol), "The early log messages should be evicted");
+ assertTrue(dump.contains("hello 999" + eol), "The late log messages should be retained");
}
@Test
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/monitoring/TestTaskMonitor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/monitoring/TestTaskMonitor.java
index 9321efe0ee5..6e3ec0d16eb 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/monitoring/TestTaskMonitor.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/monitoring/TestTaskMonitor.java
@@ -17,11 +17,11 @@
*/
package org.apache.hadoop.hbase.monitoring;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.util.ArrayList;
import java.util.Collection;
@@ -29,7 +29,6 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.client.Mutation;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Query;
@@ -37,25 +36,21 @@ import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestTaskMonitor {
private static final Logger LOG = LoggerFactory.getLogger(TestTaskMonitor.class);
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestTaskMonitor.class);
-
@Test
public void testTaskMonitorBasics() {
TaskMonitor tm = new TaskMonitor(new Configuration());
- assertTrue("Task monitor should start empty", tm.getTasks().isEmpty());
+ assertTrue(tm.getTasks().isEmpty(), "Task monitor should start empty");
// Make a task and fetch it back out
MonitoredTask task = tm.createStatus("Test task");
@@ -85,7 +80,7 @@ public class TestTaskMonitor {
@Test
public void testTasksGetAbortedOnLeak() throws InterruptedException {
final TaskMonitor tm = new TaskMonitor(new Configuration());
- assertTrue("Task monitor should start empty", tm.getTasks().isEmpty());
+ assertTrue(tm.getTasks().isEmpty(), "Task monitor should start empty");
final AtomicBoolean threadSuccess = new AtomicBoolean(false);
// Make a task in some other thread and leak it
@@ -144,7 +139,7 @@ public class TestTaskMonitor {
remainRPCTask++;
}
}
- assertEquals("RPC Tasks have been purged!", RPCTaskNums, remainRPCTask);
+ assertEquals(RPCTaskNums, remainRPCTask, "RPC Tasks have been purged!");
tm.shutdown();
}
@@ -158,21 +153,21 @@ public class TestTaskMonitor {
final TaskMonitor tm = new TaskMonitor(conf);
MonitoredRPCHandler t = tm.createRPCStatus("test task");
long beforeSetRPC = EnvironmentEdgeManager.currentTime();
- assertTrue("Validating initialization assumption", t.getWarnTime() <= beforeSetRPC);
+ assertTrue(t.getWarnTime() <= beforeSetRPC, "Validating initialization assumption");
Thread.sleep(MONITOR_INTERVAL * 2);
t.setRPC("testMethod", new Object[0], beforeSetRPC);
long afterSetRPC = EnvironmentEdgeManager.currentTime();
Thread.sleep(MONITOR_INTERVAL * 2);
- assertTrue("Validating no warn after starting RPC", t.getWarnTime() <= afterSetRPC);
+ assertTrue(t.getWarnTime() <= afterSetRPC, "Validating no warn after starting RPC");
Thread.sleep(MONITOR_INTERVAL * 2);
- assertTrue("Validating warn after RPC_WARN_TIME", t.getWarnTime() > afterSetRPC);
+ assertTrue(t.getWarnTime() > afterSetRPC, "Validating warn after RPC_WARN_TIME");
tm.shutdown();
}
@Test
public void testGetTasksWithFilter() throws Exception {
TaskMonitor tm = new TaskMonitor(new Configuration());
- assertTrue("Task monitor should start empty", tm.getTasks().isEmpty());
+ assertTrue(tm.getTasks().isEmpty(), "Task monitor should start empty");
// Create 5 general tasks
tm.createStatus("General task1");
tm.createStatus("General task2");
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/MobSnapshotTestingUtils.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/MobSnapshotTestingUtils.java
index e2892a9e701..716f828e3d5 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/MobSnapshotTestingUtils.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/MobSnapshotTestingUtils.java
@@ -17,7 +17,8 @@
*/
package org.apache.hadoop.hbase.snapshot;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import org.apache.commons.lang3.StringUtils;
@@ -39,7 +40,6 @@ import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.regionserver.BloomType;
import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.Assert;
public class MobSnapshotTestingUtils {
@@ -134,7 +134,7 @@ public class MobSnapshotTestingUtils {
count++;
for (Cell cell : res.listCells()) {
// Verify the value
- Assert.assertTrue(CellUtil.cloneValue(cell).length > 0);
+ assertTrue(CellUtil.cloneValue(cell).length > 0);
}
}
return count;
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java
index fa55d92e554..46291d2b3fd 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java
@@ -17,9 +17,10 @@
*/
package org.apache.hadoop.hbase.snapshot;
-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 static org.junit.jupiter.api.Assertions.fail;
import com.google.protobuf.ServiceException;
import java.io.IOException;
@@ -69,7 +70,6 @@ import org.apache.hadoop.hbase.util.FSTableDescriptors;
import org.apache.hadoop.hbase.util.FSVisitor;
import org.apache.hadoop.hbase.util.MD5Hash;
import org.apache.yetus.audience.InterfaceAudience;
-import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -97,7 +97,7 @@ public final class SnapshotTestingUtils {
* Assert that we don't have any snapshots lists if the admin operation fails
*/
public static void assertNoSnapshots(Admin admin) throws IOException {
- assertEquals("Have some previous snapshots", 0, admin.listSnapshots().size());
+ assertEquals(0, admin.listSnapshots().size(), "Have some previous snapshots");
}
/**
@@ -116,7 +116,7 @@ public final class SnapshotTestingUtils {
}
}
- Assert.assertTrue("No matching snapshots found.", returnedSnapshots.size() > 0);
+ assertTrue(returnedSnapshots.size() > 0, "No matching snapshots found.");
return returnedSnapshots;
}
@@ -137,7 +137,7 @@ public final class SnapshotTestingUtils {
// list the snapshot
List<SnapshotDescription> snapshots = admin.listSnapshots();
- assertEquals("Should only have 1 snapshot", 1, snapshots.size());
+ assertEquals(1, snapshots.size(), "Should only have 1 snapshot");
assertEquals(snapshotName, snapshots.get(0).getName());
assertEquals(tableName, snapshots.get(0).getTableName());
@@ -199,8 +199,8 @@ public final class SnapshotTestingUtils {
// check snapshot dir
Path snapshotDir =
SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotDescriptor, rootDir);
- assertTrue("target snapshot directory, '" + snapshotDir + "', doesn't exist.",
- fs.exists(snapshotDir));
+ assertTrue(fs.exists(snapshotDir),
+ "target snapshot directory, '" + snapshotDir + "', doesn't exist.");
SnapshotProtos.SnapshotDescription desc =
SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);
@@ -223,16 +223,17 @@ public final class SnapshotTestingUtils {
// Verify that there are store files in the specified families
if (nonEmptyTestFamilies != null) {
for (final byte[] familyName : nonEmptyTestFamilies) {
- assertTrue("Expected snapshot to contain family '" + Bytes.toString(familyName)
- + "', but it does not.", snapshotFamilies.contains(familyName));
+ assertTrue(snapshotFamilies.contains(familyName), "Expected snapshot to contain family '"
+ + Bytes.toString(familyName) + "', but it does not.");
}
}
// Verify that there are no store files in the specified families
if (emptyTestFamilies != null) {
for (final byte[] familyName : emptyTestFamilies) {
- assertFalse("Expected snapshot to skip empty family '" + Bytes.toString(familyName)
- + "', but it is present.", snapshotFamilies.contains(familyName));
+ assertFalse(snapshotFamilies.contains(familyName),
+ "Expected snapshot to skip empty family '" + Bytes.toString(familyName)
+ + "', but it is present.");
}
}
@@ -243,7 +244,7 @@ public final class SnapshotTestingUtils {
boolean hasMob =
regionManifests.containsKey(MobUtils.getMobRegionInfo(tableName).getEncodedName());
if (hasMob) {
- assertEquals("Wrong number of regions.", regions.size(), regionManifests.size() - 1);
+ assertEquals(regions.size(), regionManifests.size() - 1, "Wrong number of regions.");
} else {
// if create snapshot when table splitting, parent region will be included to the snapshot
// region manifest. we should exclude the parent regions.
@@ -255,14 +256,14 @@ public final class SnapshotTestingUtils {
}
regionCountExclusiveSplitParent++;
}
- assertEquals("Wrong number of regions.", regions.size(), regionCountExclusiveSplitParent);
+ assertEquals(regions.size(), regionCountExclusiveSplitParent, "Wrong number of regions.");
}
// Verify Regions (redundant check, see MasterSnapshotVerifier)
for (RegionInfo info : regions) {
String regionName = info.getEncodedName();
- assertTrue("Missing region name: '" + regionName + "'",
- regionManifests.containsKey(regionName));
+ assertTrue(regionManifests.containsKey(regionName),
+ "Missing region name: '" + regionName + "'");
}
}
@@ -341,14 +342,14 @@ public final class SnapshotTestingUtils {
Class<? extends HBaseSnapshotException> clazz) {
try {
master.getMasterRpcServices().isSnapshotDone(null, snapshot);
- Assert.fail("didn't fail to lookup a snapshot");
+ fail("didn't fail to lookup a snapshot");
} catch (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException se) {
try {
throw ProtobufUtil.handleRemoteException(se);
} catch (HBaseSnapshotException e) {
- assertEquals("Threw wrong snapshot exception!", clazz, e.getClass());
+ assertEquals(clazz, e.getClass(), "Threw wrong snapshot exception!");
} catch (Throwable t) {
- Assert.fail("Threw an unexpected exception:" + t);
+ fail("Threw an unexpected exception:" + t);
}
}
}
@@ -410,7 +411,7 @@ public final class SnapshotTestingUtils {
List<SnapshotDescription> snapshots =
SnapshotTestingUtils.assertExistsMatchingSnapshot(admin, snapshotNameString, tableName);
if (snapshots == null || snapshots.size() != 1) {
- Assert.fail("Incorrect number of snapshots for table " + tableName);
+ fail("Incorrect number of snapshots for table " + tableName);
}
LOG.info("validating snapshot.");
@@ -899,7 +900,7 @@ public final class SnapshotTestingUtils {
for (int i = 0; i < regionReplication; i++) {
RegionInfo replica = RegionReplicaUtil.getRegionInfoForReplica(hri, i);
if (!regions.contains(replica)) {
- Assert.fail(replica + " is not contained in the list of online regions");
+ fail(replica + " is not contained in the list of online regions");
}
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestConcurrentFlushSnapshotFromClient.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestConcurrentFlushSnapshotFromClient.java
index 9693541967d..caf11b399f2 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestConcurrentFlushSnapshotFromClient.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestConcurrentFlushSnapshotFromClient.java
@@ -18,25 +18,20 @@
package org.apache.hadoop.hbase.snapshot;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.master.snapshot.SnapshotManager;
import org.apache.hadoop.hbase.testclassification.ClientTests;
-import org.apache.hadoop.hbase.testclassification.MediumTests;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.experimental.categories.Category;
+import org.apache.hadoop.hbase.testclassification.LargeTests;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Category({ ClientTests.class, MediumTests.class })
+@Tag(ClientTests.TAG)
+@Tag(LargeTests.TAG)
public class TestConcurrentFlushSnapshotFromClient extends TestFlushSnapshotFromClient {
private static final Logger LOG = LoggerFactory.getLogger(TestFlushSnapshotFromClient.class);
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestConcurrentFlushSnapshotFromClient.class);
-
- @BeforeClass
+ @BeforeAll
public static void setupCluster() throws Exception {
setupConf(UTIL.getConfiguration());
UTIL.startMiniCluster(3);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestFlushSnapshotFromClient.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestFlushSnapshotFromClient.java
index c206687226a..a26ce09d35b 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestFlushSnapshotFromClient.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestFlushSnapshotFromClient.java
@@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.snapshot;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
import java.util.Collections;
@@ -29,7 +29,6 @@ import java.util.Map;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionInfo;
@@ -46,13 +45,13 @@ import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -66,13 +65,10 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos;
* TestSnapshotFromClient. This is worth refactoring this because there will be a few more flavors
* of snapshots that need to run these tests.
*/
-@Category({ RegionServerTests.class, LargeTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(LargeTests.TAG)
public class TestFlushSnapshotFromClient {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestFlushSnapshotFromClient.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestFlushSnapshotFromClient.class);
protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
@@ -82,8 +78,11 @@ public class TestFlushSnapshotFromClient {
protected final int DEFAULT_NUM_ROWS = 100;
protected Admin admin = null;
- @BeforeClass
- public static void setupCluster() throws Exception {
+ @BeforeAll
+ public static void setupCluster(TestInfo testInfo) throws Exception {
+ if (testInfo.getTestClass().orElse(null) != TestFlushSnapshotFromClient.class) {
+ return;
+ }
setupConf(UTIL.getConfiguration());
UTIL.startMiniCluster(NUM_RS);
}
@@ -105,7 +104,7 @@ public class TestFlushSnapshotFromClient {
ConstantSizeRegionSplitPolicy.class.getName());
}
- @Before
+ @BeforeEach
public void setup() throws Exception {
createTable();
this.admin = UTIL.getConnection().getAdmin();
@@ -115,7 +114,7 @@ public class TestFlushSnapshotFromClient {
SnapshotTestingUtils.createTable(UTIL, TABLE_NAME, TEST_FAM);
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
UTIL.deleteTable(TABLE_NAME);
SnapshotTestingUtils.deleteAllSnapshots(this.admin);
@@ -123,7 +122,7 @@ public class TestFlushSnapshotFromClient {
SnapshotTestingUtils.deleteArchiveDirectory(UTIL);
}
- @AfterClass
+ @AfterAll
public static void cleanupTest() throws Exception {
try {
UTIL.shutdownMiniCluster();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestMobFlushSnapshotFromClient.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestMobFlushSnapshotFromClient.java
index 8a0b587ca7e..4acff99bcb0 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestMobFlushSnapshotFromClient.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestMobFlushSnapshotFromClient.java
@@ -19,16 +19,14 @@ package org.apache.hadoop.hbase.snapshot;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.mob.MobConstants;
import org.apache.hadoop.hbase.testclassification.ClientTests;
-import org.apache.hadoop.hbase.testclassification.MediumTests;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.experimental.categories.Category;
+import org.apache.hadoop.hbase.testclassification.LargeTests;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,16 +37,13 @@ import org.slf4j.LoggerFactory;
* TestSnapshotFromClient. This is worth refactoring this because there will be a few more flavors
* of snapshots that need to run these tests.
*/
-@Category({ ClientTests.class, MediumTests.class })
+@Tag(ClientTests.TAG)
+@Tag(LargeTests.TAG)
public class TestMobFlushSnapshotFromClient extends TestFlushSnapshotFromClient {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestMobFlushSnapshotFromClient.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestFlushSnapshotFromClient.class);
- @BeforeClass
+ @BeforeAll
public static void setupCluster() throws Exception {
setupConf(UTIL.getConfiguration());
UTIL.startMiniCluster(3);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestMobRestoreFlushSnapshotFromClient.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestMobRestoreFlushSnapshotFromClient.java
index 07c3d42e3d6..443fec6efe1 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestMobRestoreFlushSnapshotFromClient.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestMobRestoreFlushSnapshotFromClient.java
@@ -19,16 +19,14 @@ package org.apache.hadoop.hbase.snapshot;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.mob.MobConstants;
import org.apache.hadoop.hbase.testclassification.ClientTests;
import org.apache.hadoop.hbase.testclassification.LargeTests;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,16 +35,13 @@ import org.slf4j.LoggerFactory;
* TestRestoreSnapshotFromClient. This is worth refactoring this because there will be a few more
* flavors of snapshots that need to run these tests.
*/
-@Category({ ClientTests.class, LargeTests.class })
+@Tag(ClientTests.TAG)
+@Tag(LargeTests.TAG)
public class TestMobRestoreFlushSnapshotFromClient extends TestRestoreFlushSnapshotFromClient {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestMobRestoreFlushSnapshotFromClient.class);
-
final Logger LOG = LoggerFactory.getLogger(getClass());
- @BeforeClass
+ @BeforeAll
public static void setupCluster() throws Exception {
setupConf(UTIL.getConfiguration());
UTIL.startMiniCluster(3);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestMobRestoreSnapshotHelper.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestMobRestoreSnapshotHelper.java
index f2b44e3904d..380044b733f 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestMobRestoreSnapshotHelper.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestMobRestoreSnapshotHelper.java
@@ -19,28 +19,22 @@ package org.apache.hadoop.hbase.snapshot;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.mob.MobConstants;
import org.apache.hadoop.hbase.snapshot.MobSnapshotTestingUtils.SnapshotMock;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.ClassRule;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Test the restore/clone operation from a file-system point of view.
*/
-@Category(MediumTests.class)
+@Tag(MediumTests.TAG)
public class TestMobRestoreSnapshotHelper extends TestRestoreSnapshotHelper {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestMobRestoreSnapshotHelper.class);
-
final Logger LOG = LoggerFactory.getLogger(getClass());
@Override
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestRegionSnapshotTask.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestRegionSnapshotTask.java
index 8ffff9223f7..a17cd302fce 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestRegionSnapshotTask.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestRegionSnapshotTask.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.snapshot;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-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.assertTrue;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.spy;
@@ -31,7 +31,6 @@ import java.util.concurrent.Future;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Table;
@@ -46,11 +45,10 @@ import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.CommonFSUtils;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -60,13 +58,10 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos;
* Testing the region snapshot task on a cluster.
* @see org.apache.hadoop.hbase.regionserver.snapshot.FlushSnapshotSubprocedure.RegionSnapshotTask
*/
-@Category({ MediumTests.class, RegionServerTests.class })
+@Tag(MediumTests.TAG)
+@Tag(RegionServerTests.TAG)
public class TestRegionSnapshotTask {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestRegionSnapshotTask.class);
-
private final Logger LOG = LoggerFactory.getLogger(getClass());
private static HBaseTestingUtility TEST_UTIL;
@@ -74,7 +69,7 @@ public class TestRegionSnapshotTask {
private static FileSystem fs;
private static Path rootDir;
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() throws Exception {
TEST_UTIL = new HBaseTestingUtility();
@@ -92,7 +87,7 @@ public class TestRegionSnapshotTask {
fs = TEST_UTIL.getTestFileSystem();
}
- @AfterClass
+ @AfterAll
public static void tearDown() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestRestoreFlushSnapshotFromClient.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestRestoreFlushSnapshotFromClient.java
index dafc8976cbf..c17f9bbdbca 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestRestoreFlushSnapshotFromClient.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestRestoreFlushSnapshotFromClient.java
@@ -17,9 +17,10 @@
*/
package org.apache.hadoop.hbase.snapshot;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName;
@@ -28,17 +29,17 @@ import org.apache.hadoop.hbase.client.SnapshotType;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.master.snapshot.SnapshotManager;
import org.apache.hadoop.hbase.regionserver.snapshot.RegionServerSnapshotManager;
-import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,13 +48,10 @@ import org.slf4j.LoggerFactory;
* TestRestoreSnapshotFromClient. This is worth refactoring this because there will be a few more
* flavors of snapshots that need to run these tests.
*/
-@Category({ RegionServerTests.class, MediumTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(LargeTests.TAG)
public class TestRestoreFlushSnapshotFromClient {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestRestoreFlushSnapshotFromClient.class);
-
private static final Logger LOG =
LoggerFactory.getLogger(TestRestoreFlushSnapshotFromClient.class);
@@ -69,8 +67,11 @@ public class TestRestoreFlushSnapshotFromClient {
protected TableName tableName;
protected Admin admin;
- @BeforeClass
- public static void setupCluster() throws Exception {
+ @BeforeAll
+ public static void setupCluster(TestInfo testInfo) throws Exception {
+ if (testInfo.getTestClass().orElse(null) != TestRestoreFlushSnapshotFromClient.class) {
+ return;
+ }
setupConf(UTIL.getConfiguration());
UTIL.startMiniCluster(3);
}
@@ -87,7 +88,7 @@ public class TestRestoreFlushSnapshotFromClient {
RegionServerSnapshotManager.SNAPSHOT_TIMEOUT_MILLIS_DEFAULT * 2);
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
UTIL.shutdownMiniCluster();
}
@@ -101,7 +102,7 @@ public class TestRestoreFlushSnapshotFromClient {
* snapshotName1) of different states. The tableName, snapshotNames and the number of rows in the
* snapshot are initialized.
*/
- @Before
+ @BeforeEach
public void setup() throws Exception {
this.admin = UTIL.getAdmin();
@@ -138,7 +139,7 @@ public class TestRestoreFlushSnapshotFromClient {
table.close();
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
SnapshotTestingUtils.deleteAllSnapshots(UTIL.getAdmin());
SnapshotTestingUtils.deleteArchiveDirectory(UTIL);
@@ -169,11 +170,12 @@ public class TestRestoreFlushSnapshotFromClient {
verifyRowCount(UTIL, tableName, snapshot1Rows);
}
- @Test(expected = SnapshotDoesNotExistException.class)
+ @Test
public void testCloneNonExistentSnapshot() throws IOException, InterruptedException {
String snapshotName = "random-snapshot-" + EnvironmentEdgeManager.currentTime();
TableName tableName = TableName.valueOf("random-table-" + EnvironmentEdgeManager.currentTime());
- admin.cloneSnapshot(snapshotName, tableName);
+ assertThrows(SnapshotDoesNotExistException.class,
+ () -> admin.cloneSnapshot(snapshotName, tableName));
}
@Test
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestRestoreSnapshotHelper.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestRestoreSnapshotHelper.java
index 31759c03c72..8791a42f39a 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestRestoreSnapshotHelper.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestRestoreSnapshotHelper.java
@@ -17,9 +17,10 @@
*/
package org.apache.hadoop.hbase.snapshot;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.HashMap;
@@ -30,7 +31,6 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.LocatedFileStatus;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.RemoteIterator;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.MetaTableAccessor;
@@ -62,14 +62,12 @@ import org.apache.hadoop.hbase.util.CommonFSUtils;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.FSTableDescriptors;
import org.apache.hadoop.hbase.wal.WALSplitUtil;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -79,13 +77,10 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.Snapshot
/**
* Test the restore/clone operation from a file-system point of view.
*/
-@Category({ RegionServerTests.class, MediumTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(MediumTests.TAG)
public class TestRestoreSnapshotHelper {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestRestoreSnapshotHelper.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestRestoreSnapshotHelper.class);
protected final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
@@ -99,18 +94,18 @@ public class TestRestoreSnapshotHelper {
protected void setupConf(Configuration conf) {
}
- @BeforeClass
+ @BeforeAll
public static void setupCluster() throws Exception {
TEST_UTIL.getConfiguration().setInt(AssignmentManager.ASSIGN_MAX_ATTEMPTS, 3);
TEST_UTIL.startMiniCluster();
}
- @AfterClass
+ @AfterAll
public static void tearDownCluster() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
- @Before
+ @BeforeEach
public void setup() throws Exception {
rootDir = TEST_UTIL.getDataTestDir("testRestore");
archiveDir = new Path(rootDir, HConstants.HFILE_ARCHIVE_DIRECTORY);
@@ -122,7 +117,7 @@ public class TestRestoreSnapshotHelper {
TEST_UTIL.getAdmin().balancerSwitch(false, true);
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
fs.delete(TEST_UTIL.getDataTestDir(), true);
}
@@ -191,7 +186,7 @@ public class TestRestoreSnapshotHelper {
fs, conf, restoredRegion, htd, null);
region2.initialize();
long maxSeqId2 = WALSplitUtil.getMaxRegionSequenceId(fs, recoveredEdit);
- Assert.assertTrue(maxSeqId2 > maxSeqId);
+ assertTrue(maxSeqId2 > maxSeqId);
}
}
@@ -342,7 +337,7 @@ public class TestRestoreSnapshotHelper {
CommonFSUtils.getTableDir(new Path(rootDir, HConstants.HFILE_ARCHIVE_DIRECTORY), tableName),
CommonFSUtils.getTableDir(MobUtils.getMobHome(rootDir), tableName) };
for (Path tableDir : tableDirs) {
- Assert.assertFalse(hasHFileLink(tableDir));
+ assertFalse(hasHFileLink(tableDir));
}
}
@@ -395,13 +390,13 @@ public class TestRestoreSnapshotHelper {
for (int i = 0; i < files.size(); i += 2) {
String linkFile = files.get(i);
String refFile = files.get(i + 1);
- assertTrue(linkFile + " should be a HFileLink", HFileLink.isHFileLink(linkFile));
- assertTrue(refFile + " should be a Referene", StoreFileInfo.isReference(refFile));
+ assertTrue(HFileLink.isHFileLink(linkFile), linkFile + " should be a HFileLink");
+ assertTrue(StoreFileInfo.isReference(refFile), refFile + " should be a Reference");
assertEquals(sourceHtd.getTableName(), HFileLink.getReferencedTableName(linkFile));
Path refPath = getReferredToFile(refFile);
LOG.debug("get reference name for file " + refFile + " = " + refPath);
- assertTrue(refPath.getName() + " should be a HFileLink",
- HFileLink.isHFileLink(refPath.getName()));
+ assertTrue(HFileLink.isHFileLink(refPath.getName()),
+ refPath.getName() + " should be a HFileLink");
assertEquals(linkFile, refPath.getName());
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotClientRetries.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotClientRetries.java
index 90dc65fa456..e13e2786824 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotClientRetries.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotClientRetries.java
@@ -17,15 +17,14 @@
*/
package org.apache.hadoop.hbase.snapshot;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.IOException;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName;
-import org.apache.hadoop.hbase.TableNameTestRule;
import org.apache.hadoop.hbase.client.SnapshotDescription;
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
@@ -34,52 +33,48 @@ import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment;
import org.apache.hadoop.hbase.coprocessor.MasterObserver;
import org.apache.hadoop.hbase.coprocessor.ObserverContext;
import org.apache.hadoop.hbase.testclassification.MediumTests;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Category({ MediumTests.class })
+@Tag(MediumTests.TAG)
public class TestSnapshotClientRetries {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestSnapshotClientRetries.class);
-
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final Logger LOG = LoggerFactory.getLogger(TestSnapshotClientRetries.class);
- @Rule
- public TableNameTestRule testTable = new TableNameTestRule();
-
- @Before
+ @BeforeEach
public void setUp() throws Exception {
TEST_UTIL.getConfiguration().set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY,
MasterSyncObserver.class.getName());
TEST_UTIL.startMiniCluster(1);
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
- @Test(expected = SnapshotExistsException.class)
- public void testSnapshotAlreadyExist() throws Exception {
+ @Test
+ public void testSnapshotAlreadyExist(TestInfo testInfo) throws Exception {
final String snapshotName = "testSnapshotAlreadyExist";
- TEST_UTIL.createTable(testTable.getTableName(), "f");
- TEST_UTIL.getAdmin().snapshot(snapshotName, testTable.getTableName());
- snapshotAndAssertOneRetry(snapshotName, testTable.getTableName());
+ TableName tableName = TableName.valueOf(testInfo.getTestMethod().get().getName());
+ TEST_UTIL.createTable(tableName, "f");
+ TEST_UTIL.getAdmin().snapshot(snapshotName, tableName);
+ assertThrows(SnapshotExistsException.class,
+ () -> snapshotAndAssertOneRetry(snapshotName, tableName));
}
- @Test(expected = SnapshotDoesNotExistException.class)
- public void testCloneNonExistentSnapshot() throws Exception {
+ @Test
+ public void testCloneNonExistentSnapshot(TestInfo testInfo) throws Exception {
final String snapshotName = "testCloneNonExistentSnapshot";
- cloneAndAssertOneRetry(snapshotName, testTable.getTableName());
+ TableName tableName = TableName.valueOf(testInfo.getTestMethod().get().getName());
+ assertThrows(SnapshotDoesNotExistException.class,
+ () -> cloneAndAssertOneRetry(snapshotName, tableName));
}
public static class MasterSyncObserver implements MasterCoprocessor, MasterObserver {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotDescriptionUtils.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotDescriptionUtils.java
index 9a7a683857c..5eace71b4b7 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotDescriptionUtils.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotDescriptionUtils.java
@@ -17,27 +17,25 @@
*/
package org.apache.hadoop.hbase.snapshot;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+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 java.io.IOException;
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManagerTestHelper;
-import org.junit.After;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -46,24 +44,21 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.Snapshot
/**
* Test that the {@link SnapshotDescription} helper is helping correctly.
*/
-@Category({ RegionServerTests.class, SmallTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(SmallTests.TAG)
public class TestSnapshotDescriptionUtils {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestSnapshotDescriptionUtils.class);
-
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
private static FileSystem fs;
private static Path root;
- @BeforeClass
+ @BeforeAll
public static void setupFS() throws Exception {
fs = UTIL.getTestFileSystem();
root = new Path(UTIL.getDataTestDir(), "hbase");
}
- @After
+ @AfterEach
public void cleanupFS() throws Exception {
if (fs.exists(root)) {
if (!fs.delete(root, true)) {
@@ -102,9 +97,8 @@ public class TestSnapshotDescriptionUtils {
Path workingDir = new Path(tmpDir, "not_a_snapshot");
Configuration conf = new Configuration();
FileSystem workingFs = workingDir.getFileSystem(conf);
- assertFalse(
- "Already have working snapshot dir: " + workingDir + " but shouldn't. Test file leak?",
- fs.exists(workingDir));
+ assertFalse(fs.exists(workingDir),
+ "Already have working snapshot dir: " + workingDir + " but shouldn't. Test file leak?");
SnapshotDescription snapshot = SnapshotDescription.newBuilder().setName("snapshot").build();
Path finishedDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshot, snapshotDir);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotManifest.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotManifest.java
index 7834603df5d..1f35eaf76cc 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotManifest.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotManifest.java
@@ -17,14 +17,13 @@
*/
package org.apache.hadoop.hbase.snapshot;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.TableName;
@@ -32,11 +31,10 @@ import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
import org.apache.hadoop.hbase.testclassification.MasterTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,13 +45,10 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.Snapshot
import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription;
import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotRegionManifest;
-@Category({ MasterTests.class, MediumTests.class })
+@Tag(MasterTests.TAG)
+@Tag(MediumTests.TAG)
public class TestSnapshotManifest {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestSnapshotManifest.class);
-
private final Logger LOG = LoggerFactory.getLogger(getClass());
private static final String TABLE_NAME_STR = "testSnapshotManifest";
@@ -69,7 +64,7 @@ public class TestSnapshotManifest {
private SnapshotDescription snapshotDesc;
private SnapshotTestingUtils.SnapshotMock.SnapshotBuilder builder;
- @Before
+ @BeforeEach
public void setup() throws Exception {
TEST_UTIL = HBaseTestingUtility.createLocalHTU();
@@ -84,7 +79,7 @@ public class TestSnapshotManifest {
snapshotDesc = builder.getSnapshotDescription();
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
fs.delete(rootDir, true);
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotStoreFileSize.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotStoreFileSize.java
index 02b122f704a..d9ecda74138 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotStoreFileSize.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotStoreFileSize.java
@@ -17,6 +17,8 @@
*/
package org.apache.hadoop.hbase.snapshot;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
@@ -27,7 +29,6 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
@@ -39,12 +40,10 @@ import org.apache.hadoop.hbase.regionserver.StoreFileInfo;
import org.apache.hadoop.hbase.testclassification.MasterTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.CommonFSUtils;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription;
import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotRegionManifest;
@@ -52,13 +51,10 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.Snapshot
/**
* Validate if storefile length match both snapshop manifest and filesystem.
*/
-@Category({ MasterTests.class, MediumTests.class })
+@Tag(MasterTests.TAG)
+@Tag(MediumTests.TAG)
public class TestSnapshotStoreFileSize {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestSnapshotStoreFileSize.class);
-
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
private static final TableName TABLE_NAME = TableName.valueOf("t1");
private static final String SNAPSHOT_NAME = "s1";
@@ -67,14 +63,14 @@ public class TestSnapshotStoreFileSize {
private Admin admin;
private FileSystem fs;
- @BeforeClass
+ @BeforeAll
public static void setup() throws Exception {
conf = UTIL.getConfiguration();
conf.setBoolean(SnapshotManager.HBASE_SNAPSHOT_ENABLED, true);
UTIL.startMiniCluster(1);
}
- @AfterClass
+ @AfterAll
public static void teardown() throws Exception {
UTIL.shutdownMiniCluster();
}
@@ -121,6 +117,6 @@ public class TestSnapshotStoreFileSize {
storeFileInfoFromFS.put(storeFileName, storeFilesize);
}
}
- Assert.assertEquals(storeFileInfoFromManifest, storeFileInfoFromFS);
+ assertEquals(storeFileInfoFromManifest, storeFileInfoFromFS);
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotWhenChoreCleaning.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotWhenChoreCleaning.java
index 9ce98839de4..169dabb009f 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotWhenChoreCleaning.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotWhenChoreCleaning.java
@@ -17,6 +17,9 @@
*/
package org.apache.hadoop.hbase.snapshot;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
@@ -26,10 +29,8 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName;
-import org.apache.hadoop.hbase.TableNameTestRule;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.master.HMaster;
@@ -39,13 +40,10 @@ import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.CommonFSUtils;
import org.apache.hadoop.hbase.util.FSVisitor;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -55,16 +53,12 @@ import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
/**
* Test Case for HBASE-21387
*/
-@Category({ MediumTests.class })
+@Tag(MediumTests.TAG)
public class TestSnapshotWhenChoreCleaning {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestSnapshotWhenChoreCleaning.class);
-
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final Configuration CONF = TEST_UTIL.getConfiguration();
- private static final Logger LOG = LoggerFactory.getLogger(TestSnapshotClientRetries.class);
+ private static final Logger LOG = LoggerFactory.getLogger(TestSnapshotWhenChoreCleaning.class);
private static final TableName TABLE_NAME = TableName.valueOf("testTable");
private static final int MAX_SPLIT_KEYS_NUM = 100;
private static final byte[] FAMILY = Bytes.toBytes("family");
@@ -72,10 +66,7 @@ public class TestSnapshotWhenChoreCleaning {
private static final byte[] VALUE = Bytes.toBytes("value");
private static Table TABLE;
- @Rule
- public TableNameTestRule testTable = new TableNameTestRule();
-
- @BeforeClass
+ @BeforeAll
public static void setUp() throws Exception {
// Set the hbase.snapshot.thread.pool.max to 1;
CONF.setInt("hbase.snapshot.thread.pool.max", 1);
@@ -99,7 +90,7 @@ public class TestSnapshotWhenChoreCleaning {
TABLE = TEST_UTIL.createTable(TABLE_NAME, FAMILY, splitKeys);
}
- @AfterClass
+ @AfterAll
public static void tearDown() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
@@ -156,10 +147,10 @@ public class TestSnapshotWhenChoreCleaning {
}
TEST_UTIL.getAdmin().snapshot("snapshotName_prev", TABLE_NAME);
- Assert.assertEquals(Lists.newArrayList(cleaner.getDeletableFiles(files)).size(), 0);
+ assertEquals(0, Lists.newArrayList(cleaner.getDeletableFiles(files)).size());
TEST_UTIL.getAdmin().deleteSnapshot("snapshotName_prev");
cleaner.getFileCacheForTesting().triggerCacheRefreshForTesting();
- Assert.assertEquals(Lists.newArrayList(cleaner.getDeletableFiles(files)).size(), 100);
+ assertEquals(100, Lists.newArrayList(cleaner.getDeletableFiles(files)).size());
Runnable snapshotRunnable = () -> {
try {
@@ -200,6 +191,6 @@ public class TestSnapshotWhenChoreCleaning {
t2.start();
t1.join();
t2.join();
- Assert.assertTrue(success.get());
+ assertTrue(success.get());
}
}