You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by zh...@apache.org on 2026/05/26 08:17:37 UTC
(hbase) branch branch-2.5 updated: HBASE-30123 Upgrade hbase-server to use junit5 Part13 (#8153) (#8176)(#8224)(#8273)
This is an automated email from the ASF dual-hosted git repository.
Apache9 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 c2578cfbb36 HBASE-30123 Upgrade hbase-server to use junit5 Part13 (#8153) (#8176)(#8224)(#8273)
c2578cfbb36 is described below
commit c2578cfbb36c967366dd3df90557c42725350bf6
Author: Duo Zhang <zh...@apache.org>
AuthorDate: Tue May 26 16:17:29 2026 +0800
HBASE-30123 Upgrade hbase-server to use junit5 Part13 (#8153) (#8176)(#8224)(#8273)
(cherry picked from commit eae4887cd41dc180e02f77bfb8522372a39a6f87)
Signed-off-by: Xiao Liu <li...@apache.org>
---
.gitignore | 1 +
.../hbase/HBaseParameterizedParameterResolver.java | 4 +
.../hbase/io/TestByteBufferOutputStream.java | 16 +-
.../hbase/io/TestFSDataInputStreamWrapper.java | 16 +-
.../org/apache/hadoop/hbase/io/TestFileLink.java | 28 ++-
.../org/apache/hadoop/hbase/io/TestHFileLink.java | 76 +++----
.../hadoop/hbase/io/TestHalfStoreFileReader.java | 63 +++---
.../org/apache/hadoop/hbase/io/TestHeapSize.java | 21 +-
.../hbase/io/TestImmutableBytesWritable.java | 42 ++--
.../org/apache/hadoop/hbase/io/TestMetricsIO.java | 14 +-
.../hadoop/hbase/io/compress/HFileTestBase.java | 16 +-
.../io/encoding/TestBufferedDataBlockEncoder.java | 19 +-
.../hbase/io/encoding/TestChangingEncoding.java | 23 +-
.../hbase/io/encoding/TestDataBlockEncoders.java | 58 +++--
.../hbase/io/encoding/TestDataBlockEncoding.java | 18 +-
.../hbase/io/encoding/TestEncodedSeekers.java | 42 ++--
.../io/encoding/TestLoadAndSwitchEncodeOnDisk.java | 40 ++--
.../io/encoding/TestSeekBeforeWithReverseScan.java | 23 +-
.../io/encoding/TestSeekToBlockWithEncoders.java | 48 ++--
.../apache/hadoop/hbase/io/hfile/KeySampler.java | 6 +-
.../hbase/io/hfile/TestBlockCacheReporting.java | 21 +-
.../hadoop/hbase/io/hfile/TestBlockIOUtils.java | 207 ++++++++---------
.../hadoop/hbase/io/hfile/TestBytesReadFromFs.java | 67 +++---
.../hadoop/hbase/io/hfile/TestCacheConfig.java | 25 +--
.../hadoop/hbase/io/hfile/TestCacheOnWrite.java | 85 ++++---
.../hbase/io/hfile/TestCachedBlockQueue.java | 15 +-
.../apache/hadoop/hbase/io/hfile/TestChecksum.java | 25 +--
.../hbase/io/hfile/TestCombinedBlockCache.java | 20 +-
.../hbase/io/hfile/TestFixedFileTrailer.java | 65 +++---
.../io/hfile/TestForceCacheImportantBlocks.java | 41 ++--
.../apache/hadoop/hbase/io/hfile/TestHFile.java | 163 +++++++-------
.../hadoop/hbase/io/hfile/TestHFileBlock.java | 113 +++++-----
.../hadoop/hbase/io/hfile/TestHFileBlockIndex.java | 81 +++----
.../hbase/io/hfile/TestHFileBlockUnpack.java | 66 +++---
.../hbase/io/hfile/TestHFileDataBlockEncoder.java | 54 +++--
.../hadoop/hbase/io/hfile/TestHFileEncryption.java | 39 ++--
.../TestHFileInlineToRootChunkConversion.java | 13 +-
.../hbase/io/hfile/TestHFilePrettyPrinter.java | 46 ++--
.../hadoop/hbase/io/hfile/TestHFileReaderImpl.java | 15 +-
.../hfile/TestHFileScannerImplReferenceCount.java | 249 ++++++++++-----------
.../hadoop/hbase/io/hfile/TestHFileSeek.java | 38 ++--
.../hadoop/hbase/io/hfile/TestHFileWriterV3.java | 42 ++--
.../hfile/TestHFileWriterV3WithDataEncoders.java | 63 +++---
.../io/hfile/TestLazyDataBlockDecompression.java | 100 ++++-----
.../hbase/io/hfile/TestLruAdaptiveBlockCache.java | 41 ++--
.../hadoop/hbase/io/hfile/TestLruBlockCache.java | 39 ++--
.../hadoop/hbase/io/hfile/TestLruCachedBlock.java | 21 +-
.../apache/hadoop/hbase/io/hfile/TestPrefetch.java | 48 ++--
.../apache/hadoop/hbase/io/hfile/TestReseekTo.java | 16 +-
.../hbase/io/hfile/TestRowIndexV1DataEncoder.java | 21 +-
.../hbase/io/hfile/TestRowIndexV1RoundTrip.java | 23 +-
.../hbase/io/hfile/TestScannerFromBucketCache.java | 56 ++---
.../hfile/TestScannerSelectionUsingKeyRange.java | 40 ++--
.../io/hfile/TestScannerSelectionUsingTTL.java | 35 ++-
.../io/hfile/TestSeekBeforeWithInlineBlocks.java | 31 ++-
.../apache/hadoop/hbase/io/hfile/TestSeekTo.java | 51 ++---
.../hbase/io/hfile/TestTinyLfuBlockCache.java | 25 +--
.../hbase/io/hfile/bucket/TestBucketCache.java | 152 +++++++------
.../io/hfile/bucket/TestBucketCacheRefCnt.java | 23 +-
.../io/hfile/bucket/TestBucketWriterThread.java | 25 +--
.../io/hfile/bucket/TestByteBufferIOEngine.java | 32 ++-
.../bucket/TestExclusiveMemoryMmapEngine.java | 22 +-
.../hbase/io/hfile/bucket/TestFileIOEngine.java | 39 ++--
.../hadoop/hbase/io/hfile/bucket/TestRAMCache.java | 29 ++-
.../io/hfile/bucket/TestVerifyBucketCacheFile.java | 57 +++--
.../hbase/util/TestMiniClusterLoadEncoded.java | 26 +--
.../hbase/util/TestMiniClusterLoadParallel.java | 26 +--
.../hbase/util/TestMiniClusterLoadSequential.java | 69 +++---
68 files changed, 1408 insertions(+), 1766 deletions(-)
diff --git a/.gitignore b/.gitignore
index 9ab7a972d7a..7d2c2b0e857 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,3 +26,4 @@ tmp
**/.flattened-pom.xml
.vscode/
**/__pycache__
+.opencode
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseParameterizedParameterResolver.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseParameterizedParameterResolver.java
index 1df5b22a702..ccdf9958ac1 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseParameterizedParameterResolver.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseParameterizedParameterResolver.java
@@ -53,6 +53,10 @@ public class HBaseParameterizedParameterResolver implements ParameterResolver {
// test with wrapper type, otherwise it will always return false
return Primitives.wrap(expectedType).isAssignableFrom(value.getClass());
}
+ // non-primitive type can accept null value
+ if (value == null) {
+ return true;
+ }
return expectedType.isAssignableFrom(value.getClass());
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestByteBufferOutputStream.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestByteBufferOutputStream.java
index 809ca50bd5a..894ee921596 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestByteBufferOutputStream.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestByteBufferOutputStream.java
@@ -17,24 +17,20 @@
*/
package org.apache.hadoop.hbase.io;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.nio.ByteBuffer;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+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;
-@Category(SmallTests.class)
+@Tag(SmallTests.TAG)
+@Tag(MiscTests.TAG)
public class TestByteBufferOutputStream {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestByteBufferOutputStream.class);
-
@Test
public void testByteBufferReuse() throws IOException {
byte[] someBytes = Bytes.toBytes("some bytes");
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestFSDataInputStreamWrapper.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestFSDataInputStreamWrapper.java
index bb476670f10..432fff1a572 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestFSDataInputStreamWrapper.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestFSDataInputStreamWrapper.java
@@ -17,7 +17,7 @@
*/
package org.apache.hadoop.hbase.io;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.io.InputStream;
@@ -31,20 +31,16 @@ import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSInputStream;
import org.apache.hadoop.fs.HasEnhancedByteBufferAccess;
import org.apache.hadoop.fs.ReadOption;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.io.ByteBufferPool;
-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)
+@Tag(MiscTests.TAG)
public class TestFSDataInputStreamWrapper {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestFSDataInputStreamWrapper.class);
-
@Test
public void testUnbuffer() throws Exception {
InputStream pc = new ParentClass();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestFileLink.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestFileLink.java
index 61ebde20822..eb5f589be29 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestFileLink.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestFileLink.java
@@ -17,10 +17,11 @@
*/
package org.apache.hadoop.hbase.io;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -31,7 +32,6 @@ import org.apache.hadoop.fs.FSDataInputStream;
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.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
@@ -40,21 +40,17 @@ import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.client.HdfsDataInputStream;
import org.apache.hadoop.ipc.RemoteException;
-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 FileLink switches between alternate locations when the current location moves or gets
* deleted.
*/
-@Category({ IOTests.class, MediumTests.class })
+@Tag(IOTests.TAG)
+@Tag(MediumTests.TAG)
public class TestFileLink {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestFileLink.class);
-
@Test
public void testEquals() {
Path p1 = new Path("/p1");
@@ -160,7 +156,7 @@ public class TestFileLink {
}
}
- @Test(expected = FileNotFoundException.class)
+ @Test
public void testLinkReadWithMissingFile() throws Exception {
HBaseTestingUtility testUtil = new HBaseTestingUtility();
FileSystem fs = new MyDistributedFileSystem();
@@ -173,7 +169,9 @@ public class TestFileLink {
files.add(archivedPath);
FileLink link = new FileLink(files);
- link.open(fs);
+ assertThrows(FileNotFoundException.class, () -> {
+ link.open(fs);
+ });
}
/**
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHFileLink.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHFileLink.java
index ce96f248564..a9591f22b33 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHFileLink.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHFileLink.java
@@ -17,79 +17,69 @@
*/
package org.apache.hadoop.hbase.io;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.regex.Matcher;
import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.regionserver.HRegion;
import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.CommonFSUtils;
import org.apache.hadoop.hbase.util.Pair;
-import org.junit.Assert;
-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 that FileLink switches between alternate locations when the current location moves or gets
* deleted.
*/
-@Category({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestHFileLink {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestHFileLink.class);
-
- @Rule
- public TestName name = new TestName();
-
@Test
- public void testValidLinkNames() {
+ public void testValidLinkNames(TestInfo testInfo) {
String validLinkNames[] = { "foo=fefefe-0123456", "ns=foo=abababa-fefefefe" };
for (String name : validLinkNames) {
- Assert.assertTrue("Failed validating:" + name, name.matches(HFileLink.LINK_NAME_REGEX));
+ assertTrue(name.matches(HFileLink.LINK_NAME_REGEX), "Failed validating:" + name);
}
for (String name : validLinkNames) {
- Assert.assertTrue("Failed validating:" + name, HFileLink.isHFileLink(name));
+ assertTrue(HFileLink.isHFileLink(name), "Failed validating:" + name);
}
- String testName = name.getMethodName() + "=fefefe-0123456";
- Assert.assertEquals(TableName.valueOf(name.getMethodName()),
+ String testName = testInfo.getTestMethod().get().getName() + "=fefefe-0123456";
+ assertEquals(TableName.valueOf(testInfo.getTestMethod().get().getName()),
HFileLink.getReferencedTableName(testName));
- Assert.assertEquals("fefefe", HFileLink.getReferencedRegionName(testName));
- Assert.assertEquals("0123456", HFileLink.getReferencedHFileName(testName));
- Assert.assertEquals(testName,
- HFileLink.createHFileLinkName(TableName.valueOf(name.getMethodName()), "fefefe", "0123456"));
+ assertEquals("fefefe", HFileLink.getReferencedRegionName(testName));
+ assertEquals("0123456", HFileLink.getReferencedHFileName(testName));
+ assertEquals(testName, HFileLink.createHFileLinkName(
+ TableName.valueOf(testInfo.getTestMethod().get().getName()), "fefefe", "0123456"));
- testName = "ns=" + name.getMethodName() + "=fefefe-0123456";
- Assert.assertEquals(TableName.valueOf("ns", name.getMethodName()),
+ testName = "ns=" + testInfo.getTestMethod().get().getName() + "=fefefe-0123456";
+ assertEquals(TableName.valueOf("ns", testInfo.getTestMethod().get().getName()),
HFileLink.getReferencedTableName(testName));
- Assert.assertEquals("fefefe", HFileLink.getReferencedRegionName(testName));
- Assert.assertEquals("0123456", HFileLink.getReferencedHFileName(testName));
- Assert.assertEquals(testName, HFileLink
- .createHFileLinkName(TableName.valueOf("ns", name.getMethodName()), "fefefe", "0123456"));
+ assertEquals("fefefe", HFileLink.getReferencedRegionName(testName));
+ assertEquals("0123456", HFileLink.getReferencedHFileName(testName));
+ assertEquals(testName, HFileLink.createHFileLinkName(
+ TableName.valueOf("ns", testInfo.getTestMethod().get().getName()), "fefefe", "0123456"));
for (String name : validLinkNames) {
Matcher m = HFileLink.LINK_NAME_PATTERN.matcher(name);
assertTrue(m.matches());
- Assert.assertEquals(HFileLink.getReferencedTableName(name),
+ assertEquals(HFileLink.getReferencedTableName(name),
TableName.valueOf(m.group(1), m.group(2)));
- Assert.assertEquals(HFileLink.getReferencedRegionName(name), m.group(3));
- Assert.assertEquals(HFileLink.getReferencedHFileName(name), m.group(4));
+ assertEquals(HFileLink.getReferencedRegionName(name), m.group(3));
+ assertEquals(HFileLink.getReferencedHFileName(name), m.group(4));
}
}
@Test
- public void testBackReference() {
+ public void testBackReference(TestInfo testInfo) {
Path rootDir = new Path("/root");
Path archiveDir = new Path(rootDir, ".archive");
String storeFileName = "121212";
@@ -97,8 +87,8 @@ public class TestHFileLink {
String encodedRegion = "FEFE";
String cf = "cf1";
- TableName refTables[] =
- { TableName.valueOf(name.getMethodName()), TableName.valueOf("ns", name.getMethodName()) };
+ TableName refTables[] = { TableName.valueOf(testInfo.getTestMethod().get().getName()),
+ TableName.valueOf("ns", testInfo.getTestMethod().get().getName()) };
for (TableName refTable : refTables) {
Path refTableDir = CommonFSUtils.getTableDir(archiveDir, refTable);
@@ -108,28 +98,26 @@ public class TestHFileLink {
String refStoreFileName = refTable.getNameAsString().replace(TableName.NAMESPACE_DELIM, '=')
+ "=" + encodedRegion + "-" + storeFileName;
- TableName tableNames[] = { TableName.valueOf(name.getMethodName() + "1"),
- TableName.valueOf("ns", name.getMethodName() + "2"),
- TableName.valueOf(name.getMethodName() + ":" + name.getMethodName()) };
+ TableName tableNames[] = { TableName.valueOf(testInfo.getTestMethod().get().getName() + "1"),
+ TableName.valueOf("ns", testInfo.getTestMethod().get().getName() + "2"),
+ TableName.valueOf(testInfo.getTestMethod().get().getName() + ":"
+ + testInfo.getTestMethod().get().getName()) };
for (TableName tableName : tableNames) {
Path tableDir = CommonFSUtils.getTableDir(rootDir, tableName);
Path regionDir = HRegion.getRegionDir(tableDir, encodedRegion);
Path cfDir = new Path(regionDir, cf);
- // Verify back reference creation
assertEquals(
encodedRegion + "." + tableName.getNameAsString().replace(TableName.NAMESPACE_DELIM, '='),
HFileLink.createBackReferenceName(CommonFSUtils.getTableName(tableDir).getNameAsString(),
encodedRegion));
- // verify parsing back reference
Pair<TableName, String> parsedRef = HFileLink.parseBackReferenceName(encodedRegion + "."
+ tableName.getNameAsString().replace(TableName.NAMESPACE_DELIM, '='));
assertEquals(parsedRef.getFirst(), tableName);
assertEquals(encodedRegion, parsedRef.getSecond());
- // verify resolving back reference
Path storeFileDir = new Path(refLinkDir, encodedRegion + "."
+ tableName.getNameAsString().replace(TableName.NAMESPACE_DELIM, '='));
Path linkPath = new Path(cfDir, refStoreFileName);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHalfStoreFileReader.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHalfStoreFileReader.java
index 7020ad9f559..51a246403ac 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHalfStoreFileReader.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHalfStoreFileReader.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.io;
-import static org.junit.Assert.assertEquals;
-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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
@@ -31,7 +31,6 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellComparatorImpl;
import org.apache.hadoop.hbase.CellUtil;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.KeyValueUtil;
@@ -46,27 +45,27 @@ import org.apache.hadoop.hbase.io.hfile.ReaderContextBuilder;
import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
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;
-
-@Category({ IOTests.class, SmallTests.class })
+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;
+
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestHalfStoreFileReader {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestHalfStoreFileReader.class);
+ private static final Logger LOG = LoggerFactory.getLogger(TestHalfStoreFileReader.class);
private static HBaseTestingUtility TEST_UTIL;
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() throws Exception {
TEST_UTIL = new HBaseTestingUtility();
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
TEST_UTIL.cleanupTestDir();
}
@@ -123,21 +122,19 @@ public class TestHalfStoreFileReader {
bottom, new AtomicInteger(0), TEST_UTIL.getConfiguration());
fileInfo.initMetaAndIndex(halfreader.getHFileReader());
halfreader.loadFileInfo();
- final HFileScanner scanner = halfreader.getScanner(false, false);
-
- scanner.seekTo();
- Cell curr;
- do {
- curr = scanner.getCell();
- KeyValue reseekKv = getLastOnCol(curr);
- int ret = scanner.reseekTo(reseekKv);
- assertTrue("reseek to returned: " + ret, ret > 0);
- // System.out.println(curr + ": " + ret);
- } while (scanner.next());
-
- int ret = scanner.reseekTo(getLastOnCol(curr));
- // System.out.println("Last reseek: " + ret);
- assertTrue(ret > 0);
+ try (HFileScanner scanner = halfreader.getScanner(false, false)) {
+ scanner.seekTo();
+ Cell curr;
+ do {
+ curr = scanner.getCell();
+ KeyValue reseekKv = getLastOnCol(curr);
+ int ret = scanner.reseekTo(reseekKv);
+ assertTrue(ret > 0, "reseek to returned: " + ret);
+ } while (scanner.next());
+
+ int ret = scanner.reseekTo(getLastOnCol(curr));
+ assertTrue(ret > 0);
+ }
halfreader.close(true);
}
@@ -176,8 +173,8 @@ public class TestHalfStoreFileReader {
}
beforeMidKey = item;
}
- System.out.println("midkey: " + midKV + " or: " + Bytes.toStringBinary(midkey));
- System.out.println("beforeMidKey: " + beforeMidKey);
+ LOG.info("midkey: " + midKV + " or: " + Bytes.toStringBinary(midkey));
+ LOG.info("beforeMidKey: " + beforeMidKey);
// Seek on the splitKey, should be in top, not in bottom
Cell foundKeyValue = doTestOfSeekBefore(p, fs, bottom, midKV, cacheConf);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHeapSize.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHeapSize.java
index 38b093b997e..9886e009f6e 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHeapSize.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHeapSize.java
@@ -19,8 +19,8 @@ package org.apache.hadoop.hbase.io;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.lessThan;
-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.lang.management.ManagementFactory;
@@ -42,7 +42,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.ReentrantReadWriteLock;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Mutation;
@@ -74,29 +73,25 @@ import org.apache.hadoop.hbase.regionserver.throttle.StoreHotnessProtector;
import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.ClassSize;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+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 the sizing that HeapSize offers and compares to the size given by ClassSize.
*/
-@Category({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestHeapSize {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestHeapSize.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestHeapSize.class);
// List of classes implementing HeapSize
// BatchOperation, BatchUpdate, BlockIndex, Entry, Entry<K,V>, HStoreKey
// KeyValue, LruBlockCache, Put, WALKey
- @BeforeClass
+ @BeforeAll
public static void beforeClass() throws Exception {
// Print detail on jvm so we know what is different should below test fail.
RuntimeMXBean b = ManagementFactory.getRuntimeMXBean();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestImmutableBytesWritable.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestImmutableBytesWritable.java
index 51b9b3b7618..2a82c77a333 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestImmutableBytesWritable.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestImmutableBytesWritable.java
@@ -17,28 +17,23 @@
*/
package org.apache.hadoop.hbase.io;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.IOTests;
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;
-@Category({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestImmutableBytesWritable {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestImmutableBytesWritable.class);
-
@Test
public void testHash() throws Exception {
assertEquals(new ImmutableBytesWritable(Bytes.toBytes("xxabc"), 2, 3).hashCode(),
@@ -54,7 +49,7 @@ public class TestImmutableBytesWritable {
ImmutableBytesWritable ibw1 = new ImmutableBytesWritable(new byte[] { 0x0f });
ImmutableBytesWritable ibw2 = new ImmutableBytesWritable(new byte[] { 0x00, 0x00 });
ImmutableBytesWritable.Comparator c = new ImmutableBytesWritable.Comparator();
- assertFalse("ibw1 < ibw2", c.compare(ibw1, ibw2) < 0);
+ assertFalse(c.compare(ibw1, ibw2) < 0, "ibw1 < ibw2");
}
@Test
@@ -103,23 +98,22 @@ public class TestImmutableBytesWritable {
a.write(new DataOutputStream(baosA));
b.write(new DataOutputStream(baosB));
- assertEquals("Comparing " + a + " and " + b + " as raw", signum(comparator
- .compare(baosA.toByteArray(), 0, baosA.size(), baosB.toByteArray(), 0, baosB.size())),
- expectedSignum);
+ assertEquals(signum(comparator.compare(baosA.toByteArray(), 0, baosA.size(),
+ baosB.toByteArray(), 0, baosB.size())), expectedSignum,
+ "Comparing " + a + " and " + b + " as raw");
- assertEquals(
- "Comparing " + a + " and " + b + " as raw (inverse)", -signum(comparator
- .compare(baosB.toByteArray(), 0, baosB.size(), baosA.toByteArray(), 0, baosA.size())),
- expectedSignum);
+ assertEquals(-signum(comparator.compare(baosB.toByteArray(), 0, baosB.size(),
+ baosA.toByteArray(), 0, baosA.size())), expectedSignum,
+ "Comparing " + a + " and " + b + " as raw (inverse)");
}
private void doComparisonsOnObjects(ImmutableBytesWritable a, ImmutableBytesWritable b,
int expectedSignum) {
ImmutableBytesWritable.Comparator comparator = new ImmutableBytesWritable.Comparator();
- assertEquals("Comparing " + a + " and " + b + " as objects", signum(comparator.compare(a, b)),
- expectedSignum);
- assertEquals("Comparing " + a + " and " + b + " as objects (inverse)",
- -signum(comparator.compare(b, a)), expectedSignum);
+ assertEquals(signum(comparator.compare(a, b)), expectedSignum,
+ "Comparing " + a + " and " + b + " as objects");
+ assertEquals(-signum(comparator.compare(b, a)), expectedSignum,
+ "Comparing " + a + " and " + b + " as objects (inverse)");
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestMetricsIO.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestMetricsIO.java
index 7e9217d09c0..7f3ae8ff2b4 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestMetricsIO.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestMetricsIO.java
@@ -18,20 +18,16 @@
package org.apache.hadoop.hbase.io;
import org.apache.hadoop.hbase.CompatibilityFactory;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.test.MetricsAssertHelper;
+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;
-@Category(SmallTests.class)
+@Tag(SmallTests.TAG)
+@Tag(MiscTests.TAG)
public class TestMetricsIO {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestMetricsIO.class);
-
public MetricsAssertHelper HELPER = CompatibilityFactory.getInstance(MetricsAssertHelper.class);
@Test
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/compress/HFileTestBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/compress/HFileTestBase.java
index 76a411d390b..39a63def8f4 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/compress/HFileTestBase.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/compress/HFileTestBase.java
@@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.io.compress;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
import java.util.Random;
@@ -86,11 +86,11 @@ public class HFileTestBase {
HFile.Reader reader = HFile.createReader(FS, path, cacheConf, true, conf);
try {
scanner = reader.getScanner(conf, false, false);
- assertTrue("Initial seekTo failed", scanner.seekTo());
+ assertTrue(scanner.seekTo(), "Initial seekTo failed");
do {
Cell kv = scanner.getCell();
- assertTrue("Read back an unexpected or invalid KV",
- testKvs.contains(KeyValueUtil.ensureKeyValue(kv)));
+ assertTrue(testKvs.contains(KeyValueUtil.ensureKeyValue(kv)),
+ "Read back an unexpected or invalid KV");
i++;
} while (scanner.next());
} finally {
@@ -98,7 +98,7 @@ public class HFileTestBase {
scanner.close();
}
- assertEquals("Did not read back as many KVs as written", i, testKvs.size());
+ assertEquals(i, testKvs.size(), "Did not read back as many KVs as written");
// Test random seeks with pread
Random rand = ThreadLocalRandom.current();
@@ -106,10 +106,10 @@ public class HFileTestBase {
reader = HFile.createReader(FS, path, cacheConf, true, conf);
try {
scanner = reader.getScanner(conf, false, true);
- assertTrue("Initial seekTo failed", scanner.seekTo());
+ assertTrue(scanner.seekTo(), "Initial seekTo failed");
for (i = 0; i < 100; i++) {
KeyValue kv = testKvs.get(rand.nextInt(testKvs.size()));
- assertEquals("Unable to find KV as expected: " + kv, 0, scanner.seekTo(kv));
+ assertEquals(0, scanner.seekTo(kv), "Unable to find KV as expected: " + kv);
}
} finally {
scanner.close();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestBufferedDataBlockEncoder.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestBufferedDataBlockEncoder.java
index 68ce5e359f5..698a0664cf8 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestBufferedDataBlockEncoder.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestBufferedDataBlockEncoder.java
@@ -17,15 +17,14 @@
*/
package org.apache.hadoop.hbase.io.encoding;
-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;
import java.nio.ByteBuffer;
import org.apache.hadoop.hbase.CellUtil;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.KeyValue.Type;
@@ -37,17 +36,13 @@ import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.ObjectIntPair;
-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({ IOTests.class, MediumTests.class })
+@Tag(IOTests.TAG)
+@Tag(MediumTests.TAG)
public class TestBufferedDataBlockEncoder {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestBufferedDataBlockEncoder.class);
-
byte[] row1 = Bytes.toBytes("row1");
byte[] row2 = Bytes.toBytes("row2");
byte[] row_1_0 = Bytes.toBytes("row10");
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestChangingEncoding.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestChangingEncoding.java
index ab837f4d5ca..6e28d478b28 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestChangingEncoding.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestChangingEncoding.java
@@ -17,7 +17,7 @@
*/
package org.apache.hadoop.hbase.io.encoding;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
@@ -29,7 +29,6 @@ import java.util.concurrent.ThreadLocalRandom;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
@@ -49,24 +48,20 @@ import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.Threads;
-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 changing data block encoding settings of a column family.
*/
-@Category({ IOTests.class, LargeTests.class })
+@Tag(IOTests.TAG)
+@Tag(LargeTests.TAG)
public class TestChangingEncoding {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestChangingEncoding.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestChangingEncoding.class);
static final String CF = "EncodingTestCF";
static final byte[] CF_BYTES = Bytes.toBytes(CF);
@@ -104,7 +99,7 @@ public class TestChangingEncoding {
numBatchesWritten = 0;
}
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() throws Exception {
// Use a small flush size to create more HFiles.
conf.setInt(HConstants.HREGION_MEMSTORE_FLUSH_SIZE, 1024 * 1024);
@@ -117,7 +112,7 @@ public class TestChangingEncoding {
TEST_UTIL.startMiniCluster();
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestDataBlockEncoders.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestDataBlockEncoders.java
index a502113325f..dc0dc5be772 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestDataBlockEncoders.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestDataBlockEncoders.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.io.encoding;
-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.ByteArrayInputStream;
import java.io.DataInputStream;
@@ -27,18 +27,18 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
+import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.ArrayBackedTag;
import org.apache.hadoop.hbase.ByteBufferKeyValue;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellComparatorImpl;
import org.apache.hadoop.hbase.CellUtil;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
@@ -55,13 +55,8 @@ import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.RedundantKVGenerator;
-import org.junit.Assert;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -69,14 +64,12 @@ import org.slf4j.LoggerFactory;
* Test all of the data block encoding algorithms for correctness. Most of the class generate data
* which will test different branches in code.
*/
-@Category({ IOTests.class, LargeTests.class })
-@RunWith(Parameterized.class)
+@org.junit.jupiter.api.Tag(IOTests.TAG)
+@org.junit.jupiter.api.Tag(LargeTests.TAG)
+@HBaseParameterizedTestTemplate(
+ name = "{index}: includesMemstoreTS={0}, includesTags={1}, useOffheapData={2}")
public class TestDataBlockEncoders {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestDataBlockEncoders.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestDataBlockEncoders.class);
private static int NUMBER_OF_KV = 10000;
@@ -92,9 +85,8 @@ public class TestDataBlockEncoders {
private final boolean includesTags;
private final boolean useOffheapData;
- @Parameters
- public static Collection<Object[]> parameters() {
- return HBaseTestingUtility.memStoreTSTagsAndOffheapCombination();
+ public static Stream<Arguments> parameters() {
+ return HBaseTestingUtility.memStoreTSTagsAndOffheapCombination().stream().map(Arguments::of);
}
public TestDataBlockEncoders(boolean includesMemstoreTS, boolean includesTag,
@@ -120,7 +112,7 @@ public class TestDataBlockEncoders {
/**
* Test data block encoding of empty KeyValue. On test failure.
*/
- @Test
+ @TestTemplate
public void testEmptyKeyValues() throws IOException {
List<KeyValue> kvList = new ArrayList<>();
byte[] row = new byte[0];
@@ -144,7 +136,7 @@ public class TestDataBlockEncoders {
/**
* Test KeyValues with negative timestamp. On test failure.
*/
- @Test
+ @TestTemplate
public void testNegativeTimestamps() throws IOException {
List<KeyValue> kvList = new ArrayList<>();
byte[] row = new byte[0];
@@ -169,7 +161,7 @@ public class TestDataBlockEncoders {
* Test whether compression -> decompression gives the consistent results on pseudorandom sample.
* @throws IOException On test failure.
*/
- @Test
+ @TestTemplate
public void testExecutionOnSample() throws IOException {
List<KeyValue> kvList = generator.generateTestKeyValues(NUMBER_OF_KV, includesTags);
testEncodersOnDataset(kvList, includesMemstoreTS, includesTags);
@@ -178,7 +170,7 @@ public class TestDataBlockEncoders {
/**
* Test seeking while file is encoded.
*/
- @Test
+ @TestTemplate
public void testSeekingOnSample() throws IOException {
List<KeyValue> sampleKv = generator.generateTestKeyValues(NUMBER_OF_KV, includesTags);
@@ -231,7 +223,7 @@ public class TestDataBlockEncoders {
LOG.info("Done");
}
- @Test
+ @TestTemplate
public void testSeekingToOffHeapKeyValueInSample() throws IOException {
List<KeyValue> sampleKv = generator.generateTestKeyValues(NUMBER_OF_KV, includesTags);
@@ -306,7 +298,7 @@ public class TestDataBlockEncoders {
return ByteBuffer.wrap(encodedData);
}
- @Test
+ @TestTemplate
public void testNextOnSample() throws IOException {
List<KeyValue> sampleKv = generator.generateTestKeyValues(NUMBER_OF_KV, includesTags);
@@ -348,7 +340,7 @@ public class TestDataBlockEncoders {
/**
* Test whether the decompression of first key is implemented correctly.
*/
- @Test
+ @TestTemplate
public void testFirstKeyInBlockOnSample() throws IOException {
List<KeyValue> sampleKv = generator.generateTestKeyValues(NUMBER_OF_KV, includesTags);
@@ -368,7 +360,7 @@ public class TestDataBlockEncoders {
}
}
- @Test
+ @TestTemplate
public void testRowIndexWithTagsButNoTagsInCell() throws IOException {
List<KeyValue> kvList = new ArrayList<>();
byte[] row = new byte[0];
@@ -388,7 +380,7 @@ public class TestDataBlockEncoders {
encoder.createSeeker(encoder.newDataBlockDecodingContext(conf, meta));
seeker.setCurrentBuffer(new SingleByteBuff(encodedBuffer));
Cell cell = seeker.getCell();
- Assert.assertEquals(expectedKV.getLength(), ((KeyValue) cell).getLength());
+ assertEquals(expectedKV.getLength(), ((KeyValue) cell).getLength());
}
private void checkSeekingConsistency(List<DataBlockEncoder.EncodedSeeker> encodedSeekers,
@@ -452,7 +444,7 @@ public class TestDataBlockEncoders {
}
}
- @Test
+ @TestTemplate
public void testZeroByte() throws IOException {
List<KeyValue> kvList = new ArrayList<>();
byte[] row = Bytes.toBytes("abcd");
@@ -489,8 +481,8 @@ public class TestDataBlockEncoders {
// this is because in case of prefix tree the decoded stream will not have
// the
// mvcc in it.
- assertEquals("Encoding -> decoding gives different results for " + encoder,
- Bytes.toStringBinary(unencodedDataBuf), Bytes.toStringBinary(actualDataset));
+ assertEquals(Bytes.toStringBinary(unencodedDataBuf), Bytes.toStringBinary(actualDataset),
+ "Encoding -> decoding gives different results for " + encoder);
}
private static ByteBufferKeyValue buildOffHeapKeyValue(KeyValue keyValue) throws IOException {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestDataBlockEncoding.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestDataBlockEncoding.java
index 233ba440522..384d5c44f1d 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestDataBlockEncoding.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestDataBlockEncoding.java
@@ -17,22 +17,18 @@
*/
package org.apache.hadoop.hbase.io.encoding;
-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.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;
-@Category(SmallTests.class)
+@Tag(SmallTests.TAG)
+@Tag(MiscTests.TAG)
public class TestDataBlockEncoding {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestDataBlockEncoding.class);
-
@Test
public void testGetDataBlockEncoder() throws Exception {
for (DataBlockEncoding algo : DataBlockEncoding.values()) {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestEncodedSeekers.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestEncodedSeekers.java
index dba1ca0e124..bcdfe504bfe 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestEncodedSeekers.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestEncodedSeekers.java
@@ -17,16 +17,16 @@
*/
package org.apache.hadoop.hbase.io.encoding;
-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.ArrayList;
-import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.stream.Stream;
import org.apache.hadoop.hbase.ArrayBackedTag;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
@@ -48,24 +48,17 @@ import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.LoadTestKVGenerator;
import org.apache.hadoop.hbase.util.Strings;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Tests encoded seekers by loading and reading values.
*/
-@Category({ IOTests.class, LargeTests.class })
-@RunWith(Parameterized.class)
+@org.junit.jupiter.api.Tag(IOTests.TAG)
+@org.junit.jupiter.api.Tag(LargeTests.TAG)
+@HBaseParameterizedTestTemplate
public class TestEncodedSeekers {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestEncodedSeekers.class);
-
private static final String TABLE_NAME = "encodedSeekersTable";
private static final String CF_NAME = "encodedSeekersCF";
private static final byte[] CF_BYTES = Bytes.toBytes(CF_NAME);
@@ -79,7 +72,7 @@ public class TestEncodedSeekers {
private static final int NUM_HFILES = 4;
private static final int NUM_ROWS_PER_FLUSH = NUM_ROWS / NUM_HFILES;
- private final HBaseTestingUtility testUtil = HBaseTestingUtility.createLocalHTU();
+ private final HBaseTestingUtility testUtil = new HBaseTestingUtility();
private final DataBlockEncoding encoding;
private final boolean includeTags;
private final boolean compressTags;
@@ -87,17 +80,16 @@ public class TestEncodedSeekers {
/** Enable when debugging */
private static final boolean VERBOSE = false;
- @Parameters
- public static Collection<Object[]> parameters() {
- List<Object[]> paramList = new ArrayList<>();
+ public static Stream<Arguments> parameters() {
+ List<Arguments> params = new ArrayList<>();
for (DataBlockEncoding encoding : DataBlockEncoding.values()) {
for (boolean includeTags : new boolean[] { false, true }) {
for (boolean compressTags : new boolean[] { false, true }) {
- paramList.add(new Object[] { encoding, includeTags, compressTags });
+ params.add(Arguments.of(encoding, includeTags, compressTags));
}
}
}
- return paramList;
+ return params.stream();
}
public TestEncodedSeekers(DataBlockEncoding encoding, boolean includeTags, boolean compressTags) {
@@ -106,7 +98,7 @@ public class TestEncodedSeekers {
this.compressTags = compressTags;
}
- @Test
+ @TestTemplate
public void testEncodedSeeker() throws IOException {
System.err.println("Testing encoded seekers for encoding : " + encoding + ", includeTags : "
+ includeTags + ", compressTags : " + compressTags);
@@ -146,7 +138,7 @@ public class TestEncodedSeekers {
private void doPuts(HRegion region) throws IOException {
LoadTestKVGenerator dataGenerator = new LoadTestKVGenerator(MIN_VALUE_SIZE, MAX_VALUE_SIZE);
for (int i = 0; i < NUM_ROWS; ++i) {
- byte[] key = LoadTestKVGenerator.md5PrefixedKey(i).getBytes();
+ byte[] key = Bytes.toBytes(LoadTestKVGenerator.md5PrefixedKey(i));
for (int j = 0; j < NUM_COLS_PER_ROW; ++j) {
Put put = new Put(key);
put.setDurability(Durability.ASYNC_WAL);
@@ -174,7 +166,7 @@ public class TestEncodedSeekers {
private void doGets(Region region) throws IOException {
for (int i = 0; i < NUM_ROWS; ++i) {
- final byte[] rowKey = LoadTestKVGenerator.md5PrefixedKey(i).getBytes();
+ final byte[] rowKey = Bytes.toBytes(LoadTestKVGenerator.md5PrefixedKey(i));
for (int j = 0; j < NUM_COLS_PER_ROW; ++j) {
final String qualStr = String.valueOf(j);
if (VERBOSE) {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestLoadAndSwitchEncodeOnDisk.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestLoadAndSwitchEncodeOnDisk.java
index 0f5983bd3d8..750a02d321f 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestLoadAndSwitchEncodeOnDisk.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestLoadAndSwitchEncodeOnDisk.java
@@ -17,14 +17,14 @@
*/
package org.apache.hadoop.hbase.io.encoding;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collection;
import java.util.List;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
-import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.client.Admin;
+import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
import org.apache.hadoop.hbase.client.RegionLocator;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
@@ -34,33 +34,23 @@ import org.apache.hadoop.hbase.io.compress.Compression;
import org.apache.hadoop.hbase.io.hfile.CacheConfig;
import org.apache.hadoop.hbase.regionserver.HRegionServer;
import org.apache.hadoop.hbase.testclassification.IOTests;
-import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.TestMiniClusterLoadSequential;
import org.apache.hadoop.hbase.util.Threads;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
/**
* Uses the load tester
*/
-@Category({ IOTests.class, MediumTests.class })
+@Tag(IOTests.TAG)
+@Tag(LargeTests.TAG)
+@HBaseParameterizedTestTemplate
public class TestLoadAndSwitchEncodeOnDisk extends TestMiniClusterLoadSequential {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestLoadAndSwitchEncodeOnDisk.class);
-
/** We do not alternate the multi-put flag in this test. */
private static final boolean USE_MULTI_PUT = true;
- /** Un-parameterize the test */
- @Parameters
- public static Collection<Object[]> parameters() {
- return Arrays.asList(new Object[][] { new Object[0] });
- }
-
public TestLoadAndSwitchEncodeOnDisk() {
super(USE_MULTI_PUT, DataBlockEncoding.PREFIX);
conf.setBoolean(CacheConfig.CACHE_BLOCKS_ON_WRITE_KEY, true);
@@ -72,14 +62,14 @@ public class TestLoadAndSwitchEncodeOnDisk extends TestMiniClusterLoadSequential
}
@Override
- @Test
+ @TestTemplate
public void loadTest() throws Exception {
Admin admin = TEST_UTIL.getAdmin();
compression = Compression.Algorithm.GZ; // used for table setup
super.loadTest();
- HColumnDescriptor hcd = getColumnDesc(admin);
+ ColumnFamilyDescriptor hcd = getColumnDesc(admin);
System.err.println("\nDisabling encode-on-disk. Old column descriptor: " + hcd + "\n");
Table t = TEST_UTIL.getConnection().getTable(TABLE);
assertAllOnLine(t);
@@ -114,11 +104,11 @@ public class TestLoadAndSwitchEncodeOnDisk extends TestMiniClusterLoadSequential
regions = rl.getAllRegionLocations();
}
for (HRegionLocation e : regions) {
- byte[] startkey = e.getRegionInfo().getStartKey();
- Scan s = new Scan(startkey);
+ byte[] startkey = e.getRegion().getStartKey();
+ Scan s = new Scan().withStartRow(startkey);
ResultScanner scanner = t.getScanner(s);
Result r = scanner.next();
- org.junit.Assert.assertTrue(r != null && r.size() > 0);
+ assertTrue(r != null && r.size() > 0);
scanner.close();
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestSeekBeforeWithReverseScan.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestSeekBeforeWithReverseScan.java
index 7898ac2da5d..aa4a80ece3f 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestSeekBeforeWithReverseScan.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestSeekBeforeWithReverseScan.java
@@ -17,14 +17,13 @@
*/
package org.apache.hadoop.hbase.io.encoding;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
@@ -39,19 +38,15 @@ import org.apache.hadoop.hbase.regionserver.RegionScanner;
import org.apache.hadoop.hbase.testclassification.IOTests;
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.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;
-@Category({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestSeekBeforeWithReverseScan {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestSeekBeforeWithReverseScan.class);
-
private final HBaseTestingUtility testUtil = new HBaseTestingUtility();
private HRegion region;
@@ -59,7 +54,7 @@ public class TestSeekBeforeWithReverseScan {
private byte[] cfName = Bytes.toBytes("a");
private byte[] cqName = Bytes.toBytes("b");
- @Before
+ @BeforeEach
public void setUp() throws Exception {
TableName tableName = TableName.valueOf(getClass().getSimpleName());
HTableDescriptor htd = new HTableDescriptor(tableName);
@@ -69,7 +64,7 @@ public class TestSeekBeforeWithReverseScan {
region = HBaseTestingUtility.createRegionAndWAL(info, path, testUtil.getConfiguration(), htd);
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
HBaseTestingUtility.closeRegionAndWAL(region);
testUtil.cleanupTestDir();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestSeekToBlockWithEncoders.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestSeekToBlockWithEncoders.java
index 43f4605a0fc..2ba6ce32a64 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestSeekToBlockWithEncoders.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestSeekToBlockWithEncoders.java
@@ -17,18 +17,17 @@
*/
package org.apache.hadoop.hbase.io.encoding;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
+import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
-import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.PrivateCellUtil;
@@ -39,28 +38,21 @@ import org.apache.hadoop.hbase.nio.SingleByteBuff;
import org.apache.hadoop.hbase.testclassification.IOTests;
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.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
-@Category({ IOTests.class, SmallTests.class })
-@RunWith(Parameterized.class)
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
+@HBaseParameterizedTestTemplate(name = "dataEncoding={0}")
public class TestSeekToBlockWithEncoders {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestSeekToBlockWithEncoders.class);
-
static final byte[] HFILEBLOCK_DUMMY_HEADER = new byte[HConstants.HFILEBLOCK_HEADER_SIZE];
private final boolean useOffheapData;
private final Configuration conf = HBaseConfiguration.create();
- @Parameters
- public static Collection<Object[]> parameters() {
- return HBaseCommonTestingUtility.BOOLEAN_PARAMETERIZED;
+ public static Stream<Arguments> parameters() {
+ return Stream.of(Arguments.of(true), Arguments.of(false));
}
public TestSeekToBlockWithEncoders(boolean useOffheapData) {
@@ -70,7 +62,7 @@ public class TestSeekToBlockWithEncoders {
/**
* Test seeking while file is encoded.
*/
- @Test
+ @TestTemplate
public void testSeekToBlockWithNonMatchingSeekKey() throws IOException {
List<KeyValue> sampleKv = new ArrayList<>();
KeyValue kv1 = new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q1"),
@@ -96,7 +88,7 @@ public class TestSeekToBlockWithEncoders {
/**
* Test seeking while file is encoded.
*/
- @Test
+ @TestTemplate
public void testSeekingToBlockWithBiggerNonLength1() throws IOException {
List<KeyValue> sampleKv = new ArrayList<>();
KeyValue kv1 = new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q1"),
@@ -122,7 +114,7 @@ public class TestSeekToBlockWithEncoders {
/**
* Test seeking while file is encoded.
*/
- @Test
+ @TestTemplate
public void testSeekingToBlockToANotAvailableKey() throws IOException {
List<KeyValue> sampleKv = new ArrayList<>();
KeyValue kv1 = new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q1"),
@@ -148,7 +140,7 @@ public class TestSeekToBlockWithEncoders {
/**
* Test seeking while file is encoded.
*/
- @Test
+ @TestTemplate
public void testSeekToBlockWithDecreasingCommonPrefix() throws IOException {
List<KeyValue> sampleKv = new ArrayList<>();
KeyValue kv1 = new KeyValue(Bytes.toBytes("row10aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q1"),
@@ -167,7 +159,7 @@ public class TestSeekToBlockWithEncoders {
seekToTheKey(kv3, sampleKv, toSeek);
}
- @Test
+ @TestTemplate
public void testSeekToBlockWithDiffQualifer() throws IOException {
List<KeyValue> sampleKv = new ArrayList<>();
KeyValue kv1 = new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q1"),
@@ -187,7 +179,7 @@ public class TestSeekToBlockWithEncoders {
seekToTheKey(kv5, sampleKv, toSeek);
}
- @Test
+ @TestTemplate
public void testSeekToBlockWithDiffQualiferOnSameRow() throws IOException {
List<KeyValue> sampleKv = new ArrayList<>();
KeyValue kv1 = new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q1"),
@@ -210,7 +202,7 @@ public class TestSeekToBlockWithEncoders {
seekToTheKey(kv6, sampleKv, toSeek);
}
- @Test
+ @TestTemplate
public void testSeekToBlockWithDiffQualiferOnSameRow1() throws IOException {
List<KeyValue> sampleKv = new ArrayList<>();
KeyValue kv1 = new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q1"),
@@ -233,7 +225,7 @@ public class TestSeekToBlockWithEncoders {
seekToTheKey(kv5, sampleKv, toSeek);
}
- @Test
+ @TestTemplate
public void testSeekToBlockWithDiffQualiferOnSameRowButDescendingInSize() throws IOException {
List<KeyValue> sampleKv = new ArrayList<>();
KeyValue kv1 = new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("f1"), Bytes.toBytes("qual1"),
@@ -256,7 +248,7 @@ public class TestSeekToBlockWithEncoders {
seekToTheKey(kv6, sampleKv, toSeek);
}
- @Test
+ @TestTemplate
public void testSeekToBlockWithDiffFamilyAndQualifer() throws IOException {
List<KeyValue> sampleKv = new ArrayList<>();
KeyValue kv1 = new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("fam1"), Bytes.toBytes("q1"),
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/KeySampler.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/KeySampler.java
index 116d6d7bcef..d176103a2e8 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/KeySampler.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/KeySampler.java
@@ -40,8 +40,6 @@ class KeySampler {
int lastLen = keyPrefixToInt(last);
min = Math.min(firstLen, lastLen);
max = Math.max(firstLen, lastLen);
- System.out.println(min);
- System.out.println(max);
this.keyLenRNG = keyLenRNG;
}
@@ -54,13 +52,13 @@ class KeySampler {
public void next(BytesWritable key) {
key.setSize(Math.max(MIN_KEY_LEN, keyLenRNG.nextInt()));
- random.nextBytes(key.get());
+ random.nextBytes(key.getBytes());
int rnd = 0;
if (max != min) {
rnd = random.nextInt(max - min);
}
int n = rnd + min;
- byte[] b = key.get();
+ byte[] b = key.getBytes();
b[0] = (byte) (n >> 24);
b[1] = (byte) (n >> 16);
b[2] = (byte) (n >> 8);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestBlockCacheReporting.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestBlockCacheReporting.java
index cda6c3c1372..0326c64d065 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestBlockCacheReporting.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestBlockCacheReporting.java
@@ -17,39 +17,34 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-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.Map;
import java.util.NavigableSet;
import java.util.Objects;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.io.hfile.TestCacheConfig.DataCacheEntry;
import org.apache.hadoop.hbase.io.hfile.TestCacheConfig.IndexCacheEntry;
import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+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;
-@Category({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestBlockCacheReporting {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestBlockCacheReporting.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestBlockCacheReporting.class);
private Configuration conf;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
this.conf = HBaseConfiguration.create();
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestBlockIOUtils.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestBlockIOUtils.java
index cf61d574e38..90758138e18 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestBlockIOUtils.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestBlockIOUtils.java
@@ -24,14 +24,15 @@ import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.has
import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasName;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasItems;
-import static org.junit.Assert.assertArrayEquals;
-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.Assume.assumeTrue;
+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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -39,9 +40,8 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import io.opentelemetry.api.trace.Span;
-import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.context.Scope;
-import io.opentelemetry.sdk.testing.junit4.OpenTelemetryRule;
+import io.opentelemetry.sdk.testing.junit5.OpenTelemetryExtension;
import io.opentelemetry.sdk.trace.data.SpanData;
import java.io.DataOutputStream;
import java.io.IOException;
@@ -54,7 +54,6 @@ import org.apache.hadoop.fs.FSDataInputStream;
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.MatcherPredicate;
@@ -73,34 +72,31 @@ import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.trace.TraceUtil;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
-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.rules.TestName;
-
-@Category({ IOTests.class, 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;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestBlockIOUtils {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestBlockIOUtils.class);
+ private String methodName;
- @Rule
- public TestName testName = new TestName();
-
- @Rule
- public ExpectedException exception = ExpectedException.none();
-
- @Rule
- public OpenTelemetryRule otelRule = OpenTelemetryRule.create();
+ @RegisterExtension
+ private static OpenTelemetryExtension OTEL_EXT = OpenTelemetryExtension.create();
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final int NUM_TEST_BLOCKS = 2;
private static final Compression.Algorithm COMPRESSION_ALGO = Compression.Algorithm.GZ;
+ @BeforeEach
+ public void setUp(TestInfo testInfo) {
+ methodName = testInfo.getTestMethod().get().getName();
+ }
+
@Test
public void testIsByteBufferReadable() throws IOException {
FileSystem fs = TEST_UTIL.getTestFileSystem();
@@ -130,12 +126,12 @@ public class TestBlockIOUtils {
byte[] heapBuf = new byte[s.length()];
buf.get(heapBuf, 0, heapBuf.length);
assertArrayEquals(Bytes.toBytes(s), heapBuf);
- }, testName.getMethodName());
+ }, methodName);
TEST_UTIL.waitFor(TimeUnit.MINUTES.toMillis(1), new MatcherPredicate<Iterable<SpanData>>(
- otelRule::getSpans, hasItem(allOf(hasName(testName.getMethodName()), hasEnded()))));
- assertThat(otelRule.getSpans(),
- hasItems(allOf(hasName(testName.getMethodName()),
+ OTEL_EXT::getSpans, hasItem(allOf(hasName(methodName), hasEnded()))));
+ assertThat(OTEL_EXT.getSpans(),
+ hasItems(allOf(hasName(methodName),
hasEvents(hasItem(allOf(EventMatchers.hasName("BlockIOUtils.readFully"),
hasAttributes(containsEntry("db.hbase.io.heap_bytes_read", 11))))))));
}
@@ -155,7 +151,7 @@ public class TestBlockIOUtils {
Configuration conf = TEST_UTIL.getConfiguration();
conf.setBoolean(HConstants.HFILE_PREAD_ALL_BYTES_ENABLED_KEY, readAllBytes);
FileSystem fs = TEST_UTIL.getTestFileSystem();
- Path path = new Path(TEST_UTIL.getDataTestDirOnTestFS(), testName.getMethodName());
+ Path path = new Path(TEST_UTIL.getDataTestDirOnTestFS(), methodName);
// give a fixed seed such we can see failure easily.
Random rand = new Random(randomSeed);
long totalDataBlockBytes =
@@ -246,7 +242,7 @@ public class TestBlockIOUtils {
out.writeBytes(s);
}
- Span span = TraceUtil.createSpan(testName.getMethodName());
+ Span span = TraceUtil.createSpan(methodName);
try (Scope ignored = span.makeCurrent()) {
ByteBuff buf = new SingleByteBuff(ByteBuffer.allocate(8));
try (FSDataInputStream in = fs.open(p)) {
@@ -260,14 +256,14 @@ public class TestBlockIOUtils {
span.end();
}
TEST_UTIL.waitFor(TimeUnit.MINUTES.toMillis(1), new MatcherPredicate<Iterable<SpanData>>(
- otelRule::getSpans, hasItem(allOf(hasName(testName.getMethodName()), hasEnded()))));
- assertThat(otelRule.getSpans(),
- hasItems(allOf(hasName(testName.getMethodName()),
+ OTEL_EXT::getSpans, hasItem(allOf(hasName(methodName), hasEnded()))));
+ assertThat(OTEL_EXT.getSpans(),
+ hasItems(allOf(hasName(methodName),
hasEvents(hasItem(allOf(EventMatchers.hasName("BlockIOUtils.readWithExtra"),
hasAttributes(containsEntry("db.hbase.io.heap_bytes_read", 8L))))))));
- otelRule.clearSpans();
- span = TraceUtil.createSpan(testName.getMethodName());
+ OTEL_EXT.clearSpans();
+ span = TraceUtil.createSpan(methodName);
try (Scope ignored = span.makeCurrent()) {
ByteBuff buf =
new MultiByteBuff(ByteBuffer.allocate(4), ByteBuffer.allocate(4), ByteBuffer.allocate(4));
@@ -282,30 +278,29 @@ public class TestBlockIOUtils {
span.end();
}
TEST_UTIL.waitFor(TimeUnit.MINUTES.toMillis(1), new MatcherPredicate<Iterable<SpanData>>(
- otelRule::getSpans, hasItem(allOf(hasName(testName.getMethodName()), hasEnded()))));
- assertThat(otelRule.getSpans(),
- hasItems(allOf(hasName(testName.getMethodName()),
+ OTEL_EXT::getSpans, hasItem(allOf(hasName(methodName), hasEnded()))));
+ assertThat(OTEL_EXT.getSpans(),
+ hasItems(allOf(hasName(methodName),
hasEvents(hasItem(allOf(EventMatchers.hasName("BlockIOUtils.readWithExtra"),
hasAttributes(containsEntry("db.hbase.io.heap_bytes_read", 11L))))))));
- otelRule.clearSpans();
- span = TraceUtil.createSpan(testName.getMethodName());
+ OTEL_EXT.clearSpans();
+ span = TraceUtil.createSpan(methodName);
try (Scope ignored = span.makeCurrent()) {
ByteBuff buf =
new MultiByteBuff(ByteBuffer.allocate(4), ByteBuffer.allocate(4), ByteBuffer.allocate(4));
buf.position(0).limit(12);
- exception.expect(IOException.class);
try (FSDataInputStream in = fs.open(p)) {
- BlockIOUtils.readWithExtra(buf, in, 12, 0);
- fail("Should only read 11 bytes");
+ assertThrows(IOException.class, () -> BlockIOUtils.readWithExtra(buf, in, 12, 0),
+ "Should only read 11 bytes");
}
} finally {
span.end();
}
TEST_UTIL.waitFor(TimeUnit.MINUTES.toMillis(1), new MatcherPredicate<Iterable<SpanData>>(
- otelRule::getSpans, hasItem(allOf(hasName(testName.getMethodName()), hasEnded()))));
- assertThat(otelRule.getSpans(),
- hasItems(allOf(hasName(testName.getMethodName()),
+ OTEL_EXT::getSpans, hasItem(allOf(hasName(methodName), hasEnded()))));
+ assertThat(OTEL_EXT.getSpans(),
+ hasItems(allOf(hasName(methodName),
hasEvents(hasItem(allOf(EventMatchers.hasName("BlockIOUtils.readWithExtra"),
hasAttributes(containsEntry("db.hbase.io.heap_bytes_read", 11L))))))));
}
@@ -322,18 +317,17 @@ public class TestBlockIOUtils {
FSDataInputStream in = mock(FSDataInputStream.class);
when(in.read(position, buf, bufOffset, totalLen)).thenReturn(totalLen);
when(in.hasCapability(anyString())).thenReturn(false);
- boolean ret =
- TraceUtil.trace(() -> BlockIOUtils.preadWithExtra(bb, in, position, necessaryLen, extraLen),
- testName.getMethodName());
- assertFalse("Expect false return when no extra bytes requested", ret);
+ boolean ret = TraceUtil.trace(
+ () -> BlockIOUtils.preadWithExtra(bb, in, position, necessaryLen, extraLen), methodName);
+ assertFalse(ret, "Expect false return when no extra bytes requested");
verify(in).read(position, buf, bufOffset, totalLen);
verify(in).hasCapability(anyString());
verifyNoMoreInteractions(in);
TEST_UTIL.waitFor(TimeUnit.MINUTES.toMillis(1), new MatcherPredicate<Iterable<SpanData>>(
- otelRule::getSpans, hasItem(allOf(hasName(testName.getMethodName()), hasEnded()))));
- assertThat(otelRule.getSpans(),
- hasItems(allOf(hasName(testName.getMethodName()),
+ OTEL_EXT::getSpans, hasItem(allOf(hasName(methodName), hasEnded()))));
+ assertThat(OTEL_EXT.getSpans(),
+ hasItems(allOf(hasName(methodName),
hasEvents(hasItem(allOf(EventMatchers.hasName("BlockIOUtils.preadWithExtra"),
hasAttributes(containsEntry("db.hbase.io.heap_bytes_read", totalLen))))))));
}
@@ -351,19 +345,18 @@ public class TestBlockIOUtils {
when(in.read(position, buf, bufOffset, totalLen)).thenReturn(5);
when(in.read(5, buf, 5, 5)).thenReturn(5);
when(in.hasCapability(anyString())).thenReturn(false);
- boolean ret =
- TraceUtil.trace(() -> BlockIOUtils.preadWithExtra(bb, in, position, necessaryLen, extraLen),
- testName.getMethodName());
- assertFalse("Expect false return when no extra bytes requested", ret);
+ boolean ret = TraceUtil.trace(
+ () -> BlockIOUtils.preadWithExtra(bb, in, position, necessaryLen, extraLen), methodName);
+ assertFalse(ret, "Expect false return when no extra bytes requested");
verify(in).read(position, buf, bufOffset, totalLen);
verify(in).read(5, buf, 5, 5);
verify(in).hasCapability(anyString());
verifyNoMoreInteractions(in);
TEST_UTIL.waitFor(TimeUnit.MINUTES.toMillis(1), new MatcherPredicate<Iterable<SpanData>>(
- otelRule::getSpans, hasItem(allOf(hasName(testName.getMethodName()), hasEnded()))));
- assertThat(otelRule.getSpans(),
- hasItems(allOf(hasName(testName.getMethodName()),
+ OTEL_EXT::getSpans, hasItem(allOf(hasName(methodName), hasEnded()))));
+ assertThat(OTEL_EXT.getSpans(),
+ hasItems(allOf(hasName(methodName),
hasEvents(hasItem(allOf(EventMatchers.hasName("BlockIOUtils.preadWithExtra"),
hasAttributes(containsEntry("db.hbase.io.heap_bytes_read", totalLen))))))));
}
@@ -380,18 +373,17 @@ public class TestBlockIOUtils {
FSDataInputStream in = mock(FSDataInputStream.class);
when(in.read(position, buf, bufOffset, totalLen)).thenReturn(totalLen);
when(in.hasCapability(anyString())).thenReturn(false);
- boolean ret =
- TraceUtil.trace(() -> BlockIOUtils.preadWithExtra(bb, in, position, necessaryLen, extraLen),
- testName.getMethodName());
- assertTrue("Expect true return when reading extra bytes succeeds", ret);
+ boolean ret = TraceUtil.trace(
+ () -> BlockIOUtils.preadWithExtra(bb, in, position, necessaryLen, extraLen), methodName);
+ assertTrue(ret, "Expect true return when reading extra bytes succeeds");
verify(in).read(position, buf, bufOffset, totalLen);
verify(in).hasCapability(anyString());
verifyNoMoreInteractions(in);
TEST_UTIL.waitFor(TimeUnit.MINUTES.toMillis(1), new MatcherPredicate<Iterable<SpanData>>(
- otelRule::getSpans, hasItem(allOf(hasName(testName.getMethodName()), hasEnded()))));
- assertThat(otelRule.getSpans(),
- hasItems(allOf(hasName(testName.getMethodName()),
+ OTEL_EXT::getSpans, hasItem(allOf(hasName(methodName), hasEnded()))));
+ assertThat(OTEL_EXT.getSpans(),
+ hasItems(allOf(hasName(methodName),
hasEvents(hasItem(allOf(EventMatchers.hasName("BlockIOUtils.preadWithExtra"),
hasAttributes(containsEntry("db.hbase.io.heap_bytes_read", totalLen))))))));
}
@@ -408,18 +400,17 @@ public class TestBlockIOUtils {
FSDataInputStream in = mock(FSDataInputStream.class);
when(in.read(position, buf, bufOffset, totalLen)).thenReturn(necessaryLen);
when(in.hasCapability(anyString())).thenReturn(false);
- boolean ret =
- TraceUtil.trace(() -> BlockIOUtils.preadWithExtra(bb, in, position, necessaryLen, extraLen),
- testName.getMethodName());
- assertFalse("Expect false return when reading extra bytes fails", ret);
+ boolean ret = TraceUtil.trace(
+ () -> BlockIOUtils.preadWithExtra(bb, in, position, necessaryLen, extraLen), methodName);
+ assertFalse(ret, "Expect false return when reading extra bytes fails");
verify(in).read(position, buf, bufOffset, totalLen);
verify(in).hasCapability(anyString());
verifyNoMoreInteractions(in);
TEST_UTIL.waitFor(TimeUnit.MINUTES.toMillis(1), new MatcherPredicate<Iterable<SpanData>>(
- otelRule::getSpans, hasItem(allOf(hasName(testName.getMethodName()), hasEnded()))));
- assertThat(otelRule.getSpans(),
- hasItems(allOf(hasName(testName.getMethodName()),
+ OTEL_EXT::getSpans, hasItem(allOf(hasName(methodName), hasEnded()))));
+ assertThat(OTEL_EXT.getSpans(),
+ hasItems(allOf(hasName(methodName),
hasEvents(hasItem(allOf(EventMatchers.hasName("BlockIOUtils.preadWithExtra"),
hasAttributes(containsEntry("db.hbase.io.heap_bytes_read", necessaryLen))))))));
}
@@ -437,19 +428,18 @@ public class TestBlockIOUtils {
when(in.read(position, buf, bufOffset, totalLen)).thenReturn(5);
when(in.read(5, buf, 5, 10)).thenReturn(10);
when(in.hasCapability(anyString())).thenReturn(false);
- boolean ret =
- TraceUtil.trace(() -> BlockIOUtils.preadWithExtra(bb, in, position, necessaryLen, extraLen),
- testName.getMethodName());
- assertTrue("Expect true return when reading extra bytes succeeds", ret);
+ boolean ret = TraceUtil.trace(
+ () -> BlockIOUtils.preadWithExtra(bb, in, position, necessaryLen, extraLen), methodName);
+ assertTrue(ret, "Expect true return when reading extra bytes succeeds");
verify(in).read(position, buf, bufOffset, totalLen);
verify(in).read(5, buf, 5, 10);
verify(in).hasCapability(anyString());
verifyNoMoreInteractions(in);
TEST_UTIL.waitFor(TimeUnit.MINUTES.toMillis(1), new MatcherPredicate<Iterable<SpanData>>(
- otelRule::getSpans, hasItem(allOf(hasName(testName.getMethodName()), hasEnded()))));
- assertThat(otelRule.getSpans(),
- hasItems(allOf(hasName(testName.getMethodName()),
+ OTEL_EXT::getSpans, hasItem(allOf(hasName(methodName), hasEnded()))));
+ assertThat(OTEL_EXT.getSpans(),
+ hasItems(allOf(hasName(methodName),
hasEvents(hasItem(allOf(EventMatchers.hasName("BlockIOUtils.preadWithExtra"),
hasAttributes(containsEntry("db.hbase.io.heap_bytes_read", totalLen))))))));
}
@@ -464,28 +454,27 @@ public class TestBlockIOUtils {
byte[] buf = new byte[totalLen];
ByteBuff bb = new SingleByteBuff(ByteBuffer.wrap(buf, 0, totalLen));
FSDataInputStream in = mock(FSDataInputStream.class);
- when(in.read(position, buf, bufOffset, totalLen)).thenReturn(9);
when(in.read(position, buf, bufOffset, totalLen)).thenReturn(-1);
when(in.hasCapability(anyString())).thenReturn(false);
- exception.expect(IOException.class);
- exception.expectMessage("EOF");
- Span span = TraceUtil.createSpan(testName.getMethodName());
+ Span span = TraceUtil.createSpan(methodName);
try (Scope ignored = span.makeCurrent()) {
- BlockIOUtils.preadWithExtra(bb, in, position, necessaryLen, extraLen);
- span.setStatus(StatusCode.OK);
- } catch (IOException e) {
+ IOException e = assertThrows(IOException.class,
+ () -> BlockIOUtils.preadWithExtra(bb, in, position, necessaryLen, extraLen));
+ assertThat(e.getMessage(), containsString("EOF"));
TraceUtil.setError(span, e);
- throw e;
} finally {
span.end();
-
- TEST_UTIL.waitFor(TimeUnit.MINUTES.toMillis(1), new MatcherPredicate<Iterable<SpanData>>(
- otelRule::getSpans, hasItem(allOf(hasName(testName.getMethodName()), hasEnded()))));
- assertThat(otelRule.getSpans(),
- hasItems(allOf(hasName(testName.getMethodName()),
- hasEvents(hasItem(allOf(EventMatchers.hasName("BlockIOUtils.preadWithExtra"),
- hasAttributes(AttributesMatchers.isEmpty())))))));
}
+ TEST_UTIL.waitFor(TimeUnit.MINUTES.toMillis(1), new MatcherPredicate<Iterable<SpanData>>(
+ OTEL_EXT::getSpans, hasItem(allOf(hasName(methodName), hasEnded()))));
+ assertThat(OTEL_EXT.getSpans(),
+ hasItems(allOf(hasName(methodName),
+ hasEvents(hasItem(allOf(EventMatchers.hasName("BlockIOUtils.preadWithExtra"),
+ hasAttributes(AttributesMatchers.isEmpty())))))));
+
+ verify(in).read(position, buf, bufOffset, totalLen);
+ verify(in).hasCapability(anyString());
+ verifyNoMoreInteractions(in);
}
/**
@@ -518,8 +507,8 @@ public class TestBlockIOUtils {
@Test
public void testByteBufferPositionedReadable() throws IOException {
- assumeTrue("Skip the test because ByteBufferPositionedReadable is not available",
- isByteBufferPositionedReadable());
+ assumeTrue(isByteBufferPositionedReadable(),
+ "Skip the test because ByteBufferPositionedReadable is not available");
long position = 0;
int necessaryLen = 10;
int extraLen = 1;
@@ -534,7 +523,7 @@ public class TestBlockIOUtils {
when(in.read(firstReadLen, buf)).thenReturn(secondReadLen);
when(in.hasCapability(anyString())).thenReturn(true);
boolean ret = BlockIOUtils.preadWithExtra(bb, in, position, necessaryLen, extraLen);
- assertTrue("Expect true return when reading extra bytes succeeds", ret);
+ assertTrue(ret, "Expect true return when reading extra bytes succeeds");
verify(in).read(position, buf);
verify(in).read(firstReadLen, buf);
verify(in).hasCapability(anyString());
@@ -543,8 +532,8 @@ public class TestBlockIOUtils {
@Test
public void testByteBufferPositionedReadableEOF() throws IOException {
- assumeTrue("Skip the test because ByteBufferPositionedReadable is not available",
- isByteBufferPositionedReadable());
+ assumeTrue(isByteBufferPositionedReadable(),
+ "Skip the test because ByteBufferPositionedReadable is not available");
long position = 0;
int necessaryLen = 10;
int extraLen = 0;
@@ -555,11 +544,11 @@ public class TestBlockIOUtils {
MyFSDataInputStream in = mock(MyFSDataInputStream.class);
when(in.read(position, buf)).thenReturn(firstReadLen);
- when(in.read(position, buf)).thenReturn(-1);
+ when(in.read(firstReadLen, buf)).thenReturn(-1);
when(in.hasCapability(anyString())).thenReturn(true);
- exception.expect(IOException.class);
- exception.expectMessage("EOF");
- BlockIOUtils.preadWithExtra(bb, in, position, necessaryLen, extraLen);
+ IOException e = assertThrows(IOException.class,
+ () -> BlockIOUtils.preadWithExtra(bb, in, position, necessaryLen, extraLen));
+ assertThat(e.getMessage(), containsString("EOF"));
verify(in).read(position, buf);
verify(in).read(firstReadLen, buf);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestBytesReadFromFs.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestBytesReadFromFs.java
index c85a162ad96..d32f31ef85a 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestBytesReadFromFs.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestBytesReadFromFs.java
@@ -17,6 +17,9 @@
*/
package org.apache.hadoop.hbase.io.hfile;
+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.List;
@@ -26,7 +29,6 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.CellComparator;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.io.FSDataInputStreamWrapper;
@@ -46,17 +48,14 @@ import org.apache.hadoop.hbase.util.BloomFilterFactory;
import org.apache.hadoop.hbase.util.BloomFilterUtil;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
-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.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Category({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestBytesReadFromFs {
private static final int NUM_KEYS = 100000;
private static final int BLOOM_BLOCK_SIZE = 512;
@@ -64,13 +63,6 @@ public class TestBytesReadFromFs {
private static final int DATA_BLOCK_SIZE = 4096;
private static final int ROW_PREFIX_LENGTH_IN_BLOOM_FILTER = 42;
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestBytesReadFromFs.class);
-
- @Rule
- public TestName name = new TestName();
-
private static final Logger LOG = LoggerFactory.getLogger(TestBytesReadFromFs.class);
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final Random RNG = new Random(9713312); // Just a fixed seed.
@@ -81,7 +73,7 @@ public class TestBytesReadFromFs {
private List<byte[]> keyList = new ArrayList<>();
private Path path;
- @Before
+ @BeforeEach
public void setUp() throws IOException {
conf = TEST_UTIL.getConfiguration();
conf.setInt(BloomFilterUtil.PREFIX_LENGTH_KEY, ROW_PREFIX_LENGTH_IN_BLOOM_FILTER);
@@ -129,7 +121,7 @@ public class TestBytesReadFromFs {
KeyValue keyValue = keyValues.get(0);
readBloomFilters(path, bloomType, null, keyValue);
} else {
- Assert.assertEquals(ROW_PREFIX_LENGTH_IN_BLOOM_FILTER, keyList.get(0).length);
+ assertEquals(ROW_PREFIX_LENGTH_IN_BLOOM_FILTER, keyList.get(0).length);
byte[] key = keyList.get(0);
readBloomFilters(path, bloomType, key, null);
}
@@ -238,15 +230,14 @@ public class TestBytesReadFromFs {
reader.close();
- Assert.assertEquals(isScanMetricsEnabled,
- ThreadLocalServerSideScanMetrics.isScanMetricsEnabled());
+ assertEquals(isScanMetricsEnabled, ThreadLocalServerSideScanMetrics.isScanMetricsEnabled());
bytesRead = isScanMetricsEnabled ? bytesRead : 0;
- Assert.assertEquals(bytesRead, ThreadLocalServerSideScanMetrics.getBytesReadFromFsAndReset());
- Assert.assertEquals(blockLevelsRead, trailer.getNumDataIndexLevels() + 1);
- Assert.assertEquals(0, ThreadLocalServerSideScanMetrics.getBytesReadFromBlockCacheAndReset());
+ assertEquals(bytesRead, ThreadLocalServerSideScanMetrics.getBytesReadFromFsAndReset());
+ assertEquals(blockLevelsRead, trailer.getNumDataIndexLevels() + 1);
+ assertEquals(0, ThreadLocalServerSideScanMetrics.getBytesReadFromBlockCacheAndReset());
// At every index level we read one index block and finally read data block
long blockReadOpsCount = isScanMetricsEnabled ? blockLevelsRead : 0;
- Assert.assertEquals(blockReadOpsCount,
+ assertEquals(blockReadOpsCount,
ThreadLocalServerSideScanMetrics.getBlockReadOpsCountAndReset());
}
@@ -262,9 +253,9 @@ public class TestBytesReadFromFs {
// Read HFile trailer
HFileInfo hfile = new HFileInfo(readerContext, conf);
FixedFileTrailer trailer = hfile.getTrailer();
- Assert.assertEquals(trailer.getTrailerSize(),
+ assertEquals(trailer.getTrailerSize(),
ThreadLocalServerSideScanMetrics.getBytesReadFromFsAndReset());
- Assert.assertEquals(1, ThreadLocalServerSideScanMetrics.getBlockReadOpsCountAndReset());
+ assertEquals(1, ThreadLocalServerSideScanMetrics.getBlockReadOpsCountAndReset());
CacheConfig cacheConfig = new CacheConfig(conf);
HFile.Reader reader = new HFilePreadReader(readerContext, hfile, cacheConfig, conf);
@@ -297,8 +288,8 @@ public class TestBytesReadFromFs {
reader.close();
- Assert.assertEquals(hasBloomFilters, bloomFilterIndexesRead);
- Assert.assertEquals(0, ThreadLocalServerSideScanMetrics.getBytesReadFromBlockCacheAndReset());
+ assertEquals(hasBloomFilters, bloomFilterIndexesRead);
+ assertEquals(0, ThreadLocalServerSideScanMetrics.getBytesReadFromBlockCacheAndReset());
}
private boolean readEachBlockInLoadOnOpenDataSection(HFileBlock block, boolean readNextHeader)
@@ -313,14 +304,14 @@ public class TestBytesReadFromFs {
readNextHeader = true;
}
block.release();
- Assert.assertEquals(bytesRead, ThreadLocalServerSideScanMetrics.getBytesReadFromFsAndReset());
- Assert.assertEquals(1, ThreadLocalServerSideScanMetrics.getBlockReadOpsCountAndReset());
+ assertEquals(bytesRead, ThreadLocalServerSideScanMetrics.getBytesReadFromFsAndReset());
+ assertEquals(1, ThreadLocalServerSideScanMetrics.getBlockReadOpsCountAndReset());
return readNextHeader;
}
private void readBloomFilters(Path path, BloomType bt, byte[] key, KeyValue keyValue)
throws IOException {
- Assert.assertTrue(keyValue == null || key == null);
+ assertTrue(keyValue == null || key == null);
// Assert that the bloom filter index was read and it's size is accounted in bytes read from
// fs
@@ -340,7 +331,7 @@ public class TestBytesReadFromFs {
StoreFileReader reader = sf.getReader();
BloomFilter bloomFilter = reader.getGeneralBloomFilter();
- Assert.assertTrue(bloomFilter instanceof CompoundBloomFilter);
+ assertTrue(bloomFilter instanceof CompoundBloomFilter);
CompoundBloomFilter cbf = (CompoundBloomFilter) bloomFilter;
// Get the bloom filter index reader
@@ -362,14 +353,14 @@ public class TestBytesReadFromFs {
bytesRead += HFileBlock.headerSize(true);
}
// Asser that the block read is a bloom block
- Assert.assertEquals(bloomBlock.getBlockType(), BlockType.BLOOM_CHUNK);
+ assertEquals(bloomBlock.getBlockType(), BlockType.BLOOM_CHUNK);
bloomBlock.release();
// Close the reader
reader.close(true);
- Assert.assertEquals(bytesRead, ThreadLocalServerSideScanMetrics.getBytesReadFromFsAndReset());
- Assert.assertEquals(1, ThreadLocalServerSideScanMetrics.getBlockReadOpsCountAndReset());
+ assertEquals(bytesRead, ThreadLocalServerSideScanMetrics.getBytesReadFromFsAndReset());
+ assertEquals(1, ThreadLocalServerSideScanMetrics.getBlockReadOpsCountAndReset());
}
private void writeBloomFilters(Path path, BloomType bt, int bloomBlockByteSize)
@@ -381,8 +372,8 @@ public class TestBytesReadFromFs {
.withCompression(Compression.Algorithm.NONE).build();
StoreFileWriter w = new StoreFileWriter.Builder(conf, cacheConf, fs).withFileContext(meta)
.withBloomType(bt).withFilePath(path).build();
- Assert.assertTrue(w.hasGeneralBloom());
- Assert.assertTrue(w.getGeneralBloomWriter() instanceof CompoundBloomFilterWriter);
+ assertTrue(w.hasGeneralBloom());
+ assertTrue(w.getGeneralBloomWriter() instanceof CompoundBloomFilterWriter);
CompoundBloomFilterWriter cbbf = (CompoundBloomFilterWriter) w.getGeneralBloomWriter();
byte[] cf = Bytes.toBytes("cf");
byte[] cq = Bytes.toBytes("cq");
@@ -396,7 +387,7 @@ public class TestBytesReadFromFs {
keyList.add(keyBytes);
keyValues.add(keyValue);
}
- Assert.assertEquals(keyList.size(), cbbf.getKeyCount());
+ assertEquals(keyList.size(), cbbf.getKeyCount());
w.close();
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCacheConfig.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCacheConfig.java
index bee8ca0667d..d30267c7d6b 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCacheConfig.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCacheConfig.java
@@ -17,10 +17,10 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-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.lang.management.ManagementFactory;
@@ -29,7 +29,6 @@ import java.nio.ByteBuffer;
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.HColumnDescriptor;
@@ -42,10 +41,9 @@ import org.apache.hadoop.hbase.nio.ByteBuff;
import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Threads;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+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;
@@ -56,13 +54,10 @@ import org.slf4j.LoggerFactory;
// (seconds). It is large because it depends on being able to reset the global
// blockcache instance which is in a global variable. Experience has it that
// tests clash on the global variable if this test is run as small sized test.
-@Category({ IOTests.class, MediumTests.class })
+@Tag(IOTests.TAG)
+@Tag(MediumTests.TAG)
public class TestCacheConfig {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCacheConfig.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestCacheConfig.class);
private Configuration conf;
@@ -151,7 +146,7 @@ public class TestCacheConfig {
}
}
- @Before
+ @BeforeEach
public void setUp() throws Exception {
this.conf = HBaseConfiguration.create();
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCacheOnWrite.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCacheOnWrite.java
index 5bd4497577e..1d3835aaea5 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCacheOnWrite.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCacheOnWrite.java
@@ -17,14 +17,13 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Iterator;
@@ -32,12 +31,13 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
+import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.ArrayBackedTag;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
@@ -60,15 +60,11 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.ChecksumType;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.Pair;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -79,14 +75,11 @@ import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
* Tests {@link HFile} cache-on-write functionality for the following block types: data blocks,
* non-root index blocks, and Bloom filter blocks.
*/
-@RunWith(Parameterized.class)
-@Category({ IOTests.class, LargeTests.class })
+@HBaseParameterizedTestTemplate(name = "{0}-{1}-{2}-{3}")
+@org.junit.jupiter.api.Tag(IOTests.TAG)
+@org.junit.jupiter.api.Tag(LargeTests.TAG)
public class TestCacheOnWrite {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCacheOnWrite.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestCacheOnWrite.class);
private static final HBaseTestingUtility TEST_UTIL = HBaseTestingUtility.createLocalHTU();
@@ -188,19 +181,18 @@ public class TestCacheOnWrite {
return blockcaches;
}
- @Parameters
- public static Collection<Object[]> getParameters() throws IOException {
- List<Object[]> params = new ArrayList<>();
+ public static Stream<Arguments> parameters() throws IOException {
+ List<Arguments> params = new ArrayList<>();
for (BlockCache blockCache : getBlockCaches()) {
for (CacheOnWriteType cowType : CacheOnWriteType.values()) {
for (Compression.Algorithm compress : HBaseCommonTestingUtility.COMPRESSION_ALGORITHMS) {
for (boolean cacheCompressedData : new boolean[] { false, true }) {
- params.add(new Object[] { cowType, compress, cacheCompressedData, blockCache });
+ params.add(Arguments.of(cowType, compress, cacheCompressedData, blockCache));
}
}
}
}
- return params;
+ return params.stream();
}
private void clearBlockCache(BlockCache blockCache) throws InterruptedException {
@@ -228,7 +220,7 @@ public class TestCacheOnWrite {
}
}
- @Before
+ @BeforeEach
public void setUp() throws IOException {
conf = TEST_UTIL.getConfiguration();
this.conf.set("dfs.datanode.data.dir.perm", "700");
@@ -245,12 +237,12 @@ public class TestCacheOnWrite {
fs = HFileSystem.get(conf);
}
- @After
+ @AfterEach
public void tearDown() throws IOException, InterruptedException {
clearBlockCache(blockCache);
}
- @AfterClass
+ @AfterAll
public static void afterClass() throws IOException {
TEST_UTIL.cleanupTestDir();
}
@@ -271,7 +263,7 @@ public class TestCacheOnWrite {
final boolean cacheBlocks = false;
final boolean pread = false;
HFileScanner scanner = reader.getScanner(conf, cacheBlocks, pread);
- assertTrue(testDescription, scanner.seekTo());
+ assertTrue(scanner.seekTo(), testDescription);
long offset = 0;
EnumMap<BlockType, Integer> blockCountByType = new EnumMap<>(BlockType.class);
@@ -290,11 +282,10 @@ public class TestCacheOnWrite {
cachedBlocksOffset.add(offset);
cachedBlocks.put(offset, fromCache == null ? null : Pair.newPair(block, fromCache));
boolean shouldBeCached = cowType.shouldBeCached(block.getBlockType());
- assertTrue(
+ assertTrue(shouldBeCached == isCached,
"shouldBeCached: " + shouldBeCached + "\n" + "isCached: " + isCached + "\n"
+ "Test description: " + testDescription + "\n" + "block: " + block + "\n"
- + "encodingInCache: " + encodingInCache + "\n" + "blockCacheKey: " + blockCacheKey,
- shouldBeCached == isCached);
+ + "encodingInCache: " + encodingInCache + "\n" + "blockCacheKey: " + blockCacheKey);
if (isCached) {
if (cacheConf.shouldCacheCompressed(fromCache.getBlockType().getCategory())) {
if (compress != Compression.Algorithm.NONE) {
@@ -506,30 +497,30 @@ public class TestCacheOnWrite {
if (cacheOnCompactAndNonBucketCache && cacheBlocksOnCompactionThreshold > 0) {
if (cacheBlocksOnCompactionThreshold == CACHE_COMPACTION_HIGH_THRESHOLD) {
- assertTrue(assertErrorMessage, dataBlockCached);
- assertTrue(assertErrorMessage, bloomBlockCached);
- assertTrue(assertErrorMessage, indexBlockCached);
+ assertTrue(dataBlockCached, assertErrorMessage);
+ assertTrue(bloomBlockCached, assertErrorMessage);
+ assertTrue(indexBlockCached, assertErrorMessage);
} else {
- assertFalse(assertErrorMessage, dataBlockCached);
+ assertFalse(dataBlockCached, assertErrorMessage);
if (localCacheBloomBlocksValue) {
- assertTrue(assertErrorMessage, bloomBlockCached);
+ assertTrue(bloomBlockCached, assertErrorMessage);
} else {
- assertFalse(assertErrorMessage, bloomBlockCached);
+ assertFalse(bloomBlockCached, assertErrorMessage);
}
if (localCacheIndexBlocksValue) {
- assertTrue(assertErrorMessage, indexBlockCached);
+ assertTrue(indexBlockCached, assertErrorMessage);
} else {
- assertFalse(assertErrorMessage, indexBlockCached);
+ assertFalse(indexBlockCached, assertErrorMessage);
}
}
} else {
- assertEquals(assertErrorMessage, cacheOnCompactAndNonBucketCache, dataBlockCached);
+ assertEquals(cacheOnCompactAndNonBucketCache, dataBlockCached, assertErrorMessage);
if (cacheOnCompactAndNonBucketCache) {
- assertTrue(assertErrorMessage, bloomBlockCached);
- assertTrue(assertErrorMessage, indexBlockCached);
+ assertTrue(bloomBlockCached, assertErrorMessage);
+ assertTrue(indexBlockCached, assertErrorMessage);
}
}
@@ -544,19 +535,19 @@ public class TestCacheOnWrite {
}
}
- @Test
+ @TestTemplate
public void testStoreFileCacheOnWrite() throws IOException {
testStoreFileCacheOnWriteInternals(false);
testStoreFileCacheOnWriteInternals(true);
}
- @Test
+ @TestTemplate
public void testCachingDataBlocksDuringCompaction() throws IOException, InterruptedException {
testCachingDataBlocksDuringCompactionInternals(false, false, -1);
testCachingDataBlocksDuringCompactionInternals(true, true, -1);
}
- @Test
+ @TestTemplate
public void testCachingDataBlocksThresholdDuringCompaction()
throws IOException, InterruptedException {
testCachingDataBlocksDuringCompactionInternals(false, true, CACHE_COMPACTION_HIGH_THRESHOLD);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCachedBlockQueue.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCachedBlockQueue.java
index a821b78ae64..44141eb384b 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCachedBlockQueue.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCachedBlockQueue.java
@@ -17,23 +17,18 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.nio.ByteBuffer;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.IOTests;
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;
-@Category({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestCachedBlockQueue {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCachedBlockQueue.class);
-
@Test
public void testQueue() throws Exception {
CachedBlock cb1 = new CachedBlock(1000, "cb1", 1);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestChecksum.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestChecksum.java
index 05367995209..8626e947333 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestChecksum.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestChecksum.java
@@ -19,9 +19,9 @@ package org.apache.hadoop.hbase.io.hfile;
import static org.apache.hadoop.hbase.io.compress.Compression.Algorithm.GZ;
import static org.apache.hadoop.hbase.io.compress.Compression.Algorithm.NONE;
-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.ByteArrayInputStream;
import java.io.DataInputStream;
@@ -34,7 +34,6 @@ import org.apache.hadoop.fs.FSDataInputStream;
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.fs.HFileSystem;
@@ -47,20 +46,16 @@ import org.apache.hadoop.hbase.nio.SingleByteBuff;
import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.ChecksumType;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+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;
-@Category({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestChecksum {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestChecksum.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestChecksum.class);
static final Compression.Algorithm[] COMPRESSION_ALGORITHMS = { NONE, GZ };
@@ -71,7 +66,7 @@ public class TestChecksum {
private FileSystem fs;
private HFileSystem hfs;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
fs = HFileSystem.get(TEST_UTIL.getConfiguration());
hfs = (HFileSystem) fs;
@@ -374,7 +369,7 @@ public class TestChecksum {
// validate data
for (int i = 0; i < 1234; i++) {
int val = in.readInt();
- assertEquals("testChecksumCorruption: data mismatch at index " + i, i, val);
+ assertEquals(i, val, "testChecksumCorruption: data mismatch at index " + i);
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCombinedBlockCache.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCombinedBlockCache.java
index 8f78c5fb418..d88f4c242e0 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCombinedBlockCache.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCombinedBlockCache.java
@@ -20,28 +20,24 @@ package org.apache.hadoop.hbase.io.hfile;
import static org.apache.hadoop.hbase.HConstants.BUCKET_CACHE_IOENGINE_KEY;
import static org.apache.hadoop.hbase.HConstants.BUCKET_CACHE_SIZE_KEY;
import static org.apache.hadoop.hbase.io.ByteBuffAllocator.HEAP;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.nio.ByteBuffer;
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.io.hfile.CombinedBlockCache.CombinedCacheStats;
import org.apache.hadoop.hbase.nio.ByteBuff;
+import org.apache.hadoop.hbase.testclassification.RegionServerTests;
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;
-@Category({ SmallTests.class })
+@Tag(SmallTests.TAG)
+@Tag(RegionServerTests.TAG)
public class TestCombinedBlockCache {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCombinedBlockCache.class);
-
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
@Test
@@ -138,7 +134,7 @@ public class TestCombinedBlockCache {
conf.set(BUCKET_CACHE_IOENGINE_KEY, "offheap");
conf.setInt(BUCKET_CACHE_SIZE_KEY, 32);
BlockCache blockCache = BlockCacheFactory.createBlockCache(conf);
- Assert.assertTrue(blockCache instanceof CombinedBlockCache);
+ assertTrue(blockCache instanceof CombinedBlockCache);
return (CombinedBlockCache) blockCache;
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestFixedFileTrailer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestFixedFileTrailer.java
index 06c0fe8dc37..937a5fc6e72 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestFixedFileTrailer.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestFixedFileTrailer.java
@@ -17,10 +17,11 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-import static org.junit.Assert.assertEquals;
-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.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -28,43 +29,35 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
+import java.util.stream.Stream;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.CellComparator;
import org.apache.hadoop.hbase.CellComparatorImpl;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.MetaCellComparator;
import org.apache.hadoop.hbase.testclassification.IOTests;
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.ExpectedException;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.hbase.shaded.protobuf.generated.HFileProtos;
-@RunWith(Parameterized.class)
-@Category({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: version={0}")
public class TestFixedFileTrailer {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestFixedFileTrailer.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestFixedFileTrailer.class);
private static final int MAX_COMPARATOR_NAME_LENGTH = 128;
@@ -87,23 +80,19 @@ public class TestFixedFileTrailer {
this.version = version;
}
- @Rule
- public ExpectedException expectedEx = ExpectedException.none();
-
- @Parameters
- public static Collection<Object[]> getParameters() {
+ public static Stream<Arguments> parameters() {
List<Object[]> versionsToTest = new ArrayList<>();
for (int v = HFile.MIN_FORMAT_VERSION; v <= HFile.MAX_FORMAT_VERSION; ++v)
versionsToTest.add(new Integer[] { v });
- return versionsToTest;
+ return versionsToTest.stream().map(arr -> Arguments.of(arr[0]));
}
- @Before
+ @BeforeEach
public void setUp() throws IOException {
fs = FileSystem.get(util.getConfiguration());
}
- @Test
+ @TestTemplate
public void testComparatorIsHBase1Compatible() {
FixedFileTrailer t = new FixedFileTrailer(version, HFileReaderImpl.PBUF_TRAILER_MINOR_VERSION);
t.setComparatorClass(CellComparatorImpl.COMPARATOR.getClass());
@@ -115,7 +104,7 @@ public class TestFixedFileTrailer {
assertEquals(KeyValue.META_COMPARATOR.getClass().getName(), pb.getComparatorClassName());
}
- @Test
+ @TestTemplate
public void testCreateComparator() throws IOException {
FixedFileTrailer t = new FixedFileTrailer(version, HFileReaderImpl.PBUF_TRAILER_MINOR_VERSION);
try {
@@ -148,12 +137,11 @@ public class TestFixedFileTrailer {
}
// Test an invalid comparatorClassName
- expectedEx.expect(IOException.class);
- t.createComparator("");
+ assertThrows(IOException.class, () -> t.createComparator(""));
}
- @Test
+ @TestTemplate
public void testTrailer() throws IOException {
FixedFileTrailer t = new FixedFileTrailer(version, HFileReaderImpl.PBUF_TRAILER_MINOR_VERSION);
t.setDataIndexCount(3);
@@ -210,8 +198,8 @@ public class TestFixedFileTrailer {
String msg = ex.getMessage();
String cleanMsg = msg.replaceAll("^(java(\\.[a-zA-Z]+)+:\\s+)?|\\s+\\(.*\\)\\s*$", "");
// will be followed by " expected: ..."
- assertEquals("Actual exception message is \"" + msg + "\".\nCleaned-up message",
- "Invalid HFile version: " + invalidVersion, cleanMsg);
+ assertEquals("Invalid HFile version: " + invalidVersion, cleanMsg,
+ "Actual exception message is \"" + msg + "\".\nCleaned-up message");
LOG.info("Got an expected exception: " + msg);
}
}
@@ -226,13 +214,12 @@ public class TestFixedFileTrailer {
checkLoadedTrailer(version, t, t4);
String trailerStr = t.toString();
- assertEquals(
- "Invalid number of fields in the string representation " + "of the trailer: " + trailerStr,
- NUM_FIELDS_BY_VERSION[version - 2], trailerStr.split(", ").length);
+ assertEquals(NUM_FIELDS_BY_VERSION[version - 2], trailerStr.split(", ").length,
+ "Invalid number of fields in the string representation " + "of the trailer: " + trailerStr);
assertEquals(trailerStr, t4.toString());
}
- @Test
+ @TestTemplate
public void testTrailerForV2NonPBCompatibility() throws Exception {
if (version == 2) {
FixedFileTrailer t = new FixedFileTrailer(version, HFileReaderImpl.MINOR_VERSION_NO_CHECKSUM);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestForceCacheImportantBlocks.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestForceCacheImportantBlocks.java
index 346fd1acef2..99b95be5f69 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestForceCacheImportantBlocks.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestForceCacheImportantBlocks.java
@@ -17,13 +17,12 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collection;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import java.util.stream.Stream;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
@@ -36,13 +35,10 @@ import org.apache.hadoop.hbase.regionserver.HRegion;
import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Make sure we always cache important block types, such as index blocks, as long as we have a block
@@ -52,15 +48,12 @@ import org.junit.runners.Parameterized.Parameters;
* to reveal more about what is being cached whether DATA or INDEX blocks and then we could do more
* verification in this test.
*/
-@Category({ IOTests.class, MediumTests.class })
-@RunWith(Parameterized.class)
+@Tag(IOTests.TAG)
+@Tag(MediumTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: hfileVersion={0}, cfCacheEnabled={1}")
public class TestForceCacheImportantBlocks {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestForceCacheImportantBlocks.class);
-
- private final HBaseTestingUtility TEST_UTIL = HBaseTestingUtility.createLocalHTU();
+ private final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final String TABLE = "myTable";
private static final String CF = "myCF";
@@ -84,10 +77,8 @@ public class TestForceCacheImportantBlocks {
private final int hfileVersion;
private final boolean cfCacheEnabled;
- @Parameters
- public static Collection<Object[]> parameters() {
- // HFile versions
- return Arrays.asList(new Object[] { 3, true }, new Object[] { 3, false });
+ public static Stream<Arguments> parameters() {
+ return Stream.of(Arguments.of(3, true), Arguments.of(3, false));
}
public TestForceCacheImportantBlocks(int hfileVersion, boolean cfCacheEnabled) {
@@ -96,12 +87,12 @@ public class TestForceCacheImportantBlocks {
TEST_UTIL.getConfiguration().setInt(HFile.FORMAT_VERSION_KEY, hfileVersion);
}
- @Before
+ @BeforeEach
public void setup() {
HFile.DATABLOCK_READ_COUNT.reset();
}
- @Test
+ @TestTemplate
public void testCacheBlocks() throws IOException {
// Set index block size to be the same as normal block size.
TEST_UTIL.getConfiguration().setInt(HFileBlockIndex.MAX_CHUNK_SIZE_KEY, BLOCK_SIZE);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFile.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFile.java
index 66e2db5e67c..342ba6c6670 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFile.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFile.java
@@ -24,11 +24,12 @@ import static org.apache.hadoop.hbase.io.ByteBuffAllocator.MAX_BUFFER_COUNT_KEY;
import static org.apache.hadoop.hbase.io.ByteBuffAllocator.MIN_ALLOCATE_SIZE_KEY;
import static org.apache.hadoop.hbase.io.hfile.BlockCacheFactory.BLOCKCACHE_POLICY_KEY;
import static org.apache.hadoop.hbase.io.hfile.CacheConfig.EVICT_BLOCKS_ON_CLOSE_KEY;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.DataInput;
import java.io.DataOutput;
@@ -55,7 +56,6 @@ import org.apache.hadoop.hbase.CellBuilderType;
import org.apache.hadoop.hbase.CellComparatorImpl;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.ExtendedCellBuilderFactory;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseTestingUtility;
@@ -82,13 +82,9 @@ import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.ByteBufferUtils;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.Writable;
-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.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -96,15 +92,10 @@ import org.slf4j.LoggerFactory;
/**
* test hfile features.
*/
-@Category({ IOTests.class, SmallTests.class })
+@org.junit.jupiter.api.Tag(IOTests.TAG)
+@org.junit.jupiter.api.Tag(SmallTests.TAG)
public class TestHFile {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestHFile.class);
-
- @Rule
- public TestName testName = new TestName();
-
private static final Logger LOG = LoggerFactory.getLogger(TestHFile.class);
private static final int NUM_VALID_KEY_TYPES = KeyValue.Type.values().length - 2;
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
@@ -115,7 +106,7 @@ public class TestHFile {
private static Configuration conf;
private static FileSystem fs;
- @BeforeClass
+ @BeforeAll
public static void setUp() throws Exception {
conf = TEST_UTIL.getConfiguration();
cacheConf = new CacheConfig(conf);
@@ -150,10 +141,10 @@ public class TestHFile {
List<ByteBuff> buffs = new ArrayList<>();
for (int i = 0; i < bufCount; i++) {
buffs.add(alloc.allocateOneBuffer());
- Assert.assertEquals(alloc.getFreeBufferCount(), 0);
+ assertEquals(alloc.getFreeBufferCount(), 0);
}
buffs.forEach(ByteBuff::release);
- Assert.assertEquals(alloc.getFreeBufferCount(), bufCount);
+ assertEquals(alloc.getFreeBufferCount(), bufCount);
}
@Test
@@ -165,7 +156,7 @@ public class TestHFile {
// start write to store file.
Path path = writeStoreFile();
readStoreFile(path, conf, alloc);
- Assert.assertEquals(bufCount, alloc.getFreeBufferCount());
+ assertEquals(bufCount, alloc.getFreeBufferCount());
alloc.clean();
}
@@ -189,15 +180,15 @@ public class TestHFile {
offset += block.getOnDiskSizeWithHeader();
// Ensure the block is an heap one.
Cacheable cachedBlock = lru.getBlock(key, false, false, true);
- Assert.assertNotNull(cachedBlock);
- Assert.assertTrue(cachedBlock instanceof HFileBlock);
- Assert.assertFalse(((HFileBlock) cachedBlock).isSharedMem());
+ assertNotNull(cachedBlock);
+ assertTrue(cachedBlock instanceof HFileBlock);
+ assertFalse(((HFileBlock) cachedBlock).isSharedMem());
// Should never allocate off-heap block from allocator because ensure that it's LRU.
- Assert.assertEquals(bufCount, alloc.getFreeBufferCount());
+ assertEquals(bufCount, alloc.getFreeBufferCount());
block.release(); // return back the ByteBuffer back to allocator.
}
reader.close();
- Assert.assertEquals(bufCount, alloc.getFreeBufferCount());
+ assertEquals(bufCount, alloc.getFreeBufferCount());
alloc.clean();
lru.shutdown();
}
@@ -213,7 +204,7 @@ public class TestHFile {
// Initialize the block cache and HFile reader
BlockCache lru = BlockCacheFactory.createBlockCache(conf);
- Assert.assertTrue(lru instanceof LruBlockCache);
+ assertTrue(lru instanceof LruBlockCache);
CacheConfig cacheConfig = new CacheConfig(conf, null, lru, ByteBuffAllocator.HEAP);
HFileReaderImpl reader =
(HFileReaderImpl) HFile.createReader(fs, storeFilePath, cacheConfig, true, conf);
@@ -222,34 +213,34 @@ public class TestHFile {
final int offset = 0;
BlockCacheKey cacheKey = new BlockCacheKey(storeFilePath.getName(), offset);
HFileBlock block = (HFileBlock) lru.getBlock(cacheKey, false, false, true);
- Assert.assertNull(block);
+ assertNull(block);
// Assert that first block has not been cached in the block cache and no disk I/O happened to
// check that.
ThreadLocalServerSideScanMetrics.getBytesReadFromBlockCacheAndReset();
ThreadLocalServerSideScanMetrics.getBytesReadFromFsAndReset();
block = reader.getCachedBlock(cacheKey, false, false, true, BlockType.DATA, null);
- Assert.assertEquals(0, ThreadLocalServerSideScanMetrics.getBytesReadFromBlockCacheAndReset());
- Assert.assertEquals(0, ThreadLocalServerSideScanMetrics.getBytesReadFromFsAndReset());
+ assertEquals(0, ThreadLocalServerSideScanMetrics.getBytesReadFromBlockCacheAndReset());
+ assertEquals(0, ThreadLocalServerSideScanMetrics.getBytesReadFromFsAndReset());
// Read the first block from the HFile.
block = reader.readBlock(offset, -1, true, true, false, true, BlockType.DATA, null);
- Assert.assertNotNull(block);
+ assertNotNull(block);
int bytesReadFromFs = block.getOnDiskSizeWithHeader();
if (block.getNextBlockOnDiskSize() > 0) {
bytesReadFromFs += block.headerSize();
}
block.release();
// Assert that disk I/O happened to read the first block.
- Assert.assertEquals(isScanMetricsEnabled ? bytesReadFromFs : 0,
+ assertEquals(isScanMetricsEnabled ? bytesReadFromFs : 0,
ThreadLocalServerSideScanMetrics.getBytesReadFromFsAndReset());
- Assert.assertEquals(0, ThreadLocalServerSideScanMetrics.getBytesReadFromBlockCacheAndReset());
+ assertEquals(0, ThreadLocalServerSideScanMetrics.getBytesReadFromBlockCacheAndReset());
// Read the first block again and assert that it has been cached in the block cache.
block = reader.getCachedBlock(cacheKey, false, false, true, BlockType.DATA, encoding);
long bytesReadFromCache = 0;
if (encoding == DataBlockEncoding.NONE) {
- Assert.assertNotNull(block);
+ assertNotNull(block);
bytesReadFromCache = block.getOnDiskSizeWithHeader();
if (block.getNextBlockOnDiskSize() > 0) {
bytesReadFromCache += block.headerSize();
@@ -257,13 +248,13 @@ public class TestHFile {
block.release();
// Assert that bytes read from block cache account for same number of bytes that would have
// been read from FS if block cache wasn't there.
- Assert.assertEquals(bytesReadFromFs, bytesReadFromCache);
+ assertEquals(bytesReadFromFs, bytesReadFromCache);
} else {
- Assert.assertNull(block);
+ assertNull(block);
}
- Assert.assertEquals(isScanMetricsEnabled ? bytesReadFromCache : 0,
+ assertEquals(isScanMetricsEnabled ? bytesReadFromCache : 0,
ThreadLocalServerSideScanMetrics.getBytesReadFromBlockCacheAndReset());
- Assert.assertEquals(0, ThreadLocalServerSideScanMetrics.getBytesReadFromFsAndReset());
+ assertEquals(0, ThreadLocalServerSideScanMetrics.getBytesReadFromFsAndReset());
reader.close();
}
@@ -292,8 +283,8 @@ public class TestHFile {
that.set(BUCKET_CACHE_IOENGINE_KEY, "offheap");
that.set(BLOCKCACHE_POLICY_KEY, l1CachePolicy);
BlockCache bc = BlockCacheFactory.createBlockCache(that);
- Assert.assertNotNull(bc);
- Assert.assertTrue(bc instanceof CombinedBlockCache);
+ assertNotNull(bc);
+ assertTrue(bc instanceof CombinedBlockCache);
return bc;
}
@@ -319,15 +310,15 @@ public class TestHFile {
// Read the cached block.
Cacheable cachedBlock = combined.getBlock(key, false, false, true);
try {
- Assert.assertNotNull(cachedBlock);
- Assert.assertTrue(cachedBlock instanceof HFileBlock);
+ assertNotNull(cachedBlock);
+ assertTrue(cachedBlock instanceof HFileBlock);
HFileBlock hfb = (HFileBlock) cachedBlock;
// Data block will be cached in BucketCache, so it should be an off-heap block.
if (hfb.getBlockType().isData()) {
- Assert.assertTrue(hfb.isSharedMem());
+ assertTrue(hfb.isSharedMem());
} else {
// Non-data block will be cached in LRUBlockCache, so it must be an on-heap block.
- Assert.assertFalse(hfb.isSharedMem());
+ assertFalse(hfb.isSharedMem());
}
} finally {
cachedBlock.release();
@@ -336,7 +327,7 @@ public class TestHFile {
}
reader.close();
combined.shutdown();
- Assert.assertEquals(bufCount, alloc.getFreeBufferCount());
+ assertEquals(bufCount, alloc.getFreeBufferCount());
alloc.clean();
}
@@ -392,7 +383,7 @@ public class TestHFile {
}
reader.close();
- Assert.assertEquals(bufCount, alloc.getFreeBufferCount());
+ assertEquals(bufCount, alloc.getFreeBufferCount());
alloc.clean();
lru.shutdown();
}
@@ -452,7 +443,7 @@ public class TestHFile {
reader.close();
combined.shutdown();
- Assert.assertEquals(bufCount, alloc.getFreeBufferCount());
+ assertEquals(bufCount, alloc.getFreeBufferCount());
alloc.clean();
}
@@ -469,13 +460,13 @@ public class TestHFile {
throw e;
}
- Assert.assertEquals(expectSharedMem, block.isSharedMem());
+ assertEquals(expectSharedMem, block.isSharedMem());
if (expectSharedMem) {
- Assert.assertTrue(alloc.getFreeBufferCount() < alloc.getTotalBufferCount());
+ assertTrue(alloc.getFreeBufferCount() < alloc.getTotalBufferCount());
} else {
// Should never allocate off-heap block from allocator because ensure that it's LRU.
- Assert.assertEquals(alloc.getTotalBufferCount(), alloc.getFreeBufferCount());
+ assertEquals(alloc.getTotalBufferCount(), alloc.getFreeBufferCount());
}
try {
@@ -537,8 +528,8 @@ public class TestHFile {
* Test empty HFile. Test all features work reasonably when hfile is empty of entries.
*/
@Test
- public void testEmptyHFile() throws IOException {
- Path f = new Path(ROOT_DIR, testName.getMethodName());
+ public void testEmptyHFile(TestInfo testInfo) throws IOException {
+ Path f = new Path(ROOT_DIR, testInfo.getTestMethod().get().getName());
HFileContext context = new HFileContextBuilder().withIncludesTags(false).build();
Writer w =
HFile.getWriterFactory(conf, cacheConf).withPath(fs, f).withFileContext(context).create();
@@ -552,8 +543,8 @@ public class TestHFile {
* Create 0-length hfile and show that it fails
*/
@Test
- public void testCorrupt0LengthHFile() throws IOException {
- Path f = new Path(ROOT_DIR, testName.getMethodName());
+ public void testCorrupt0LengthHFile(TestInfo testInfo) throws IOException {
+ Path f = new Path(ROOT_DIR, testInfo.getTestMethod().get().getName());
FSDataOutputStream fsos = fs.create(f);
fsos.close();
@@ -567,13 +558,13 @@ public class TestHFile {
}
@Test
- public void testCorruptOutOfOrderHFileWrite() throws IOException {
- Path path = new Path(ROOT_DIR, testName.getMethodName());
+ public void testCorruptOutOfOrderHFileWrite(TestInfo testInfo) throws IOException {
+ Path path = new Path(ROOT_DIR, testInfo.getTestMethod().get().getName());
FSDataOutputStream mockedOutputStream = Mockito.mock(FSDataOutputStream.class);
String columnFamily = "MyColumnFamily";
String tableName = "MyTableName";
HFileContext fileContext =
- new HFileContextBuilder().withHFileName(testName.getMethodName() + "HFile")
+ new HFileContextBuilder().withHFileName(testInfo.getTestMethod().get().getName() + "HFile")
.withBlockSize(minBlockSize).withColumnFamily(Bytes.toBytes(columnFamily))
.withTableName(Bytes.toBytes(tableName)).withHBaseCheckSum(false)
.withCompression(Compression.Algorithm.NONE).withCompressTags(false).build();
@@ -596,12 +587,12 @@ public class TestHFile {
writer.append(secondCell);
} catch (IOException ie) {
String message = ie.getMessage();
- Assert.assertTrue(message.contains("not lexically larger"));
- Assert.assertTrue(message.contains(tableName));
- Assert.assertTrue(message.contains(columnFamily));
+ assertTrue(message.contains("not lexically larger"));
+ assertTrue(message.contains(tableName));
+ assertTrue(message.contains(columnFamily));
return;
}
- Assert.fail("Exception wasn't thrown even though Cells were appended in the wrong order!");
+ fail("Exception wasn't thrown even though Cells were appended in the wrong order!");
}
public static void truncateFile(FileSystem fs, Path src, Path dst) throws IOException {
@@ -623,8 +614,8 @@ public class TestHFile {
* Create a truncated hfile and verify that exception thrown.
*/
@Test
- public void testCorruptTruncatedHFile() throws IOException {
- Path f = new Path(ROOT_DIR, testName.getMethodName());
+ public void testCorruptTruncatedHFile(TestInfo testInfo) throws IOException {
+ Path f = new Path(ROOT_DIR, testInfo.getTestMethod().get().getName());
HFileContext context = new HFileContextBuilder().build();
Writer w = HFile.getWriterFactory(conf, cacheConf).withPath(this.fs, f).withFileContext(context)
.create();
@@ -684,11 +675,11 @@ public class TestHFile {
Bytes.toBytes("qual"), Bytes.toBytes(valStr));
byte[] keyBytes =
new KeyValue.KeyOnlyKeyValue(Bytes.toBytes(key), 0, Bytes.toBytes(key).length).getKey();
- assertTrue("bytes for keys do not match " + keyStr + " " + Bytes.toString(Bytes.toBytes(key)),
- Arrays.equals(kv.getKey(), keyBytes));
+ assertTrue(Arrays.equals(kv.getKey(), keyBytes),
+ "bytes for keys do not match " + keyStr + " " + Bytes.toString(Bytes.toBytes(key)));
byte[] valBytes = Bytes.toBytes(val);
- assertTrue("bytes for vals do not match " + valStr + " " + Bytes.toString(valBytes),
- Arrays.equals(Bytes.toBytes(valStr), valBytes));
+ assertTrue(Arrays.equals(Bytes.toBytes(valStr), valBytes),
+ "bytes for vals do not match " + valStr + " " + Bytes.toString(valBytes));
if (!scanner.next()) {
break;
}
@@ -733,7 +724,7 @@ public class TestHFile {
FSDataInputStream fin = fs.open(ncHFile);
ReaderContext context = new ReaderContextBuilder().withFileSystemAndPath(fs, ncHFile).build();
Reader reader = createReaderFromStream(context, cacheConf, conf);
- System.out.println(cacheConf.toString());
+ LOG.info(cacheConf.toString());
// Load up the index.
// Get a scanner that caches and that does not use pread.
HFileScanner scanner = reader.getScanner(conf, true, false);
@@ -741,12 +732,12 @@ public class TestHFile {
scanner.seekTo();
readAllRecords(scanner);
int seekTo = scanner.seekTo(KeyValueUtil.createKeyValueFromKey(getSomeKey(50)));
- System.out.println(seekTo);
- assertTrue("location lookup failed",
- scanner.seekTo(KeyValueUtil.createKeyValueFromKey(getSomeKey(50))) == 0);
+ LOG.info("" + seekTo);
+ assertTrue(scanner.seekTo(KeyValueUtil.createKeyValueFromKey(getSomeKey(50))) == 0,
+ "location lookup failed");
// read the key and see if it matches
ByteBuffer readKey = ByteBuffer.wrap(((KeyValue) scanner.getKey()).getKey());
- assertTrue("seeked key does not match", Arrays.equals(getSomeKey(50), Bytes.toBytes(readKey)));
+ assertTrue(Arrays.equals(getSomeKey(50), Bytes.toBytes(readKey)), "seeked key does not match");
scanner.seekTo(KeyValueUtil.createKeyValueFromKey(getSomeKey(0)));
ByteBuffer val1 = scanner.getValue();
@@ -799,9 +790,9 @@ public class TestHFile {
private void readNumMetablocks(Reader reader, int n) throws IOException {
for (int i = 0; i < n; i++) {
ByteBuff actual = reader.getMetaBlock("HFileMeta" + i, false).getBufferWithoutHeader();
- ByteBuffer expected = ByteBuffer.wrap(("something to test" + i).getBytes());
- assertEquals("failed to match metadata", Bytes.toStringBinary(expected), Bytes.toStringBinary(
- actual.array(), actual.arrayOffset() + actual.position(), actual.capacity()));
+ ByteBuffer expected = ByteBuffer.wrap(Bytes.toBytes("something to test" + i));
+ assertEquals(Bytes.toStringBinary(expected), Bytes.toStringBinary(actual.array(),
+ actual.arrayOffset() + actual.position(), actual.capacity()), "failed to match metadata");
}
}
@@ -1049,13 +1040,13 @@ public class TestHFile {
}
@Test
- public void testDBEShipped() throws IOException {
+ public void testDBEShipped(TestInfo testInfo) throws IOException {
for (DataBlockEncoding encoding : DataBlockEncoding.values()) {
DataBlockEncoder encoder = encoding.getEncoder();
if (encoder == null) {
continue;
}
- Path f = new Path(ROOT_DIR, testName.getMethodName() + "_" + encoding);
+ Path f = new Path(ROOT_DIR, testInfo.getTestMethod().get().getName() + "_" + encoding);
HFileContext context =
new HFileContextBuilder().withIncludesTags(false).withDataBlockEncoding(encoding).build();
HFileWriterImpl writer = (HFileWriterImpl) HFile.getWriterFactory(conf, cacheConf)
@@ -1128,14 +1119,14 @@ public class TestHFile {
// Read the cached block.
cachedBlock = combined.getBlock(key, false, false, true);
try {
- Assert.assertNotNull(cachedBlock);
- Assert.assertTrue(cachedBlock instanceof HFileBlock);
+ assertNotNull(cachedBlock);
+ assertTrue(cachedBlock instanceof HFileBlock);
HFileBlock hfb = (HFileBlock) cachedBlock;
// Data block will be cached in BucketCache, so it should be an off-heap block.
if (hfb.getBlockType().isData()) {
- Assert.assertTrue(hfb.isSharedMem());
+ assertTrue(hfb.isSharedMem());
} else if (!l1CachePolicy.equals("TinyLfu")) {
- Assert.assertFalse(hfb.isSharedMem());
+ assertFalse(hfb.isSharedMem());
}
} finally {
cachedBlock.release();
@@ -1145,9 +1136,9 @@ public class TestHFile {
reader.close();
combined.shutdown();
if (cachedBlock != null) {
- Assert.assertEquals(0, cachedBlock.refCnt());
+ assertEquals(0, cachedBlock.refCnt());
}
- Assert.assertEquals(bufCount, alloc.getFreeBufferCount());
+ assertEquals(bufCount, alloc.getFreeBufferCount());
alloc.clean();
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileBlock.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileBlock.java
index 33788b692b9..1116ce8f3ee 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileBlock.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileBlock.java
@@ -20,7 +20,11 @@ package org.apache.hadoop.hbase.io.hfile;
import static org.apache.hadoop.hbase.io.ByteBuffAllocator.HEAP;
import static org.apache.hadoop.hbase.io.compress.Compression.Algorithm.GZ;
import static org.apache.hadoop.hbase.io.compress.Compression.Algorithm.NONE;
-import static org.junit.Assert.*;
+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.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
@@ -28,7 +32,6 @@ import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -41,6 +44,7 @@ import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
+import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
@@ -49,8 +53,8 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.ArrayBackedTag;
import org.apache.hadoop.hbase.CellComparatorImpl;
import org.apache.hadoop.hbase.CellUtil;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
@@ -72,26 +76,20 @@ import org.apache.hadoop.hbase.util.ClassSize;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.io.WritableUtils;
import org.apache.hadoop.io.compress.Compressor;
-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.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Category({ IOTests.class, LargeTests.class })
-@RunWith(Parameterized.class)
+@org.junit.jupiter.api.Tag(IOTests.TAG)
+@org.junit.jupiter.api.Tag(LargeTests.TAG)
+@HBaseParameterizedTestTemplate(
+ name = "{index}: includesMemstoreTS={0}, includesTag={1}, useHeapAllocator={2}")
public class TestHFileBlock {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestHFileBlock.class);
-
// change this value to activate more logs
private static final boolean detailedLogging = false;
private static final boolean[] BOOLEAN_VALUES = new boolean[] { false, true };
@@ -126,18 +124,15 @@ public class TestHFileBlock {
assertAllocator();
}
- @Parameters
- public static Collection<Object[]> parameters() {
- List<Object[]> params = new ArrayList<>();
- // Generate boolean triples from 000 to 111
+ public static Stream<Arguments> parameters() {
+ List<Arguments> params = new ArrayList<>();
for (int i = 0; i < (1 << 3); i++) {
- Object[] flags = new Boolean[3];
- for (int k = 0; k < 3; k++) {
- flags[k] = (i & (1 << k)) != 0;
- }
- params.add(flags);
+ boolean v0 = (i & (1 << 0)) != 0;
+ boolean v1 = (i & (1 << 1)) != 0;
+ boolean v2 = (i & (1 << 2)) != 0;
+ params.add(Arguments.of(v0, v1, v2));
}
- return params;
+ return params.stream();
}
private ByteBuffAllocator createOffHeapAlloc() {
@@ -162,12 +157,12 @@ public class TestHFileBlock {
}
}
- @Before
+ @BeforeEach
public void setUp() throws IOException {
fs = HFileSystem.get(TEST_UTIL.getConfiguration());
}
- @After
+ @AfterEach
public void tearDown() throws IOException {
assertAllocator();
alloc.clean();
@@ -290,7 +285,7 @@ public class TestHFileBlock {
return Bytes.toStringBinary(testV2Block);
}
- @Test
+ @TestTemplate
public void testNoCompression() throws IOException {
CacheConfig cacheConf = Mockito.mock(CacheConfig.class);
Mockito.when(cacheConf.getBlockCache()).thenReturn(Optional.empty());
@@ -302,7 +297,7 @@ public class TestHFileBlock {
assertTrue(block.isUnpacked());
}
- @Test
+ @TestTemplate
public void testGzipCompression() throws IOException {
// @formatter:off
String correctTestBlockStr = "DATABLK*\\x00\\x00\\x00>\\x00\\x00\\x0F\\xA0\\xFF\\xFF\\xFF\\xFF"
@@ -333,7 +328,7 @@ public class TestHFileBlock {
testBlockStr.substring(0, correctGzipBlockLength - 4));
}
- @Test
+ @TestTemplate
public void testReaderV2() throws IOException {
testReaderV2Internals();
}
@@ -406,10 +401,9 @@ public class TestHFileBlock {
fail("Exception expected");
} catch (IOException ex) {
String expectedPrefix = "Passed in onDiskSizeWithHeader=";
- assertTrue(
+ assertTrue(ex.getMessage().startsWith(expectedPrefix),
"Invalid exception message: '" + ex.getMessage()
- + "'.\nMessage is expected to start with: '" + expectedPrefix + "'",
- ex.getMessage().startsWith(expectedPrefix));
+ + "'.\nMessage is expected to start with: '" + expectedPrefix + "'");
}
assertRelease(b);
is.close();
@@ -423,7 +417,7 @@ public class TestHFileBlock {
* Test encoding/decoding data blocks.
* @throws IOException a bug or a problem with temporary files.
*/
- @Test
+ @TestTemplate
public void testDataBlockEncoding() throws IOException {
testInternals();
}
@@ -497,18 +491,17 @@ public class TestHFileBlock {
LOG.info("packedHeapsize=" + packedHeapsize + ", unpackedHeadsize="
+ blockUnpacked.heapSize());
assertFalse(packedHeapsize == blockUnpacked.heapSize());
- assertTrue("Packed heapSize should be < unpacked heapSize",
- packedHeapsize < blockUnpacked.heapSize());
+ assertTrue(packedHeapsize < blockUnpacked.heapSize(),
+ "Packed heapSize should be < unpacked heapSize");
}
ByteBuff actualBuffer = blockUnpacked.getBufferWithoutHeader();
if (encoding != DataBlockEncoding.NONE) {
// We expect a two-byte big-endian encoding id.
- assertEquals(
- "Unexpected first byte with " + buildMessageDetails(algo, encoding, pread),
- Long.toHexString(0), Long.toHexString(actualBuffer.get(0)));
- assertEquals(
- "Unexpected second byte with " + buildMessageDetails(algo, encoding, pread),
- Long.toHexString(encoding.getId()), Long.toHexString(actualBuffer.get(1)));
+ assertEquals(Long.toHexString(0), Long.toHexString(actualBuffer.get(0)),
+ "Unexpected first byte with " + buildMessageDetails(algo, encoding, pread));
+ assertEquals(Long.toHexString(encoding.getId()),
+ Long.toHexString(actualBuffer.get(1)),
+ "Unexpected second byte with " + buildMessageDetails(algo, encoding, pread));
actualBuffer.position(2);
actualBuffer = actualBuffer.slice();
}
@@ -525,12 +518,12 @@ public class TestHFileBlock {
blockFromHFile.serialize(serialized, true);
HFileBlock deserialized = (HFileBlock) blockFromHFile.getDeserializer()
.deserialize(new SingleByteBuff(serialized), HEAP);
- assertEquals("Serialization did not preserve block state. reuseBuffer=" + reuseBuffer,
- blockFromHFile, deserialized);
+ assertEquals(blockFromHFile, deserialized,
+ "Serialization did not preserve block state. reuseBuffer=" + reuseBuffer);
// intentional reference comparison
if (blockFromHFile != blockUnpacked) {
- assertEquals("Deserialized block cannot be unpacked correctly.", blockUnpacked,
- deserialized.unpack(meta, hbr));
+ assertEquals(blockUnpacked, deserialized.unpack(meta, hbr),
+ "Deserialized block cannot be unpacked correctly.");
}
}
assertRelease(blockUnpacked);
@@ -575,7 +568,7 @@ public class TestHFileBlock {
+ (numBytes < maxBytes ? "..." : "");
}
- @Test
+ @TestTemplate
public void testPreviousOffset() throws IOException {
testPreviousOffsetInternals();
}
@@ -620,10 +613,11 @@ public class TestHFileBlock {
if (detailedLogging) {
LOG.info("Block #" + i + ": " + b);
}
- assertEquals("Invalid block #" + i + "'s type:", expectedTypes.get(i),
- b.getBlockType());
- assertEquals("Invalid previous block offset for block " + i + " of " + "type "
- + b.getBlockType() + ":", (long) expectedPrevOffsets.get(i), b.getPrevBlockOffset());
+ assertEquals(expectedTypes.get(i), b.getBlockType(),
+ "Invalid block #" + i + "'s type:");
+ assertEquals((long) expectedPrevOffsets.get(i), b.getPrevBlockOffset(),
+ "Invalid previous block offset for block " + i + " of " + "type " + b.getBlockType()
+ + ":");
b.sanityCheck();
assertEquals(curOffset, b.getOffset());
@@ -679,7 +673,7 @@ public class TestHFileBlock {
LOG.warn(wrongBytesMsg);
}
}
- assertTrue(wrongBytesMsg, bytesAreCorrect);
+ assertTrue(bytesAreCorrect, wrongBytesMsg);
assertRelease(newBlock);
if (newBlock != b) {
assertRelease(b);
@@ -768,7 +762,7 @@ public class TestHFileBlock {
}
}
- @Test
+ @TestTemplate
public void testConcurrentReading() throws Exception {
testConcurrentReadingInternals();
}
@@ -869,7 +863,7 @@ public class TestHFileBlock {
return totalSize;
}
- @Test
+ @TestTemplate
public void testBlockHeapSize() {
testBlockHeapSizeInternals();
}
@@ -896,15 +890,14 @@ public class TestHFileBlock {
long hfileMetaSize = ClassSize.align(ClassSize.estimateBase(HFileContext.class, true));
long hfileBlockExpectedSize = ClassSize.align(ClassSize.estimateBase(HFileBlock.class, true));
long expected = hfileBlockExpectedSize + byteBufferExpectedSize + hfileMetaSize;
- assertEquals(
+ assertEquals(expected, block.heapSize(),
"Block data size: " + size + ", byte buffer expected " + "size: " + byteBufferExpectedSize
+ ", HFileBlock class expected " + "size: " + hfileBlockExpectedSize
- + " HFileContext class expected size: " + hfileMetaSize + "; ",
- expected, block.heapSize());
+ + " HFileContext class expected size: " + hfileMetaSize + "; ");
}
}
- @Test
+ @TestTemplate
public void testSerializeWithoutNextBlockMetadata() {
int size = 100;
int length = HConstants.HFILEBLOCK_HEADER_SIZE + size;
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileBlockIndex.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileBlockIndex.java
index d0be6ad6d21..e597ef97238 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileBlockIndex.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileBlockIndex.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-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.ByteArrayOutputStream;
import java.io.DataOutput;
@@ -28,12 +28,12 @@ import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
@@ -41,8 +41,8 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.CellComparatorImpl;
import org.apache.hadoop.hbase.CellUtil;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
@@ -66,29 +66,23 @@ import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.ClassSize;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hbase.thirdparty.io.netty.util.ResourceLeakDetector;
-@RunWith(Parameterized.class)
-@Category({ IOTests.class, MediumTests.class })
+@Tag(IOTests.TAG)
+@Tag(MediumTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: compr={0}")
public class TestHFileBlockIndex {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestHFileBlockIndex.class);
-
- @Parameters
- public static Collection<Object[]> compressionAlgorithms() {
- return HBaseCommonTestingUtility.COMPRESSION_ALGORITHMS_PARAMETERIZED;
+ public static Stream<Arguments> parameters() {
+ return HBaseCommonTestingUtility.COMPRESSION_ALGORITHMS_PARAMETERIZED.stream()
+ .map(Arguments::of);
}
public TestHFileBlockIndex(Compression.Algorithm compr) {
@@ -124,7 +118,7 @@ public class TestHFileBlockIndex {
assert INDEX_CHUNK_SIZES.length == UNCOMPRESSED_INDEX_SIZES.length;
}
- @Before
+ @BeforeEach
public void setUp() throws IOException {
keys.clear();
firstKeyInFile = null;
@@ -137,7 +131,7 @@ public class TestHFileBlockIndex {
fs = HFileSystem.get(conf);
}
- @Test
+ @TestTemplate
public void testBlockIndex() throws IOException {
testBlockIndexInternals(false);
clear();
@@ -175,7 +169,7 @@ public class TestHFileBlockIndex {
outputStream.close();
}
- @Test
+ @TestTemplate
public void testBlockIndexWithOffHeapBuffer() throws Exception {
ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID);
path = new Path(TEST_UTIL.getDataTestDir(), "block_index_testBlockIndexWithOffHeapBuffer");
@@ -318,7 +312,7 @@ public class TestHFileBlockIndex {
String keyStr = "key #" + i + ", " + Bytes.toStringBinary(key);
- assertTrue("seekToDataBlock failed for " + keyStr, b != null);
+ assertTrue(b != null, "seekToDataBlock failed for " + keyStr);
if (prevOffset == b.getOffset()) {
assertEquals(++expectedHitCount, brw.hitCount);
@@ -373,7 +367,7 @@ public class TestHFileBlockIndex {
return i * i * 37 + i * 19 + 13;
}
- @Test
+ @TestTemplate
public void testSecondaryIndexBinarySearch() throws IOException {
int numTotalKeys = 99;
assertTrue(numTotalKeys % 2 == 1); // Ensure no one made this even.
@@ -472,7 +466,7 @@ public class TestHFileBlockIndex {
referenceItem = i - 1;
}
- assertEquals(lookupFailureMsg, expectedResult, searchResult);
+ assertEquals(expectedResult, searchResult, lookupFailureMsg);
// Now test we can get the offset and the on-disk-size using a
// higher-level API function.s
@@ -485,14 +479,14 @@ public class TestHFileBlockIndex {
} else {
assertTrue(locateBlockResult);
String errorMsg = "i=" + i + ", position=" + nonRootIndex.position();
- assertEquals(errorMsg, getDummyFileOffset(referenceItem), nonRootIndex.getLong());
- assertEquals(errorMsg, getDummyOnDiskSize(referenceItem), nonRootIndex.getInt());
+ assertEquals(getDummyFileOffset(referenceItem), nonRootIndex.getLong(), errorMsg);
+ assertEquals(getDummyOnDiskSize(referenceItem), nonRootIndex.getInt(), errorMsg);
}
}
}
- @Test
+ @TestTemplate
public void testBlockIndexChunk() throws IOException {
BlockIndexChunk c = new HFileBlockIndex.BlockIndexChunkImpl();
HFileIndexBlockEncoder indexBlockEncoder = NoOpIndexBlockEncoder.INSTANCE;
@@ -528,7 +522,7 @@ public class TestHFileBlockIndex {
}
/** Checks if the HeapSize calculator is within reason */
- @Test
+ @TestTemplate
public void testHeapSizeForBlockIndex() throws IOException {
Class<HFileBlockIndex.BlockIndexReader> cl = HFileBlockIndex.BlockIndexReader.class;
long expected = ClassSize.estimateBase(cl, false);
@@ -551,7 +545,7 @@ public class TestHFileBlockIndex {
/**
* to check if looks good when midKey on a leaf index block boundary
*/
- @Test
+ @TestTemplate
public void testMidKeyOnLeafIndexBlockBoundary() throws IOException {
Path hfilePath = new Path(TEST_UTIL.getDataTestDir(), "hfile_for_midkey");
int maxChunkSize = 512;
@@ -607,7 +601,7 @@ public class TestHFileBlockIndex {
* Testing block index through the HFile writer/reader APIs. Allows to test setting index block
* size through configuration, intermediate-level index blocks, and caching index blocks on write.
*/
- @Test
+ @TestTemplate
public void testHFileWriterAndReader() throws IOException {
Path hfilePath = new Path(TEST_UTIL.getDataTestDir(), "hfile_for_block_index");
CacheConfig cacheConf = new CacheConfig(conf, BlockCacheFactory.createBlockCache(conf));
@@ -705,8 +699,8 @@ public class TestHFileBlockIndex {
// If the first key of the block is not among the keys written, we
// are not parsing the non-root index block format correctly.
- assertTrue("Invalid block key from leaf-level block: " + blockKeyStr,
- keyStrSet.contains(blockKeyStr));
+ assertTrue(keyStrSet.contains(blockKeyStr),
+ "Invalid block key from leaf-level block: " + blockKeyStr);
}
}
@@ -723,15 +717,14 @@ public class TestHFileBlockIndex {
}
private void checkSeekTo(byte[][] keys, HFileScanner scanner, int i) throws IOException {
- assertEquals("Failed to seek to key #" + i + " (" + Bytes.toStringBinary(keys[i]) + ")", 0,
- scanner.seekTo(KeyValueUtil.createKeyValueFromKey(keys[i])));
+ assertEquals(0, scanner.seekTo(KeyValueUtil.createKeyValueFromKey(keys[i])),
+ "Failed to seek to key #" + i + " (" + Bytes.toStringBinary(keys[i]) + ")");
}
private void assertArrayEqualsBuffer(String msgPrefix, byte[] arr, ByteBuffer buf) {
- assertEquals(
- msgPrefix + ": expected " + Bytes.toStringBinary(arr) + ", actual "
- + Bytes.toStringBinary(buf),
- 0, Bytes.compareTo(arr, 0, arr.length, buf.array(), buf.arrayOffset(), buf.limit()));
+ assertEquals(0,
+ Bytes.compareTo(arr, 0, arr.length, buf.array(), buf.arrayOffset(), buf.limit()), msgPrefix
+ + ": expected " + Bytes.toStringBinary(arr) + ", actual " + Bytes.toStringBinary(buf));
}
/** Check a key/value pair after it was read by the reader */
@@ -743,12 +736,12 @@ public class TestHFileBlockIndex {
assertArrayEqualsBuffer(msgPrefix + "Invalid value", expectedValue, valueRead);
}
- @Test
+ @TestTemplate
public void testIntermediateLevelIndicesWithLargeKeys() throws IOException {
testIntermediateLevelIndicesWithLargeKeys(16);
}
- @Test
+ @TestTemplate
public void testIntermediateLevelIndicesWithLargeKeysWithMinNumEntries() throws IOException {
// because of the large rowKeys, we will end up with a 50-level block index without sanity check
testIntermediateLevelIndicesWithLargeKeys(2);
@@ -790,7 +783,7 @@ public class TestHFileBlockIndex {
* This test is for HBASE-27940, which midkey metadata in root index block would always be ignored
* by {@link BlockIndexReader#readMultiLevelIndexRoot}.
*/
- @Test
+ @TestTemplate
public void testMidKeyReadSuccessfullyFromRootIndexBlock() throws IOException {
conf.setInt(HFileBlockIndex.MAX_CHUNK_SIZE_KEY, 128);
Path hfilePath =
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileBlockUnpack.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileBlockUnpack.java
index a8a32595ebd..714ef880162 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileBlockUnpack.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileBlockUnpack.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
@@ -30,7 +30,6 @@ import org.apache.hadoop.fs.FSDataInputStream;
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.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
@@ -43,19 +42,14 @@ import org.apache.hadoop.hbase.nio.ByteBuff;
import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
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({ IOTests.class, MediumTests.class })
-public class TestHFileBlockUnpack {
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestHFileBlockUnpack.class);
+@Tag(IOTests.TAG)
+@Tag(MediumTests.TAG)
+public class TestHFileBlockUnpack {
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
@@ -66,11 +60,9 @@ public class TestHFileBlockUnpack {
ByteBuffAllocator allocator;
- @Rule
- public TestName name = new TestName();
private FileSystem fs;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
fs = HFileSystem.get(TEST_UTIL.getConfiguration());
Configuration conf = HBaseConfiguration.create(TEST_UTIL.getConfiguration());
@@ -85,8 +77,8 @@ public class TestHFileBlockUnpack {
* https://issues.apache.org/jira/browse/HBASE-27053
*/
@Test
- public void itUnpacksIdenticallyEachTime() throws IOException {
- Path path = new Path(TEST_UTIL.getDataTestDir(), name.getMethodName());
+ public void itUnpacksIdenticallyEachTime(TestInfo testInfo) throws IOException {
+ Path path = new Path(TEST_UTIL.getDataTestDir(), testInfo.getTestMethod().get().getName());
int totalSize = createTestBlock(path);
// Allocate a bunch of random buffers, so we can be sure that unpack will only have "dirty"
@@ -142,28 +134,27 @@ public class TestHFileBlockUnpack {
* {@link HFileBlock#isSharedMem()} == true See https://issues.apache.org/jira/browse/HBASE-27170
*/
@Test
- public void itUsesSharedMemoryIfUnpackedBlockExceedsMinAllocationSize() throws IOException {
- Path path = new Path(TEST_UTIL.getDataTestDir(), name.getMethodName());
+ public void itUsesSharedMemoryIfUnpackedBlockExceedsMinAllocationSize(TestInfo testInfo)
+ throws IOException {
+ Path path = new Path(TEST_UTIL.getDataTestDir(), testInfo.getTestMethod().get().getName());
int totalSize = createTestBlock(path);
HFileBlockWrapper blockFromHFile = readBlock(path, totalSize);
- assertFalse("expected hfile block to NOT be unpacked", blockFromHFile.original.isUnpacked());
- assertFalse("expected hfile block to NOT use shared memory",
- blockFromHFile.original.isSharedMem());
+ assertFalse(blockFromHFile.original.isUnpacked(), "expected hfile block to NOT be unpacked");
+ assertFalse(blockFromHFile.original.isSharedMem(),
+ "expected hfile block to NOT use shared memory");
- assertTrue(
+ assertTrue(blockFromHFile.original.getOnDiskSizeWithHeader() < MIN_ALLOCATION_SIZE,
"expected generated block size " + blockFromHFile.original.getOnDiskSizeWithHeader()
- + " to be less than " + MIN_ALLOCATION_SIZE,
- blockFromHFile.original.getOnDiskSizeWithHeader() < MIN_ALLOCATION_SIZE);
- assertTrue(
+ + " to be less than " + MIN_ALLOCATION_SIZE);
+ assertTrue(blockFromHFile.original.getUncompressedSizeWithoutHeader() > MIN_ALLOCATION_SIZE,
"expected generated block uncompressed size "
+ blockFromHFile.original.getUncompressedSizeWithoutHeader() + " to be more than "
- + MIN_ALLOCATION_SIZE,
- blockFromHFile.original.getUncompressedSizeWithoutHeader() > MIN_ALLOCATION_SIZE);
+ + MIN_ALLOCATION_SIZE);
- assertTrue("expected unpacked block to be unpacked", blockFromHFile.unpacked.isUnpacked());
- assertTrue("expected unpacked block to use shared memory",
- blockFromHFile.unpacked.isSharedMem());
+ assertTrue(blockFromHFile.unpacked.isUnpacked(), "expected unpacked block to be unpacked");
+ assertTrue(blockFromHFile.unpacked.isSharedMem(),
+ "expected unpacked block to use shared memory");
}
private final static class HFileBlockWrapper {
@@ -207,9 +198,8 @@ public class TestHFileBlockUnpack {
writeTestKeyValues(hbw, MIN_ALLOCATION_SIZE - 1);
hbw.writeHeaderAndData(os);
totalSize = hbw.getOnDiskSizeWithHeader();
- assertTrue(
- "expected generated block size " + totalSize + " to be less than " + MIN_ALLOCATION_SIZE,
- totalSize < MIN_ALLOCATION_SIZE);
+ assertTrue(totalSize < MIN_ALLOCATION_SIZE,
+ "expected generated block size " + totalSize + " to be less than " + MIN_ALLOCATION_SIZE);
}
return totalSize;
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileDataBlockEncoder.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileDataBlockEncoder.java
index d62cd168ea1..e273823028e 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileDataBlockEncoder.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileDataBlockEncoder.java
@@ -17,20 +17,20 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-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.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
+import java.util.stream.Stream;
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.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.io.ByteArrayOutputStream;
@@ -45,20 +45,18 @@ import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.ChecksumType;
import org.apache.hadoop.hbase.util.RedundantKVGenerator;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
-@RunWith(Parameterized.class)
-@Category({ IOTests.class, MediumTests.class })
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Tag(IOTests.TAG)
+@Tag(MediumTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: dataBlockEncoding={0}, includesMemstoreTS={1}")
public class TestHFileDataBlockEncoder {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestHFileDataBlockEncoder.class);
+ private static final Logger LOG = LoggerFactory.getLogger(TestHFileDataBlockEncoder.class);
private final Configuration conf = HBaseConfiguration.create();
private final RedundantKVGenerator generator = new RedundantKVGenerator();
@@ -72,14 +70,14 @@ public class TestHFileDataBlockEncoder {
public TestHFileDataBlockEncoder(HFileDataBlockEncoder blockEncoder, boolean includesMemstoreTS) {
this.blockEncoder = blockEncoder;
this.includesMemstoreTS = includesMemstoreTS;
- System.err.println("Encoding: " + blockEncoder.getDataBlockEncoding() + ", includesMemstoreTS: "
+ LOG.info("Encoding: " + blockEncoder.getDataBlockEncoding() + ", includesMemstoreTS: "
+ includesMemstoreTS);
}
/**
* Test putting and taking out blocks into cache with different encoding options.
*/
- @Test
+ @TestTemplate
public void testEncodingWithCache() throws IOException {
testEncodingWithCacheInternals(false);
testEncodingWithCacheInternals(true);
@@ -104,14 +102,14 @@ public class TestHFileDataBlockEncoder {
assertEquals(block.getBufferReadOnly(), returnedBlock.getBufferReadOnly());
} else {
if (BlockType.ENCODED_DATA != returnedBlock.getBlockType()) {
- System.out.println(blockEncoder);
+ LOG.info("" + blockEncoder);
}
assertEquals(BlockType.ENCODED_DATA, returnedBlock.getBlockType());
}
}
/** Test for HBASE-5746. */
- @Test
+ @TestTemplate
public void testHeaderSizeInCacheWithoutChecksum() throws Exception {
testHeaderSizeInCacheWithoutChecksumInternals(false);
testHeaderSizeInCacheWithoutChecksumInternals(true);
@@ -139,7 +137,7 @@ public class TestHFileDataBlockEncoder {
/**
* Test encoding.
*/
- @Test
+ @TestTemplate
public void testEncoding() throws IOException {
testEncodingInternals(false);
testEncodingInternals(true);
@@ -149,7 +147,7 @@ public class TestHFileDataBlockEncoder {
* Test encoding with offheap keyvalue. This test just verifies if the encoders work with DBB and
* does not use the getXXXArray() API
*/
- @Test
+ @TestTemplate
public void testEncodingWithOffheapKeyValue() throws IOException {
// usually we have just block without headers, but don't complicate that
try {
@@ -229,20 +227,18 @@ public class TestHFileDataBlockEncoder {
}
}
- /** Returns All possible data block encoding configurations */
- @Parameters
- public static Collection<Object[]> getAllConfigurations() {
- List<Object[]> configurations = new ArrayList<>();
+ public static Stream<Arguments> parameters() {
+ List<Arguments> configurations = new ArrayList<>();
for (DataBlockEncoding diskAlgo : DataBlockEncoding.values()) {
for (boolean includesMemstoreTS : new boolean[] { false, true }) {
HFileDataBlockEncoder dbe = (diskAlgo == DataBlockEncoding.NONE)
? NoOpDataBlockEncoder.INSTANCE
: new HFileDataBlockEncoderImpl(diskAlgo);
- configurations.add(new Object[] { dbe, includesMemstoreTS });
+ configurations.add(Arguments.of(dbe, includesMemstoreTS));
}
}
- return configurations;
+ return configurations.stream();
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileEncryption.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileEncryption.java
index 5b1e1a133a7..a61fade1909 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileEncryption.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileEncryption.java
@@ -17,11 +17,11 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-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.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.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@@ -35,7 +35,6 @@ import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
@@ -51,27 +50,23 @@ import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.RedundantKVGenerator;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+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({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestHFileEncryption {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestHFileEncryption.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestHFileEncryption.class);
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static FileSystem fs;
private static Encryption.Context cryptoContext;
- @BeforeClass
+ @BeforeAll
public static void setUp() throws Exception {
Configuration conf = TEST_UTIL.getConfiguration();
// Disable block cache in this test.
@@ -240,11 +235,11 @@ public class TestHFileEncryption {
FixedFileTrailer trailer = reader.getTrailer();
assertNotNull(trailer.getEncryptionKey());
scanner = reader.getScanner(conf, false, false);
- assertTrue("Initial seekTo failed", scanner.seekTo());
+ assertTrue(scanner.seekTo(), "Initial seekTo failed");
do {
Cell kv = scanner.getCell();
- assertTrue("Read back an unexpected or invalid KV",
- testKvs.contains(KeyValueUtil.ensureKeyValue(kv)));
+ assertTrue(testKvs.contains(KeyValueUtil.ensureKeyValue(kv)),
+ "Read back an unexpected or invalid KV");
i++;
} while (scanner.next());
} finally {
@@ -252,7 +247,7 @@ public class TestHFileEncryption {
scanner.close();
}
- assertEquals("Did not read back as many KVs as written", i, testKvs.size());
+ assertEquals(i, testKvs.size(), "Did not read back as many KVs as written");
// Test random seeks with pread
LOG.info("Random seeking with " + fileContext);
@@ -260,10 +255,10 @@ public class TestHFileEncryption {
reader = HFile.createReader(fs, path, cacheConf, true, conf);
try {
scanner = reader.getScanner(conf, false, true);
- assertTrue("Initial seekTo failed", scanner.seekTo());
+ assertTrue(scanner.seekTo(), "Initial seekTo failed");
for (i = 0; i < 100; i++) {
KeyValue kv = testKvs.get(rand.nextInt(testKvs.size()));
- assertEquals("Unable to find KV as expected: " + kv, 0, scanner.seekTo(kv));
+ assertEquals(0, scanner.seekTo(kv), "Unable to find KV as expected: " + kv);
}
} finally {
scanner.close();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileInlineToRootChunkConversion.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileInlineToRootChunkConversion.java
index edab56a7afc..726ea5fd4e7 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileInlineToRootChunkConversion.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileInlineToRootChunkConversion.java
@@ -23,14 +23,12 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.CellUtil;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.testclassification.IOTests;
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;
/**
* Test a case when an inline index chunk is converted to a root one. This reproduces the bug in
@@ -43,13 +41,10 @@ import org.junit.experimental.categories.Category;
* entry to the root-level block, and that would prevent us from upgrading the leaf-level chunk to
* the root chunk, thus not triggering the bug.
*/
-@Category({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestHFileInlineToRootChunkConversion {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestHFileInlineToRootChunkConversion.class);
-
private final HBaseTestingUtility testUtil = new HBaseTestingUtility();
private final Configuration conf = testUtil.getConfiguration();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFilePrettyPrinter.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFilePrettyPrinter.java
index 9ec5dc1c576..ee3d6d39c17 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFilePrettyPrinter.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFilePrettyPrinter.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.codahale.metrics.MetricRegistry;
import java.io.ByteArrayOutputStream;
@@ -27,28 +27,22 @@ import java.io.PrintStream;
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.regionserver.TestHRegionServerBulkLoad;
import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.CommonFSUtils;
-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;
-@Category({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestHFilePrettyPrinter {
-
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestHFilePrettyPrinter.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestHFilePrettyPrinter.class);
private final static HBaseTestingUtility UTIL = new HBaseTestingUtility();
@@ -61,7 +55,7 @@ public class TestHFilePrettyPrinter {
private static PrintStream ps;
private static ByteArrayOutputStream stream;
- @Before
+ @BeforeEach
public void setup() throws Exception {
conf = UTIL.getConfiguration();
// Runs on local filesystem. Test does not need sync. Turn off checks.
@@ -71,7 +65,7 @@ public class TestHFilePrettyPrinter {
ps = new PrintStream(stream);
}
- @After
+ @AfterEach
public void teardown() {
original = System.out;
System.setOut(original);
@@ -81,8 +75,8 @@ public class TestHFilePrettyPrinter {
public void testHFilePrettyPrinterNonRootDir() throws Exception {
Path fileNotInRootDir = UTIL.getDataTestDir("hfile");
TestHRegionServerBulkLoad.createHFile(fs, fileNotInRootDir, cf, fam, value, 1000);
- assertNotEquals("directory used is not an HBase root dir", UTIL.getDefaultRootDirPath(),
- fileNotInRootDir);
+ assertNotEquals(UTIL.getDefaultRootDirPath(), fileNotInRootDir,
+ "directory used is not an HBase root dir");
System.setOut(ps);
new HFilePrettyPrinter(conf).run(new String[] { "-v", String.valueOf(fileNotInRootDir) });
@@ -97,7 +91,7 @@ public class TestHFilePrettyPrinter {
String rootString = rootPath + rootPath.SEPARATOR;
Path fileInRootDir = new Path(rootString + "hfile");
TestHRegionServerBulkLoad.createHFile(fs, fileInRootDir, cf, fam, value, 1000);
- assertTrue("directory used is a root dir", fileInRootDir.toString().startsWith(rootString));
+ assertTrue(fileInRootDir.toString().startsWith(rootString), "directory used is a root dir");
System.setOut(ps);
HFilePrettyPrinter printer = new HFilePrettyPrinter();
@@ -113,8 +107,8 @@ public class TestHFilePrettyPrinter {
public void testHFilePrettyPrinterSeekFirstRow() throws Exception {
Path fileNotInRootDir = UTIL.getDataTestDir("hfile");
TestHRegionServerBulkLoad.createHFile(fs, fileNotInRootDir, cf, fam, value, 1000);
- assertNotEquals("directory used is not an HBase root dir", UTIL.getDefaultRootDirPath(),
- fileNotInRootDir);
+ assertNotEquals(UTIL.getDefaultRootDirPath(), fileNotInRootDir,
+ "directory used is not an HBase root dir");
HFile.Reader reader =
HFile.createReader(fs, fileNotInRootDir, CacheConfig.DISABLED, true, conf);
@@ -132,8 +126,8 @@ public class TestHFilePrettyPrinter {
public void testHistograms() throws Exception {
Path fileNotInRootDir = UTIL.getDataTestDir("hfile");
TestHRegionServerBulkLoad.createHFile(fs, fileNotInRootDir, cf, fam, value, 1000);
- assertNotEquals("directory used is not an HBase root dir", UTIL.getDefaultRootDirPath(),
- fileNotInRootDir);
+ assertNotEquals(UTIL.getDefaultRootDirPath(), fileNotInRootDir,
+ "directory used is not an HBase root dir");
System.setOut(ps);
new HFilePrettyPrinter(conf).run(new String[] { "-s", "-d", String.valueOf(fileNotInRootDir) });
@@ -158,8 +152,8 @@ public class TestHFilePrettyPrinter {
private void assertContainsRanges(String result, int... rangeCountPairs) {
for (int i = 0; i < rangeCountPairs.length - 1; i += 2) {
String expected = rangeCountPairs[i + 1] + " <= " + rangeCountPairs[i];
- assertTrue("expected:\n" + result + "\nto contain: '" + expected + "'",
- result.contains(expected));
+ assertTrue(result.contains(expected),
+ "expected:\n" + result + "\nto contain: '" + expected + "'");
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileReaderImpl.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileReaderImpl.java
index b85c5edb9b6..083230f69f5 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileReaderImpl.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileReaderImpl.java
@@ -17,7 +17,7 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
@@ -25,29 +25,24 @@ import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.io.hfile.bucket.BucketCache;
import org.apache.hadoop.hbase.testclassification.IOTests;
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.apache.hbase.thirdparty.com.google.common.collect.Lists;
/**
* Test
*/
-@Category({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestHFileReaderImpl {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestHFileReaderImpl.class);
-
private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
static KeyValue toKV(String row) {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileScannerImplReferenceCount.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileScannerImplReferenceCount.java
index 85a0ac33d55..d3a95a7b19b 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileScannerImplReferenceCount.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileScannerImplReferenceCount.java
@@ -25,17 +25,20 @@ import static org.apache.hadoop.hbase.io.ByteBuffAllocator.MAX_BUFFER_COUNT_KEY;
import static org.apache.hadoop.hbase.io.ByteBuffAllocator.MIN_ALLOCATE_SIZE_KEY;
import static org.apache.hadoop.hbase.io.hfile.HFileBlockIndex.MAX_CHUNK_SIZE_KEY;
import static org.apache.hadoop.hbase.io.hfile.HFileBlockIndex.MIN_INDEX_NUM_ENTRIES_KEY;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collection;
import java.util.Random;
+import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
@@ -49,42 +52,32 @@ import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
-import org.junit.After;
-import org.junit.Assert;
-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.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameter;
-import org.junit.runners.Parameterized.Parameters;
+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.TestInfo;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@RunWith(Parameterized.class)
-@Category({ IOTests.class, LargeTests.class })
+@Tag(IOTests.TAG)
+@Tag(LargeTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: ioengine={0}")
public class TestHFileScannerImplReferenceCount {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestHFileScannerImplReferenceCount.class);
+ public static Stream<Arguments> parameters() {
+ return Stream.of(Arguments.of("file"), Arguments.of("offheap"), Arguments.of("mmap"),
+ Arguments.of("pmem"));
+ }
- @Rule
- public TestName CASE = new TestName();
+ private String ioengine;
- @Parameters(name = "{index}: ioengine={0}")
- public static Collection<Object[]> data() {
- return Arrays.asList(new Object[] { "file" }, new Object[] { "offheap" },
- new Object[] { "mmap" }, new Object[] { "pmem" });
+ public TestHFileScannerImplReferenceCount(String ioengine) {
+ this.ioengine = ioengine;
}
- @Parameter
- public String ioengine;
-
private static final Logger LOG =
LoggerFactory.getLogger(TestHFileScannerImplReferenceCount.class);
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
@@ -109,7 +102,7 @@ public class TestHFileScannerImplReferenceCount {
private Cell secondCell = null;
private ByteBuffAllocator allocator;
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() {
Configuration conf = UTIL.getConfiguration();
// Set the max chunk size and min entries key to be very small for index block, so that we can
@@ -125,9 +118,9 @@ public class TestHFileScannerImplReferenceCount {
conf.setInt(MIN_ALLOCATE_SIZE_KEY, 0);
}
- @Before
- public void setUp() throws IOException {
- String caseName = CASE.getMethodName().replaceAll("[^a-zA-Z0-9]", "_");
+ @BeforeEach
+ public void setUp(TestInfo testInfo) throws IOException {
+ String caseName = testInfo.getDisplayName().replaceAll("[^a-zA-Z0-9]", "_");
this.workDir = UTIL.getDataTestDir(caseName);
if (!"offheap".equals(ioengine)) {
ioengine = ioengine + ":" + workDir.toString() + "/cachedata";
@@ -142,17 +135,17 @@ public class TestHFileScannerImplReferenceCount {
LOG.info("Start to write {} cells into hfile: {}, case:{}", CELL_COUNT, hfilePath, caseName);
}
- @After
+ @AfterEach
public void tearDown() throws IOException {
this.allocator.clean();
this.fs.delete(this.workDir, true);
}
private void waitBucketCacheFlushed(BlockCache cache) throws InterruptedException {
- Assert.assertTrue(cache instanceof CombinedBlockCache);
+ assertTrue(cache instanceof CombinedBlockCache);
BlockCache[] blockCaches = cache.getBlockCaches();
- Assert.assertEquals(blockCaches.length, 2);
- Assert.assertTrue(blockCaches[1] instanceof BucketCache);
+ assertEquals(blockCaches.length, 2);
+ assertTrue(blockCaches[1] instanceof BucketCache);
TestBucketCache.waitUntilAllFlushedToBucket((BucketCache) blockCaches[1]);
}
@@ -189,30 +182,30 @@ public class TestHFileScannerImplReferenceCount {
HFileBlock curBlock, prevBlock;
BlockCache defaultBC = BlockCacheFactory.createBlockCache(conf);
CacheConfig cacheConfig = new CacheConfig(conf, null, defaultBC, allocator);
- Assert.assertNotNull(defaultBC);
- Assert.assertTrue(cacheConfig.isCombinedBlockCache());
+ assertNotNull(defaultBC);
+ assertTrue(cacheConfig.isCombinedBlockCache());
HFile.Reader reader = HFile.createReader(fs, hfilePath, cacheConfig, true, conf);
- Assert.assertTrue(reader instanceof HFileReaderImpl);
+ assertTrue(reader instanceof HFileReaderImpl);
// We've build a HFile tree with index = 16.
- Assert.assertEquals(16, reader.getTrailer().getNumDataIndexLevels());
+ assertEquals(16, reader.getTrailer().getNumDataIndexLevels());
HFileScannerImpl scanner = (HFileScannerImpl) reader.getScanner(conf, true, true, false);
HFileBlock block1 = reader.getDataBlockIndexReader()
.loadDataBlockWithScanInfo(firstCell, null, true, true, false, DataBlockEncoding.NONE, reader)
.getHFileBlock();
waitBucketCacheFlushed(defaultBC);
- Assert.assertTrue(block1.getBlockType().isData());
- Assert.assertFalse(block1 instanceof ExclusiveMemHFileBlock);
+ assertTrue(block1.getBlockType().isData());
+ assertFalse(block1 instanceof ExclusiveMemHFileBlock);
HFileBlock block2 = reader.getDataBlockIndexReader().loadDataBlockWithScanInfo(secondCell, null,
true, true, false, DataBlockEncoding.NONE, reader).getHFileBlock();
waitBucketCacheFlushed(defaultBC);
- Assert.assertTrue(block2.getBlockType().isData());
- Assert.assertFalse(block2 instanceof ExclusiveMemHFileBlock);
+ assertTrue(block2.getBlockType().isData());
+ assertFalse(block2 instanceof ExclusiveMemHFileBlock);
// Only one refCnt for RPC path.
- Assert.assertEquals(block1.refCnt(), 1);
- Assert.assertEquals(block2.refCnt(), 1);
- Assert.assertFalse(block1 == block2);
+ assertEquals(block1.refCnt(), 1);
+ assertEquals(block2.refCnt(), 1);
+ assertFalse(block1 == block2);
scanner.seekTo(firstCell);
curBlock = scanner.curBlock;
@@ -221,7 +214,7 @@ public class TestHFileScannerImplReferenceCount {
// Seek to the block again, the curBlock won't change and won't read from BlockCache. so
// refCnt should be unchanged.
scanner.seekTo(firstCell);
- Assert.assertTrue(curBlock == scanner.curBlock);
+ assertTrue(curBlock == scanner.curBlock);
this.assertRefCnt(curBlock, 2);
prevBlock = curBlock;
@@ -246,16 +239,16 @@ public class TestHFileScannerImplReferenceCount {
this.assertRefCnt(curBlock, 1);
// Finish the block & block2 RPC path
- Assert.assertTrue(block1.release());
- Assert.assertTrue(block2.release());
+ assertTrue(block1.release());
+ assertTrue(block2.release());
// Evict the LRUBlockCache
- Assert.assertTrue(defaultBC.evictBlocksByHfileName(hfilePath.getName()) >= 2);
- Assert.assertEquals(prevBlock.refCnt(), 0);
- Assert.assertEquals(curBlock.refCnt(), 0);
+ assertTrue(defaultBC.evictBlocksByHfileName(hfilePath.getName()) >= 2);
+ assertEquals(prevBlock.refCnt(), 0);
+ assertEquals(curBlock.refCnt(), 0);
int count = 0;
- Assert.assertTrue(scanner.seekTo());
+ assertTrue(scanner.seekTo());
++count;
while (scanner.next()) {
count++;
@@ -266,57 +259,57 @@ public class TestHFileScannerImplReferenceCount {
/**
* See HBASE-22480
*/
- @Test
+ @TestTemplate
public void testSeekBefore() throws Exception {
HFileBlock curBlock, prevBlock;
writeHFile(conf, fs, hfilePath, Algorithm.NONE, DataBlockEncoding.NONE, CELL_COUNT);
BlockCache defaultBC = BlockCacheFactory.createBlockCache(conf);
CacheConfig cacheConfig = new CacheConfig(conf, null, defaultBC, allocator);
- Assert.assertNotNull(defaultBC);
- Assert.assertTrue(cacheConfig.isCombinedBlockCache());
+ assertNotNull(defaultBC);
+ assertTrue(cacheConfig.isCombinedBlockCache());
HFile.Reader reader = HFile.createReader(fs, hfilePath, cacheConfig, true, conf);
- Assert.assertTrue(reader instanceof HFileReaderImpl);
+ assertTrue(reader instanceof HFileReaderImpl);
// We've build a HFile tree with index = 16.
- Assert.assertEquals(16, reader.getTrailer().getNumDataIndexLevels());
+ assertEquals(16, reader.getTrailer().getNumDataIndexLevels());
HFileScannerImpl scanner = (HFileScannerImpl) reader.getScanner(conf, true, true, false);
HFileBlock block1 = reader.getDataBlockIndexReader()
.loadDataBlockWithScanInfo(firstCell, null, true, true, false, DataBlockEncoding.NONE, reader)
.getHFileBlock();
- Assert.assertTrue(block1.getBlockType().isData());
- Assert.assertFalse(block1 instanceof ExclusiveMemHFileBlock);
+ assertTrue(block1.getBlockType().isData());
+ assertFalse(block1 instanceof ExclusiveMemHFileBlock);
HFileBlock block2 = reader.getDataBlockIndexReader().loadDataBlockWithScanInfo(secondCell, null,
true, true, false, DataBlockEncoding.NONE, reader).getHFileBlock();
- Assert.assertTrue(block2.getBlockType().isData());
- Assert.assertFalse(block2 instanceof ExclusiveMemHFileBlock);
+ assertTrue(block2.getBlockType().isData());
+ assertFalse(block2 instanceof ExclusiveMemHFileBlock);
// Wait until flushed to IOEngine;
waitBucketCacheFlushed(defaultBC);
// One RPC reference path.
- Assert.assertEquals(block1.refCnt(), 1);
- Assert.assertEquals(block2.refCnt(), 1);
+ assertEquals(block1.refCnt(), 1);
+ assertEquals(block2.refCnt(), 1);
// Let the curBlock refer to block2.
scanner.seekTo(secondCell);
curBlock = scanner.curBlock;
- Assert.assertFalse(curBlock == block2);
- Assert.assertEquals(1, block2.refCnt());
+ assertFalse(curBlock == block2);
+ assertEquals(1, block2.refCnt());
this.assertRefCnt(curBlock, 2);
prevBlock = scanner.curBlock;
// Release the block1, no other reference.
- Assert.assertTrue(block1.release());
- Assert.assertEquals(0, block1.refCnt());
+ assertTrue(block1.release());
+ assertEquals(0, block1.refCnt());
// Release the block2, no other reference.
- Assert.assertTrue(block2.release());
- Assert.assertEquals(0, block2.refCnt());
+ assertTrue(block2.release());
+ assertEquals(0, block2.refCnt());
// Do the seekBefore: the newBlock will be the previous block of curBlock.
- Assert.assertTrue(scanner.seekBefore(secondCell));
- Assert.assertEquals(scanner.prevBlocks.size(), 1);
- Assert.assertTrue(scanner.prevBlocks.get(0) == prevBlock);
+ assertTrue(scanner.seekBefore(secondCell));
+ assertEquals(scanner.prevBlocks.size(), 1);
+ assertTrue(scanner.prevBlocks.get(0) == prevBlock);
curBlock = scanner.curBlock;
// the curBlock is read from IOEngine, so a different block.
- Assert.assertFalse(curBlock == block1);
+ assertFalse(curBlock == block1);
// Two reference for curBlock: 1. scanner; 2. blockCache.
this.assertRefCnt(curBlock, 2);
// Reference count of prevBlock must be unchanged because we haven't shipped.
@@ -324,20 +317,20 @@ public class TestHFileScannerImplReferenceCount {
// Do the shipped
scanner.shipped();
- Assert.assertEquals(scanner.prevBlocks.size(), 0);
- Assert.assertNotNull(scanner.curBlock);
+ assertEquals(scanner.prevBlocks.size(), 0);
+ assertNotNull(scanner.curBlock);
this.assertRefCnt(curBlock, 2);
this.assertRefCnt(prevBlock, 1);
// Do the close
scanner.close();
- Assert.assertNull(scanner.curBlock);
+ assertNull(scanner.curBlock);
this.assertRefCnt(curBlock, 1);
this.assertRefCnt(prevBlock, 1);
- Assert.assertTrue(defaultBC.evictBlocksByHfileName(hfilePath.getName()) >= 2);
- Assert.assertEquals(0, curBlock.refCnt());
- Assert.assertEquals(0, prevBlock.refCnt());
+ assertTrue(defaultBC.evictBlocksByHfileName(hfilePath.getName()) >= 2);
+ assertEquals(0, curBlock.refCnt());
+ assertEquals(0, prevBlock.refCnt());
// Reload the block1 again.
block1 = reader.getDataBlockIndexReader()
@@ -345,55 +338,55 @@ public class TestHFileScannerImplReferenceCount {
.getHFileBlock();
// Wait until flushed to IOEngine;
waitBucketCacheFlushed(defaultBC);
- Assert.assertTrue(block1.getBlockType().isData());
- Assert.assertFalse(block1 instanceof ExclusiveMemHFileBlock);
- Assert.assertTrue(block1.release());
- Assert.assertEquals(0, block1.refCnt());
+ assertTrue(block1.getBlockType().isData());
+ assertFalse(block1 instanceof ExclusiveMemHFileBlock);
+ assertTrue(block1.release());
+ assertEquals(0, block1.refCnt());
// Re-seek to the begin.
- Assert.assertTrue(scanner.seekTo());
+ assertTrue(scanner.seekTo());
curBlock = scanner.curBlock;
- Assert.assertFalse(curBlock == block1);
+ assertFalse(curBlock == block1);
this.assertRefCnt(curBlock, 2);
// Return false because firstCell <= c[0]
- Assert.assertFalse(scanner.seekBefore(firstCell));
+ assertFalse(scanner.seekBefore(firstCell));
// The block1 shouldn't be released because we still don't do the shipped or close.
this.assertRefCnt(curBlock, 2);
scanner.close();
this.assertRefCnt(curBlock, 1);
- Assert.assertTrue(defaultBC.evictBlocksByHfileName(hfilePath.getName()) >= 1);
- Assert.assertEquals(0, curBlock.refCnt());
+ assertTrue(defaultBC.evictBlocksByHfileName(hfilePath.getName()) >= 1);
+ assertEquals(0, curBlock.refCnt());
}
private void assertRefCnt(HFileBlock block, int value) {
if (ioengine.startsWith("offheap") || ioengine.startsWith("pmem")) {
- Assert.assertEquals(value, block.refCnt());
+ assertEquals(value, block.refCnt());
} else {
- Assert.assertEquals(value - 1, block.refCnt());
+ assertEquals(value - 1, block.refCnt());
}
}
- @Test
+ @TestTemplate
public void testDefault() throws Exception {
testReleaseBlock(Algorithm.NONE, DataBlockEncoding.NONE);
}
- @Test
+ @TestTemplate
public void testCompression() throws Exception {
testReleaseBlock(Algorithm.GZ, DataBlockEncoding.NONE);
}
- @Test
+ @TestTemplate
public void testDataBlockEncoding() throws Exception {
testReleaseBlock(Algorithm.NONE, DataBlockEncoding.ROW_INDEX_V1);
}
- @Test
+ @TestTemplate
public void testDataBlockEncodingAndCompression() throws Exception {
testReleaseBlock(Algorithm.GZ, DataBlockEncoding.ROW_INDEX_V1);
}
- @Test
+ @TestTemplate
public void testWithLruBlockCache() throws Exception {
HFileBlock curBlock;
writeHFile(conf, fs, hfilePath, Algorithm.NONE, DataBlockEncoding.NONE, CELL_COUNT);
@@ -401,70 +394,70 @@ public class TestHFileScannerImplReferenceCount {
conf.set(BUCKET_CACHE_IOENGINE_KEY, "");
BlockCache defaultBC = BlockCacheFactory.createBlockCache(conf);
CacheConfig cacheConfig = new CacheConfig(conf, null, defaultBC, allocator);
- Assert.assertNotNull(defaultBC);
- Assert.assertFalse(cacheConfig.isCombinedBlockCache()); // Must be LruBlockCache.
+ assertNotNull(defaultBC);
+ assertFalse(cacheConfig.isCombinedBlockCache()); // Must be LruBlockCache.
HFile.Reader reader = HFile.createReader(fs, hfilePath, cacheConfig, true, conf);
- Assert.assertTrue(reader instanceof HFileReaderImpl);
+ assertTrue(reader instanceof HFileReaderImpl);
// We've build a HFile tree with index = 16.
- Assert.assertEquals(16, reader.getTrailer().getNumDataIndexLevels());
+ assertEquals(16, reader.getTrailer().getNumDataIndexLevels());
HFileScannerImpl scanner = (HFileScannerImpl) reader.getScanner(conf, true, true, false);
HFileBlock block1 = reader.getDataBlockIndexReader()
.loadDataBlockWithScanInfo(firstCell, null, true, true, false, DataBlockEncoding.NONE, reader)
.getHFileBlock();
- Assert.assertTrue(block1.getBlockType().isData());
- Assert.assertTrue(block1 instanceof ExclusiveMemHFileBlock);
+ assertTrue(block1.getBlockType().isData());
+ assertTrue(block1 instanceof ExclusiveMemHFileBlock);
HFileBlock block2 = reader.getDataBlockIndexReader().loadDataBlockWithScanInfo(secondCell, null,
true, true, false, DataBlockEncoding.NONE, reader).getHFileBlock();
- Assert.assertTrue(block2.getBlockType().isData());
- Assert.assertTrue(block2 instanceof ExclusiveMemHFileBlock);
+ assertTrue(block2.getBlockType().isData());
+ assertTrue(block2 instanceof ExclusiveMemHFileBlock);
// One RPC reference path.
- Assert.assertEquals(block1.refCnt(), 0);
- Assert.assertEquals(block2.refCnt(), 0);
+ assertEquals(block1.refCnt(), 0);
+ assertEquals(block2.refCnt(), 0);
scanner.seekTo(firstCell);
curBlock = scanner.curBlock;
- Assert.assertTrue(curBlock == block1);
- Assert.assertEquals(curBlock.refCnt(), 0);
- Assert.assertTrue(scanner.prevBlocks.isEmpty());
+ assertTrue(curBlock == block1);
+ assertEquals(curBlock.refCnt(), 0);
+ assertTrue(scanner.prevBlocks.isEmpty());
// Switch to next block
scanner.seekTo(secondCell);
curBlock = scanner.curBlock;
- Assert.assertTrue(curBlock == block2);
- Assert.assertEquals(curBlock.refCnt(), 0);
- Assert.assertEquals(curBlock.retain().refCnt(), 0);
+ assertTrue(curBlock == block2);
+ assertEquals(curBlock.refCnt(), 0);
+ assertEquals(curBlock.retain().refCnt(), 0);
// Only pooled HFileBlock will be kept in prevBlocks and ExclusiveMemHFileBlock will never keep
// in prevBlocks.
- Assert.assertTrue(scanner.prevBlocks.isEmpty());
+ assertTrue(scanner.prevBlocks.isEmpty());
// close the scanner
scanner.close();
- Assert.assertNull(scanner.curBlock);
- Assert.assertTrue(scanner.prevBlocks.isEmpty());
+ assertNull(scanner.curBlock);
+ assertTrue(scanner.prevBlocks.isEmpty());
}
- @Test
+ @TestTemplate
public void testDisabledBlockCache() throws Exception {
writeHFile(conf, fs, hfilePath, Algorithm.NONE, DataBlockEncoding.NONE, CELL_COUNT);
// Set LruBlockCache
conf.setFloat(HFILE_BLOCK_CACHE_SIZE_KEY, 0.0f);
BlockCache defaultBC = BlockCacheFactory.createBlockCache(conf);
- Assert.assertNull(defaultBC);
+ assertNull(defaultBC);
CacheConfig cacheConfig = new CacheConfig(conf, null, defaultBC, allocator);
- Assert.assertFalse(cacheConfig.isCombinedBlockCache()); // Must be LruBlockCache.
+ assertFalse(cacheConfig.isCombinedBlockCache()); // Must be LruBlockCache.
HFile.Reader reader = HFile.createReader(fs, hfilePath, cacheConfig, true, conf);
- Assert.assertTrue(reader instanceof HFileReaderImpl);
+ assertTrue(reader instanceof HFileReaderImpl);
// We've build a HFile tree with index = 16.
- Assert.assertEquals(16, reader.getTrailer().getNumDataIndexLevels());
+ assertEquals(16, reader.getTrailer().getNumDataIndexLevels());
HFileBlock block1 = reader.getDataBlockIndexReader()
.loadDataBlockWithScanInfo(firstCell, null, true, true, false, DataBlockEncoding.NONE, reader)
.getHFileBlock();
- Assert.assertTrue(block1.isSharedMem());
- Assert.assertTrue(block1 instanceof SharedMemHFileBlock);
- Assert.assertEquals(1, block1.refCnt());
- Assert.assertTrue(block1.release());
+ assertTrue(block1.isSharedMem());
+ assertTrue(block1 instanceof SharedMemHFileBlock);
+ assertEquals(1, block1.refCnt());
+ assertTrue(block1.release());
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileSeek.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileSeek.java
index 3e5e20858cc..8ffcdc46641 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileSeek.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileSeek.java
@@ -26,20 +26,19 @@ import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.RawLocalFileSystem;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.io.hfile.HFile.Reader;
import org.apache.hadoop.hbase.io.hfile.HFile.Writer;
import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.RandomDistribution;
import org.apache.hadoop.io.BytesWritable;
-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;
@@ -59,15 +58,12 @@ import org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException;
* Remove after tfile is committed and use the tfile version of this class instead.
* </p>
*/
-@Category({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestHFileSeek {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestHFileSeek.class);
-
- private static final byte[] CF = "f1".getBytes();
- private static final byte[] QUAL = "q1".getBytes();
+ private static final byte[] CF = Bytes.toBytes("f1");
+ private static final byte[] QUAL = Bytes.toBytes("q1");
private static final boolean USE_PREAD = true;
private MyOptions options;
private Configuration conf;
@@ -80,7 +76,7 @@ public class TestHFileSeek {
private static final Logger LOG = LoggerFactory.getLogger(TestHFileSeek.class);
- @Before
+ @BeforeEach
public void setUp() throws IOException {
if (options == null) {
options = new MyOptions(new String[0]);
@@ -107,7 +103,7 @@ public class TestHFileSeek {
kvGen = new KVGenerator(rng, true, keyLenGen, valLenGen, wordLenGen, options.dictSize);
}
- @After
+ @AfterEach
public void tearDown() {
try {
fs.close();
@@ -162,10 +158,10 @@ public class TestHFileSeek {
double duration = (double) timer.read() / 1000; // in us.
long fsize = fs.getFileStatus(path).getLen();
- System.out.printf("time: %s...uncompressed: %.2fMB...raw thrpt: %.2fMB/s\n", timer.toString(),
- (double) totalBytes / 1024 / 1024, totalBytes / duration);
- System.out.printf("time: %s...file size: %.2fMB...disk thrpt: %.2fMB/s\n", timer.toString(),
- (double) fsize / 1024 / 1024, fsize / duration);
+ LOG.info(String.format("time: %s...uncompressed: %.2fMB...raw thrpt: %.2fMB/s\n",
+ timer.toString(), (double) totalBytes / 1024 / 1024, totalBytes / duration));
+ LOG.info(String.format("time: %s...file size: %.2fMB...disk thrpt: %.2fMB/s\n",
+ timer.toString(), (double) fsize / 1024 / 1024, fsize / duration));
}
public void seekTFile() throws IOException {
@@ -194,9 +190,9 @@ public class TestHFileSeek {
}
}
timer.stop();
- System.out.printf("time: %s...avg seek: %s...%d hit...%d miss...avg I/O size: %.2fKB\n",
+ LOG.info(String.format("time: %s...avg seek: %s...%d hit...%d miss...avg I/O size: %.2fKB\n",
timer.toString(), NanoTimer.nanoTimeToString(timer.read() / options.seekCount),
- options.seekCount - miss, miss, (double) totalBytes / 1024 / (options.seekCount - miss));
+ options.seekCount - miss, miss, (double) totalBytes / 1024 / (options.seekCount - miss)));
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileWriterV3.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileWriterV3.java
index 40220f07bb7..08b073e6798 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileWriterV3.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileWriterV3.java
@@ -17,17 +17,17 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-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.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import java.util.Random;
+import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
@@ -35,8 +35,8 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.ArrayBackedTag;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellComparator;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
@@ -53,27 +53,20 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Writables;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.WritableUtils;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Testing writing a version 3 {@link HFile}.
*/
-@RunWith(Parameterized.class)
-@Category({ IOTests.class, SmallTests.class })
+@org.junit.jupiter.api.Tag(IOTests.TAG)
+@org.junit.jupiter.api.Tag(SmallTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: useTags={0}")
public class TestHFileWriterV3 {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestHFileWriterV3.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestHFileWriterV3.class);
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final Random RNG = new Random(9713312); // Just a fixed seed.
@@ -86,18 +79,17 @@ public class TestHFileWriterV3 {
this.useTags = useTags;
}
- @Parameters
- public static Collection<Object[]> parameters() {
- return HBaseCommonTestingUtility.BOOLEAN_PARAMETERIZED;
+ public static Stream<Arguments> parameters() {
+ return HBaseCommonTestingUtility.BOOLEAN_PARAMETERIZED.stream().map(arr -> Arguments.of(arr));
}
- @Before
+ @BeforeEach
public void setUp() throws IOException {
conf = TEST_UTIL.getConfiguration();
fs = FileSystem.get(conf);
}
- @Test
+ @TestTemplate
public void testHFileFormatV3() throws IOException {
testHFileFormatV3Internals(useTags);
}
@@ -109,7 +101,7 @@ public class TestHFileWriterV3 {
writeDataAndReadFromHFile(hfilePath, compressAlgo, entryCount, false, useTags);
}
- @Test
+ @TestTemplate
public void testMidKeyInHFile() throws IOException {
testMidKeyInHFileInternals(useTags);
}
@@ -197,7 +189,7 @@ public class TestHFileWriterV3 {
hfile.initMetaAndIndex(reader);
if (findMidKey) {
Cell midkey = dataBlockIndexReader.midkey(reader);
- assertNotNull("Midkey should not be null", midkey);
+ assertNotNull(midkey, "Midkey should not be null");
}
// Meta index.
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileWriterV3WithDataEncoders.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileWriterV3WithDataEncoders.java
index 09c25947925..92e2814dca1 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileWriterV3WithDataEncoders.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileWriterV3WithDataEncoders.java
@@ -17,12 +17,14 @@
*/
package org.apache.hadoop.hbase.io.hfile;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
import java.util.List;
import java.util.Random;
+import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
@@ -31,7 +33,7 @@ import org.apache.hadoop.hbase.ArrayBackedTag;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellComparator;
import org.apache.hadoop.hbase.CellComparatorImpl;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
@@ -48,27 +50,20 @@ import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Writables;
import org.apache.hadoop.io.Text;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Testing writing a version 3 {@link HFile} for all encoded blocks
*/
-@RunWith(Parameterized.class)
-@Category({ IOTests.class, MediumTests.class })
+@org.junit.jupiter.api.Tag(IOTests.TAG)
+@org.junit.jupiter.api.Tag(MediumTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: useTags={0}, dataBlockEncoding={1}")
public class TestHFileWriterV3WithDataEncoders {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestHFileWriterV3WithDataEncoders.class);
-
private static final Logger LOG =
LoggerFactory.getLogger(TestHFileWriterV3WithDataEncoders.class);
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
@@ -84,28 +79,26 @@ public class TestHFileWriterV3WithDataEncoders {
this.dataBlockEncoding = dataBlockEncoding;
}
- @Parameterized.Parameters
- public static Collection<Object[]> parameters() {
+ public static Stream<Arguments> parameters() {
DataBlockEncoding[] dataBlockEncodings = DataBlockEncoding.values();
- Object[][] params = new Object[dataBlockEncodings.length * 2 - 2][];
- int i = 0;
+ Stream.Builder<Arguments> builder = Stream.builder();
for (DataBlockEncoding dataBlockEncoding : dataBlockEncodings) {
if (dataBlockEncoding == DataBlockEncoding.NONE) {
continue;
}
- params[i++] = new Object[] { false, dataBlockEncoding };
- params[i++] = new Object[] { true, dataBlockEncoding };
+ builder.add(Arguments.of(false, dataBlockEncoding));
+ builder.add(Arguments.of(true, dataBlockEncoding));
}
- return Arrays.asList(params);
+ return builder.build();
}
- @Before
+ @BeforeEach
public void setUp() throws IOException {
conf = TEST_UTIL.getConfiguration();
fs = FileSystem.get(conf);
}
- @Test
+ @TestTemplate
public void testHFileFormatV3() throws IOException {
testHFileFormatV3Internals(useTags);
}
@@ -117,7 +110,7 @@ public class TestHFileWriterV3WithDataEncoders {
writeDataAndReadFromHFile(hfilePath, compressAlgo, entryCount, false, useTags);
}
- @Test
+ @TestTemplate
public void testMidKeyInHFile() throws IOException {
testMidKeyInHFileInternals(useTags);
}
@@ -147,8 +140,8 @@ public class TestHFileWriterV3WithDataEncoders {
long fileSize = fs.getFileStatus(hfilePath).getLen();
FixedFileTrailer trailer = FixedFileTrailer.readFromStream(fsdis, fileSize);
- Assert.assertEquals(3, trailer.getMajorVersion());
- Assert.assertEquals(entryCount, trailer.getEntryCount());
+ assertEquals(3, trailer.getMajorVersion());
+ assertEquals(entryCount, trailer.getEntryCount());
HFileContext meta = new HFileContextBuilder().withCompression(compressAlgo)
.withIncludesMvcc(true).withIncludesTags(useTags).withDataBlockEncoding(dataBlockEncoding)
.withHBaseCheckSum(true).build();
@@ -180,7 +173,7 @@ public class TestHFileWriterV3WithDataEncoders {
hfile.initMetaAndIndex(reader);
if (findMidKey) {
Cell midkey = dataBlockIndexReader.midkey(reader);
- Assert.assertNotNull("Midkey should not be null", midkey);
+ assertNotNull(midkey, "Midkey should not be null");
}
// Meta index.
@@ -213,7 +206,7 @@ public class TestHFileWriterV3WithDataEncoders {
trailer.getLoadOnOpenDataOffset());
HFileBlock block =
blockReader.readBlockData(curBlockPos, -1, false, false, true).unpack(context, blockReader);
- Assert.assertEquals(BlockType.META, block.getBlockType());
+ assertEquals(BlockType.META, block.getBlockType());
Text t = new Text();
ByteBuff buf = block.getBufferWithoutHeader();
if (Writables.getWritable(buf.array(), buf.arrayOffset(), buf.limit(), t) == null) {
@@ -223,7 +216,7 @@ public class TestHFileWriterV3WithDataEncoders {
Text expectedText = (metaCounter == 0 ? new Text("Paris")
: metaCounter == 1 ? new Text("Moscow")
: new Text("Washington, D.C."));
- Assert.assertEquals(expectedText, t);
+ assertEquals(expectedText, t);
LOG.info("Read meta block data: " + t);
++metaCounter;
curBlockPos += block.getOnDiskSizeWithHeader();
@@ -244,7 +237,7 @@ public class TestHFileWriterV3WithDataEncoders {
HFileBlockDecodingContext ctx = blockReader.getBlockDecodingContext();
HFileBlock block =
blockReader.readBlockData(curBlockPos, -1, false, false, true).unpack(context, blockReader);
- Assert.assertEquals(BlockType.ENCODED_DATA, block.getBlockType());
+ assertEquals(BlockType.ENCODED_DATA, block.getBlockType());
ByteBuff origBlock = block.getBufferReadOnly();
int pos = block.headerSize() + DataBlockEncoding.ID_SIZE;
origBlock.position(pos);
@@ -255,19 +248,19 @@ public class TestHFileWriterV3WithDataEncoders {
seeker.setCurrentBuffer(buf);
Cell res = seeker.getCell();
KeyValue kv = keyValues.get(entriesRead);
- Assert.assertEquals(0, CellComparatorImpl.COMPARATOR.compare(res, kv));
+ assertEquals(0, CellComparatorImpl.COMPARATOR.compare(res, kv));
++entriesRead;
while (seeker.next()) {
res = seeker.getCell();
kv = keyValues.get(entriesRead);
- Assert.assertEquals(0, CellComparatorImpl.COMPARATOR.compare(res, kv));
+ assertEquals(0, CellComparatorImpl.COMPARATOR.compare(res, kv));
++entriesRead;
}
++blocksRead;
curBlockPos += block.getOnDiskSizeWithHeader();
}
LOG.info("Finished reading: entries={}, blocksRead = {}", entriesRead, blocksRead);
- Assert.assertEquals(entryCount, entriesRead);
+ assertEquals(entryCount, entriesRead);
return curBlockPos;
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLazyDataBlockDecompression.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLazyDataBlockDecompression.java
index f212eeb6bb5..4696372ee2e 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLazyDataBlockDecompression.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLazyDataBlockDecompression.java
@@ -17,21 +17,21 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Random;
+import java.util.stream.Stream;
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.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
@@ -40,13 +40,11 @@ import org.apache.hadoop.hbase.io.compress.Compression;
import org.apache.hadoop.hbase.testclassification.IOTests;
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.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -56,33 +54,33 @@ import org.apache.hbase.thirdparty.com.google.common.collect.Iterables;
* A kind of integration test at the intersection of {@link HFileBlock}, {@link CacheConfig}, and
* {@link LruBlockCache}.
*/
-@Category({ IOTests.class, SmallTests.class })
-@RunWith(Parameterized.class)
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: cacheOnWrite={0}")
public class TestLazyDataBlockDecompression {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestLazyDataBlockDecompression.class);
private static final Logger LOG = LoggerFactory.getLogger(TestLazyDataBlockDecompression.class);
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final Random RNG = new Random(9713312); // Just a fixed seed.
private FileSystem fs;
- @Parameterized.Parameter(0)
- public boolean cacheOnWrite;
+ private final boolean cacheOnWrite;
- @Parameterized.Parameters
- public static Iterable<Object[]> data() {
- return Arrays.asList(new Object[][] { { false }, { true } });
+ public static Stream<Arguments> parameters() {
+ return Stream.of(Arguments.of(false), Arguments.of(true));
}
- @Before
+ public TestLazyDataBlockDecompression(boolean cacheOnWrite) {
+ this.cacheOnWrite = cacheOnWrite;
+ }
+
+ @BeforeEach
public void setUp() throws IOException {
fs = FileSystem.get(TEST_UTIL.getConfiguration());
}
- @After
+ @AfterEach
public void tearDown() {
fs = null;
}
@@ -134,7 +132,7 @@ public class TestLazyDataBlockDecompression {
reader.close();
}
- @Test
+ @TestTemplate
public void testCompressionIncreasesEffectiveBlockCacheSize() throws Exception {
// enough room for 2 uncompressed block
int maxSize = (int) (HConstants.DEFAULT_BLOCKSIZE * 2.1);
@@ -156,11 +154,11 @@ public class TestLazyDataBlockDecompression {
assertFalse(cc.isCombinedBlockCache());
LruBlockCache disabledBlockCache = (LruBlockCache) cc.getBlockCache().get();
LOG.info("disabledBlockCache=" + disabledBlockCache);
- assertEquals("test inconsistency detected.", maxSize, disabledBlockCache.getMaxSize());
- assertTrue("eviction thread spawned unintentionally.",
- disabledBlockCache.getEvictionThread() == null);
- assertEquals("freshly created blockcache contains blocks.", 0,
- disabledBlockCache.getBlockCount());
+ assertEquals(maxSize, disabledBlockCache.getMaxSize(), "test inconsistency detected.");
+ assertTrue(disabledBlockCache.getEvictionThread() == null,
+ "eviction thread spawned unintentionally.");
+ assertEquals(0, disabledBlockCache.getBlockCount(),
+ "freshly created blockcache contains blocks.");
// 2000 kv's is ~3.6 full unencoded data blocks.
// Requires a conf and CacheConfig but should not be specific to this instance's cache settings
@@ -169,13 +167,13 @@ public class TestLazyDataBlockDecompression {
// populate the cache
cacheBlocks(lazyCompressDisabled, cc, fs, hfilePath, context);
long disabledBlockCount = disabledBlockCache.getBlockCount();
- assertTrue("blockcache should contain blocks. disabledBlockCount=" + disabledBlockCount,
- disabledBlockCount > 0);
+ assertTrue(disabledBlockCount > 0,
+ "blockcache should contain blocks. disabledBlockCount=" + disabledBlockCount);
long disabledEvictedCount = disabledBlockCache.getStats().getEvictedCount();
for (Map.Entry<BlockCacheKey, LruCachedBlock> e : disabledBlockCache.getMapForTests()
.entrySet()) {
HFileBlock block = (HFileBlock) e.getValue().getBuffer();
- assertTrue("found a packed block, block=" + block, block.isUnpacked());
+ assertTrue(block.isUnpacked(), "found a packed block, block=" + block);
}
// count blocks with lazy decompression
@@ -186,20 +184,20 @@ public class TestLazyDataBlockDecompression {
lazyCompressEnabled.setBoolean(CacheConfig.CACHE_DATA_BLOCKS_COMPRESSED_KEY, true);
cc = new CacheConfig(lazyCompressEnabled,
new LruBlockCache(maxSize, HConstants.DEFAULT_BLOCKSIZE, false, lazyCompressEnabled));
- assertTrue("test improperly configured.", cc.shouldCacheDataCompressed());
+ assertTrue(cc.shouldCacheDataCompressed(), "test improperly configured.");
assertTrue(cc.getBlockCache().get() instanceof LruBlockCache);
LruBlockCache enabledBlockCache = (LruBlockCache) cc.getBlockCache().get();
LOG.info("enabledBlockCache=" + enabledBlockCache);
- assertEquals("test inconsistency detected", maxSize, enabledBlockCache.getMaxSize());
- assertTrue("eviction thread spawned unintentionally.",
- enabledBlockCache.getEvictionThread() == null);
- assertEquals("freshly created blockcache contains blocks.", 0,
- enabledBlockCache.getBlockCount());
+ assertEquals(maxSize, enabledBlockCache.getMaxSize(), "test inconsistency detected");
+ assertTrue(enabledBlockCache.getEvictionThread() == null,
+ "eviction thread spawned unintentionally.");
+ assertEquals(0, enabledBlockCache.getBlockCount(),
+ "freshly created blockcache contains blocks.");
cacheBlocks(lazyCompressEnabled, cc, fs, hfilePath, context);
long enabledBlockCount = enabledBlockCache.getBlockCount();
- assertTrue("blockcache should contain blocks. enabledBlockCount=" + enabledBlockCount,
- enabledBlockCount > 0);
+ assertTrue(enabledBlockCount > 0,
+ "blockcache should contain blocks. enabledBlockCount=" + enabledBlockCount);
long enabledEvictedCount = enabledBlockCache.getStats().getEvictedCount();
int candidatesFound = 0;
for (Map.Entry<BlockCacheKey, LruCachedBlock> e : enabledBlockCache.getMapForTests()
@@ -207,24 +205,24 @@ public class TestLazyDataBlockDecompression {
candidatesFound++;
HFileBlock block = (HFileBlock) e.getValue().getBuffer();
if (cc.shouldCacheCompressed(block.getBlockType().getCategory())) {
- assertFalse("found an unpacked block, block=" + block + ", block buffer capacity="
- + block.getBufferWithoutHeader().capacity(), block.isUnpacked());
+ assertFalse(block.isUnpacked(), "found an unpacked block, block=" + block
+ + ", block buffer capacity=" + block.getBufferWithoutHeader().capacity());
}
}
- assertTrue("did not find any candidates for compressed caching. Invalid test.",
- candidatesFound > 0);
+ assertTrue(candidatesFound > 0,
+ "did not find any candidates for compressed caching. Invalid test.");
LOG.info(
"disabledBlockCount=" + disabledBlockCount + ", enabledBlockCount=" + enabledBlockCount);
- assertTrue(
+ assertTrue(disabledBlockCount < enabledBlockCount,
"enabling compressed data blocks should increase the effective cache size. "
- + "disabledBlockCount=" + disabledBlockCount + ", enabledBlockCount=" + enabledBlockCount,
- disabledBlockCount < enabledBlockCount);
+ + "disabledBlockCount=" + disabledBlockCount + ", enabledBlockCount=" + enabledBlockCount);
LOG.info("disabledEvictedCount=" + disabledEvictedCount + ", enabledEvictedCount="
+ enabledEvictedCount);
- assertTrue("enabling compressed data blocks should reduce the number of evictions. "
- + "disabledEvictedCount=" + disabledEvictedCount + ", enabledEvictedCount="
- + enabledEvictedCount, enabledEvictedCount < disabledEvictedCount);
+ assertTrue(enabledEvictedCount < disabledEvictedCount,
+ "enabling compressed data blocks should reduce the number of evictions. "
+ + "disabledEvictedCount=" + disabledEvictedCount + ", enabledEvictedCount="
+ + enabledEvictedCount);
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruAdaptiveBlockCache.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruAdaptiveBlockCache.java
index b065c7c6374..1ccd1d27f76 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruAdaptiveBlockCache.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruAdaptiveBlockCache.java
@@ -18,10 +18,11 @@
package org.apache.hadoop.hbase.io.hfile;
import static org.apache.hadoop.hbase.io.ByteBuffAllocator.HEAP;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.nio.ByteBuffer;
import java.util.Random;
@@ -32,7 +33,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.HConstants;
import org.apache.hadoop.hbase.Waiter;
@@ -43,10 +43,8 @@ import org.apache.hadoop.hbase.nio.ByteBuff;
import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.ClassSize;
-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;
@@ -56,13 +54,10 @@ import org.slf4j.LoggerFactory;
* Tests will ensure it grows and shrinks in size properly, evictions run when they're supposed to
* and do what they should, and that cached blocks are accessible when expected to be.
*/
-@Category({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestLruAdaptiveBlockCache {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestLruAdaptiveBlockCache.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestLruAdaptiveBlockCache.class);
private static final Configuration CONF = HBaseConfiguration.create();
@@ -73,7 +68,7 @@ public class TestLruAdaptiveBlockCache {
int numBlocks = 9;
int testRuns = 10;
final long blockSize = calculateBlockSizeDefault(maxSize, numBlocks);
- assertTrue("calculateBlockSize appears broken.", blockSize * numBlocks <= maxSize);
+ assertTrue(blockSize * numBlocks <= maxSize, "calculateBlockSize appears broken.");
final LruAdaptiveBlockCache cache = new LruAdaptiveBlockCache(maxSize, blockSize);
EvictionThread evictionThread = cache.getEvictionThread();
@@ -121,7 +116,7 @@ public class TestLruAdaptiveBlockCache {
long maxSize = 100000;
int numBlocks = 9;
long blockSize = calculateBlockSizeDefault(maxSize, numBlocks);
- assertTrue("calculateBlockSize appears broken.", blockSize * numBlocks <= maxSize);
+ assertTrue(blockSize * numBlocks <= maxSize, "calculateBlockSize appears broken.");
LruAdaptiveBlockCache cache = new LruAdaptiveBlockCache(maxSize, blockSize);
EvictionThread evictionThread = cache.getEvictionThread();
@@ -162,7 +157,7 @@ public class TestLruAdaptiveBlockCache {
for (long prevCnt = 0 /* < number of blocks added */, curCnt = cache.getBlockCount(); prevCnt
!= curCnt; prevCnt = curCnt, curCnt = cache.getBlockCount()) {
Thread.sleep(200);
- assertTrue("Cache never stabilized.", n++ < 100);
+ assertTrue(n++ < 100, "Cache never stabilized.");
}
long evictionCount = cache.getStats().getEvictionCount();
@@ -207,8 +202,8 @@ public class TestLruAdaptiveBlockCache {
for (CachedItem block : blocks) {
cache.cacheBlock(block.cacheKey, block);
}
- assertEquals("Cache should ignore cache requests for blocks already in cache",
- expectedBlockCount, cache.getBlockCount());
+ assertEquals(expectedBlockCount, cache.getBlockCount(),
+ "Cache should ignore cache requests for blocks already in cache");
// Verify correctly calculated cache heap size
assertEquals(expectedCacheSize, cache.heapSize());
@@ -976,9 +971,9 @@ public class TestLruAdaptiveBlockCache {
t1.join();
t2.join();
t3.join();
- Assert.assertFalse(err1.get());
- Assert.assertFalse(err2.get());
- Assert.assertFalse(err3.get());
+ assertFalse(err1.get());
+ assertFalse(err2.get());
+ assertFalse(err3.get());
}
@Test
@@ -1001,7 +996,7 @@ public class TestLruAdaptiveBlockCache {
long maxSize = 100000000;
int numBlocks = 100000;
final long blockSize = calculateBlockSizeDefault(maxSize, numBlocks);
- assertTrue("calculateBlockSize appears broken.", blockSize * numBlocks <= maxSize);
+ assertTrue(blockSize * numBlocks <= maxSize, "calculateBlockSize appears broken.");
final LruAdaptiveBlockCache cache = new LruAdaptiveBlockCache(maxSize, blockSize, true,
(int) Math.ceil(1.2 * maxSize / blockSize), LruAdaptiveBlockCache.DEFAULT_LOAD_FACTOR,
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruBlockCache.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruBlockCache.java
index ecd5fa2dd9a..50b1ebb162c 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruBlockCache.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruBlockCache.java
@@ -18,10 +18,11 @@
package org.apache.hadoop.hbase.io.hfile;
import static org.apache.hadoop.hbase.io.ByteBuffAllocator.HEAP;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.nio.ByteBuffer;
import java.util.Random;
@@ -32,7 +33,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.HConstants;
import org.apache.hadoop.hbase.Waiter;
@@ -43,10 +43,8 @@ import org.apache.hadoop.hbase.nio.ByteBuff;
import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.ClassSize;
-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;
@@ -56,13 +54,10 @@ import org.slf4j.LoggerFactory;
* Tests will ensure it grows and shrinks in size properly, evictions run when they're supposed to
* and do what they should, and that cached blocks are accessible when expected to be.
*/
-@Category({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestLruBlockCache {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestLruBlockCache.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestLruBlockCache.class);
private static final Configuration CONF = HBaseConfiguration.create();
@@ -73,7 +68,7 @@ public class TestLruBlockCache {
int numBlocks = 9;
int testRuns = 10;
final long blockSize = calculateBlockSizeDefault(maxSize, numBlocks);
- assertTrue("calculateBlockSize appears broken.", blockSize * numBlocks <= maxSize);
+ assertTrue(blockSize * numBlocks <= maxSize, "calculateBlockSize appears broken.");
final LruBlockCache cache = new LruBlockCache(maxSize, blockSize);
EvictionThread evictionThread = cache.getEvictionThread();
@@ -124,7 +119,7 @@ public class TestLruBlockCache {
long maxSize = 100000;
int numBlocks = 9;
long blockSize = calculateBlockSizeDefault(maxSize, numBlocks);
- assertTrue("calculateBlockSize appears broken.", blockSize * numBlocks <= maxSize);
+ assertTrue(blockSize * numBlocks <= maxSize, "calculateBlockSize appears broken.");
LruBlockCache cache = new LruBlockCache(maxSize, blockSize);
EvictionThread evictionThread = cache.getEvictionThread();
@@ -165,7 +160,7 @@ public class TestLruBlockCache {
for (long prevCnt = 0 /* < number of blocks added */, curCnt = cache.getBlockCount(); prevCnt
!= curCnt; prevCnt = curCnt, curCnt = cache.getBlockCount()) {
Thread.sleep(200);
- assertTrue("Cache never stabilized.", n++ < 100);
+ assertTrue(n++ < 100, "Cache never stabilized.");
}
long evictionCount = cache.getStats().getEvictionCount();
@@ -210,8 +205,8 @@ public class TestLruBlockCache {
for (CachedItem block : blocks) {
cache.cacheBlock(block.cacheKey, block);
}
- assertEquals("Cache should ignore cache requests for blocks already in cache",
- expectedBlockCount, cache.getBlockCount());
+ assertEquals(expectedBlockCount, cache.getBlockCount(),
+ "Cache should ignore cache requests for blocks already in cache");
// Verify correctly calculated cache heap size
assertEquals(expectedCacheSize, cache.heapSize());
@@ -978,9 +973,9 @@ public class TestLruBlockCache {
t1.join();
t2.join();
t3.join();
- Assert.assertFalse(err1.get());
- Assert.assertFalse(err2.get());
- Assert.assertFalse(err3.get());
+ assertFalse(err1.get());
+ assertFalse(err2.get());
+ assertFalse(err3.get());
}
@Test
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruCachedBlock.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruCachedBlock.java
index eb57b0acd65..ff7e495142e 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruCachedBlock.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruCachedBlock.java
@@ -17,30 +17,25 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
-@Category({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestLruCachedBlock {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestLruCachedBlock.class);
-
LruCachedBlock block;
LruCachedBlock blockEqual;
LruCachedBlock blockNotEqual;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
BlockCacheKey cacheKey = new BlockCacheKey("name", 0);
BlockCacheKey otherKey = new BlockCacheKey("name2", 1);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestPrefetch.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestPrefetch.java
index ca8cbeace93..f8d21364f2f 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestPrefetch.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestPrefetch.java
@@ -28,12 +28,12 @@ import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.not;
-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 io.opentelemetry.sdk.testing.junit4.OpenTelemetryRule;
+import io.opentelemetry.sdk.testing.junit5.OpenTelemetryExtension;
import io.opentelemetry.sdk.trace.data.SpanData;
import java.io.IOException;
import java.util.List;
@@ -47,7 +47,6 @@ import java.util.function.Consumer;
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.KeyValue;
@@ -74,21 +73,18 @@ import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.trace.TraceUtil;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.CommonFSUtils;
-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.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Category({ IOTests.class, MediumTests.class })
+@Tag(IOTests.TAG)
+@Tag(MediumTests.TAG)
public class TestPrefetch {
- private static final Logger LOG = LoggerFactory.getLogger(TestPrefetch.class);
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestPrefetch.class);
+ private static final Logger LOG = LoggerFactory.getLogger(TestPrefetch.class);
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
@@ -100,10 +96,10 @@ public class TestPrefetch {
private FileSystem fs;
private BlockCache blockCache;
- @Rule
- public OpenTelemetryRule otelRule = OpenTelemetryRule.create();
+ @RegisterExtension
+ private static OpenTelemetryExtension OTEL_EXT = OpenTelemetryExtension.create();
- @Before
+ @BeforeEach
public void setUp() throws IOException {
conf = TEST_UTIL.getConfiguration();
conf.setBoolean(CacheConfig.PREFETCH_BLOCKS_ON_OPEN_KEY, true);
@@ -163,9 +159,9 @@ public class TestPrefetch {
readStoreFile(storeFile);
}, "testPrefetch");
- TEST_UTIL.waitFor(TimeUnit.MINUTES.toMillis(1), new MatcherPredicate<>(otelRule::getSpans,
+ TEST_UTIL.waitFor(TimeUnit.MINUTES.toMillis(1), new MatcherPredicate<>(OTEL_EXT::getSpans,
hasItems(hasName("testPrefetch"), hasName("PrefetchExecutor.request"))));
- final List<SpanData> spans = otelRule.getSpans();
+ final List<SpanData> spans = OTEL_EXT.getSpans();
if (LOG.isDebugEnabled()) {
StringTraceRenderer renderer = new StringTraceRenderer(spans);
renderer.render(LOG::debug);
@@ -315,16 +311,16 @@ public class TestPrefetch {
// Wait for 20 seconds, no thread should start prefetch
Thread.sleep(20000);
- assertFalse("Prefetch threads should not be running at this point", reader.prefetchStarted());
+ assertFalse(reader.prefetchStarted(), "Prefetch threads should not be running at this point");
while (!reader.prefetchStarted()) {
- assertTrue("Prefetch delay has not been expired yet",
- getElapsedTime(startTime) < PrefetchExecutor.getPrefetchDelay());
+ assertTrue(getElapsedTime(startTime) < PrefetchExecutor.getPrefetchDelay(),
+ "Prefetch delay has not been expired yet");
}
if (reader.prefetchStarted()) {
// Added some delay as we have started the timer a bit late.
Thread.sleep(500);
- assertTrue("Prefetch should start post configured delay",
- getElapsedTime(startTime) > PrefetchExecutor.getPrefetchDelay());
+ assertTrue(getElapsedTime(startTime) > PrefetchExecutor.getPrefetchDelay(),
+ "Prefetch should start post configured delay");
}
conf.setInt(PREFETCH_DELAY, 1000);
conf.setFloat(PREFETCH_DELAY_VARIATION, PREFETCH_DELAY_VARIATION_DEFAULT_VALUE);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestReseekTo.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestReseekTo.java
index 3089fe36901..ac6cd15b282 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestReseekTo.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestReseekTo.java
@@ -17,7 +17,7 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.util.ArrayList;
@@ -25,7 +25,6 @@ import java.util.List;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.ArrayBackedTag;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
@@ -33,20 +32,15 @@ import org.apache.hadoop.hbase.Tag;
import org.apache.hadoop.hbase.testclassification.IOTests;
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.Test;
/**
* Test {@link HFileScanner#reseekTo(org.apache.hadoop.hbase.Cell)}
*/
-@Category({ IOTests.class, SmallTests.class })
+@org.junit.jupiter.api.Tag(IOTests.TAG)
+@org.junit.jupiter.api.Tag(SmallTests.TAG)
public class TestReseekTo {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestReseekTo.class);
-
private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
@Test
@@ -128,7 +122,7 @@ public class TestReseekTo {
long start = System.nanoTime();
scanner.reseekTo(new KeyValue(Bytes.toBytes(key), Bytes.toBytes("family"),
Bytes.toBytes("qual"), Bytes.toBytes(value)));
- assertEquals("i is " + i, value, scanner.getValueString());
+ assertEquals(value, scanner.getValueString(), "i is " + i);
}
reader.close();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestRowIndexV1DataEncoder.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestRowIndexV1DataEncoder.java
index 8653c4d416d..5cd6f635aaf 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestRowIndexV1DataEncoder.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestRowIndexV1DataEncoder.java
@@ -17,6 +17,8 @@
*/
package org.apache.hadoop.hbase.io.hfile;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
@@ -26,23 +28,18 @@ import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.CellComparatorImpl;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category({ IOTests.class, MediumTests.class })
+@Tag(IOTests.TAG)
+@Tag(MediumTests.TAG)
public class TestRowIndexV1DataEncoder {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestRowIndexV1DataEncoder.class);
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
@@ -50,7 +47,7 @@ public class TestRowIndexV1DataEncoder {
private FileSystem fs;
private DataBlockEncoding dataBlockEncoding;
- @Before
+ @BeforeEach
public void setUp() throws IOException {
conf = TEST_UTIL.getConfiguration();
fs = FileSystem.get(conf);
@@ -89,7 +86,7 @@ public class TestRowIndexV1DataEncoder {
// Without the patch it would have produced 244 blocks (each block of 1236 bytes)
// Earlier this would create blocks ~20% greater than the block size of 1024 bytes
// After this patch actual block size is ~2% greater than the block size of 1024 bytes
- Assert.assertEquals(278, trailer.getDataIndexCount());
+ assertEquals(278, trailer.getDataIndexCount());
}
private void writeKeyValues(int entryCount, HFile.Writer writer, List<KeyValue> keyValues)
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestRowIndexV1RoundTrip.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestRowIndexV1RoundTrip.java
index 2004e20aad6..44ff11cd7c8 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestRowIndexV1RoundTrip.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestRowIndexV1RoundTrip.java
@@ -18,9 +18,9 @@
package org.apache.hadoop.hbase.io.hfile;
import static org.apache.hadoop.hbase.io.ByteBuffAllocator.MIN_ALLOCATE_SIZE_KEY;
-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.nio.ByteBuffer;
@@ -31,7 +31,6 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.CellComparatorImpl;
import org.apache.hadoop.hbase.CellUtil;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.SizeCachedNoTagsByteBufferKeyValue;
@@ -41,16 +40,14 @@ import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category({ IOTests.class, MediumTests.class })
+@Tag(IOTests.TAG)
+@Tag(MediumTests.TAG)
public class TestRowIndexV1RoundTrip {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestRowIndexV1RoundTrip.class);
+
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final DataBlockEncoding DATA_BLOCK_ENCODING = DataBlockEncoding.ROW_INDEX_V1;
private static final int ENTRY_COUNT = 100;
@@ -58,7 +55,7 @@ public class TestRowIndexV1RoundTrip {
private Configuration conf;
private FileSystem fs;
- @Before
+ @BeforeEach
public void setUp() throws IOException {
conf = TEST_UTIL.getConfiguration();
conf.setLong(MIN_ALLOCATE_SIZE_KEY, 0);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestScannerFromBucketCache.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestScannerFromBucketCache.java
index a5389c75a8c..33a93e7085f 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestScannerFromBucketCache.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestScannerFromBucketCache.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
@@ -27,7 +27,6 @@ import java.util.List;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.ByteBufferKeyValue;
import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
@@ -47,25 +46,18 @@ import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManagerTestHelper;
-import org.junit.After;
-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.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Category({ RegionServerTests.class, SmallTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(SmallTests.TAG)
public class TestScannerFromBucketCache {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestScannerFromBucketCache.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestScannerFromBucketCache.class);
- @Rule
- public TestName name = new TestName();
HRegion region = null;
private HBaseTestingUtility test_util;
@@ -76,8 +68,8 @@ public class TestScannerFromBucketCache {
// Test names
private TableName tableName;
- private void setUp(boolean useBucketCache) throws IOException {
- test_util = HBaseTestingUtility.createLocalHTU();
+ private void setUp(boolean useBucketCache, TestInfo testInfo) throws IOException {
+ test_util = new HBaseTestingUtility();
conf = test_util.getConfiguration();
if (useBucketCache) {
conf.setInt("hbase.bucketcache.size", 400);
@@ -86,23 +78,23 @@ public class TestScannerFromBucketCache {
conf.setFloat("hfile.block.cache.size", 0.2f);
conf.setFloat("hbase.regionserver.global.memstore.size", 0.1f);
}
- tableName = TableName.valueOf(name.getMethodName());
+ tableName = TableName.valueOf(testInfo.getTestMethod().get().getName());
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
EnvironmentEdgeManagerTestHelper.reset();
LOG.info("Cleaning test directory: " + test_util.getDataTestDir());
test_util.cleanupTestDir();
}
- String getName() {
- return name.getMethodName();
+ String getName(TestInfo testInfo) {
+ return testInfo.getTestMethod().get().getName();
}
@Test
- public void testBasicScanWithLRUCache() throws IOException {
- setUp(false);
+ public void testBasicScanWithLRUCache(TestInfo testInfo) throws IOException {
+ setUp(false, testInfo);
byte[] row1 = Bytes.toBytes("row1");
byte[] qf1 = Bytes.toBytes("qualifier1");
byte[] qf2 = Bytes.toBytes("qualifier2");
@@ -113,7 +105,7 @@ public class TestScannerFromBucketCache {
long ts3 = ts1 + 2;
// Setting up region
- String method = this.getName();
+ String method = this.getName(testInfo);
this.region = initHRegion(tableName, method, conf, test_util, fam1);
try {
List<Cell> expected = insertData(row1, qf1, qf2, fam1, ts1, ts2, ts3, false);
@@ -139,8 +131,8 @@ public class TestScannerFromBucketCache {
}
@Test
- public void testBasicScanWithOffheapBucketCache() throws IOException {
- setUp(true);
+ public void testBasicScanWithOffheapBucketCache(TestInfo testInfo) throws IOException {
+ setUp(true, testInfo);
byte[] row1 = Bytes.toBytes("row1offheap");
byte[] qf1 = Bytes.toBytes("qualifier1");
byte[] qf2 = Bytes.toBytes("qualifier2");
@@ -151,7 +143,7 @@ public class TestScannerFromBucketCache {
long ts3 = ts1 + 2;
// Setting up region
- String method = this.getName();
+ String method = this.getName(testInfo);
this.region = initHRegion(tableName, method, conf, test_util, fam1);
try {
List<Cell> expected = insertData(row1, qf1, qf2, fam1, ts1, ts2, ts3, false);
@@ -180,8 +172,8 @@ public class TestScannerFromBucketCache {
}
@Test
- public void testBasicScanWithOffheapBucketCacheWithMBB() throws IOException {
- setUp(true);
+ public void testBasicScanWithOffheapBucketCacheWithMBB(TestInfo testInfo) throws IOException {
+ setUp(true, testInfo);
byte[] row1 = Bytes.toBytes("row1offheap");
byte[] qf1 = Bytes.toBytes("qualifier1");
byte[] qf2 = Bytes.toBytes("qualifier2");
@@ -192,7 +184,7 @@ public class TestScannerFromBucketCache {
long ts3 = ts1 + 2;
// Setting up region
- String method = this.getName();
+ String method = this.getName(testInfo);
this.region = initHRegion(tableName, method, conf, test_util, fam1);
try {
List<Cell> expected = insertData(row1, qf1, qf2, fam1, ts1, ts2, ts3, true);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestScannerSelectionUsingKeyRange.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestScannerSelectionUsingKeyRange.java
index fa3ecf7a876..f9b0b2224cb 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestScannerSelectionUsingKeyRange.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestScannerSelectionUsingKeyRange.java
@@ -17,18 +17,18 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HRegionInfo;
@@ -42,26 +42,19 @@ import org.apache.hadoop.hbase.regionserver.InternalScanner;
import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.AfterClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Test the optimization that does not scan files where all key ranges are excluded.
*/
-@RunWith(Parameterized.class)
-@Category({ IOTests.class, SmallTests.class })
+@HBaseParameterizedTestTemplate(name = "{0}")
+@org.junit.jupiter.api.Tag(IOTests.TAG)
+@org.junit.jupiter.api.Tag(SmallTests.TAG)
public class TestScannerSelectionUsingKeyRange {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestScannerSelectionUsingKeyRange.class);
-
- private static final HBaseTestingUtility TEST_UTIL = HBaseTestingUtility.createLocalHTU();
+ private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static TableName TABLE = TableName.valueOf("myTable");
private static String FAMILY = "myCF";
private static byte[] FAMILY_BYTES = Bytes.toBytes(FAMILY);
@@ -78,13 +71,12 @@ public class TestScannerSelectionUsingKeyRange {
private BloomType bloomType;
private int expectedCount;
- @Parameters
- public static Collection<Object[]> parameters() {
- List<Object[]> params = new ArrayList<>();
+ public static Stream<Arguments> parameters() {
+ List<Arguments> params = new ArrayList<>();
for (Object type : TYPE_COUNT.keySet()) {
- params.add(new Object[] { type, TYPE_COUNT.get(type) });
+ params.add(Arguments.of(type, TYPE_COUNT.get(type)));
}
- return params;
+ return params.stream();
}
public TestScannerSelectionUsingKeyRange(Object type, Object count) {
@@ -92,12 +84,12 @@ public class TestScannerSelectionUsingKeyRange {
expectedCount = (Integer) count;
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
TEST_UTIL.cleanupTestDir();
}
- @Test
+ @TestTemplate
public void testScannerSelection() throws IOException {
Configuration conf = TEST_UTIL.getConfiguration();
conf.setInt("hbase.hstore.compactionThreshold", 10000);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestScannerSelectionUsingTTL.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestScannerSelectionUsingTTL.java
index 6a9667bd891..612910e21b7 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestScannerSelectionUsingTTL.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestScannerSelectionUsingTTL.java
@@ -17,16 +17,16 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import java.util.Set;
+import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
@@ -43,26 +43,20 @@ import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.Threads;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Test the optimization that does not scan files where all timestamps are expired.
*/
-@RunWith(Parameterized.class)
-@Category({ IOTests.class, LargeTests.class })
+@HBaseParameterizedTestTemplate(name = "numFreshFiles={0}")
+@Tag(IOTests.TAG)
+@Tag(LargeTests.TAG)
public class TestScannerSelectionUsingTTL {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestScannerSelectionUsingTTL.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestScannerSelectionUsingTTL.class);
private static final HBaseTestingUtility TEST_UTIL = HBaseTestingUtility.createLocalHTU();
@@ -79,13 +73,12 @@ public class TestScannerSelectionUsingTTL {
public final int numFreshFiles, totalNumFiles;
- @Parameters
- public static Collection<Object[]> parameters() {
- List<Object[]> params = new ArrayList<>();
+ public static Stream<Arguments> parameters() {
+ List<Arguments> params = new ArrayList<>();
for (int numFreshFiles = 1; numFreshFiles <= 3; ++numFreshFiles) {
- params.add(new Object[] { numFreshFiles });
+ params.add(Arguments.of(numFreshFiles));
}
- return params;
+ return params.stream();
}
public TestScannerSelectionUsingTTL(int numFreshFiles) {
@@ -93,7 +86,7 @@ public class TestScannerSelectionUsingTTL {
this.totalNumFiles = numFreshFiles + NUM_EXPIRED_FILES;
}
- @Test
+ @TestTemplate
public void testScannerSelection() throws IOException {
Configuration conf = TEST_UTIL.getConfiguration();
conf.setBoolean("hbase.store.delete.expired.storefile", false);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestSeekBeforeWithInlineBlocks.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestSeekBeforeWithInlineBlocks.java
index 6fe90105f81..13153f6d053 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestSeekBeforeWithInlineBlocks.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestSeekBeforeWithInlineBlocks.java
@@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-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.Random;
@@ -27,7 +27,6 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
@@ -39,19 +38,15 @@ import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.BloomFilterFactory;
import org.apache.hadoop.hbase.util.BloomFilterUtil;
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;
-@Category({ IOTests.class, MediumTests.class })
+@Tag(IOTests.TAG)
+@Tag(MediumTests.TAG)
public class TestSeekBeforeWithInlineBlocks {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestSeekBeforeWithInlineBlocks.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestSeekBeforeWithInlineBlocks.class);
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
@@ -164,19 +159,19 @@ public class TestSeekBeforeWithInlineBlocks {
}
private void checkSeekBefore(Cell[] cells, HFileScanner scanner, int i) throws IOException {
- assertEquals(
- "Failed to seek to the key before #" + i + " (" + CellUtil.getCellKeyAsString(cells[i]) + ")",
- true, scanner.seekBefore(cells[i]));
+ assertEquals(true, scanner.seekBefore(cells[i]), "Failed to seek to the key before #" + i + " ("
+ + CellUtil.getCellKeyAsString(cells[i]) + ")");
}
private void checkNoSeekBefore(Cell[] cells, HFileScanner scanner, int i) throws IOException {
- assertEquals("Incorrectly succeeded in seeking to before first key ("
- + CellUtil.getCellKeyAsString(cells[i]) + ")", false, scanner.seekBefore(cells[i]));
+ assertEquals(false, scanner.seekBefore(cells[i]),
+ "Incorrectly succeeded in seeking to before first key ("
+ + CellUtil.getCellKeyAsString(cells[i]) + ")");
}
/** Check a key/value pair after it was read by the reader */
private void checkCell(Cell expected, Cell actual) {
- assertTrue(String.format("Expected key %s, but was %s", CellUtil.getCellKeyAsString(expected),
- CellUtil.getCellKeyAsString(actual)), CellUtil.equals(expected, actual));
+ assertTrue(CellUtil.equals(expected, actual), String.format("Expected key %s, but was %s",
+ CellUtil.getCellKeyAsString(expected), CellUtil.getCellKeyAsString(actual)));
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestSeekTo.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestSeekTo.java
index 8ddbd95679e..9eddea90781 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestSeekTo.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestSeekTo.java
@@ -17,15 +17,15 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
@@ -33,7 +33,7 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.ArrayBackedTag;
import org.apache.hadoop.hbase.ByteBufferKeyValue;
import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
@@ -43,34 +43,31 @@ import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
import org.apache.hadoop.hbase.testclassification.IOTests;
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.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Test {@link HFileScanner#seekTo(Cell)} and its variants.
*/
-@Category({ IOTests.class, SmallTests.class })
-@RunWith(Parameterized.class)
+@org.junit.jupiter.api.Tag(IOTests.TAG)
+@org.junit.jupiter.api.Tag(SmallTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: encoding={0}")
public class TestSeekTo {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestSeekTo.class);
+ private static final Logger LOG = LoggerFactory.getLogger(TestSeekTo.class);
private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private final DataBlockEncoding encoding;
- @Parameters
- public static Collection<Object[]> parameters() {
- List<Object[]> paramList = new ArrayList<>();
+ public static Stream<Arguments> parameters() {
+ List<Arguments> paramList = new ArrayList<>();
for (DataBlockEncoding encoding : DataBlockEncoding.values()) {
- paramList.add(new Object[] { encoding });
+ paramList.add(Arguments.of(encoding));
}
- return paramList;
+ return paramList.stream();
}
static boolean switchKVs = false;
@@ -79,7 +76,7 @@ public class TestSeekTo {
this.encoding = encoding;
}
- @Before
+ @BeforeEach
public void setUp() {
// reset
switchKVs = false;
@@ -137,7 +134,7 @@ public class TestSeekTo {
return ncTFile;
}
- @Test
+ @TestTemplate
public void testSeekBefore() throws Exception {
testSeekBeforeInternals(TagUsage.NO_TAG);
testSeekBeforeInternals(TagUsage.ONLY_TAG);
@@ -195,7 +192,7 @@ public class TestSeekTo {
}
}
- @Test
+ @TestTemplate
public void testSeekBeforeWithReSeekTo() throws Exception {
testSeekBeforeWithReSeekToInternals(TagUsage.NO_TAG);
testSeekBeforeWithReSeekToInternals(TagUsage.ONLY_TAG);
@@ -288,7 +285,7 @@ public class TestSeekTo {
deleteTestDir(fs);
}
- @Test
+ @TestTemplate
public void testSeekTo() throws Exception {
testSeekToInternals(TagUsage.NO_TAG);
testSeekToInternals(TagUsage.ONLY_TAG);
@@ -320,7 +317,7 @@ public class TestSeekTo {
deleteTestDir(fs);
}
- @Test
+ @TestTemplate
public void testBlockContainingKey() throws Exception {
testBlockContainingKeyInternals(TagUsage.NO_TAG);
testBlockContainingKeyInternals(TagUsage.ONLY_TAG);
@@ -333,7 +330,7 @@ public class TestSeekTo {
Configuration conf = TEST_UTIL.getConfiguration();
HFile.Reader reader = HFile.createReader(fs, p, new CacheConfig(conf), true, conf);
HFileBlockIndex.BlockIndexReader blockIndexReader = reader.getDataBlockIndexReader();
- System.out.println(blockIndexReader.toString());
+ LOG.info(blockIndexReader.toString());
// falls before the start of the file.
assertEquals(-1, blockIndexReader.rootBlockContainingKey(toKV("a", tagUsage)));
assertEquals(0, blockIndexReader.rootBlockContainingKey(toKV("c", tagUsage)));
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestTinyLfuBlockCache.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestTinyLfuBlockCache.java
index 31166bd5fa4..2e6595fb552 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestTinyLfuBlockCache.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestTinyLfuBlockCache.java
@@ -17,33 +17,28 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.nio.ByteBuffer;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.io.HeapSize;
import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.ClassSize;
-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;
/**
* Tests the concurrent TinyLfuBlockCache.
*/
-@Category({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestTinyLfuBlockCache {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestTinyLfuBlockCache.class);
-
@Test
public void testCacheSimple() throws Exception {
@@ -82,8 +77,8 @@ public class TestTinyLfuBlockCache {
for (CachedItem block : blocks) {
cache.cacheBlock(block.cacheKey, block);
}
- assertEquals("Cache should ignore cache requests for blocks already in cache",
- expectedBlockCount, cache.getBlockCount());
+ assertEquals(expectedBlockCount, cache.getBlockCount(),
+ "Cache should ignore cache requests for blocks already in cache");
// Verify correctly calculated cache heap size
assertEquals(expectedCacheSize, cache.heapSize());
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketCache.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketCache.java
index 203927d5949..f3f6b998acd 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketCache.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketCache.java
@@ -17,12 +17,13 @@
*/
package org.apache.hadoop.hbase.io.hfile.bucket;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-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.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 static org.mockito.Mockito.when;
import java.io.File;
@@ -37,10 +38,11 @@ import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.LongAdder;
import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.io.ByteBuffAllocator;
@@ -62,14 +64,11 @@ import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.hbase.util.Threads;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
import org.mockito.Mockito;
import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap;
@@ -79,29 +78,23 @@ import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap;
* <p>
* Tests will ensure that blocks' data correctness under several threads concurrency
*/
-@RunWith(Parameterized.class)
-@Category({ IOTests.class, LargeTests.class })
+@Tag(IOTests.TAG)
+@Tag(LargeTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: blockSize={0}, bucketSizes={1}")
public class TestBucketCache {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestBucketCache.class);
-
- @Parameterized.Parameters(name = "{index}: blockSize={0}, bucketSizes={1}")
- public static Iterable<Object[]> data() {
- return Arrays.asList(new Object[][] { { 8192, null }, // TODO: why is 8k the default blocksize
- // for these tests?
- { 16 * 1024,
+ public static Stream<Arguments> parameters() {
+ // TODO: why is 8k the default blocksize for these tests?
+ return Stream.of(Arguments.of(8192, null),
+ Arguments.of(16 * 1024,
new int[] { 2 * 1024 + 1024, 4 * 1024 + 1024, 8 * 1024 + 1024, 16 * 1024 + 1024,
28 * 1024 + 1024, 32 * 1024 + 1024, 64 * 1024 + 1024, 96 * 1024 + 1024,
- 128 * 1024 + 1024 } } });
+ 128 * 1024 + 1024 }));
}
- @Parameterized.Parameter(0)
- public int constructedBlockSize;
+ private int constructedBlockSize;
- @Parameterized.Parameter(1)
- public int[] constructedBlockSizes;
+ private int[] constructedBlockSizes;
BucketCache cache;
final int CACHE_SIZE = 1000000;
@@ -137,13 +130,18 @@ public class TestBucketCache {
}
}
- @Before
+ public TestBucketCache(int constructedBlockSize, int[] constructedBlockSizes) {
+ this.constructedBlockSize = constructedBlockSize;
+ this.constructedBlockSizes = constructedBlockSizes;
+ }
+
+ @BeforeEach
public void setup() throws IOException {
cache = new MockedBucketCache(ioEngineName, capacitySize, constructedBlockSize,
constructedBlockSizes, writeThreads, writerQLen, persistencePath);
}
- @After
+ @AfterEach
public void tearDown() {
cache.shutdown();
}
@@ -166,7 +164,7 @@ public class TestBucketCache {
return a.get(ThreadLocalRandom.current().nextInt(a.size()));
}
- @Test
+ @TestTemplate
public void testBucketAllocator() throws BucketAllocatorException {
BucketAllocator mAllocator = cache.getAllocator();
/*
@@ -193,7 +191,7 @@ public class TestBucketCache {
for (Integer blockSize : BLOCKSIZES) {
BucketSizeInfo bucketSizeInfo = mAllocator.roundUpToBucketSizeInfo(blockSize);
IndexStatistics indexStatistics = bucketSizeInfo.statistics();
- assertEquals("unexpected freeCount for " + bucketSizeInfo, 0, indexStatistics.freeCount());
+ assertEquals(0, indexStatistics.freeCount(), "unexpected freeCount for " + bucketSizeInfo);
// we know the block sizes above are multiples of 1024, but default bucket sizes give an
// additional 1024 on top of that so this counts towards fragmentation in our test
@@ -211,17 +209,17 @@ public class TestBucketCache {
assertEquals(0, mAllocator.getUsedSize());
}
- @Test
+ @TestTemplate
public void testCacheSimple() throws Exception {
CacheTestUtils.testCacheSimple(cache, BLOCK_SIZE, NUM_QUERIES);
}
- @Test
+ @TestTemplate
public void testCacheMultiThreadedSingleKey() throws Exception {
CacheTestUtils.hammerSingleKey(cache, 2 * NUM_THREADS, 2 * NUM_QUERIES);
}
- @Test
+ @TestTemplate
public void testHeapSizeChanges() throws Exception {
cache.stopWriterThreads();
CacheTestUtils.testHeapSizeChanges(cache, BLOCK_SIZE);
@@ -250,7 +248,7 @@ public class TestBucketCache {
waitUntilFlushedToBucket(cache, cacheKey);
}
- @Test
+ @TestTemplate
public void testMemoryLeak() throws Exception {
final BlockCacheKey cacheKey = new BlockCacheKey("dummy", 1L);
cacheAndWaitUntilFlushedToBucket(cache, cacheKey,
@@ -292,10 +290,10 @@ public class TestBucketCache {
*/
assertEquals(1L, cache.getBlockCount());
assertTrue(cache.getCurrentSize() > 0L);
- assertTrue("We should have a block!", cache.iterator().hasNext());
+ assertTrue(cache.iterator().hasNext(), "We should have a block!");
}
- @Test
+ @TestTemplate
public void testRetrieveFromFile() throws Exception {
HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
Path testDir = TEST_UTIL.getDataTestDir();
@@ -344,7 +342,7 @@ public class TestBucketCache {
TEST_UTIL.cleanupTestDir();
}
- @Test
+ @TestTemplate
public void testBucketAllocatorLargeBuckets() throws BucketAllocatorException {
long availableSpace = 20 * 1024L * 1024 * 1024;
int[] bucketSizes = new int[] { 1024, 1024 * 1024, 1024 * 1024 * 1024 };
@@ -352,7 +350,7 @@ public class TestBucketCache {
assertTrue(allocator.getBuckets().length > 0);
}
- @Test
+ @TestTemplate
public void testGetPartitionSize() throws IOException {
// Test default values
validateGetPartitionSize(cache, BucketCache.DEFAULT_SINGLE_FACTOR,
@@ -372,7 +370,7 @@ public class TestBucketCache {
validateGetPartitionSize(cache, 0.2f, 0.5f);
}
- @Test
+ @TestTemplate
public void testValidBucketCacheConfigs() throws IOException {
Configuration conf = HBaseConfiguration.create();
conf.setFloat(BucketCache.ACCEPT_FACTOR_CONFIG_NAME, 0.9f);
@@ -385,21 +383,21 @@ public class TestBucketCache {
BucketCache cache = new BucketCache(ioEngineName, capacitySize, constructedBlockSize,
constructedBlockSizes, writeThreads, writerQLen, persistencePath, 100, conf);
- assertEquals(BucketCache.ACCEPT_FACTOR_CONFIG_NAME + " failed to propagate.", 0.9f,
- cache.getAcceptableFactor(), 0);
- assertEquals(BucketCache.MIN_FACTOR_CONFIG_NAME + " failed to propagate.", 0.5f,
- cache.getMinFactor(), 0);
- assertEquals(BucketCache.EXTRA_FREE_FACTOR_CONFIG_NAME + " failed to propagate.", 0.5f,
- cache.getExtraFreeFactor(), 0);
- assertEquals(BucketCache.SINGLE_FACTOR_CONFIG_NAME + " failed to propagate.", 0.1f,
- cache.getSingleFactor(), 0);
- assertEquals(BucketCache.MULTI_FACTOR_CONFIG_NAME + " failed to propagate.", 0.7f,
- cache.getMultiFactor(), 0);
- assertEquals(BucketCache.MEMORY_FACTOR_CONFIG_NAME + " failed to propagate.", 0.2f,
- cache.getMemoryFactor(), 0);
- }
-
- @Test
+ assertEquals(0.9f, cache.getAcceptableFactor(), 0,
+ BucketCache.ACCEPT_FACTOR_CONFIG_NAME + " failed to propagate.");
+ assertEquals(0.5f, cache.getMinFactor(), 0,
+ BucketCache.MIN_FACTOR_CONFIG_NAME + " failed to propagate.");
+ assertEquals(0.5f, cache.getExtraFreeFactor(), 0,
+ BucketCache.EXTRA_FREE_FACTOR_CONFIG_NAME + " failed to propagate.");
+ assertEquals(0.1f, cache.getSingleFactor(), 0,
+ BucketCache.SINGLE_FACTOR_CONFIG_NAME + " failed to propagate.");
+ assertEquals(0.7f, cache.getMultiFactor(), 0,
+ BucketCache.MULTI_FACTOR_CONFIG_NAME + " failed to propagate.");
+ assertEquals(0.2f, cache.getMemoryFactor(), 0,
+ BucketCache.MEMORY_FACTOR_CONFIG_NAME + " failed to propagate.");
+ }
+
+ @TestTemplate
public void testInvalidAcceptFactorConfig() throws IOException {
float[] configValues = { -1f, 0.2f, 0.86f, 1.05f };
boolean[] expectedOutcomes = { false, false, true, false };
@@ -409,7 +407,7 @@ public class TestBucketCache {
checkConfigValues(conf, configMappings, expectedOutcomes);
}
- @Test
+ @TestTemplate
public void testInvalidMinFactorConfig() throws IOException {
float[] configValues = { -1f, 0f, 0.96f, 1.05f };
// throws due to <0, in expected range, minFactor > acceptableFactor, > 1.0
@@ -420,7 +418,7 @@ public class TestBucketCache {
checkConfigValues(conf, configMappings, expectedOutcomes);
}
- @Test
+ @TestTemplate
public void testInvalidExtraFreeFactorConfig() throws IOException {
float[] configValues = { -1f, 0f, 0.2f, 1.05f };
// throws due to <0, in expected range, in expected range, config can be > 1.0
@@ -431,7 +429,7 @@ public class TestBucketCache {
checkConfigValues(conf, configMappings, expectedOutcomes);
}
- @Test
+ @TestTemplate
public void testInvalidCacheSplitFactorConfig() throws IOException {
float[] singleFactorConfigValues = { 0.2f, 0f, -0.2f, 1f };
float[] multiFactorConfigValues = { 0.4f, 0f, 1f, .05f };
@@ -457,11 +455,11 @@ public class TestBucketCache {
}
BucketCache cache = new BucketCache(ioEngineName, capacitySize, constructedBlockSize,
constructedBlockSizes, writeThreads, writerQLen, persistencePath, 100, conf);
- assertTrue("Created BucketCache and expected it to succeed: " + expectSuccess[i]
- + ", but it actually was: " + !expectSuccess[i], expectSuccess[i]);
+ assertTrue(expectSuccess[i], "Created BucketCache and expected it to succeed: "
+ + expectSuccess[i] + ", but it actually was: " + !expectSuccess[i]);
} catch (IllegalArgumentException e) {
- assertFalse("Created BucketCache and expected it to succeed: " + expectSuccess[i]
- + ", but it actually was: " + !expectSuccess[i], expectSuccess[i]);
+ assertFalse(expectSuccess[i], "Created BucketCache and expected it to succeed: "
+ + expectSuccess[i] + ", but it actually was: " + !expectSuccess[i]);
}
}
}
@@ -473,7 +471,7 @@ public class TestBucketCache {
assertEquals(expectedOutput, bucketCache.getPartitionSize(partitionFactor));
}
- @Test
+ @TestTemplate
public void testOffsetProducesPositiveOutput() {
// This number is picked because it produces negative output if the values isn't ensured to be
// positive. See HBASE-18757 for more information.
@@ -484,7 +482,7 @@ public class TestBucketCache {
assertEquals(testValue, bucketEntry.offset());
}
- @Test
+ @TestTemplate
public void testEvictionCount() throws InterruptedException {
int size = 100;
int length = HConstants.HFILEBLOCK_HEADER_SIZE + size;
@@ -534,7 +532,7 @@ public class TestBucketCache {
assertEquals(1, cache.getStats().getEvictionCount());
}
- @Test
+ @TestTemplate
public void testCacheBlockNextBlockMetadataMissing() throws Exception {
int size = 100;
int length = HConstants.HFILEBLOCK_HEADER_SIZE + size;
@@ -592,7 +590,7 @@ public class TestBucketCache {
assertEquals(1, blockWithoutNextBlockMetadata.getBufferReadOnly().refCnt());
}
- @Test
+ @TestTemplate
public void testRAMCache() {
int size = 100;
int length = HConstants.HFILEBLOCK_HEADER_SIZE + size;
@@ -631,7 +629,7 @@ public class TestBucketCache {
assertEquals(1, ((HFileBlock) re2.getData()).getBufferReadOnly().refCnt());
}
- @Test
+ @TestTemplate
public void testFreeBlockWhenIOEngineWriteFailure() throws IOException {
// initialize an block.
int size = 100, offset = 20;
@@ -657,14 +655,14 @@ public class TestBucketCache {
BlockCacheKey key = new BlockCacheKey("dummy", 1L);
RAMQueueEntry re = new RAMQueueEntry(key, block, 1, true);
- Assert.assertEquals(0, allocator.getUsedSize());
+ assertEquals(0, allocator.getUsedSize());
try {
re.writeToCache(ioEngine, allocator, null, null,
ByteBuffer.allocate(HFileBlock.BLOCK_METADATA_SPACE));
- Assert.fail();
+ fail();
} catch (Exception e) {
}
- Assert.assertEquals(0, allocator.getUsedSize());
+ assertEquals(0, allocator.getUsedSize());
}
/**
@@ -672,7 +670,7 @@ public class TestBucketCache {
* could not be freed even if corresponding {@link HFileBlock} is evicted from
* {@link BucketCache}.
*/
- @Test
+ @TestTemplate
public void testFreeBucketEntryRestoredFromFile() throws Exception {
try {
final Path dataTestDir = createAndGetTestDir();
@@ -719,7 +717,7 @@ public class TestBucketCache {
}
}
- @Test
+ @TestTemplate
public void testBlockAdditionWaitWhenCache() throws Exception {
try {
final Path dataTestDir = createAndGetTestDir();
@@ -774,7 +772,7 @@ public class TestBucketCache {
}
}
- @Test
+ @TestTemplate
public void testIOTimePerHitReturnsZeroWhenNoHits()
throws NoSuchFieldException, IllegalAccessException {
CacheStats cacheStats = cache.getStats();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketCacheRefCnt.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketCacheRefCnt.java
index e71817e6a3f..18eab24a1c2 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketCacheRefCnt.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketCacheRefCnt.java
@@ -17,11 +17,11 @@
*/
package org.apache.hadoop.hbase.io.hfile.bucket;
-import static org.junit.Assert.assertEquals;
-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.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.nio.ByteBuffer;
@@ -30,7 +30,6 @@ import java.util.List;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.io.ByteBuffAllocator;
import org.apache.hadoop.hbase.io.hfile.BlockCacheKey;
@@ -45,17 +44,13 @@ import org.apache.hadoop.hbase.nio.ByteBuff;
import org.apache.hadoop.hbase.nio.RefCnt;
import org.apache.hadoop.hbase.testclassification.IOTests;
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;
-@Category({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestBucketCacheRefCnt {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestBucketCacheRefCnt.class);
-
private static final String IO_ENGINE = "offheap";
private static final long CAPACITY_SIZE = 32 * 1024 * 1024;
private static final int BLOCK_SIZE = 1024;
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketWriterThread.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketWriterThread.java
index f20dedda8e7..39f08a8cb51 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketWriterThread.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketWriterThread.java
@@ -19,15 +19,14 @@ package org.apache.hadoop.hbase.io.hfile.bucket;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-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.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.io.hfile.BlockCacheKey;
import org.apache.hadoop.hbase.io.hfile.Cacheable;
@@ -35,20 +34,16 @@ import org.apache.hadoop.hbase.io.hfile.HFileBlock;
import org.apache.hadoop.hbase.io.hfile.bucket.BucketCache.RAMQueueEntry;
import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-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.mockito.Mockito;
-@Category({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestBucketWriterThread {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestBucketWriterThread.class);
-
private BucketCache bc;
private BucketCache.WriterThread wt;
private BlockingQueue<RAMQueueEntry> q;
@@ -75,7 +70,7 @@ public class TestBucketWriterThread {
* Set up variables and get BucketCache and WriterThread into state where tests can manually
* control the running of WriterThread and BucketCache is empty.
*/
- @Before
+ @BeforeEach
public void setUp() throws Exception {
// Arbitrary capacity.
final int capacity = 16;
@@ -98,7 +93,7 @@ public class TestBucketWriterThread {
assertTrue(q.isEmpty());
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
if (this.bc != null) this.bc.shutdown();
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestByteBufferIOEngine.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestByteBufferIOEngine.java
index 820e91aa6e8..8ad0afd50c7 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestByteBufferIOEngine.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestByteBufferIOEngine.java
@@ -17,9 +17,10 @@
*/
package org.apache.hadoop.hbase.io.hfile.bucket;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
import java.io.IOException;
import java.nio.ByteBuffer;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.io.ByteBuffAllocator;
import org.apache.hadoop.hbase.io.hfile.Cacheable;
import org.apache.hadoop.hbase.io.hfile.CacheableDeserializer;
@@ -27,21 +28,16 @@ import org.apache.hadoop.hbase.io.hfile.CacheableDeserializerIdManager;
import org.apache.hadoop.hbase.nio.ByteBuff;
import org.apache.hadoop.hbase.testclassification.IOTests;
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;
/**
* Basic test for {@link ByteBufferIOEngine}
*/
-@Category({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestByteBufferIOEngine {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestByteBufferIOEngine.class);
-
/**
* Override the {@link BucketEntry} so that we can set an arbitrary offset.
*/
@@ -114,10 +110,10 @@ public class TestByteBufferIOEngine {
BucketEntry be = createBucketEntry(offset, blockSize);
ioEngine.read(be);
ByteBuff dst = getByteBuff(be);
- Assert.assertEquals(src.remaining(), blockSize);
- Assert.assertEquals(dst.remaining(), blockSize);
- Assert.assertEquals(0, ByteBuff.compareTo(src, src.position(), src.remaining(), dst,
- dst.position(), dst.remaining()));
+ assertEquals(src.remaining(), blockSize);
+ assertEquals(dst.remaining(), blockSize);
+ assertEquals(0, ByteBuff.compareTo(src, src.position(), src.remaining(), dst, dst.position(),
+ dst.remaining()));
}
assert testOffsetAtStartNum == 0;
assert testOffsetAtEndNum == 0;
@@ -189,10 +185,10 @@ public class TestByteBufferIOEngine {
BucketEntry be = createBucketEntry(offset, blockSize);
ioEngine.read(be);
ByteBuff dst = getByteBuff(be);
- Assert.assertEquals(src.remaining(), blockSize);
- Assert.assertEquals(dst.remaining(), blockSize);
- Assert.assertEquals(0, ByteBuff.compareTo(src, src.position(), src.remaining(), dst,
- dst.position(), dst.remaining()));
+ assertEquals(src.remaining(), blockSize);
+ assertEquals(dst.remaining(), blockSize);
+ assertEquals(0, ByteBuff.compareTo(src, src.position(), src.remaining(), dst, dst.position(),
+ dst.remaining()));
}
assert testOffsetAtStartNum == 0;
assert testOffsetAtEndNum == 0;
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestExclusiveMemoryMmapEngine.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestExclusiveMemoryMmapEngine.java
index 8cde8c6347d..dbd7ab047cf 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestExclusiveMemoryMmapEngine.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestExclusiveMemoryMmapEngine.java
@@ -19,28 +19,23 @@ package org.apache.hadoop.hbase.io.hfile.bucket;
import static org.apache.hadoop.hbase.io.hfile.bucket.TestByteBufferIOEngine.createBucketEntry;
import static org.apache.hadoop.hbase.io.hfile.bucket.TestByteBufferIOEngine.getByteBuff;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.File;
import java.io.IOException;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.nio.ByteBuff;
import org.apache.hadoop.hbase.testclassification.IOTests;
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;
/**
* Basic test for {@link ExclusiveMemoryMmapIOEngine}
*/
-@Category({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestExclusiveMemoryMmapEngine {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestExclusiveMemoryMmapEngine.class);
-
@Test
public void testFileMmapEngine() throws IOException {
int size = 2 * 1024 * 1024; // 2 MB
@@ -63,10 +58,9 @@ public class TestExclusiveMemoryMmapEngine {
fileMmapEngine.read(be);
ByteBuff dst = getByteBuff(be);
- Assert.assertEquals(src.remaining(), len);
- Assert.assertEquals(dst.remaining(), len);
- Assert.assertEquals(0,
- ByteBuff.compareTo(src, pos, len, dst, dst.position(), dst.remaining()));
+ assertEquals(src.remaining(), len);
+ assertEquals(dst.remaining(), len);
+ assertEquals(0, ByteBuff.compareTo(src, pos, len, dst, dst.position(), dst.remaining()));
}
} finally {
File file = new File(filePath);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestFileIOEngine.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestFileIOEngine.java
index af70c61c12c..f19d13d8490 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestFileIOEngine.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestFileIOEngine.java
@@ -19,11 +19,11 @@ package org.apache.hadoop.hbase.io.hfile.bucket;
import static org.apache.hadoop.hbase.io.hfile.bucket.TestByteBufferIOEngine.createBucketEntry;
import static org.apache.hadoop.hbase.io.hfile.bucket.TestByteBufferIOEngine.getByteBuff;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.io.IOException;
@@ -31,18 +31,15 @@ import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.List;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.io.ByteBuffAllocator;
import org.apache.hadoop.hbase.nio.ByteBuff;
import org.apache.hadoop.hbase.nio.RefCnt;
import org.apache.hadoop.hbase.testclassification.IOTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.After;
-import org.junit.Assert;
-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.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -50,13 +47,10 @@ import org.mockito.stubbing.Answer;
/**
* Basic test for {@link FileIOEngine}
*/
-@Category({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestFileIOEngine {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestFileIOEngine.class);
-
private static final long TOTAL_CAPACITY = 6 * 1024 * 1024; // 6 MB
private static final String[] FILE_PATHS =
{ "testFileIOEngine1", "testFileIOEngine2", "testFileIOEngine3" };
@@ -81,12 +75,12 @@ public class TestFileIOEngine {
boundaryStopPositions.add(SIZE_PER_FILE * FILE_PATHS.length - 1);
}
- @Before
+ @BeforeEach
public void setUp() throws IOException {
fileIOEngine = new FileIOEngine(TOTAL_CAPACITY, false, FILE_PATHS);
}
- @After
+ @AfterEach
public void cleanUp() {
fileIOEngine.shutdown();
for (String filePath : FILE_PATHS) {
@@ -177,10 +171,9 @@ public class TestFileIOEngine {
fileIOEngine.read(be);
ByteBuff dst = getByteBuff(be);
- Assert.assertEquals(src.remaining(), len);
- Assert.assertEquals(dst.remaining(), len);
- Assert.assertEquals(0,
- ByteBuff.compareTo(src, pos, len, dst, dst.position(), dst.remaining()));
+ assertEquals(src.remaining(), len);
+ assertEquals(dst.remaining(), len);
+ assertEquals(0, ByteBuff.compareTo(src, pos, len, dst, dst.position(), dst.remaining()));
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestRAMCache.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestRAMCache.java
index 0e777a4a7b9..fdaa25ee091 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestRAMCache.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestRAMCache.java
@@ -17,10 +17,14 @@
*/
package org.apache.hadoop.hbase.io.hfile.bucket;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.nio.ByteBuffer;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.io.ByteBuffAllocator;
import org.apache.hadoop.hbase.io.hfile.BlockCacheKey;
@@ -33,21 +37,16 @@ import org.apache.hadoop.hbase.io.hfile.bucket.BucketCache.RAMQueueEntry;
import org.apache.hadoop.hbase.nio.ByteBuff;
import org.apache.hadoop.hbase.testclassification.IOTests;
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({ IOTests.class, SmallTests.class })
+@Tag(IOTests.TAG)
+@Tag(SmallTests.TAG)
public class TestRAMCache {
private static final Logger LOG = LoggerFactory.getLogger(TestRAMCache.class);
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestRAMCache.class);
-
// Define a mock HFileBlock.
private static class MockHFileBlock extends HFileBlock {
@@ -92,8 +91,8 @@ public class TestRAMCache {
new HFileContextBuilder().build(), ByteBuffAllocator.HEAP);
RAMQueueEntry re = new RAMQueueEntry(key, blk, 1, false);
- Assert.assertNull(cache.putIfAbsent(key, re));
- Assert.assertEquals(cache.putIfAbsent(key, re), re);
+ assertNull(cache.putIfAbsent(key, re));
+ assertEquals(cache.putIfAbsent(key, re), re);
CountDownLatch latch = new CountDownLatch(1);
blk.setLatch(latch);
@@ -116,11 +115,11 @@ public class TestRAMCache {
});
t2.start();
Thread.sleep(200);
- Assert.assertFalse(removed.get());
+ assertFalse(removed.get());
latch.countDown();
Thread.sleep(200);
- Assert.assertTrue(removed.get());
- Assert.assertFalse(error.get());
+ assertTrue(removed.get());
+ assertFalse(error.get());
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestVerifyBucketCacheFile.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestVerifyBucketCacheFile.java
index 60cab9c82df..d871eb4c53f 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestVerifyBucketCacheFile.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestVerifyBucketCacheFile.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.io.hfile.bucket;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
@@ -28,49 +28,48 @@ import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.attribute.FileTime;
import java.time.Instant;
-import java.util.Arrays;
+import java.util.stream.Stream;
import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.io.hfile.BlockCacheKey;
import org.apache.hadoop.hbase.io.hfile.CacheTestUtils;
import org.apache.hadoop.hbase.io.hfile.Cacheable;
-import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.apache.hadoop.hbase.testclassification.IOTests;
+import org.apache.hadoop.hbase.testclassification.LargeTests;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Basic test for check file's integrity before start BucketCache in fileIOEngine
*/
-@RunWith(Parameterized.class)
-@Category(SmallTests.class)
+@Tag(IOTests.TAG)
+@Tag(LargeTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: blockSize={0}, bucketSizes={1}")
public class TestVerifyBucketCacheFile {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestVerifyBucketCacheFile.class);
-
- @Parameterized.Parameters(name = "{index}: blockSize={0}, bucketSizes={1}")
- public static Iterable<Object[]> data() {
- return Arrays.asList(new Object[][] { { 8192, null },
- { 16 * 1024,
+
+ public static Stream<Arguments> parameters() {
+ return Stream.of(Arguments.of(8192, null),
+ Arguments.of(16 * 1024,
new int[] { 2 * 1024 + 1024, 4 * 1024 + 1024, 8 * 1024 + 1024, 16 * 1024 + 1024,
28 * 1024 + 1024, 32 * 1024 + 1024, 64 * 1024 + 1024, 96 * 1024 + 1024,
- 128 * 1024 + 1024 } } });
+ 128 * 1024 + 1024 }));
}
- @Parameterized.Parameter(0)
- public int constructedBlockSize;
+ private int constructedBlockSize;
- @Parameterized.Parameter(1)
- public int[] constructedBlockSizes;
+ private int[] constructedBlockSizes;
final long capacitySize = 32 * 1024 * 1024;
final int writeThreads = BucketCache.DEFAULT_WRITER_THREADS;
final int writerQLen = BucketCache.DEFAULT_WRITER_QUEUE_ITEMS;
+ public TestVerifyBucketCacheFile(int constructedBlockSize, int[] constructedBlockSizes) {
+ this.constructedBlockSize = constructedBlockSize;
+ this.constructedBlockSizes = constructedBlockSizes;
+ }
+
/**
* Test cache file or persistence file does not exist whether BucketCache starts normally (1)
* Start BucketCache and add some blocks, then shutdown BucketCache and persist cache to file.
@@ -81,7 +80,7 @@ public class TestVerifyBucketCacheFile {
* cache file and persistence file would be deleted before BucketCache start normally.
* @throws Exception the exception
*/
- @Test
+ @TestTemplate
public void testRetrieveFromFile() throws Exception {
HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
Path testDir = TEST_UTIL.getDataTestDir();
@@ -150,7 +149,7 @@ public class TestVerifyBucketCacheFile {
* persistence file would be deleted before BucketCache start normally.
* @throws Exception the exception
*/
- @Test
+ @TestTemplate
public void testModifiedBucketCacheFileData() throws Exception {
HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
Path testDir = TEST_UTIL.getDataTestDir();
@@ -197,7 +196,7 @@ public class TestVerifyBucketCacheFile {
* BucketCache start normally.
* @throws Exception the exception
*/
- @Test
+ @TestTemplate
public void testModifiedBucketCacheFileTime() throws Exception {
HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
Path testDir = TEST_UTIL.getDataTestDir();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestMiniClusterLoadEncoded.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestMiniClusterLoadEncoded.java
index c45e396fc91..f27f8ece682 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestMiniClusterLoadEncoded.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestMiniClusterLoadEncoded.java
@@ -18,38 +18,34 @@
package org.apache.hadoop.hbase.util;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import java.util.stream.Stream;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.testclassification.MiscTests;
-import org.junit.ClassRule;
-import org.junit.experimental.categories.Category;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Runs a load test on a mini HBase cluster with data block encoding turned on. Compared to other
* load-test-style unit tests, this one writes a smaller amount of data, but goes through all
* available data block encoding algorithms.
*/
-@Category({ MiscTests.class, LargeTests.class })
+@Tag(MiscTests.TAG)
+@Tag(LargeTests.TAG)
+@HBaseParameterizedTestTemplate
public class TestMiniClusterLoadEncoded extends TestMiniClusterLoadParallel {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestMiniClusterLoadEncoded.class);
-
/** We do not alternate the multi-put flag in this test. */
private static final boolean USE_MULTI_PUT = true;
- @Parameters
- public static Collection<Object[]> parameters() {
- List<Object[]> parameters = new ArrayList<>();
+ public static Stream<Arguments> parameters() {
+ List<Arguments> params = new ArrayList<>();
for (DataBlockEncoding dataBlockEncoding : DataBlockEncoding.values()) {
- parameters.add(new Object[] { dataBlockEncoding });
+ params.add(Arguments.of(dataBlockEncoding));
}
- return parameters;
+ return params.stream();
}
public TestMiniClusterLoadEncoded(DataBlockEncoding encoding) {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestMiniClusterLoadParallel.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestMiniClusterLoadParallel.java
index e5136a1ffd4..b655b280e1d 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestMiniClusterLoadParallel.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestMiniClusterLoadParallel.java
@@ -17,36 +17,36 @@
*/
package org.apache.hadoop.hbase.util;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import java.util.stream.Stream;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.testclassification.MiscTests;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
/**
* A write/read/verify load test on a mini HBase cluster. Tests reading and writing at the same
* time.
*/
-@Category({ MiscTests.class, LargeTests.class })
-@RunWith(Parameterized.class)
+@Tag(MiscTests.TAG)
+@Tag(LargeTests.TAG)
+@HBaseParameterizedTestTemplate
public class TestMiniClusterLoadParallel extends TestMiniClusterLoadSequential {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestMiniClusterLoadParallel.class);
+ public static Stream<Arguments> parameters() {
+ return TestMiniClusterLoadSequential.parameters();
+ }
public TestMiniClusterLoadParallel(boolean isMultiPut, DataBlockEncoding encoding) {
super(isMultiPut, encoding);
}
@Override
- @Test
+ @TestTemplate
public void loadTest() throws Exception {
prepareForLoadTest();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestMiniClusterLoadSequential.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestMiniClusterLoadSequential.java
index 6fd4b4111b2..6bfa039ced2 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestMiniClusterLoadSequential.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestMiniClusterLoadSequential.java
@@ -17,50 +17,46 @@
*/
package org.apache.hadoop.hbase.util;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.EnumSet;
import java.util.List;
+import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.ClusterMetrics.Option;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.HBaseTestingUtility;
-import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
-import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.client.Admin;
+import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
+import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
+import org.apache.hadoop.hbase.client.TableDescriptor;
+import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.io.compress.Compression;
import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.util.test.LoadTestDataGenerator;
-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.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A write/read/verify load test on a mini HBase cluster. Tests reading and then writing.
*/
-@Category({ MiscTests.class, LargeTests.class })
-@RunWith(Parameterized.class)
+@Tag(MiscTests.TAG)
+@Tag(LargeTests.TAG)
+@HBaseParameterizedTestTemplate
public class TestMiniClusterLoadSequential {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestMiniClusterLoadSequential.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestMiniClusterLoadSequential.class);
protected static final TableName TABLE = TableName.valueOf("load_test_tbl");
@@ -89,25 +85,24 @@ public class TestMiniClusterLoadSequential {
conf.setFloat(HConstants.LOAD_BALANCER_SLOP_KEY, 10.0f);
}
- @Parameters
- public static Collection<Object[]> parameters() {
- List<Object[]> parameters = new ArrayList<>();
+ public static Stream<Arguments> parameters() {
+ List<Arguments> params = new ArrayList<>();
for (boolean multiPut : new boolean[] { false, true }) {
for (DataBlockEncoding dataBlockEncoding : new DataBlockEncoding[] { DataBlockEncoding.NONE,
DataBlockEncoding.PREFIX }) {
- parameters.add(new Object[] { multiPut, dataBlockEncoding });
+ params.add(Arguments.of(multiPut, dataBlockEncoding));
}
}
- return parameters;
+ return params.stream();
}
- @Before
+ @BeforeEach
public void setUp() throws Exception {
LOG.debug("Test setup: isMultiPut=" + isMultiPut);
TEST_UTIL.startMiniCluster(NUM_RS);
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
LOG.debug("Test teardown: isMultiPut=" + isMultiPut);
TEST_UTIL.shutdownMiniCluster();
@@ -126,7 +121,7 @@ public class TestMiniClusterLoadSequential {
return writer;
}
- @Test
+ @TestTemplate
public void loadTest() throws Exception {
prepareForLoadTest();
runLoadTestOnExistingTable();
@@ -144,10 +139,10 @@ public class TestMiniClusterLoadSequential {
assertEquals(numKeys, readerThreads.getNumKeysVerified());
}
- protected void createPreSplitLoadTestTable(HTableDescriptor htd, HColumnDescriptor hcd)
- throws IOException {
- HBaseTestingUtility.createPreSplitLoadTestTable(conf, htd, hcd);
- TEST_UTIL.waitUntilAllRegionsAssigned(htd.getTableName());
+ protected void createPreSplitLoadTestTable(TableDescriptor tableDescriptor,
+ ColumnFamilyDescriptor familyDescriptor) throws IOException {
+ HBaseTestingUtility.createPreSplitLoadTestTable(conf, tableDescriptor, familyDescriptor);
+ TEST_UTIL.waitUntilAllRegionsAssigned(tableDescriptor.getTableName());
}
protected void prepareForLoadTest() throws IOException {
@@ -164,10 +159,10 @@ public class TestMiniClusterLoadSequential {
}
admin.close();
- HTableDescriptor htd = new HTableDescriptor(TABLE);
- HColumnDescriptor hcd = new HColumnDescriptor(CF).setCompressionType(compression)
- .setDataBlockEncoding(dataBlockEncoding);
- createPreSplitLoadTestTable(htd, hcd);
+ TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(TABLE).build();
+ ColumnFamilyDescriptor familyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(CF)
+ .setCompressionType(compression).setDataBlockEncoding(dataBlockEncoding).build();
+ createPreSplitLoadTestTable(tableDescriptor, familyDescriptor);
LoadTestDataGenerator dataGen = new MultiThreadedAction.DefaultDataGenerator(CF);
writerThreads = prepareWriterThreads(dataGen, conf, TABLE);
@@ -178,9 +173,9 @@ public class TestMiniClusterLoadSequential {
return 1000;
}
- protected HColumnDescriptor getColumnDesc(Admin admin)
+ protected ColumnFamilyDescriptor getColumnDesc(Admin admin)
throws TableNotFoundException, IOException {
- return admin.getTableDescriptor(TABLE).getFamily(CF);
+ return admin.getDescriptor(TABLE).getColumnFamily(CF);
}
}