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/19 01:48:09 UTC
(hbase) branch branch-2 updated: HBASE-30153 Upgrade hbase-common to junit5 (#8219) (#8249)
This is an automated email from the ASF dual-hosted git repository.
Apache9 pushed a commit to branch branch-2
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2 by this push:
new 228f9a20bf9 HBASE-30153 Upgrade hbase-common to junit5 (#8219) (#8249)
228f9a20bf9 is described below
commit 228f9a20bf96656fe2d8286df2a0cb9279b68321
Author: Duo Zhang <zh...@apache.org>
AuthorDate: Tue May 19 09:48:02 2026 +0800
HBASE-30153 Upgrade hbase-common to junit5 (#8219) (#8249)
(cherry picked from commit 5c74212f24a290d2a19580829d705dbb8fc9bf2e)
Signed-off-by: Xiao Liu <li...@apache.org>
---
hbase-common/pom.xml | 5 +
.../hbase/TestBuildThreadDiagnosticString.java | 6 +-
.../hadoop/hbase/TestByteBufferKeyValue.java | 17 +-
.../org/apache/hadoop/hbase/TestCellBuilder.java | 16 +-
.../apache/hadoop/hbase/TestCellComparator.java | 19 +-
.../java/org/apache/hadoop/hbase/TestCellUtil.java | 118 +++---
.../org/apache/hadoop/hbase/TestChoreService.java | 103 +++---
.../org/apache/hadoop/hbase/TestClassFinder.java | 72 ++--
.../hadoop/hbase/TestCompoundConfiguration.java | 30 +-
.../hadoop/hbase/TestHBaseConfiguration.java | 29 +-
.../hadoop/hbase/TestIndividualBytesFieldCell.java | 83 +++--
.../java/org/apache/hadoop/hbase/TestKeyValue.java | 27 +-
.../org/apache/hadoop/hbase/TestServerName.java | 22 +-
.../org/apache/hadoop/hbase/TestStorageSize.java | 14 +-
.../apache/hadoop/hbase/TestSystemExitInTest.java | 18 +-
.../org/apache/hadoop/hbase/TestTableName.java | 19 +-
.../org/apache/hadoop/hbase/TestTagBuilder.java | 17 +-
.../java/org/apache/hadoop/hbase/TestTagUtil.java | 13 +-
.../java/org/apache/hadoop/hbase/TestTimeout.java | 17 +-
.../test/java/org/apache/hadoop/hbase/Waiter.java | 2 +-
.../apache/hadoop/hbase/codec/TestCellCodec.java | 19 +-
.../hadoop/hbase/codec/TestCellCodecWithTags.java | 18 +-
.../hadoop/hbase/codec/TestKeyValueCodec.java | 19 +-
.../hbase/codec/TestKeyValueCodecWithTags.java | 18 +-
.../apache/hadoop/hbase/conf/TestConfigKey.java | 14 +-
.../hbase/conf/TestConfigurationManager.java | 17 +-
.../hadoop/hbase/io/TestByteBuffAllocator.java | 57 ++-
.../io/TestByteBuffAllocatorLeakDetection.java | 17 +-
.../hbase/io/TestByteBufferListOutputStream.java | 17 +-
.../hadoop/hbase/io/TestFileChangeWatcher.java | 12 +-
.../hbase/io/TestMultiByteBuffInputStream.java | 15 +-
.../hadoop/hbase/io/TestTagCompressionContext.java | 14 +-
.../hbase/io/compress/CompressionTestBase.java | 11 +-
.../hadoop/hbase/io/compress/TestCodecPool.java | 59 ++-
.../hadoop/hbase/io/crypto/TestCipherProvider.java | 19 +-
.../hadoop/hbase/io/crypto/TestEncryption.java | 22 +-
.../hadoop/hbase/io/crypto/TestKeyProvider.java | 33 +-
.../hbase/io/crypto/TestKeyStoreKeyProvider.java | 31 +-
.../apache/hadoop/hbase/io/crypto/aes/TestAES.java | 26 +-
.../hadoop/hbase/io/crypto/aes/TestCommonsAES.java | 27 +-
.../crypto/tls/AbstractTestX509Parameterized.java | 52 ++-
.../hbase/io/crypto/tls/TestBCFKSFileLoader.java | 117 +++---
.../tls/TestFileKeyStoreLoaderBuilderProvider.java | 29 +-
.../io/crypto/tls/TestHBaseHostnameVerifier.java | 30 +-
.../hbase/io/crypto/tls/TestHBaseTrustManager.java | 33 +-
.../hbase/io/crypto/tls/TestJKSFileLoader.java | 118 +++---
.../hbase/io/crypto/tls/TestKeyStoreFileType.java | 97 +++--
.../hbase/io/crypto/tls/TestPEMFileLoader.java | 98 ++---
.../hbase/io/crypto/tls/TestPKCS12FileLoader.java | 118 +++---
.../hadoop/hbase/io/crypto/tls/TestX509Util.java | 154 ++++----
.../hadoopbackport/TestThrottledInputStream.java | 15 +-
.../hadoop/hbase/io/util/TestLRUDictionary.java | 56 ++-
.../apache/hadoop/hbase/logging/TestJul2Slf4j.java | 22 +-
.../hadoop/hbase/logging/TestLog4jUtils.java | 16 +-
.../apache/hadoop/hbase/net/BoundSocketMaker.java | 4 -
.../org/apache/hadoop/hbase/net/TestAddress.java | 15 +-
.../apache/hadoop/hbase/nio/TestMultiByteBuff.java | 23 +-
.../hadoop/hbase/nio/TestSingleByteBuff.java | 15 +-
.../hadoop/hbase/types/TestCopyOnWriteMaps.java | 28 +-
.../hadoop/hbase/types/TestFixedLengthWrapper.java | 40 +-
.../apache/hadoop/hbase/types/TestOrderedBlob.java | 22 +-
.../hadoop/hbase/types/TestOrderedBlobVar.java | 22 +-
.../hadoop/hbase/types/TestOrderedString.java | 22 +-
.../apache/hadoop/hbase/types/TestRawString.java | 22 +-
.../org/apache/hadoop/hbase/types/TestStruct.java | 60 ++-
.../hbase/types/TestStructNullExtension.java | 98 +++--
.../hadoop/hbase/types/TestTerminatedWrapper.java | 38 +-
.../org/apache/hadoop/hbase/types/TestUnion2.java | 14 +-
.../hadoop/hbase/util/AbstractHBaseToolTest.java | 19 +-
.../hadoop/hbase/util/ByteBufferUtilsTestBase.java | 4 +-
.../hadoop/hbase/util/ClassLoaderTestHelper.java | 55 ++-
.../org/apache/hadoop/hbase/util/TestAvlUtil.java | 23 +-
.../hadoop/hbase/util/TestByteBufferArray.java | 21 +-
.../hadoop/hbase/util/TestByteBufferUtils.java | 5 +
.../hbase/util/TestByteBufferUtilsWoUnsafe.java | 9 +-
.../hadoop/hbase/util/TestByteRangeUtils.java | 18 +-
.../util/TestByteRangeWithKVSerialization.java | 24 +-
.../org/apache/hadoop/hbase/util/TestClasses.java | 23 +-
.../hadoop/hbase/util/TestCommonFSUtils.java | 30 +-
.../hadoop/hbase/util/TestConcatenatedLists.java | 72 +---
.../hbase/util/TestCoprocessorClassLoader.java | 36 +-
.../org/apache/hadoop/hbase/util/TestCounter.java | 20 +-
.../hadoop/hbase/util/TestDynamicClassLoader.java | 27 +-
.../hbase/util/TestEnvironmentEdgeManager.java | 21 +-
.../hadoop/hbase/util/TestFastStringPool.java | 2 +
.../apache/hadoop/hbase/util/TestFutureUtils.java | 68 ++--
.../org/apache/hadoop/hbase/util/TestGsonUtil.java | 15 +-
.../apache/hadoop/hbase/util/TestJRubyFormat.java | 16 +-
.../apache/hadoop/hbase/util/TestKeyLocker.java | 42 +--
.../hadoop/hbase/util/TestLoadTestKVGenerator.java | 17 +-
.../hadoop/hbase/util/TestMovingAverage.java | 73 ++--
.../org/apache/hadoop/hbase/util/TestOrder.java | 14 +-
.../apache/hadoop/hbase/util/TestOrderedBytes.java | 411 ++++++++++-----------
.../hadoop/hbase/util/TestReservoirSample.java | 19 +-
.../apache/hadoop/hbase/util/TestRetryCounter.java | 14 +-
.../hadoop/hbase/util/TestShowProperties.java | 13 +-
.../hadoop/hbase/util/TestSimpleKdcServerUtil.java | 12 +-
.../hbase/util/TestSimpleMutableByteRange.java | 78 ++--
.../util/TestSimplePositionedMutableByteRange.java | 67 ++--
.../org/apache/hadoop/hbase/util/TestStrings.java | 22 +-
.../org/apache/hadoop/hbase/util/TestThreads.java | 23 +-
.../apache/hadoop/hbase/util/TestVersionInfo.java | 16 +-
.../hadoop/hbase/util/TestWeakObjectPool.java | 38 +-
.../hadoop/hbase/zookeeper/TestZKConfig.java | 27 +-
104 files changed, 1776 insertions(+), 2108 deletions(-)
diff --git a/hbase-common/pom.xml b/hbase-common/pom.xml
index 7a6174553df..f018ea1d742 100644
--- a/hbase-common/pom.xml
+++ b/hbase-common/pom.xml
@@ -155,6 +155,11 @@
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestBuildThreadDiagnosticString.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestBuildThreadDiagnosticString.java
index 4071f18e2dd..74a4448983e 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestBuildThreadDiagnosticString.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestBuildThreadDiagnosticString.java
@@ -24,15 +24,19 @@ import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
@Tag(MiscTests.TAG)
@Tag(SmallTests.TAG)
public class TestBuildThreadDiagnosticString {
+ private static final Logger LOG = LoggerFactory.getLogger(TestBuildThreadDiagnosticString.class);
+
@Test
public void test() {
String threadDump = TimedOutTestsListener.buildThreadDiagnosticString();
- System.out.println(threadDump);
+ LOG.info(threadDump);
assertThat(threadDump,
containsString(getClass().getName() + ".test(" + getClass().getSimpleName() + ".java:"));
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestByteBufferKeyValue.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestByteBufferKeyValue.java
index dcf7d9e5256..a3abedb8688 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestByteBufferKeyValue.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestByteBufferKeyValue.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase;
-import static junit.framework.TestCase.assertTrue;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.nio.ByteBuffer;
import java.util.ArrayList;
@@ -29,17 +29,12 @@ import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.ByteBufferUtils;
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;
-@Category({ MiscTests.class, SmallTests.class })
+@org.junit.jupiter.api.Tag(MiscTests.TAG)
+@org.junit.jupiter.api.Tag(SmallTests.TAG)
public class TestByteBufferKeyValue {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestByteBufferKeyValue.class);
-
private static final String QUAL2 = "qual2";
private static final String FAM2 = "fam2";
private static final String QUAL1 = "qual1";
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellBuilder.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellBuilder.java
index 15ccf3a0455..a360e7a3fee 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellBuilder.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellBuilder.java
@@ -17,21 +17,19 @@
*/
package org.apache.hadoop.hbase;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
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;
+import org.junit.jupiter.api.extension.ExtendWith;
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
+@ExtendWith(HBaseJupiterExtension.class)
public class TestCellBuilder {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCellBuilder.class);
-
private static final byte OLD_DATA = 87;
private static final byte NEW_DATA = 100;
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java
index c4b24728b42..e705f11bcd7 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java
@@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase;
-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.nio.ByteBuffer;
import java.util.Collections;
@@ -28,17 +28,13 @@ import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestCellComparator {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCellComparator.class);
-
private CellComparator comparator = CellComparator.getInstance();
private CellComparator innerStoreComparator = InnerStoreCellComparator.INNER_STORE_COMPARATOR;
@@ -265,7 +261,8 @@ public class TestCellComparator {
Collections.addAll(set, keys);
count = 0;
for (Cell k : set) {
- assertTrue("count=" + count + ", " + k.toString(), count++ == k.getTimestamp());
+ int currentCount = count++;
+ assertTrue(currentCount == k.getTimestamp(), "count=" + currentCount + ", " + k.toString());
}
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellUtil.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellUtil.java
index 8eaa6cb2d12..9018e24f125 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellUtil.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellUtil.java
@@ -17,10 +17,10 @@
*/
package org.apache.hadoop.hbase;
-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.ByteArrayOutputStream;
import java.io.IOException;
@@ -33,17 +33,17 @@ import java.util.TreeMap;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
-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.mockito.Mockito;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestCellUtil {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCellUtil.class);
+
+ private static final Logger LOG = LoggerFactory.getLogger(TestCellUtil.class);
/**
* CellScannable used in test. Returns a {@link TestCellScanner}
@@ -271,7 +271,7 @@ public class TestCellUtil {
while (scanner.advance()) {
count++;
}
- Assert.assertEquals(expected, count);
+ assertEquals(expected, count);
}
@Test
@@ -283,43 +283,43 @@ public class TestCellUtil {
byte[] d = Bytes.toBytes("d");
// overlaps
- Assert.assertTrue(PrivateCellUtil.overlappingKeys(a, b, a, b));
- Assert.assertTrue(PrivateCellUtil.overlappingKeys(a, c, a, b));
- Assert.assertTrue(PrivateCellUtil.overlappingKeys(a, b, a, c));
- Assert.assertTrue(PrivateCellUtil.overlappingKeys(b, c, a, c));
- Assert.assertTrue(PrivateCellUtil.overlappingKeys(a, c, b, c));
- Assert.assertTrue(PrivateCellUtil.overlappingKeys(a, d, b, c));
- Assert.assertTrue(PrivateCellUtil.overlappingKeys(b, c, a, d));
+ assertTrue(PrivateCellUtil.overlappingKeys(a, b, a, b));
+ assertTrue(PrivateCellUtil.overlappingKeys(a, c, a, b));
+ assertTrue(PrivateCellUtil.overlappingKeys(a, b, a, c));
+ assertTrue(PrivateCellUtil.overlappingKeys(b, c, a, c));
+ assertTrue(PrivateCellUtil.overlappingKeys(a, c, b, c));
+ assertTrue(PrivateCellUtil.overlappingKeys(a, d, b, c));
+ assertTrue(PrivateCellUtil.overlappingKeys(b, c, a, d));
- Assert.assertTrue(PrivateCellUtil.overlappingKeys(empty, b, a, b));
- Assert.assertTrue(PrivateCellUtil.overlappingKeys(empty, b, a, c));
+ assertTrue(PrivateCellUtil.overlappingKeys(empty, b, a, b));
+ assertTrue(PrivateCellUtil.overlappingKeys(empty, b, a, c));
- Assert.assertTrue(PrivateCellUtil.overlappingKeys(a, b, empty, b));
- Assert.assertTrue(PrivateCellUtil.overlappingKeys(a, b, empty, c));
+ assertTrue(PrivateCellUtil.overlappingKeys(a, b, empty, b));
+ assertTrue(PrivateCellUtil.overlappingKeys(a, b, empty, c));
- Assert.assertTrue(PrivateCellUtil.overlappingKeys(a, empty, a, b));
- Assert.assertTrue(PrivateCellUtil.overlappingKeys(a, empty, a, c));
+ assertTrue(PrivateCellUtil.overlappingKeys(a, empty, a, b));
+ assertTrue(PrivateCellUtil.overlappingKeys(a, empty, a, c));
- Assert.assertTrue(PrivateCellUtil.overlappingKeys(a, b, empty, empty));
- Assert.assertTrue(PrivateCellUtil.overlappingKeys(empty, empty, a, b));
+ assertTrue(PrivateCellUtil.overlappingKeys(a, b, empty, empty));
+ assertTrue(PrivateCellUtil.overlappingKeys(empty, empty, a, b));
// non overlaps
- Assert.assertFalse(PrivateCellUtil.overlappingKeys(a, b, c, d));
- Assert.assertFalse(PrivateCellUtil.overlappingKeys(c, d, a, b));
-
- Assert.assertFalse(PrivateCellUtil.overlappingKeys(b, c, c, d));
- Assert.assertFalse(PrivateCellUtil.overlappingKeys(b, c, c, empty));
- Assert.assertFalse(PrivateCellUtil.overlappingKeys(b, c, d, empty));
- Assert.assertFalse(PrivateCellUtil.overlappingKeys(c, d, b, c));
- Assert.assertFalse(PrivateCellUtil.overlappingKeys(c, empty, b, c));
- Assert.assertFalse(PrivateCellUtil.overlappingKeys(d, empty, b, c));
-
- Assert.assertFalse(PrivateCellUtil.overlappingKeys(b, c, a, b));
- Assert.assertFalse(PrivateCellUtil.overlappingKeys(b, c, empty, b));
- Assert.assertFalse(PrivateCellUtil.overlappingKeys(b, c, empty, a));
- Assert.assertFalse(PrivateCellUtil.overlappingKeys(a, b, b, c));
- Assert.assertFalse(PrivateCellUtil.overlappingKeys(empty, b, b, c));
- Assert.assertFalse(PrivateCellUtil.overlappingKeys(empty, a, b, c));
+ assertFalse(PrivateCellUtil.overlappingKeys(a, b, c, d));
+ assertFalse(PrivateCellUtil.overlappingKeys(c, d, a, b));
+
+ assertFalse(PrivateCellUtil.overlappingKeys(b, c, c, d));
+ assertFalse(PrivateCellUtil.overlappingKeys(b, c, c, empty));
+ assertFalse(PrivateCellUtil.overlappingKeys(b, c, d, empty));
+ assertFalse(PrivateCellUtil.overlappingKeys(c, d, b, c));
+ assertFalse(PrivateCellUtil.overlappingKeys(c, empty, b, c));
+ assertFalse(PrivateCellUtil.overlappingKeys(d, empty, b, c));
+
+ assertFalse(PrivateCellUtil.overlappingKeys(b, c, a, b));
+ assertFalse(PrivateCellUtil.overlappingKeys(b, c, empty, b));
+ assertFalse(PrivateCellUtil.overlappingKeys(b, c, empty, a));
+ assertFalse(PrivateCellUtil.overlappingKeys(a, b, b, c));
+ assertFalse(PrivateCellUtil.overlappingKeys(empty, b, b, c));
+ assertFalse(PrivateCellUtil.overlappingKeys(empty, a, b, c));
}
@Test
@@ -327,32 +327,32 @@ public class TestCellUtil {
// The whole key matching case
KeyValue kv1 =
new KeyValue(Bytes.toBytes("r1"), Bytes.toBytes("f1"), Bytes.toBytes("q1"), null);
- Assert.assertEquals(kv1.getKeyLength(),
+ assertEquals(kv1.getKeyLength(),
PrivateCellUtil.findCommonPrefixInFlatKey(kv1, kv1, true, true));
- Assert.assertEquals(kv1.getKeyLength(),
+ assertEquals(kv1.getKeyLength(),
PrivateCellUtil.findCommonPrefixInFlatKey(kv1, kv1, false, true));
- Assert.assertEquals(kv1.getKeyLength() - KeyValue.TIMESTAMP_TYPE_SIZE,
+ assertEquals(kv1.getKeyLength() - KeyValue.TIMESTAMP_TYPE_SIZE,
PrivateCellUtil.findCommonPrefixInFlatKey(kv1, kv1, true, false));
// The rk length itself mismatch
KeyValue kv2 =
new KeyValue(Bytes.toBytes("r12"), Bytes.toBytes("f1"), Bytes.toBytes("q1"), null);
- Assert.assertEquals(1, PrivateCellUtil.findCommonPrefixInFlatKey(kv1, kv2, true, true));
+ assertEquals(1, PrivateCellUtil.findCommonPrefixInFlatKey(kv1, kv2, true, true));
// part of rk is same
KeyValue kv3 =
new KeyValue(Bytes.toBytes("r14"), Bytes.toBytes("f1"), Bytes.toBytes("q1"), null);
- Assert.assertEquals(KeyValue.ROW_LENGTH_SIZE + Bytes.toBytes("r1").length,
+ assertEquals(KeyValue.ROW_LENGTH_SIZE + Bytes.toBytes("r1").length,
PrivateCellUtil.findCommonPrefixInFlatKey(kv2, kv3, true, true));
// entire rk is same but different cf name
KeyValue kv4 =
new KeyValue(Bytes.toBytes("r14"), Bytes.toBytes("f2"), Bytes.toBytes("q1"), null);
- Assert.assertEquals(
+ assertEquals(
KeyValue.ROW_LENGTH_SIZE + kv3.getRowLength() + KeyValue.FAMILY_LENGTH_SIZE
+ Bytes.toBytes("f").length,
PrivateCellUtil.findCommonPrefixInFlatKey(kv3, kv4, false, true));
// rk and family are same and part of qualifier
KeyValue kv5 =
new KeyValue(Bytes.toBytes("r14"), Bytes.toBytes("f2"), Bytes.toBytes("q123"), null);
- Assert.assertEquals(
+ assertEquals(
KeyValue.ROW_LENGTH_SIZE + kv3.getRowLength() + KeyValue.FAMILY_LENGTH_SIZE
+ kv4.getFamilyLength() + kv4.getQualifierLength(),
PrivateCellUtil.findCommonPrefixInFlatKey(kv4, kv5, true, true));
@@ -360,18 +360,18 @@ public class TestCellUtil {
KeyValue kv6 = new KeyValue(Bytes.toBytes("rk"), 1234L);
KeyValue kv7 = new KeyValue(Bytes.toBytes("rk"), 1235L);
// only last byte out of 8 ts bytes in ts part differs
- Assert.assertEquals(
+ assertEquals(
KeyValue.ROW_LENGTH_SIZE + kv6.getRowLength() + KeyValue.FAMILY_LENGTH_SIZE
+ kv6.getFamilyLength() + kv6.getQualifierLength() + 7,
PrivateCellUtil.findCommonPrefixInFlatKey(kv6, kv7, true, true));
// rk, cf, q and ts are same. Only type differs
KeyValue kv8 = new KeyValue(Bytes.toBytes("rk"), 1234L, KeyValue.Type.Delete);
- Assert.assertEquals(
+ assertEquals(
KeyValue.ROW_LENGTH_SIZE + kv6.getRowLength() + KeyValue.FAMILY_LENGTH_SIZE
+ kv6.getFamilyLength() + kv6.getQualifierLength() + KeyValue.TIMESTAMP_SIZE,
PrivateCellUtil.findCommonPrefixInFlatKey(kv6, kv8, true, true));
// With out TS_TYPE check
- Assert.assertEquals(
+ assertEquals(
KeyValue.ROW_LENGTH_SIZE + kv6.getRowLength() + KeyValue.FAMILY_LENGTH_SIZE
+ kv6.getFamilyLength() + kv6.getQualifierLength(),
PrivateCellUtil.findCommonPrefixInFlatKey(kv6, kv8, true, false));
@@ -418,13 +418,13 @@ public class TestCellUtil {
String nonVerbose = CellUtil.toString(cell, false);
String verbose = CellUtil.toString(cell, true);
- System.out.println("nonVerbose=" + nonVerbose);
- System.out.println("verbose=" + verbose);
+ LOG.info("nonVerbose=" + nonVerbose);
+ LOG.info("verbose=" + verbose);
- Assert.assertEquals(String.format("%s/%s:%s/%d/%s/vlen=%s/seqid=%s", row, family, qualifier,
- timestamp, type.toString(), Bytes.toBytes(value).length, seqId), nonVerbose);
+ assertEquals(String.format("%s/%s:%s/%d/%s/vlen=%s/seqid=%s", row, family, qualifier, timestamp,
+ type.toString(), Bytes.toBytes(value).length, seqId), nonVerbose);
- Assert.assertEquals(String.format("%s/%s:%s/%d/%s/vlen=%s/seqid=%s/%s", row, family, qualifier,
+ assertEquals(String.format("%s/%s:%s/%d/%s/vlen=%s/seqid=%s/%s", row, family, qualifier,
timestamp, type.toString(), Bytes.toBytes(value).length, seqId, value), verbose);
// TODO: test with tags
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestChoreService.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestChoreService.java
index 8828ac7bd1b..aa0ef5ed63f 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestChoreService.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestChoreService.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
@@ -30,40 +30,35 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.util.Threads;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Category({ MiscTests.class, MediumTests.class })
+@Tag(MiscTests.TAG)
+@Tag(MediumTests.TAG)
public class TestChoreService {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestChoreService.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestChoreService.class);
private static final Configuration CONF = HBaseConfiguration.create();
- @Rule
- public TestName name = new TestName();
-
private int initialCorePoolSize = 3;
private ChoreService service;
- @Before
- public void setUp() {
- service = new ChoreService(name.getMethodName(), initialCorePoolSize, false);
+ private String testName;
+
+ @BeforeEach
+ public void setUp(TestInfo testInfo) {
+ testName = testInfo.getTestMethod().get().getName();
+ service = new ChoreService(testName, initialCorePoolSize, false);
}
- @After
+ @AfterEach
public void tearDown() {
shutdownService(service);
}
@@ -286,10 +281,10 @@ public class TestChoreService {
}
};
- assertEquals("Name construction failed", NAME, chore1.getName());
- assertEquals("Period construction failed", PERIOD, chore1.getPeriod());
- assertEquals("Initial Delay construction failed", VALID_DELAY, chore1.getInitialDelay());
- assertEquals("TimeUnit construction failed", UNIT, chore1.getTimeUnit());
+ assertEquals(NAME, chore1.getName(), "Name construction failed");
+ assertEquals(PERIOD, chore1.getPeriod(), "Period construction failed");
+ assertEquals(VALID_DELAY, chore1.getInitialDelay(), "Initial Delay construction failed");
+ assertEquals(UNIT, chore1.getTimeUnit(), "TimeUnit construction failed");
ScheduledChore invalidDelayChore =
new ScheduledChore(NAME, new SampleStopper(), PERIOD, INVALID_DELAY, UNIT) {
@@ -299,8 +294,8 @@ public class TestChoreService {
}
};
- assertEquals("Initial Delay should be set to 0 when invalid", 0,
- invalidDelayChore.getInitialDelay());
+ assertEquals(0, invalidDelayChore.getInitialDelay(),
+ "Initial Delay should be set to 0 when invalid");
}
@Test
@@ -340,10 +335,10 @@ public class TestChoreService {
service.scheduleChore(chore);
Thread.sleep(10 * period + delta);
- assertEquals("10 periods have elapsed.", 11, chore.getCountOfChoreCalls());
+ assertEquals(11, chore.getCountOfChoreCalls(), "10 periods have elapsed.");
Thread.sleep(10 * period + delta);
- assertEquals("20 periods have elapsed.", 21, chore.getCountOfChoreCalls());
+ assertEquals(21, chore.getCountOfChoreCalls(), "20 periods have elapsed.");
}
public void shutdownService(ChoreService service) {
@@ -359,7 +354,7 @@ public class TestChoreService {
service.scheduleChore(chore);
Thread.sleep(10 * period + delta);
- assertEquals("10 periods have elapsed.", 11, chore.getCountOfChoreCalls());
+ assertEquals(11, chore.getCountOfChoreCalls(), "10 periods have elapsed.");
// Force five runs of the chore to occur, sleeping between triggers to ensure the
// chore has time to run
@@ -374,19 +369,19 @@ public class TestChoreService {
chore.triggerNow();
Thread.sleep(delta);
- assertEquals("Trigger was called 5 times after 10 periods.", 16, chore.getCountOfChoreCalls());
+ assertEquals(16, chore.getCountOfChoreCalls(), "Trigger was called 5 times after 10 periods.");
Thread.sleep(10 * period + delta);
// Be loosey-goosey. It used to be '26' but it was a big flakey relying on timing.
- assertTrue("Expected at least 16 invocations, instead got " + chore.getCountOfChoreCalls(),
- chore.getCountOfChoreCalls() > 16);
+ assertTrue(chore.getCountOfChoreCalls() > 16,
+ "Expected at least 16 invocations, instead got " + chore.getCountOfChoreCalls());
}
@Test
public void testCorePoolIncrease() throws InterruptedException {
- assertEquals("Setting core pool size gave unexpected results.", initialCorePoolSize,
- service.getCorePoolSize());
+ assertEquals(initialCorePoolSize, service.getCorePoolSize(),
+ "Setting core pool size gave unexpected results.");
final int slowChorePeriod = 100;
SlowChore slowChore1 = new SlowChore("slowChore1", slowChorePeriod);
@@ -398,22 +393,22 @@ public class TestChoreService {
service.scheduleChore(slowChore3);
Thread.sleep(slowChorePeriod * 10);
- assertEquals("Should not create more pools than scheduled chores", 3,
- service.getCorePoolSize());
+ assertEquals(3, service.getCorePoolSize(),
+ "Should not create more pools than scheduled chores");
SlowChore slowChore4 = new SlowChore("slowChore4", slowChorePeriod);
service.scheduleChore(slowChore4);
Thread.sleep(slowChorePeriod * 10);
- assertEquals("Chores are missing their start time. Should expand core pool size", 4,
- service.getCorePoolSize());
+ assertEquals(4, service.getCorePoolSize(),
+ "Chores are missing their start time. Should expand core pool size");
SlowChore slowChore5 = new SlowChore("slowChore5", slowChorePeriod);
service.scheduleChore(slowChore5);
Thread.sleep(slowChorePeriod * 10);
- assertEquals("Chores are missing their start time. Should expand core pool size", 5,
- service.getCorePoolSize());
+ assertEquals(5, service.getCorePoolSize(),
+ "Chores are missing their start time. Should expand core pool size");
}
@Test
@@ -430,20 +425,20 @@ public class TestChoreService {
service.scheduleChore(slowChore3);
Thread.sleep(chorePeriod * 10);
- assertEquals("Should not create more pools than scheduled chores",
- service.getNumberOfScheduledChores(), service.getCorePoolSize());
+ assertEquals(service.getNumberOfScheduledChores(), service.getCorePoolSize(),
+ "Should not create more pools than scheduled chores");
SlowChore slowChore4 = new SlowChore("slowChore4", chorePeriod);
service.scheduleChore(slowChore4);
Thread.sleep(chorePeriod * 10);
- assertEquals("Chores are missing their start time. Should expand core pool size",
- service.getNumberOfScheduledChores(), service.getCorePoolSize());
+ assertEquals(service.getNumberOfScheduledChores(), service.getCorePoolSize(),
+ "Chores are missing their start time. Should expand core pool size");
SlowChore slowChore5 = new SlowChore("slowChore5", chorePeriod);
service.scheduleChore(slowChore5);
Thread.sleep(chorePeriod * 10);
- assertEquals("Chores are missing their start time. Should expand core pool size",
- service.getNumberOfScheduledChores(), service.getCorePoolSize());
+ assertEquals(service.getNumberOfScheduledChores(), service.getCorePoolSize(),
+ "Chores are missing their start time. Should expand core pool size");
assertEquals(5, service.getNumberOfChoresMissingStartTime());
// Now we begin to cancel the chores that caused an increase in the core thread pool of the
@@ -496,21 +491,21 @@ public class TestChoreService {
service.scheduleChore(dn5);
Thread.sleep(sleepTime);
- assertEquals("Scheduled chore mismatch", 5, service.getNumberOfScheduledChores());
+ assertEquals(5, service.getNumberOfScheduledChores(), "Scheduled chore mismatch");
dn1.cancel();
Thread.sleep(sleepTime);
- assertEquals("Scheduled chore mismatch", 4, service.getNumberOfScheduledChores());
+ assertEquals(4, service.getNumberOfScheduledChores(), "Scheduled chore mismatch");
dn2.cancel();
dn3.cancel();
dn4.cancel();
Thread.sleep(sleepTime);
- assertEquals("Scheduled chore mismatch", 1, service.getNumberOfScheduledChores());
+ assertEquals(1, service.getNumberOfScheduledChores(), "Scheduled chore mismatch");
dn5.cancel();
Thread.sleep(sleepTime);
- assertEquals("Scheduled chore mismatch", 0, service.getNumberOfScheduledChores());
+ assertEquals(0, service.getNumberOfScheduledChores(), "Scheduled chore mismatch");
}
@Test
@@ -596,10 +591,10 @@ public class TestChoreService {
}
@Test
- public void testChangingChoreServices() throws InterruptedException {
+ public void testChangingChoreServices(TestInfo testInfo) throws InterruptedException {
final int period = 100;
final int sleepTime = 10;
- ChoreService anotherService = new ChoreService(name.getMethodName() + "_2");
+ ChoreService anotherService = new ChoreService(testInfo.getTestMethod().get().getName() + "_2");
ScheduledChore chore = new DoNothingChore("sample", period);
try {
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestClassFinder.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestClassFinder.java
index eeabc0aefed..d7cbf508c22 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestClassFinder.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestClassFinder.java
@@ -19,9 +19,9 @@ package org.apache.hadoop.hbase;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.arrayContainingInAnyOrder;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.io.FileInputStream;
@@ -41,26 +41,20 @@ import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestClassFinder {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestClassFinder.class);
private static final Logger LOG = LoggerFactory.getLogger(TestClassFinder.class);
- @Rule
- public TestName name = new TestName();
private static final HBaseCommonTestingUtility testUtil = new HBaseCommonTestingUtility();
private static final String BASEPKG = "tfcpkg";
private static final String PREFIX = "Prefix";
@@ -75,7 +69,7 @@ public class TestClassFinder {
private static CustomClassloader classLoader;
- @BeforeClass
+ @BeforeAll
public static void createTestDir() throws IOException {
basePath = testUtil.getDataTestDir(TestClassFinder.class.getSimpleName()).toString();
if (!basePath.endsWith("/")) {
@@ -92,7 +86,7 @@ public class TestClassFinder {
classLoader = new CustomClassloader(new URL[0], ClassLoader.getSystemClassLoader());
}
- @AfterClass
+ @AfterAll
public static void deleteTestDir() {
testUtil.cleanupTestDir(TestClassFinder.class.getSimpleName());
}
@@ -125,10 +119,10 @@ public class TestClassFinder {
}
@Test
- public void testClassFinderHandlesNestedPackages() throws Exception {
+ public void testClassFinderHandlesNestedPackages(TestInfo testInfo) throws Exception {
final String NESTED = ".nested";
- final String CLASSNAME1 = name.getMethodName() + "1";
- final String CLASSNAME2 = name.getMethodName() + "2";
+ final String CLASSNAME1 = testInfo.getTestMethod().get().getName() + "1";
+ final String CLASSNAME2 = testInfo.getTestMethod().get().getName() + "2";
long counter = testCounter.incrementAndGet();
FileAndPath c1 = compileTestClass(counter, "", "c1");
FileAndPath c2 = compileTestClass(counter, NESTED, CLASSNAME1);
@@ -147,9 +141,9 @@ public class TestClassFinder {
}
@Test
- public void testClassFinderFiltersByNameInJar() throws Exception {
+ public void testClassFinderFiltersByNameInJar(TestInfo testInfo) throws Exception {
final long counter = testCounter.incrementAndGet();
- final String classNamePrefix = name.getMethodName();
+ final String classNamePrefix = testInfo.getTestMethod().get().getName();
LOG.info("Created jar " + createAndLoadJar("", classNamePrefix, counter));
ClassFinder.FileNameFilter notExcNameFilter =
@@ -162,9 +156,9 @@ public class TestClassFinder {
}
@Test
- public void testClassFinderFiltersByClassInJar() throws Exception {
+ public void testClassFinderFiltersByClassInJar(TestInfo testInfo) throws Exception {
final long counter = testCounter.incrementAndGet();
- final String classNamePrefix = name.getMethodName();
+ final String classNamePrefix = testInfo.getTestMethod().get().getName();
LOG.info("Created jar " + createAndLoadJar("", classNamePrefix, counter));
final ClassFinder.ClassFilter notExcClassFilter = c -> !c.getSimpleName().startsWith(PREFIX);
@@ -184,8 +178,8 @@ public class TestClassFinder {
}
@Test
- public void testClassFinderFiltersByPathInJar() throws Exception {
- final String CLASSNAME = name.getMethodName();
+ public void testClassFinderFiltersByPathInJar(TestInfo testInfo) throws Exception {
+ final String CLASSNAME = testInfo.getTestMethod().get().getName();
long counter = testCounter.incrementAndGet();
FileAndPath c1 = compileTestClass(counter, "", CLASSNAME);
FileAndPath c2 = compileTestClass(counter, "", "c2");
@@ -207,17 +201,17 @@ public class TestClassFinder {
}
@Test
- public void testClassFinderCanFindClassesInDirs() throws Exception {
+ public void testClassFinderCanFindClassesInDirs(TestInfo testInfo) throws Exception {
// Make some classes for us to find. Class naming and packaging is kinda cryptic.
// TODO: Fix.
final long counter = testCounter.incrementAndGet();
- final String classNamePrefix = name.getMethodName();
- String pkgNameSuffix = name.getMethodName();
+ final String classNamePrefix = testInfo.getTestMethod().get().getName();
+ String pkgNameSuffix = testInfo.getTestMethod().get().getName();
LOG.info("Created jar " + createAndLoadJar(pkgNameSuffix, classNamePrefix, counter));
ClassFinder allClassesFinder = new ClassFinder(classLoader);
String pkgName = makePackageName(pkgNameSuffix, counter);
Set<Class<?>> allClasses = allClassesFinder.findClasses(pkgName, false);
- assertTrue("Classes in " + pkgName, allClasses.size() > 0);
+ assertTrue(allClasses.size() > 0, "Classes in " + pkgName);
String classNameToFind = classNamePrefix + counter;
assertTrue(contains(allClasses, classNameToFind));
}
@@ -232,12 +226,12 @@ public class TestClassFinder {
}
@Test
- public void testClassFinderFiltersByNameInDirs() throws Exception {
+ public void testClassFinderFiltersByNameInDirs(TestInfo testInfo) throws Exception {
// Make some classes for us to find. Class naming and packaging is kinda cryptic.
// TODO: Fix.
final long counter = testCounter.incrementAndGet();
- final String classNamePrefix = name.getMethodName();
- String pkgNameSuffix = name.getMethodName();
+ final String classNamePrefix = testInfo.getTestMethod().get().getName();
+ String pkgNameSuffix = testInfo.getTestMethod().get().getName();
LOG.info("Created jar " + createAndLoadJar(pkgNameSuffix, classNamePrefix, counter));
final String classNameToFilterOut = classNamePrefix + counter;
final ClassFinder.FileNameFilter notThisFilter =
@@ -245,7 +239,7 @@ public class TestClassFinder {
String pkgName = makePackageName(pkgNameSuffix, counter);
ClassFinder allClassesFinder = new ClassFinder(classLoader);
Set<Class<?>> allClasses = allClassesFinder.findClasses(pkgName, false);
- assertTrue("Classes in " + pkgName, allClasses.size() > 0);
+ assertTrue(allClasses.size() > 0, "Classes in " + pkgName);
ClassFinder notThisClassFinder = new ClassFinder(null, notThisFilter, null, classLoader);
Set<Class<?>> notAllClasses = notThisClassFinder.findClasses(pkgName, false);
assertFalse(contains(notAllClasses, classNameToFilterOut));
@@ -253,19 +247,19 @@ public class TestClassFinder {
}
@Test
- public void testClassFinderFiltersByClassInDirs() throws Exception {
+ public void testClassFinderFiltersByClassInDirs(TestInfo testInfo) throws Exception {
// Make some classes for us to find. Class naming and packaging is kinda cryptic.
// TODO: Fix.
final long counter = testCounter.incrementAndGet();
- final String classNamePrefix = name.getMethodName();
- String pkgNameSuffix = name.getMethodName();
+ final String classNamePrefix = testInfo.getTestMethod().get().getName();
+ String pkgNameSuffix = testInfo.getTestMethod().get().getName();
LOG.info("Created jar " + createAndLoadJar(pkgNameSuffix, classNamePrefix, counter));
final Class<?> clazz = makeClass(pkgNameSuffix, classNamePrefix, counter);
final ClassFinder.ClassFilter notThisFilter = c -> c != clazz;
String pkgName = makePackageName(pkgNameSuffix, counter);
ClassFinder allClassesFinder = new ClassFinder(classLoader);
Set<Class<?>> allClasses = allClassesFinder.findClasses(pkgName, false);
- assertTrue("Classes in " + pkgName, allClasses.size() > 0);
+ assertTrue(allClasses.size() > 0, "Classes in " + pkgName);
ClassFinder notThisClassFinder = new ClassFinder(null, null, notThisFilter, classLoader);
Set<Class<?>> notAllClasses = notThisClassFinder.findClasses(pkgName, false);
assertFalse(contains(notAllClasses, clazz.getSimpleName()));
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCompoundConfiguration.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCompoundConfiguration.java
index 81922b7869a..340d849ab78 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCompoundConfiguration.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCompoundConfiguration.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-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 java.util.HashMap;
import java.util.Map;
@@ -27,22 +27,18 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.testclassification.MiscTests;
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.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestCompoundConfiguration {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCompoundConfiguration.class);
-
private Configuration baseConf;
private int baseConfSize;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
baseConf = new Configuration();
baseConf.set("A", "1");
@@ -61,12 +57,8 @@ public class TestCompoundConfiguration {
assertEquals(CompoundConfiguration.class,
compoundConf.getClassByName(CompoundConfiguration.class.getName()));
- try {
- compoundConf.getClassByName("bad_class_name");
- fail("Trying to load bad_class_name should throw an exception");
- } catch (ClassNotFoundException e) {
- // win!
- }
+ assertThrows(ClassNotFoundException.class, () -> compoundConf.getClassByName("bad_class_name"),
+ "Trying to load bad_class_name should throw an exception");
}
@Test
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestHBaseConfiguration.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestHBaseConfiguration.java
index af944ad2a0f..60bce371e3a 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestHBaseConfiguration.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestHBaseConfiguration.java
@@ -17,9 +17,10 @@
*/
package org.apache.hadoop.hbase;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-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.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.io.IOException;
@@ -30,27 +31,23 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.AfterClass;
-import org.junit.Assert;
-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.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap;
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestHBaseConfiguration {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestHBaseConfiguration.class);
private static final Logger LOG = LoggerFactory.getLogger(TestHBaseConfiguration.class);
private static HBaseCommonTestingUtility UTIL = new HBaseCommonTestingUtility();
- @AfterClass
+ @AfterAll
public static void tearDown() throws IOException {
UTIL.cleanupTestDir();
}
@@ -104,13 +101,13 @@ public class TestHBaseConfiguration {
public void testSecurityConfCaseInsensitive() {
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.security.authentication", "kerberos");
- Assert.assertTrue(User.isHBaseSecurityEnabled(conf));
+ assertTrue(User.isHBaseSecurityEnabled(conf));
conf.set("hbase.security.authentication", "KERBEROS");
- Assert.assertTrue(User.isHBaseSecurityEnabled(conf));
+ assertTrue(User.isHBaseSecurityEnabled(conf));
conf.set("hbase.security.authentication", "KERBeros");
- Assert.assertTrue(User.isHBaseSecurityEnabled(conf));
+ assertTrue(User.isHBaseSecurityEnabled(conf));
}
@Test
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestIndividualBytesFieldCell.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestIndividualBytesFieldCell.java
index 20c279366c3..1b09b4cbc16 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestIndividualBytesFieldCell.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestIndividualBytesFieldCell.java
@@ -17,9 +17,10 @@
*/
package org.apache.hadoop.hbase;
-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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.nio.ByteBuffer;
@@ -27,22 +28,18 @@ import org.apache.hadoop.hbase.io.ByteArrayOutputStream;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
-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;
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestIndividualBytesFieldCell {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestIndividualBytesFieldCell.class);
-
private static IndividualBytesFieldCell ic0 = null;
private static KeyValue kv0 = null;
- @BeforeClass
+ @BeforeAll
public static void testConstructorAndVerify() {
// Immutable inputs
byte[] row = Bytes.toBytes("immutable-row");
@@ -185,46 +182,58 @@ public class TestIndividualBytesFieldCell {
ec.deepClone(); // Do something with ec
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testIllegalRow() {
- new IndividualBytesFieldCell(Bytes.toBytes("row"), 0, 100, HConstants.EMPTY_BYTE_ARRAY, 0, 0,
- HConstants.EMPTY_BYTE_ARRAY, 0, 0, 0L, KeyValue.Type.Put, 0, HConstants.EMPTY_BYTE_ARRAY, 0,
- 0, HConstants.EMPTY_BYTE_ARRAY, 0, 0);
+ assertThrows(IllegalArgumentException.class, () -> {
+ new IndividualBytesFieldCell(Bytes.toBytes("row"), 0, 100, HConstants.EMPTY_BYTE_ARRAY, 0, 0,
+ HConstants.EMPTY_BYTE_ARRAY, 0, 0, 0L, KeyValue.Type.Put, 0, HConstants.EMPTY_BYTE_ARRAY, 0,
+ 0, HConstants.EMPTY_BYTE_ARRAY, 0, 0);
+ });
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testIllegalFamily() {
- new IndividualBytesFieldCell(Bytes.toBytes("row"), 0, 3, Bytes.toBytes("family"), 0, 100,
- HConstants.EMPTY_BYTE_ARRAY, 0, 0, 0L, KeyValue.Type.Put, 0, HConstants.EMPTY_BYTE_ARRAY, 0,
- 0, HConstants.EMPTY_BYTE_ARRAY, 0, 0);
+ assertThrows(IllegalArgumentException.class, () -> {
+ new IndividualBytesFieldCell(Bytes.toBytes("row"), 0, 3, Bytes.toBytes("family"), 0, 100,
+ HConstants.EMPTY_BYTE_ARRAY, 0, 0, 0L, KeyValue.Type.Put, 0, HConstants.EMPTY_BYTE_ARRAY, 0,
+ 0, HConstants.EMPTY_BYTE_ARRAY, 0, 0);
+ });
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testIllegalQualifier() {
- new IndividualBytesFieldCell(Bytes.toBytes("row"), 0, 3, Bytes.toBytes("family"), 0, 6,
- Bytes.toBytes("qualifier"), 0, 100, 0L, KeyValue.Type.Put, 0, HConstants.EMPTY_BYTE_ARRAY, 0,
- 0, HConstants.EMPTY_BYTE_ARRAY, 0, 0);
+ assertThrows(IllegalArgumentException.class, () -> {
+ new IndividualBytesFieldCell(Bytes.toBytes("row"), 0, 3, Bytes.toBytes("family"), 0, 6,
+ Bytes.toBytes("qualifier"), 0, 100, 0L, KeyValue.Type.Put, 0, HConstants.EMPTY_BYTE_ARRAY,
+ 0, 0, HConstants.EMPTY_BYTE_ARRAY, 0, 0);
+ });
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testIllegalTimestamp() {
- new IndividualBytesFieldCell(Bytes.toBytes("row"), 0, 3, Bytes.toBytes("family"), 0, 6,
- Bytes.toBytes("qualifier"), 0, 9, -100, KeyValue.Type.Put, 0, HConstants.EMPTY_BYTE_ARRAY, 0,
- 0, HConstants.EMPTY_BYTE_ARRAY, 0, 0);
+ assertThrows(IllegalArgumentException.class, () -> {
+ new IndividualBytesFieldCell(Bytes.toBytes("row"), 0, 3, Bytes.toBytes("family"), 0, 6,
+ Bytes.toBytes("qualifier"), 0, 9, -100, KeyValue.Type.Put, 0, HConstants.EMPTY_BYTE_ARRAY,
+ 0, 0, HConstants.EMPTY_BYTE_ARRAY, 0, 0);
+ });
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testIllegalValue() {
- new IndividualBytesFieldCell(Bytes.toBytes("row"), 0, 3, Bytes.toBytes("family"), 0, 6,
- Bytes.toBytes("qualifier"), 0, 9, 0L, KeyValue.Type.Put, 0, Bytes.toBytes("value"), 0, 100,
- HConstants.EMPTY_BYTE_ARRAY, 0, 0);
+ assertThrows(IllegalArgumentException.class, () -> {
+ new IndividualBytesFieldCell(Bytes.toBytes("row"), 0, 3, Bytes.toBytes("family"), 0, 6,
+ Bytes.toBytes("qualifier"), 0, 9, 0L, KeyValue.Type.Put, 0, Bytes.toBytes("value"), 0, 100,
+ HConstants.EMPTY_BYTE_ARRAY, 0, 0);
+ });
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testIllegalTags() {
- new IndividualBytesFieldCell(Bytes.toBytes("row"), 0, 3, Bytes.toBytes("family"), 0, 6,
- Bytes.toBytes("qualifier"), 0, 9, 0L, KeyValue.Type.Put, 0, Bytes.toBytes("value"), 0, 5,
- Bytes.toBytes("tags"), 0, 100);
+ assertThrows(IllegalArgumentException.class, () -> {
+ new IndividualBytesFieldCell(Bytes.toBytes("row"), 0, 3, Bytes.toBytes("family"), 0, 6,
+ Bytes.toBytes("qualifier"), 0, 9, 0L, KeyValue.Type.Put, 0, Bytes.toBytes("value"), 0, 5,
+ Bytes.toBytes("tags"), 0, 100);
+ });
}
@Test
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java
index 6eaebcaa0f9..635bf141951 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java
@@ -17,13 +17,13 @@
*/
package org.apache.hadoop.hbase;
-import static org.junit.Assert.assertArrayEquals;
-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.assertTrue;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -34,21 +34,18 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
+import org.apache.hadoop.hbase.testclassification.MiscTests;
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.hbase.util.EnvironmentEdgeManager;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Category(SmallTests.class)
+@org.junit.jupiter.api.Tag(MiscTests.TAG)
+@org.junit.jupiter.api.Tag(SmallTests.TAG)
public class TestKeyValue {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestKeyValue.class);
private static final Logger LOG = LoggerFactory.getLogger(TestKeyValue.class);
@Test
@@ -719,7 +716,7 @@ public class TestKeyValue {
fail("Should fail when parse kv from an invalid bytes, case#" + i + ". " + c);
}
} catch (IllegalArgumentException e) {
- assertEquals("Case#" + i + " failed," + c, c.getExpectedMessage(), e.getMessage());
+ assertEquals(c.getExpectedMessage(), e.getMessage(), "Case#" + i + " failed," + c);
}
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestServerName.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestServerName.java
index 31ea6589de7..655dc10ac5f 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestServerName.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestServerName.java
@@ -17,11 +17,11 @@
*/
package org.apache.hadoop.hbase;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
-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.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.HashSet;
import java.util.Set;
@@ -30,17 +30,13 @@ import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Addressing;
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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestServerName {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestServerName.class);
-
@Test
public void testHash() {
ServerName sn1 = ServerName.parseServerName("asf903.gq1.ygridcore.net,52690,1517835491385");
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestStorageSize.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestStorageSize.java
index 386221947d5..8ed6263e450 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestStorageSize.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestStorageSize.java
@@ -17,21 +17,17 @@
*/
package org.apache.hadoop.hbase;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestStorageSize {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestStorageSize.class);
-
@Test
public void testParse() {
// megabytes
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestSystemExitInTest.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestSystemExitInTest.java
index c8438bc77d1..54fece09f39 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestSystemExitInTest.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestSystemExitInTest.java
@@ -17,22 +17,20 @@
*/
package org.apache.hadoop.hbase;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestSystemExitInTest {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestSystemExitInTest.class);
-
- @Test(expected = SystemExitRule.SystemExitInTestException.class)
+ @Test
public void testSystemExit() {
- System.exit(1);
+ assertThrows(SystemExitRule.SystemExitInTestException.class, () -> System.exit(1));
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTableName.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTableName.java
index d9281d8953e..58e89c48329 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTableName.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTableName.java
@@ -17,10 +17,10 @@
*/
package org.apache.hadoop.hbase;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.nio.ByteBuffer;
import java.util.HashMap;
@@ -28,18 +28,15 @@ import java.util.Map;
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;
/**
* Tests for various kinds of TableNames.
*/
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestTableName {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestTableName.class);
private static String[] emptyNames = { "", " " };
private static String[] invalidNamespace = { ":a", "%:a" };
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTagBuilder.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTagBuilder.java
index a0c8aea937a..838671d05ad 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTagBuilder.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTagBuilder.java
@@ -17,24 +17,19 @@
*/
package org.apache.hadoop.hbase;
-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 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.Test;
-@Category({ MiscTests.class, SmallTests.class })
+@org.junit.jupiter.api.Tag(MiscTests.TAG)
+@org.junit.jupiter.api.Tag(SmallTests.TAG)
public class TestTagBuilder {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestTagBuilder.class);
-
@Test
public void testArrayBackedTagBuilder() {
byte type = (byte) 50;
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTagUtil.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTagUtil.java
index 9ac858e9914..51e8c7fcb36 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTagUtil.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTagUtil.java
@@ -17,22 +17,17 @@
*/
package org.apache.hadoop.hbase;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.List;
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.Test;
-@Category({ MiscTests.class, SmallTests.class })
+@org.junit.jupiter.api.Tag(MiscTests.TAG)
+@org.junit.jupiter.api.Tag(SmallTests.TAG)
public class TestTagUtil {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestTagUtil.class);
-
@Test
public void testCarryForwardTTLTag() throws Exception {
// No tags so far and the TTL tag must get added to the Tags list
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimeout.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimeout.java
index 557bd14f67a..7a6eaf0cb9a 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimeout.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimeout.java
@@ -17,19 +17,16 @@
*/
package org.apache.hadoop.hbase;
+import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.ClassRule;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category(SmallTests.class)
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestTimeout {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestTimeout.class);
-
@Test
public void run1() throws InterruptedException {
Thread.sleep(100);
@@ -39,7 +36,7 @@ public class TestTimeout {
* Enable to check if timeout works. Can't enable as it waits 30seconds and expected doesn't do
* Exception catching
*/
- @Ignore
+ @Disabled
@Test
public void infiniteLoop() {
// Launch a background non-daemon thread.
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/Waiter.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/Waiter.java
index f687b95804a..bfb425c89f4 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/Waiter.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/Waiter.java
@@ -17,7 +17,7 @@
*/
package org.apache.hadoop.hbase;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.fail;
import java.text.MessageFormat;
import org.apache.hadoop.conf.Configuration;
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodec.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodec.java
index 9963e37c17f..f24a6d68c31 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodec.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodec.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.codec;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -28,25 +28,20 @@ import java.io.DataOutputStream;
import java.io.IOException;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.apache.hbase.thirdparty.com.google.common.io.CountingInputStream;
import org.apache.hbase.thirdparty.com.google.common.io.CountingOutputStream;
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestCellCodec {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCellCodec.class);
-
@Test
public void testEmptyWorks() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodecWithTags.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodecWithTags.java
index b44473ee49e..54ddf7a6e4d 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodecWithTags.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodecWithTags.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.codec;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -30,7 +30,6 @@ import java.util.List;
import org.apache.hadoop.hbase.ArrayBackedTag;
import org.apache.hadoop.hbase.Cell;
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.PrivateCellUtil;
@@ -38,19 +37,14 @@ import org.apache.hadoop.hbase.Tag;
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.Test;
import org.apache.hbase.thirdparty.com.google.common.io.CountingInputStream;
import org.apache.hbase.thirdparty.com.google.common.io.CountingOutputStream;
-@Category({ MiscTests.class, SmallTests.class })
+@org.junit.jupiter.api.Tag(MiscTests.TAG)
+@org.junit.jupiter.api.Tag(SmallTests.TAG)
public class TestCellCodecWithTags {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCellCodecWithTags.class);
-
@Test
public void testCellWithTag() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodec.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodec.java
index ca3561692f6..fe90311852e 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodec.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodec.java
@@ -17,34 +17,29 @@
*/
package org.apache.hadoop.hbase.codec;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.apache.hbase.thirdparty.com.google.common.io.CountingInputStream;
import org.apache.hbase.thirdparty.com.google.common.io.CountingOutputStream;
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestKeyValueCodec {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestKeyValueCodec.class);
-
@Test
public void testEmptyWorks() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodecWithTags.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodecWithTags.java
index 66a874e5c5e..acc0d4a8f36 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodecWithTags.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodecWithTags.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.codec;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -30,7 +30,6 @@ import java.util.List;
import org.apache.hadoop.hbase.ArrayBackedTag;
import org.apache.hadoop.hbase.Cell;
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.PrivateCellUtil;
@@ -38,19 +37,14 @@ import org.apache.hadoop.hbase.Tag;
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.Test;
import org.apache.hbase.thirdparty.com.google.common.io.CountingInputStream;
import org.apache.hbase.thirdparty.com.google.common.io.CountingOutputStream;
-@Category({ MiscTests.class, SmallTests.class })
+@org.junit.jupiter.api.Tag(MiscTests.TAG)
+@org.junit.jupiter.api.Tag(SmallTests.TAG)
public class TestKeyValueCodecWithTags {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestKeyValueCodecWithTags.class);
-
@Test
public void testKeyValueWithTag() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/conf/TestConfigKey.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/conf/TestConfigKey.java
index eedf0964f2a..92e02f12c84 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/conf/TestConfigKey.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/conf/TestConfigKey.java
@@ -17,24 +17,20 @@
*/
package org.apache.hadoop.hbase.conf;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.fail;
import java.util.UUID;
import java.util.function.Consumer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CompoundConfiguration;
-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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestConfigKey {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestConfigKey.class);
private interface Interface {
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/conf/TestConfigurationManager.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/conf/TestConfigurationManager.java
index d38a4ee5efc..907e83ef7aa 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/conf/TestConfigurationManager.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/conf/TestConfigurationManager.java
@@ -17,26 +17,21 @@
*/
package org.apache.hadoop.hbase.conf;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.ClientTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Category({ SmallTests.class, ClientTests.class })
+@Tag(SmallTests.TAG)
+@Tag(ClientTests.TAG)
public class TestConfigurationManager {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestConfigurationManager.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestConfigurationManager.class);
static class DummyConfigurationObserver implements ConfigurationObserver {
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestByteBuffAllocator.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestByteBuffAllocator.java
index 8dcb1465684..583cbc27546 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestByteBuffAllocator.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestByteBuffAllocator.java
@@ -19,33 +19,27 @@ package org.apache.hadoop.hbase.io;
import static org.apache.hadoop.hbase.io.ByteBuffAllocator.HEAP;
import static org.apache.hadoop.hbase.io.ByteBuffAllocator.getHeapAllocationRatio;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-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.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.nio.ByteBuffer;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.nio.ByteBuff;
import org.apache.hadoop.hbase.nio.MultiByteBuff;
import org.apache.hadoop.hbase.nio.SingleByteBuff;
import org.apache.hadoop.hbase.testclassification.RPCTests;
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({ RPCTests.class, SmallTests.class })
+@Tag(RPCTests.TAG)
+@Tag(SmallTests.TAG)
public class TestByteBuffAllocator {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestByteBuffAllocator.class);
-
@Test
public void testRecycleOnlyPooledBuffers() {
int maxBuffersInPool = 10;
@@ -364,25 +358,25 @@ public class TestByteBuffAllocator {
conf.setInt(ByteBuffAllocator.DEPRECATED_MAX_BUFFER_COUNT_KEY, 10);
conf.setInt(ByteBuffAllocator.DEPRECATED_BUFFER_SIZE_KEY, 1024);
ByteBuffAllocator allocator = ByteBuffAllocator.create(conf, true);
- Assert.assertEquals(1024, allocator.getBufferSize());
- Assert.assertEquals(10, allocator.getTotalBufferCount());
+ assertEquals(1024, allocator.getBufferSize());
+ assertEquals(10, allocator.getTotalBufferCount());
conf = new Configuration();
conf.setInt(ByteBuffAllocator.MAX_BUFFER_COUNT_KEY, 11);
conf.setInt(ByteBuffAllocator.BUFFER_SIZE_KEY, 2048);
allocator = ByteBuffAllocator.create(conf, true);
- Assert.assertEquals(2048, allocator.getBufferSize());
- Assert.assertEquals(11, allocator.getTotalBufferCount());
+ assertEquals(2048, allocator.getBufferSize());
+ assertEquals(11, allocator.getTotalBufferCount());
conf = new Configuration();
conf.setBoolean(ByteBuffAllocator.DEPRECATED_ALLOCATOR_POOL_ENABLED_KEY, false);
- Assert.assertFalse(conf.getBoolean(ByteBuffAllocator.ALLOCATOR_POOL_ENABLED_KEY, true));
+ assertFalse(conf.getBoolean(ByteBuffAllocator.ALLOCATOR_POOL_ENABLED_KEY, true));
conf.setBoolean(ByteBuffAllocator.DEPRECATED_ALLOCATOR_POOL_ENABLED_KEY, true);
- Assert.assertTrue(conf.getBoolean(ByteBuffAllocator.ALLOCATOR_POOL_ENABLED_KEY, false));
+ assertTrue(conf.getBoolean(ByteBuffAllocator.ALLOCATOR_POOL_ENABLED_KEY, false));
conf.setBoolean(ByteBuffAllocator.ALLOCATOR_POOL_ENABLED_KEY, true);
- Assert.assertTrue(conf.getBoolean(ByteBuffAllocator.ALLOCATOR_POOL_ENABLED_KEY, false));
+ assertTrue(conf.getBoolean(ByteBuffAllocator.ALLOCATOR_POOL_ENABLED_KEY, false));
conf.setBoolean(ByteBuffAllocator.ALLOCATOR_POOL_ENABLED_KEY, false);
- Assert.assertFalse(conf.getBoolean(ByteBuffAllocator.ALLOCATOR_POOL_ENABLED_KEY, true));
+ assertFalse(conf.getBoolean(ByteBuffAllocator.ALLOCATOR_POOL_ENABLED_KEY, true));
}
@Test
@@ -391,31 +385,30 @@ public class TestByteBuffAllocator {
conf.setInt(ByteBuffAllocator.MAX_BUFFER_COUNT_KEY, 11);
conf.setInt(ByteBuffAllocator.BUFFER_SIZE_KEY, 2048);
ByteBuffAllocator alloc1 = ByteBuffAllocator.create(conf, true);
- Assert.assertEquals(getHeapAllocationRatio(alloc1), 0.0f, 1e-6);
+ assertEquals(getHeapAllocationRatio(alloc1), 0.0f, 1e-6);
alloc1.allocate(1);
- Assert.assertEquals(getHeapAllocationRatio(alloc1), 1.0f, 1e-6);
+ assertEquals(getHeapAllocationRatio(alloc1), 1.0f, 1e-6);
alloc1.allocate(2048 / 6 - 1);
- Assert.assertEquals(getHeapAllocationRatio(alloc1), 1.0f, 1e-6);
+ assertEquals(getHeapAllocationRatio(alloc1), 1.0f, 1e-6);
alloc1.allocate(24);
alloc1.allocate(1024);
- Assert.assertEquals(getHeapAllocationRatio(alloc1), 24 / (24f + 2048), 1e-6);
- Assert.assertEquals(getHeapAllocationRatio(alloc1), 0.0f, 1e-6);
+ assertEquals(getHeapAllocationRatio(alloc1), 24 / (24f + 2048), 1e-6);
+ assertEquals(getHeapAllocationRatio(alloc1), 0.0f, 1e-6);
// Allocate something from HEAP
HEAP.allocate(1024);
alloc1.allocate(24);
alloc1.allocate(1024);
- Assert.assertEquals(getHeapAllocationRatio(HEAP, alloc1), (1024f + 24) / (1024f + 24 + 2048),
- 1e-6);
- Assert.assertEquals(getHeapAllocationRatio(HEAP, alloc1), 0.0f, 1e-6);
+ assertEquals(getHeapAllocationRatio(HEAP, alloc1), (1024f + 24) / (1024f + 24 + 2048), 1e-6);
+ assertEquals(getHeapAllocationRatio(HEAP, alloc1), 0.0f, 1e-6);
// Check duplicated heap allocator, say even if we passed (HEAP, HEAP, alloc1), it will only
// caculate the allocation from (HEAP, alloc1).
HEAP.allocate(1024);
alloc1.allocate(1024);
- Assert.assertEquals(getHeapAllocationRatio(HEAP, HEAP, alloc1), 1024f / (1024f + 2048f), 1e-6);
+ assertEquals(getHeapAllocationRatio(HEAP, HEAP, alloc1), 1024f / (1024f + 2048f), 1e-6);
}
/**
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestByteBuffAllocatorLeakDetection.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestByteBuffAllocatorLeakDetection.java
index ffc0292902e..df75245a87a 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestByteBuffAllocatorLeakDetection.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestByteBuffAllocatorLeakDetection.java
@@ -17,17 +17,15 @@
*/
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.concurrent.atomic.AtomicInteger;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.nio.ByteBuff;
import org.apache.hadoop.hbase.testclassification.RPCTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.apache.hbase.thirdparty.io.netty.util.ResourceLeakDetector;
import org.apache.hbase.thirdparty.io.netty.util.internal.logging.InternalLogLevel;
@@ -35,13 +33,10 @@ import org.apache.hbase.thirdparty.io.netty.util.internal.logging.InternalLogger
import org.apache.hbase.thirdparty.io.netty.util.internal.logging.InternalLoggerFactory;
import org.apache.hbase.thirdparty.io.netty.util.internal.logging.Slf4JLoggerFactory;
-@Category({ RPCTests.class, SmallTests.class })
+@Tag(RPCTests.TAG)
+@Tag(SmallTests.TAG)
public class TestByteBuffAllocatorLeakDetection {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestByteBuffAllocatorLeakDetection.class);
-
@SuppressWarnings("unused")
@Test
public void testLeakDetection() throws InterruptedException {
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestByteBufferListOutputStream.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestByteBufferListOutputStream.java
index 4f9ec7d09f8..9198860d7e8 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestByteBufferListOutputStream.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestByteBufferListOutputStream.java
@@ -17,28 +17,23 @@
*/
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.nio.ByteBuffer;
import java.util.List;
-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.apache.hadoop.hbase.util.ByteBufferUtils;
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 TestByteBufferListOutputStream {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestByteBufferListOutputStream.class);
-
@Test
public void testWrites() throws Exception {
ByteBuffAllocator alloc = new ByteBuffAllocator(true, 3, 10, 10 / 6);
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestFileChangeWatcher.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestFileChangeWatcher.java
index ff906e3bb83..55291306b5f 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestFileChangeWatcher.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestFileChangeWatcher.java
@@ -20,11 +20,11 @@ package org.apache.hadoop.hbase.io;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.endsWith;
-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.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 java.io.File;
import java.io.IOException;
@@ -155,7 +155,7 @@ public class TestFileChangeWatcher {
watcher.start();
awaitWatcherThreadInitialized();
await().during(Duration.ofSeconds(2)).atMost(Duration.ofSeconds(3))
- .untilAsserted(() -> assertEquals("Should not have been notified", 0, notifiedPaths.size()));
+ .untilAsserted(() -> assertEquals(0, notifiedPaths.size(), "Should not have been notified"));
}
@Test
@@ -173,7 +173,7 @@ public class TestFileChangeWatcher {
FileUtils.writeStringToFile(tempFile, "Hello world " + index + "\n", StandardCharsets.UTF_8,
true);
await().atMost(Duration.ofSeconds(2)).untilAsserted(
- () -> assertEquals("Wrong number of notifications", index + 1, notifiedPaths.size()));
+ () -> assertEquals(index + 1, notifiedPaths.size(), "Wrong number of notifications"));
Path path = notifiedPaths.get(index);
assertEquals(tempFile.getPath(), path.toString());
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestMultiByteBuffInputStream.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestMultiByteBuffInputStream.java
index a82441f9509..02a8621e3bc 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestMultiByteBuffInputStream.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestMultiByteBuffInputStream.java
@@ -17,28 +17,23 @@
*/
package org.apache.hadoop.hbase.io;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.nio.ByteBuffer;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.nio.MultiByteBuff;
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 TestMultiByteBuffInputStream {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestMultiByteBuffInputStream.class);
-
@Test
public void testReads() throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream(100);
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestTagCompressionContext.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestTagCompressionContext.java
index 4c80d0de041..771a224e58e 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestTagCompressionContext.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestTagCompressionContext.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.ByteArrayInputStream;
import java.io.DataOutputStream;
@@ -28,7 +28,6 @@ import org.apache.hadoop.hbase.ArrayBackedTag;
import org.apache.hadoop.hbase.ByteBufferExtendedCell;
import org.apache.hadoop.hbase.ByteBufferKeyValue;
import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.Tag;
import org.apache.hadoop.hbase.io.util.LRUDictionary;
@@ -37,17 +36,12 @@ import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.ByteBufferUtils;
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;
-@Category({ MiscTests.class, SmallTests.class })
+@org.junit.jupiter.api.Tag(MiscTests.TAG)
+@org.junit.jupiter.api.Tag(SmallTests.TAG)
public class TestTagCompressionContext {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestTagCompressionContext.class);
-
private static final byte[] ROW = Bytes.toBytes("r1");
private static final byte[] CF = Bytes.toBytes("f");
private static final byte[] Q = Bytes.toBytes("q");
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/compress/CompressionTestBase.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/compress/CompressionTestBase.java
index 0134d52eebb..78d2915a7f1 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/compress/CompressionTestBase.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/compress/CompressionTestBase.java
@@ -17,7 +17,7 @@
*/
package org.apache.hadoop.hbase.io.compress;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -94,8 +94,9 @@ public class CompressionTestBase {
LOG.info("{} compressed {} bytes to {} bytes in {} ms", codec.getClass().getSimpleName(), inLen,
compressed.length, end - start);
if (expectedCompressedSize != null) {
- assertTrue("Expected compressed size does not match: (expected=" + expectedCompressedSize
- + ", actual=" + compressed.length + ")", expectedCompressedSize == compressed.length);
+ assertEquals(expectedCompressedSize, compressed.length,
+ "Expected compressed size does not match: (expected=" + expectedCompressedSize + ", actual="
+ + compressed.length + ")");
}
// Decompress
final byte[] plain = new byte[inLen];
@@ -111,8 +112,8 @@ public class CompressionTestBase {
// Decompressed bytes should equal the original
int offset = 0;
for (int i = 0; i < input.length; i++) {
- assertTrue("Comparison failed at offset " + offset,
- Bytes.compareTo(plain, offset, input[i].length, input[i], 0, input[i].length) == 0);
+ assertEquals(0, Bytes.compareTo(plain, offset, input[i].length, input[i], 0, input[i].length),
+ "Comparison failed at offset " + offset);
offset += input[i].length;
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/compress/TestCodecPool.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/compress/TestCodecPool.java
index 166c12a658c..bd148b1360a 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/compress/TestCodecPool.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/compress/TestCodecPool.java
@@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.io.compress;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -32,7 +32,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
import org.apache.hadoop.conf.Configuration;
-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.compress.CompressionInputStream;
@@ -41,55 +40,51 @@ import org.apache.hadoop.io.compress.Decompressor;
import org.apache.hadoop.io.compress.DefaultCodec;
import org.apache.hadoop.io.compress.GzipCodec;
import org.apache.hadoop.io.compress.zlib.BuiltInGzipDecompressor;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
/**
* Along with CodecPool, this is copied from the class of the same name in hadoop-common. Modified
* to accommodate changes to HBase's CodecPool.
*/
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestCodecPool {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCodecPool.class);
-
private final String LEASE_COUNT_ERR = "Incorrect number of leased (de)compressors";
DefaultCodec codec;
- @BeforeClass
+ @BeforeAll
public static void beforeClass() {
CodecPool.initLeaseCounting();
}
- @Before
+ @BeforeEach
public void setup() {
this.codec = new DefaultCodec();
this.codec.setConf(new Configuration());
}
- @Test(timeout = 10000)
+ @Test
public void testCompressorPoolCounts() {
// Get two compressors and return them
Compressor comp1 = CodecPool.getCompressor(codec);
Compressor comp2 = CodecPool.getCompressor(codec);
- assertEquals(LEASE_COUNT_ERR, 2, CodecPool.getLeasedCompressorsCount(codec));
+ assertEquals(2, CodecPool.getLeasedCompressorsCount(codec), LEASE_COUNT_ERR);
CodecPool.returnCompressor(comp2);
- assertEquals(LEASE_COUNT_ERR, 1, CodecPool.getLeasedCompressorsCount(codec));
+ assertEquals(1, CodecPool.getLeasedCompressorsCount(codec), LEASE_COUNT_ERR);
CodecPool.returnCompressor(comp1);
- assertEquals(LEASE_COUNT_ERR, 0, CodecPool.getLeasedCompressorsCount(codec));
+ assertEquals(0, CodecPool.getLeasedCompressorsCount(codec), LEASE_COUNT_ERR);
CodecPool.returnCompressor(comp1);
- assertEquals(LEASE_COUNT_ERR, 0, CodecPool.getLeasedCompressorsCount(codec));
+ assertEquals(0, CodecPool.getLeasedCompressorsCount(codec), LEASE_COUNT_ERR);
}
- @Test(timeout = 10000)
+ @Test
public void testCompressorNotReturnSameInstance() {
Compressor comp = CodecPool.getCompressor(codec);
CodecPool.returnCompressor(comp);
@@ -104,24 +99,24 @@ public class TestCodecPool {
}
}
- @Test(timeout = 10000)
+ @Test
public void testDecompressorPoolCounts() {
// Get two decompressors and return them
Decompressor decomp1 = CodecPool.getDecompressor(codec);
Decompressor decomp2 = CodecPool.getDecompressor(codec);
- assertEquals(LEASE_COUNT_ERR, 2, CodecPool.getLeasedDecompressorsCount(codec));
+ assertEquals(2, CodecPool.getLeasedDecompressorsCount(codec), LEASE_COUNT_ERR);
CodecPool.returnDecompressor(decomp2);
- assertEquals(LEASE_COUNT_ERR, 1, CodecPool.getLeasedDecompressorsCount(codec));
+ assertEquals(1, CodecPool.getLeasedDecompressorsCount(codec), LEASE_COUNT_ERR);
CodecPool.returnDecompressor(decomp1);
- assertEquals(LEASE_COUNT_ERR, 0, CodecPool.getLeasedDecompressorsCount(codec));
+ assertEquals(0, CodecPool.getLeasedDecompressorsCount(codec), LEASE_COUNT_ERR);
CodecPool.returnDecompressor(decomp1);
- assertEquals(LEASE_COUNT_ERR, 0, CodecPool.getLeasedCompressorsCount(codec));
+ assertEquals(0, CodecPool.getLeasedCompressorsCount(codec), LEASE_COUNT_ERR);
}
- @Test(timeout = 10000)
+ @Test
public void testMultiThreadedCompressorPool() throws InterruptedException {
final int iterations = 4;
ExecutorService threadpool = Executors.newFixedThreadPool(3);
@@ -155,10 +150,10 @@ public class TestCodecPool {
threadpool.shutdown();
threadpool.awaitTermination(1000, TimeUnit.SECONDS);
- assertEquals(LEASE_COUNT_ERR, 0, CodecPool.getLeasedCompressorsCount(codec));
+ assertEquals(0, CodecPool.getLeasedCompressorsCount(codec), LEASE_COUNT_ERR);
}
- @Test(timeout = 10000)
+ @Test
public void testMultiThreadedDecompressorPool() throws InterruptedException {
final int iterations = 4;
ExecutorService threadpool = Executors.newFixedThreadPool(3);
@@ -192,10 +187,10 @@ public class TestCodecPool {
threadpool.shutdown();
threadpool.awaitTermination(1000, TimeUnit.SECONDS);
- assertEquals(LEASE_COUNT_ERR, 0, CodecPool.getLeasedDecompressorsCount(codec));
+ assertEquals(0, CodecPool.getLeasedDecompressorsCount(codec), LEASE_COUNT_ERR);
}
- @Test(timeout = 10000)
+ @Test
public void testDecompressorNotReturnSameInstance() {
Decompressor decomp = CodecPool.getDecompressor(codec);
CodecPool.returnDecompressor(decomp);
@@ -210,7 +205,7 @@ public class TestCodecPool {
}
}
- @Test(timeout = 10000)
+ @Test
public void testDoNotPoolDecompressorNotUseableAfterReturn() throws Exception {
final GzipCodec gzipCodec = new GzipCodec();
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestCipherProvider.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestCipherProvider.java
index 1cafaaf7ecb..67e07b538b4 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestCipherProvider.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestCipherProvider.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.io.crypto;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.io.InputStream;
@@ -27,23 +27,18 @@ import java.io.OutputStream;
import java.security.Key;
import java.util.Arrays;
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.crypto.aes.AES;
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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestCipherProvider {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCipherProvider.class);
-
public static class MyCipherProvider implements CipherProvider {
private Configuration conf;
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestEncryption.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestEncryption.java
index 4e67c814c2a..34e5896e5fd 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestEncryption.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestEncryption.java
@@ -17,31 +17,27 @@
*/
package org.apache.hadoop.hbase.io.crypto;
-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.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.security.Key;
import javax.crypto.spec.SecretKeySpec;
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.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestEncryption {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestEncryption.class);
private static final Logger LOG = LoggerFactory.getLogger(TestEncryption.class);
@@ -135,9 +131,9 @@ public class TestEncryption {
Encryption.decrypt(decOut, encIn, plaintext.length, d);
byte[] result = decOut.toByteArray();
- assertEquals("Decrypted result has different length than plaintext", result.length,
- plaintext.length);
- assertTrue("Transformation was not symmetric", Bytes.equals(result, plaintext));
+ assertEquals(result.length, plaintext.length,
+ "Decrypted result has different length than plaintext");
+ assertTrue(Bytes.equals(result, plaintext), "Transformation was not symmetric");
}
private byte[] getRandomBlock(int size) {
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestKeyProvider.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestKeyProvider.java
index 3d549ed2913..347a363830b 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestKeyProvider.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestKeyProvider.java
@@ -17,42 +17,39 @@
*/
package org.apache.hadoop.hbase.io.crypto;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.security.Key;
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.crypto.aes.AES;
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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestKeyProvider {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestKeyProvider.class);
-
@Test
public void testTestProvider() {
Configuration conf = HBaseConfiguration.create();
conf.set(HConstants.CRYPTO_KEYPROVIDER_CONF_KEY, KeyProviderForTesting.class.getName());
KeyProvider provider = Encryption.getKeyProvider(conf);
- assertNotNull("Null returned for provider", provider);
- assertTrue("Provider is not the expected type", provider instanceof KeyProviderForTesting);
+ assertNotNull(provider, "Null returned for provider");
+ assertThat("Provider is not the expected type", provider,
+ instanceOf(KeyProviderForTesting.class));
Key key = provider.getKey("foo");
- assertNotNull("Test provider did not return a key as expected", key);
- assertEquals("Test provider did not create a key for AES", "AES", key.getAlgorithm());
- assertEquals("Test provider did not create a key of adequate length", AES.KEY_LENGTH,
- key.getEncoded().length);
+ assertNotNull(key, "Test provider did not return a key as expected");
+ assertEquals("AES", key.getAlgorithm(), "Test provider did not create a key for AES");
+ assertEquals(AES.KEY_LENGTH, key.getEncoded().length,
+ "Test provider did not create a key of adequate length");
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestKeyStoreKeyProvider.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestKeyStoreKeyProvider.java
index 0608f489c29..558c76eb715 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestKeyStoreKeyProvider.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/TestKeyStoreKeyProvider.java
@@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.io.crypto;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.File;
import java.io.FileOutputStream;
@@ -28,23 +28,18 @@ import java.security.KeyStore;
import java.security.MessageDigest;
import java.util.Properties;
import javax.crypto.spec.SecretKeySpec;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
-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;
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestKeyStoreKeyProvider {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestKeyStoreKeyProvider.class);
-
static final HBaseCommonTestingUtility TEST_UTIL = new HBaseCommonTestingUtility();
static final String ALIAS = "test";
static final String PASSWORD = "password";
@@ -53,7 +48,7 @@ public class TestKeyStoreKeyProvider {
static File storeFile;
static File passwordFile;
- @BeforeClass
+ @BeforeAll
public static void setUp() throws Exception {
KEY = MessageDigest.getInstance("SHA-256").digest(Bytes.toBytes(ALIAS));
// Create a JKECS store containing a test secret key
@@ -66,21 +61,15 @@ public class TestKeyStoreKeyProvider {
new File(dataDir).mkdirs();
// Write the keystore file
storeFile = new File(dataDir, "keystore.jks");
- FileOutputStream os = new FileOutputStream(storeFile);
- try {
+ try (FileOutputStream os = new FileOutputStream(storeFile)) {
store.store(os, PASSWORD.toCharArray());
- } finally {
- os.close();
}
// Write the password file
Properties p = new Properties();
p.setProperty(ALIAS, PASSWORD);
passwordFile = new File(dataDir, "keystore.pw");
- os = new FileOutputStream(passwordFile);
- try {
+ try (FileOutputStream os = new FileOutputStream(passwordFile)) {
p.store(os, "");
- } finally {
- os.close();
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/aes/TestAES.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/aes/TestAES.java
index c50da383dc9..c44ded01d1b 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/aes/TestAES.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/aes/TestAES.java
@@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.io.crypto.aes;
-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.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -32,7 +32,6 @@ import java.security.Security;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.io.IOUtils;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.io.crypto.Cipher;
import org.apache.hadoop.hbase.io.crypto.DefaultCipherProvider;
@@ -41,16 +40,13 @@ import org.apache.hadoop.hbase.io.crypto.Encryptor;
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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestAES {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestAES.class);
-
// Validation for AES in CTR mode with a 128 bit key
// From NIST Special Publication 800-38A
@Test
@@ -74,13 +70,13 @@ public class TestAES {
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
byte[] b = new byte[16];
IOUtils.readFully(in, b);
- assertTrue("Failed #1", Bytes.equals(b, Bytes.fromHex("874d6191b620e3261bef6864990db6ce")));
+ assertTrue(Bytes.equals(b, Bytes.fromHex("874d6191b620e3261bef6864990db6ce")), "Failed #1");
IOUtils.readFully(in, b);
- assertTrue("Failed #2", Bytes.equals(b, Bytes.fromHex("9806f66b7970fdff8617187bb9fffdff")));
+ assertTrue(Bytes.equals(b, Bytes.fromHex("9806f66b7970fdff8617187bb9fffdff")), "Failed #2");
IOUtils.readFully(in, b);
- assertTrue("Failed #3", Bytes.equals(b, Bytes.fromHex("5ae4df3edbd5d35e5b4f09020db03eab")));
+ assertTrue(Bytes.equals(b, Bytes.fromHex("5ae4df3edbd5d35e5b4f09020db03eab")), "Failed #3");
IOUtils.readFully(in, b);
- assertTrue("Failed #4", Bytes.equals(b, Bytes.fromHex("1e031dda2fbe03d1792170a0f3009cee")));
+ assertTrue(Bytes.equals(b, Bytes.fromHex("1e031dda2fbe03d1792170a0f3009cee")), "Failed #4");
}
@Test
@@ -93,7 +89,7 @@ public class TestAES {
DefaultCipherProvider.getInstance().setConf(conf);
AES aes = new AES(DefaultCipherProvider.getInstance());
- assertEquals("AES did not find alternate RNG", "TestRNG", aes.getRNG().getAlgorithm());
+ assertEquals("TestRNG", aes.getRNG().getAlgorithm(), "AES did not find alternate RNG");
}
static class TestProvider extends Provider {
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/aes/TestCommonsAES.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/aes/TestCommonsAES.java
index 2114ebbfb14..74b8c0d4cc2 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/aes/TestCommonsAES.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/aes/TestCommonsAES.java
@@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.io.crypto.aes;
-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.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -32,7 +32,6 @@ import java.security.Security;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.io.IOUtils;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.io.crypto.Cipher;
import org.apache.hadoop.hbase.io.crypto.DefaultCipherProvider;
@@ -41,17 +40,13 @@ import org.apache.hadoop.hbase.io.crypto.Encryptor;
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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestCommonsAES {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCommonsAES.class);
-
// Validation for AES in CTR mode with a 128 bit key
// From NIST Special Publication 800-38A
@Test
@@ -75,13 +70,13 @@ public class TestCommonsAES {
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
byte[] b = new byte[16];
IOUtils.readFully(in, b);
- assertTrue("Failed #1", Bytes.equals(b, Bytes.fromHex("874d6191b620e3261bef6864990db6ce")));
+ assertTrue(Bytes.equals(b, Bytes.fromHex("874d6191b620e3261bef6864990db6ce")), "Failed #1");
IOUtils.readFully(in, b);
- assertTrue("Failed #2", Bytes.equals(b, Bytes.fromHex("9806f66b7970fdff8617187bb9fffdff")));
+ assertTrue(Bytes.equals(b, Bytes.fromHex("9806f66b7970fdff8617187bb9fffdff")), "Failed #2");
IOUtils.readFully(in, b);
- assertTrue("Failed #3", Bytes.equals(b, Bytes.fromHex("5ae4df3edbd5d35e5b4f09020db03eab")));
+ assertTrue(Bytes.equals(b, Bytes.fromHex("5ae4df3edbd5d35e5b4f09020db03eab")), "Failed #3");
IOUtils.readFully(in, b);
- assertTrue("Failed #4", Bytes.equals(b, Bytes.fromHex("1e031dda2fbe03d1792170a0f3009cee")));
+ assertTrue(Bytes.equals(b, Bytes.fromHex("1e031dda2fbe03d1792170a0f3009cee")), "Failed #4");
}
@Test
@@ -94,7 +89,7 @@ public class TestCommonsAES {
DefaultCipherProvider.getInstance().setConf(conf);
AES aes = new AES(DefaultCipherProvider.getInstance());
- assertEquals("AES did not find alternate RNG", "TestRNG", aes.getRNG().getAlgorithm());
+ assertEquals("TestRNG", aes.getRNG().getAlgorithm(), "AES did not find alternate RNG");
}
static class TestProvider extends Provider {
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/AbstractTestX509Parameterized.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/AbstractTestX509Parameterized.java
index c2a9743fc6f..a549e832282 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/AbstractTestX509Parameterized.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/AbstractTestX509Parameterized.java
@@ -21,17 +21,17 @@ import java.io.File;
import java.io.IOException;
import java.security.Security;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
+import java.util.stream.Stream;
import org.apache.commons.io.FileUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.provider.Arguments;
/**
* Base class for parameterized unit tests that use X509TestContext for testing different X509
@@ -51,35 +51,31 @@ public abstract class AbstractTestX509Parameterized {
private static final HBaseCommonTestingUtility UTIL = new HBaseCommonTestingUtility();
private static X509TestContextProvider PROVIDER;
- @Parameterized.Parameter()
- public X509KeyType caKeyType;
+ private X509KeyType caKeyType;
+ private X509KeyType certKeyType;
+ private char[] keyPassword;
- @Parameterized.Parameter(value = 1)
- public X509KeyType certKeyType;
-
- @Parameterized.Parameter(value = 2)
- public char[] keyPassword;
-
- @Parameterized.Parameter(value = 3)
- public Integer paramIndex;
+ public AbstractTestX509Parameterized(X509KeyType caKeyType, X509KeyType certKeyType,
+ char[] keyPassword) {
+ this.caKeyType = caKeyType;
+ this.certKeyType = certKeyType;
+ this.keyPassword = keyPassword;
+ }
/**
* Default parameters suitable for most subclasses. See example usage in {@link TestX509Util}.
- * @return an array of parameter combinations to test with.
+ * @return a stream of parameter combinations to test with.
*/
- @Parameterized.Parameters(
- name = "{index}: caKeyType={0}, certKeyType={1}, keyPassword={2}, paramIndex={3}")
- public static Collection<Object[]> defaultParams() {
- List<Object[]> result = new ArrayList<>();
- int paramIndex = 0;
+ public static Stream<Arguments> parameters() {
+ List<Arguments> result = new ArrayList<>();
for (X509KeyType caKeyType : X509KeyType.values()) {
for (X509KeyType certKeyType : X509KeyType.values()) {
for (char[] keyPassword : new char[][] { "".toCharArray(), "pa$$w0rd".toCharArray() }) {
- result.add(new Object[] { caKeyType, certKeyType, keyPassword, paramIndex++ });
+ result.add(Arguments.of(caKeyType, certKeyType, keyPassword));
}
}
}
- return result;
+ return result.stream();
}
/**
@@ -92,7 +88,7 @@ public abstract class AbstractTestX509Parameterized {
protected X509TestContext x509TestContext;
- @BeforeClass
+ @BeforeAll
public static void setUpBaseClass() throws Exception {
Security.addProvider(new BouncyCastleProvider());
File dir = new File(UTIL.getDataTestDir(TestX509Util.class.getSimpleName()).toString())
@@ -101,20 +97,20 @@ public abstract class AbstractTestX509Parameterized {
PROVIDER = new X509TestContextProvider(UTIL.getConfiguration(), dir);
}
- @AfterClass
+ @AfterAll
public static void cleanUpBaseClass() {
Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME);
UTIL.cleanupTestDir();
}
- @Before
+ @BeforeEach
public void setUp() throws IOException {
x509TestContext = PROVIDER.get(caKeyType, certKeyType, keyPassword);
x509TestContext.setConfigurations(KeyStoreFileType.JKS, KeyStoreFileType.JKS);
conf = new Configuration(UTIL.getConfiguration());
}
- @After
+ @AfterEach
public void cleanUp() {
x509TestContext.clearConfigurations();
x509TestContext.getConf().unset(X509Util.TLS_CONFIG_OCSP);
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestBCFKSFileLoader.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestBCFKSFileLoader.java
index 060c60a7a0c..645d5e2c7ea 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestBCFKSFileLoader.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestBCFKSFileLoader.java
@@ -17,17 +17,16 @@
*/
package org.apache.hadoop.hbase.io.crypto.tls;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
import java.io.IOException;
import java.security.KeyStore;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.testclassification.SecurityTests;
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.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
/**
* This file has been copied from the Apache ZooKeeper project.
@@ -35,84 +34,102 @@ import org.junit.runners.Parameterized;
* "https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/test/java/org/apache/zookeeper/common/BCFKSFileLoaderTest.java">Base
* revision</a>
*/
-@RunWith(Parameterized.class)
-@Category({ SecurityTests.class, SmallTests.class })
+@Tag(SecurityTests.TAG)
+@Tag(SmallTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: caKeyType={0}, certKeyType={1}, keyPassword={2}")
public class TestBCFKSFileLoader extends AbstractTestX509Parameterized {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestBCFKSFileLoader.class);
+ public TestBCFKSFileLoader(X509KeyType caKeyType, X509KeyType certKeyType, char[] keyPassword) {
+ super(caKeyType, certKeyType, keyPassword);
+ }
- @Test
+ @TestTemplate
public void testLoadKeyStore() throws Exception {
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.BCFKS).getAbsolutePath();
KeyStore ks = new BCFKSFileLoader.Builder().setKeyStorePath(path)
.setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore();
- Assert.assertEquals(1, ks.size());
+ assertEquals(1, ks.size());
}
- @Test(expected = Exception.class)
- public void testLoadKeyStoreWithWrongPassword() throws Exception {
+ @TestTemplate
+ public void testLoadKeyStoreWithWrongPassword() throws IOException {
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.BCFKS).getAbsolutePath();
- new BCFKSFileLoader.Builder().setKeyStorePath(path)
- .setKeyStorePassword("wrong password".toCharArray()).build().loadKeyStore();
+ assertThrows(IOException.class, () -> {
+ new BCFKSFileLoader.Builder().setKeyStorePath(path)
+ .setKeyStorePassword("wrong password".toCharArray()).build().loadKeyStore();
+ });
}
- @Test(expected = IOException.class)
- public void testLoadKeyStoreWithWrongFilePath() throws Exception {
+ @TestTemplate
+ public void testLoadKeyStoreWithWrongFilePath() throws IOException {
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.BCFKS).getAbsolutePath();
- new BCFKSFileLoader.Builder().setKeyStorePath(path + ".does_not_exist")
- .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore();
+ assertThrows(IOException.class, () -> {
+ new BCFKSFileLoader.Builder().setKeyStorePath(path + ".does_not_exist")
+ .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore();
+ });
}
- @Test(expected = NullPointerException.class)
- public void testLoadKeyStoreWithNullFilePath() throws Exception {
- new BCFKSFileLoader.Builder().setKeyStorePassword(x509TestContext.getKeyStorePassword()).build()
- .loadKeyStore();
+ @TestTemplate
+ public void testLoadKeyStoreWithNullFilePath() {
+ assertThrows(NullPointerException.class, () -> {
+ new BCFKSFileLoader.Builder().setKeyStorePassword(x509TestContext.getKeyStorePassword())
+ .build().loadKeyStore();
+ });
}
- @Test(expected = IOException.class)
- public void testLoadKeyStoreWithWrongFileType() throws Exception {
- // Trying to load a PEM file with BCFKS loader should fail
+ @TestTemplate
+ public void testLoadKeyStoreWithWrongFileType() throws IOException {
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath();
- new BCFKSFileLoader.Builder().setKeyStorePath(path)
- .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore();
+ assertThrows(IOException.class, () -> {
+ // Trying to load a PEM file with BCFKS loader should fail
+ new BCFKSFileLoader.Builder().setKeyStorePath(path)
+ .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore();
+ });
}
- @Test
+ @TestTemplate
public void testLoadTrustStore() throws Exception {
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.BCFKS).getAbsolutePath();
KeyStore ts = new BCFKSFileLoader.Builder().setTrustStorePath(path)
.setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore();
- Assert.assertEquals(1, ts.size());
+ assertEquals(1, ts.size());
}
- @Test(expected = Exception.class)
- public void testLoadTrustStoreWithWrongPassword() throws Exception {
+ @TestTemplate
+ public void testLoadTrustStoreWithWrongPassword() throws IOException {
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.BCFKS).getAbsolutePath();
- new BCFKSFileLoader.Builder().setTrustStorePath(path)
- .setTrustStorePassword("wrong password".toCharArray()).build().loadTrustStore();
+ assertThrows(IOException.class, () -> {
+
+ new BCFKSFileLoader.Builder().setTrustStorePath(path)
+ .setTrustStorePassword("wrong password".toCharArray()).build().loadTrustStore();
+ });
}
- @Test(expected = IOException.class)
- public void testLoadTrustStoreWithWrongFilePath() throws Exception {
+ @TestTemplate
+ public void testLoadTrustStoreWithWrongFilePath() throws IOException {
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.BCFKS).getAbsolutePath();
- new BCFKSFileLoader.Builder().setTrustStorePath(path + ".does_not_exist")
- .setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore();
+ assertThrows(IOException.class, () -> {
+ new BCFKSFileLoader.Builder().setTrustStorePath(path + ".does_not_exist")
+ .setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore();
+ });
}
- @Test(expected = NullPointerException.class)
- public void testLoadTrustStoreWithNullFilePath() throws Exception {
- new BCFKSFileLoader.Builder().setTrustStorePassword(x509TestContext.getTrustStorePassword())
- .build().loadTrustStore();
+ @TestTemplate
+ public void testLoadTrustStoreWithNullFilePath() {
+ assertThrows(NullPointerException.class, () -> {
+ new BCFKSFileLoader.Builder().setTrustStorePassword(x509TestContext.getTrustStorePassword())
+ .build().loadTrustStore();
+ });
}
- @Test(expected = IOException.class)
- public void testLoadTrustStoreWithWrongFileType() throws Exception {
- // Trying to load a PEM file with BCFKS loader should fail
+ @TestTemplate
+ public void testLoadTrustStoreWithWrongFileType() throws IOException {
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM).getAbsolutePath();
- new BCFKSFileLoader.Builder().setTrustStorePath(path)
- .setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore();
+ assertThrows(IOException.class, () -> {
+ // Trying to load a PEM file with BCFKS loader should fail
+ new BCFKSFileLoader.Builder().setTrustStorePath(path)
+ .setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore();
+ });
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestFileKeyStoreLoaderBuilderProvider.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestFileKeyStoreLoaderBuilderProvider.java
index a8010348334..439ca41d342 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestFileKeyStoreLoaderBuilderProvider.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestFileKeyStoreLoaderBuilderProvider.java
@@ -17,13 +17,14 @@
*/
package org.apache.hadoop.hbase.io.crypto.tls;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
import org.apache.hadoop.hbase.testclassification.SecurityTests;
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;
/**
* This file has been copied from the Apache ZooKeeper project.
@@ -31,36 +32,34 @@ import org.junit.experimental.categories.Category;
* "https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/test/java/org/apache/zookeeper/common/FileKeyStoreLoaderBuilderProviderTest.java">Base
* revision</a>
*/
-@Category({ SecurityTests.class, SmallTests.class })
+@Tag(SecurityTests.TAG)
+@Tag(SmallTests.TAG)
public class TestFileKeyStoreLoaderBuilderProvider {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestFileKeyStoreLoaderBuilderProvider.class);
-
@Test
public void testGetBuilderForJKSFileType() {
FileKeyStoreLoader.Builder<?> builder =
FileKeyStoreLoaderBuilderProvider.getBuilderForKeyStoreFileType(KeyStoreFileType.JKS);
- Assert.assertTrue(builder instanceof JKSFileLoader.Builder);
+ assertThat(builder, instanceOf(JKSFileLoader.Builder.class));
}
@Test
public void testGetBuilderForPEMFileType() {
FileKeyStoreLoader.Builder<?> builder =
FileKeyStoreLoaderBuilderProvider.getBuilderForKeyStoreFileType(KeyStoreFileType.PEM);
- Assert.assertTrue(builder instanceof PEMFileLoader.Builder);
+ assertThat(builder, instanceOf(PEMFileLoader.Builder.class));
}
@Test
public void testGetBuilderForPKCS12FileType() {
FileKeyStoreLoader.Builder<?> builder =
FileKeyStoreLoaderBuilderProvider.getBuilderForKeyStoreFileType(KeyStoreFileType.PKCS12);
- Assert.assertTrue(builder instanceof PKCS12FileLoader.Builder);
+ assertThat(builder, instanceOf(PKCS12FileLoader.Builder.class));
}
- @Test(expected = NullPointerException.class)
+ @Test
public void testGetBuilderForNullFileType() {
- FileKeyStoreLoaderBuilderProvider.getBuilderForKeyStoreFileType(null);
+ assertThrows(NullPointerException.class,
+ () -> FileKeyStoreLoaderBuilderProvider.getBuilderForKeyStoreFileType(null));
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestHBaseHostnameVerifier.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestHBaseHostnameVerifier.java
index 12de6175836..e5fd85f9b87 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestHBaseHostnameVerifier.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestHBaseHostnameVerifier.java
@@ -17,7 +17,7 @@
*/
package org.apache.hadoop.hbase.io.crypto.tls;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
@@ -27,7 +27,6 @@ import java.security.Security;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import javax.net.ssl.SSLException;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.bouncycastle.asn1.x500.X500Name;
@@ -36,11 +35,10 @@ import org.bouncycastle.asn1.x500.style.BCStyle;
import org.bouncycastle.asn1.x509.GeneralName;
import org.bouncycastle.asn1.x509.GeneralNames;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.apache.hbase.thirdparty.com.google.common.net.InetAddresses;
@@ -50,15 +48,13 @@ import org.apache.hbase.thirdparty.com.google.common.net.InetAddresses;
* "https://github.com/apache/zookeeper/blob/5820d10d9dc58c8e12d2e25386fdf92acb360359/zookeeper-server/src/test/java/org/apache/zookeeper/common/ZKHostnameVerifierTest.java">Base
* revision</a>
*/
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestHBaseHostnameVerifier {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestHBaseHostnameVerifier.class);
private static CertificateCreator certificateCreator;
private HBaseHostnameVerifier impl;
- @BeforeClass
+ @BeforeAll
public static void setupClass() throws Exception {
Security.addProvider(new BouncyCastleProvider());
X500NameBuilder caNameBuilder = new X500NameBuilder(BCStyle.INSTANCE);
@@ -69,7 +65,7 @@ public class TestHBaseHostnameVerifier {
certificateCreator = new CertificateCreator(keyPair, caCert);
}
- @Before
+ @BeforeEach
public void setup() {
impl = new HBaseHostnameVerifier();
}
@@ -242,11 +238,7 @@ public class TestHBaseHostnameVerifier {
private void exceptionPlease(final HBaseHostnameVerifier hv, final String host,
final X509Certificate x509) {
- try {
- hv.verify(host, x509);
- fail("HostnameVerifier shouldn't allow [" + host + "]");
- } catch (final SSLException e) {
- // whew! we're okay!
- }
+ assertThrows(SSLException.class, () -> hv.verify(host, x509),
+ "HostnameVerifier shouldn't allow [" + host + "]");
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestHBaseTrustManager.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestHBaseTrustManager.java
index 31a443758f9..beea99a336f 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestHBaseTrustManager.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestHBaseTrustManager.java
@@ -17,7 +17,7 @@
*/
package org.apache.hadoop.hbase.io.crypto.tls;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -39,7 +39,6 @@ import java.util.List;
import java.util.Random;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.X509ExtendedTrustManager;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.bouncycastle.asn1.x500.X500NameBuilder;
@@ -55,12 +54,11 @@ import org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.operator.ContentSigner;
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.mockito.stubbing.Answer;
//
@@ -71,13 +69,10 @@ import org.mockito.stubbing.Answer;
* "https://github.com/apache/zookeeper/blob/c74658d398cdc1d207aa296cb6e20de00faec03e/zookeeper-server/src/test/java/org/apache/zookeeper/common/HBaseTrustManagerTest.java">Base
* revision</a>
*/
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestHBaseTrustManager {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestHBaseTrustManager.class);
-
private static KeyPair keyPair;
private X509ExtendedTrustManager mockX509ExtendedTrustManager;
@@ -91,7 +86,7 @@ public class TestHBaseTrustManager {
private SSLEngine mockSSLEngineWithoutPeerhost;
private SSLEngine mockSSLEngineWithPeerhost;
- @BeforeClass
+ @BeforeAll
public static void createKeyPair() throws Exception {
Security.addProvider(new BouncyCastleProvider());
KeyPairGenerator keyPairGenerator =
@@ -100,12 +95,12 @@ public class TestHBaseTrustManager {
keyPair = keyPairGenerator.genKeyPair();
}
- @AfterClass
+ @AfterAll
public static void removeBouncyCastleProvider() throws Exception {
Security.removeProvider("BC");
}
- @Before
+ @BeforeEach
public void setup() throws Exception {
mockX509ExtendedTrustManager = mock(X509ExtendedTrustManager.class);
@@ -192,7 +187,6 @@ public class TestHBaseTrustManager {
mockSocketWithHostname);
}
- @SuppressWarnings("checkstyle:linelength")
@Test
public void testServerTrustedWithHostnameVerificationDisabled() throws Exception {
HBaseTrustManager trustManager =
@@ -370,12 +364,13 @@ public class TestHBaseTrustManager {
trustManager.checkClientTrusted(certificateChain, null, mockSSLEngineWithPeerhost);
}
- @Test(expected = CertificateException.class)
+ @Test
public void testClientTrustedSslEngineWithPeerHostNoReverseLookup() throws Exception {
HBaseTrustManager trustManager =
new HBaseTrustManager(mockX509ExtendedTrustManager, true, false);
X509Certificate[] certificateChain = createSelfSignedCertificateChain(null, HOSTNAME);
- trustManager.checkClientTrusted(certificateChain, null, mockSSLEngineWithPeerhost);
+ assertThrows(CertificateException.class,
+ () -> trustManager.checkClientTrusted(certificateChain, null, mockSSLEngineWithPeerhost));
}
@Test
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestJKSFileLoader.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestJKSFileLoader.java
index 6640e3b22f9..51867524c1d 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestJKSFileLoader.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestJKSFileLoader.java
@@ -17,17 +17,16 @@
*/
package org.apache.hadoop.hbase.io.crypto.tls;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
import java.io.IOException;
import java.security.KeyStore;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.testclassification.SecurityTests;
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.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
/**
* This file has been copied from the Apache ZooKeeper project.
@@ -35,83 +34,100 @@ import org.junit.runners.Parameterized;
* "https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/test/java/org/apache/zookeeper/common/JKSFileLoaderTest.java">Base
* revision</a>
*/
-@RunWith(Parameterized.class)
-@Category({ SecurityTests.class, SmallTests.class })
+@Tag(SecurityTests.TAG)
+@Tag(SmallTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: caKeyType={0}, certKeyType={1}, keyPassword={2}")
public class TestJKSFileLoader extends AbstractTestX509Parameterized {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestJKSFileLoader.class);
+ public TestJKSFileLoader(X509KeyType caKeyType, X509KeyType certKeyType, char[] keyPassword) {
+ super(caKeyType, certKeyType, keyPassword);
+ }
- @Test
+ @TestTemplate
public void testLoadKeyStore() throws Exception {
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS).getAbsolutePath();
KeyStore ks = new JKSFileLoader.Builder().setKeyStorePath(path)
.setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore();
- Assert.assertEquals(1, ks.size());
+ assertEquals(1, ks.size());
}
- @Test(expected = Exception.class)
- public void testLoadKeyStoreWithWrongPassword() throws Exception {
+ @TestTemplate
+ public void testLoadKeyStoreWithWrongPassword() throws IOException {
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS).getAbsolutePath();
- new JKSFileLoader.Builder().setKeyStorePath(path)
- .setKeyStorePassword("wrong password".toCharArray()).build().loadKeyStore();
+ assertThrows(IOException.class, () -> {
+ new JKSFileLoader.Builder().setKeyStorePath(path)
+ .setKeyStorePassword("wrong password".toCharArray()).build().loadKeyStore();
+ });
}
- @Test(expected = IOException.class)
- public void testLoadKeyStoreWithWrongFilePath() throws Exception {
+ @TestTemplate
+ public void testLoadKeyStoreWithWrongFilePath() throws IOException {
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS).getAbsolutePath();
- new JKSFileLoader.Builder().setKeyStorePath(path + ".does_not_exist")
- .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore();
+ assertThrows(IOException.class, () -> {
+ new JKSFileLoader.Builder().setKeyStorePath(path + ".does_not_exist")
+ .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore();
+ });
}
- @Test(expected = NullPointerException.class)
- public void testLoadKeyStoreWithNullFilePath() throws Exception {
- new JKSFileLoader.Builder().setKeyStorePassword(x509TestContext.getKeyStorePassword()).build()
- .loadKeyStore();
+ @TestTemplate
+ public void testLoadKeyStoreWithNullFilePath() {
+ assertThrows(NullPointerException.class, () -> {
+ new JKSFileLoader.Builder().setKeyStorePassword(x509TestContext.getKeyStorePassword()).build()
+ .loadKeyStore();
+ });
}
- @Test(expected = IOException.class)
- public void testLoadKeyStoreWithWrongFileType() throws Exception {
- // Trying to load a PEM file with JKS loader should fail
+ @TestTemplate
+ public void testLoadKeyStoreWithWrongFileType() throws IOException {
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath();
- new JKSFileLoader.Builder().setKeyStorePath(path)
- .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore();
+ assertThrows(IOException.class, () -> {
+ // Trying to load a PEM file with JKS loader should fail
+ new JKSFileLoader.Builder().setKeyStorePath(path)
+ .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore();
+ });
}
- @Test
+ @TestTemplate
public void testLoadTrustStore() throws Exception {
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS).getAbsolutePath();
KeyStore ts = new JKSFileLoader.Builder().setTrustStorePath(path)
.setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore();
- Assert.assertEquals(1, ts.size());
+ assertEquals(1, ts.size());
}
- @Test(expected = Exception.class)
- public void testLoadTrustStoreWithWrongPassword() throws Exception {
+ @TestTemplate
+ public void testLoadTrustStoreWithWrongPassword() throws IOException {
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS).getAbsolutePath();
- new JKSFileLoader.Builder().setTrustStorePath(path)
- .setTrustStorePassword("wrong password".toCharArray()).build().loadTrustStore();
+ assertThrows(IOException.class, () -> {
+ new JKSFileLoader.Builder().setTrustStorePath(path)
+ .setTrustStorePassword("wrong password".toCharArray()).build().loadTrustStore();
+ });
}
- @Test(expected = IOException.class)
- public void testLoadTrustStoreWithWrongFilePath() throws Exception {
+ @TestTemplate
+ public void testLoadTrustStoreWithWrongFilePath() throws IOException {
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS).getAbsolutePath();
- new JKSFileLoader.Builder().setTrustStorePath(path + ".does_not_exist")
- .setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore();
+ assertThrows(IOException.class, () -> {
+ new JKSFileLoader.Builder().setTrustStorePath(path + ".does_not_exist")
+ .setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore();
+ });
}
- @Test(expected = NullPointerException.class)
- public void testLoadTrustStoreWithNullFilePath() throws Exception {
- new JKSFileLoader.Builder().setTrustStorePassword(x509TestContext.getTrustStorePassword())
- .build().loadTrustStore();
+ @TestTemplate
+ public void testLoadTrustStoreWithNullFilePath() {
+ assertThrows(NullPointerException.class, () -> {
+ new JKSFileLoader.Builder().setTrustStorePassword(x509TestContext.getTrustStorePassword())
+ .build().loadTrustStore();
+ });
}
- @Test(expected = IOException.class)
- public void testLoadTrustStoreWithWrongFileType() throws Exception {
- // Trying to load a PEM file with JKS loader should fail
- String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM).getAbsolutePath();
- new JKSFileLoader.Builder().setTrustStorePath(path)
- .setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore();
+ @TestTemplate
+ public void testLoadTrustStoreWithWrongFileType() {
+ assertThrows(IOException.class, () -> {
+ // Trying to load a PEM file with JKS loader should fail
+ String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM).getAbsolutePath();
+ new JKSFileLoader.Builder().setTrustStorePath(path)
+ .setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore();
+ });
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestKeyStoreFileType.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestKeyStoreFileType.java
index d3f457fb4d3..b79a9d03420 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestKeyStoreFileType.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestKeyStoreFileType.java
@@ -17,13 +17,14 @@
*/
package org.apache.hadoop.hbase.io.crypto.tls;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+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 org.apache.hadoop.hbase.testclassification.SecurityTests;
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;
/**
* This file has been copied from the Apache ZooKeeper project.
@@ -31,90 +32,88 @@ import org.junit.experimental.categories.Category;
* "https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/test/java/org/apache/zookeeper/common/KeyStoreFileTypeTest.java">Base
* revision</a>
*/
-@Category({ SecurityTests.class, SmallTests.class })
+@Tag(SecurityTests.TAG)
+@Tag(SmallTests.TAG)
public class TestKeyStoreFileType {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestKeyStoreFileType.class);
-
@Test
public void testGetPropertyValue() {
- Assert.assertEquals("PEM", KeyStoreFileType.PEM.getPropertyValue());
- Assert.assertEquals("JKS", KeyStoreFileType.JKS.getPropertyValue());
- Assert.assertEquals("PKCS12", KeyStoreFileType.PKCS12.getPropertyValue());
- Assert.assertEquals("BCFKS", KeyStoreFileType.BCFKS.getPropertyValue());
+ assertEquals("PEM", KeyStoreFileType.PEM.getPropertyValue());
+ assertEquals("JKS", KeyStoreFileType.JKS.getPropertyValue());
+ assertEquals("PKCS12", KeyStoreFileType.PKCS12.getPropertyValue());
+ assertEquals("BCFKS", KeyStoreFileType.BCFKS.getPropertyValue());
}
@Test
public void testFromPropertyValue() {
- Assert.assertEquals(KeyStoreFileType.PEM, KeyStoreFileType.fromPropertyValue("PEM"));
- Assert.assertEquals(KeyStoreFileType.JKS, KeyStoreFileType.fromPropertyValue("JKS"));
- Assert.assertEquals(KeyStoreFileType.PKCS12, KeyStoreFileType.fromPropertyValue("PKCS12"));
- Assert.assertEquals(KeyStoreFileType.BCFKS, KeyStoreFileType.fromPropertyValue("BCFKS"));
- Assert.assertNull(KeyStoreFileType.fromPropertyValue(""));
- Assert.assertNull(KeyStoreFileType.fromPropertyValue(null));
+ assertEquals(KeyStoreFileType.PEM, KeyStoreFileType.fromPropertyValue("PEM"));
+ assertEquals(KeyStoreFileType.JKS, KeyStoreFileType.fromPropertyValue("JKS"));
+ assertEquals(KeyStoreFileType.PKCS12, KeyStoreFileType.fromPropertyValue("PKCS12"));
+ assertEquals(KeyStoreFileType.BCFKS, KeyStoreFileType.fromPropertyValue("BCFKS"));
+ assertNull(KeyStoreFileType.fromPropertyValue(""));
+ assertNull(KeyStoreFileType.fromPropertyValue(null));
}
@Test
public void testFromPropertyValueIgnoresCase() {
- Assert.assertEquals(KeyStoreFileType.PEM, KeyStoreFileType.fromPropertyValue("pem"));
- Assert.assertEquals(KeyStoreFileType.JKS, KeyStoreFileType.fromPropertyValue("jks"));
- Assert.assertEquals(KeyStoreFileType.PKCS12, KeyStoreFileType.fromPropertyValue("pkcs12"));
- Assert.assertEquals(KeyStoreFileType.BCFKS, KeyStoreFileType.fromPropertyValue("bcfks"));
- Assert.assertNull(KeyStoreFileType.fromPropertyValue(""));
- Assert.assertNull(KeyStoreFileType.fromPropertyValue(null));
+ assertEquals(KeyStoreFileType.PEM, KeyStoreFileType.fromPropertyValue("pem"));
+ assertEquals(KeyStoreFileType.JKS, KeyStoreFileType.fromPropertyValue("jks"));
+ assertEquals(KeyStoreFileType.PKCS12, KeyStoreFileType.fromPropertyValue("pkcs12"));
+ assertEquals(KeyStoreFileType.BCFKS, KeyStoreFileType.fromPropertyValue("bcfks"));
+ assertNull(KeyStoreFileType.fromPropertyValue(""));
+ assertNull(KeyStoreFileType.fromPropertyValue(null));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testFromPropertyValueThrowsOnBadPropertyValue() {
- KeyStoreFileType.fromPropertyValue("foobar");
+ assertThrows(IllegalArgumentException.class,
+ () -> KeyStoreFileType.fromPropertyValue("foobar"));
}
@Test
public void testFromFilename() {
- Assert.assertEquals(KeyStoreFileType.JKS, KeyStoreFileType.fromFilename("mykey.jks"));
- Assert.assertEquals(KeyStoreFileType.JKS,
- KeyStoreFileType.fromFilename("/path/to/key/dir/mykey.jks"));
- Assert.assertEquals(KeyStoreFileType.PEM, KeyStoreFileType.fromFilename("mykey.pem"));
- Assert.assertEquals(KeyStoreFileType.PEM,
- KeyStoreFileType.fromFilename("/path/to/key/dir/mykey.pem"));
- Assert.assertEquals(KeyStoreFileType.PKCS12, KeyStoreFileType.fromFilename("mykey.p12"));
- Assert.assertEquals(KeyStoreFileType.PKCS12,
+ assertEquals(KeyStoreFileType.JKS, KeyStoreFileType.fromFilename("mykey.jks"));
+ assertEquals(KeyStoreFileType.JKS, KeyStoreFileType.fromFilename("/path/to/key/dir/mykey.jks"));
+ assertEquals(KeyStoreFileType.PEM, KeyStoreFileType.fromFilename("mykey.pem"));
+ assertEquals(KeyStoreFileType.PEM, KeyStoreFileType.fromFilename("/path/to/key/dir/mykey.pem"));
+ assertEquals(KeyStoreFileType.PKCS12, KeyStoreFileType.fromFilename("mykey.p12"));
+ assertEquals(KeyStoreFileType.PKCS12,
KeyStoreFileType.fromFilename("/path/to/key/dir/mykey.p12"));
- Assert.assertEquals(KeyStoreFileType.BCFKS, KeyStoreFileType.fromFilename("mykey.bcfks"));
- Assert.assertEquals(KeyStoreFileType.BCFKS,
+ assertEquals(KeyStoreFileType.BCFKS, KeyStoreFileType.fromFilename("mykey.bcfks"));
+ assertEquals(KeyStoreFileType.BCFKS,
KeyStoreFileType.fromFilename("/path/to/key/dir/mykey.bcfks"));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testFromFilenameThrowsOnBadFileExtension() {
- KeyStoreFileType.fromFilename("prod.key");
+ assertThrows(IllegalArgumentException.class, () -> KeyStoreFileType.fromFilename("prod.key"));
}
@Test
public void testFromPropertyValueOrFileName() {
// Property value takes precedence if provided
- Assert.assertEquals(KeyStoreFileType.JKS,
+ assertEquals(KeyStoreFileType.JKS,
KeyStoreFileType.fromPropertyValueOrFileName("JKS", "prod.key"));
- Assert.assertEquals(KeyStoreFileType.PEM,
+ assertEquals(KeyStoreFileType.PEM,
KeyStoreFileType.fromPropertyValueOrFileName("PEM", "prod.key"));
- Assert.assertEquals(KeyStoreFileType.PKCS12,
+ assertEquals(KeyStoreFileType.PKCS12,
KeyStoreFileType.fromPropertyValueOrFileName("PKCS12", "prod.key"));
- Assert.assertEquals(KeyStoreFileType.BCFKS,
+ assertEquals(KeyStoreFileType.BCFKS,
KeyStoreFileType.fromPropertyValueOrFileName("BCFKS", "prod.key"));
// Falls back to filename detection if no property value
- Assert.assertEquals(KeyStoreFileType.JKS,
+ assertEquals(KeyStoreFileType.JKS,
KeyStoreFileType.fromPropertyValueOrFileName("", "prod.jks"));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testFromPropertyValueOrFileNameThrowsOnBadPropertyValue() {
- KeyStoreFileType.fromPropertyValueOrFileName("foobar", "prod.jks");
+ assertThrows(IllegalArgumentException.class,
+ () -> KeyStoreFileType.fromPropertyValueOrFileName("foobar", "prod.jks"));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testFromPropertyValueOrFileNameThrowsOnBadFileExtension() {
- KeyStoreFileType.fromPropertyValueOrFileName("", "prod.key");
+ assertThrows(IllegalArgumentException.class,
+ () -> KeyStoreFileType.fromPropertyValueOrFileName("", "prod.key"));
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestPEMFileLoader.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestPEMFileLoader.java
index 0c9924f0907..86a90cb40b3 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestPEMFileLoader.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestPEMFileLoader.java
@@ -17,18 +17,17 @@
*/
package org.apache.hadoop.hbase.io.crypto.tls;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
import java.io.IOException;
import java.security.KeyStore;
import java.security.KeyStoreException;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.testclassification.SecurityTests;
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.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
/**
* This file has been copied from the Apache ZooKeeper project.
@@ -36,77 +35,90 @@ import org.junit.runners.Parameterized;
* "https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/test/java/org/apache/zookeeper/common/PEMFileLoaderTest.java">Base
* revision</a>
*/
-@RunWith(Parameterized.class)
-@Category({ SecurityTests.class, SmallTests.class })
+@Tag(SecurityTests.TAG)
+@Tag(SmallTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: caKeyType={0}, certKeyType={1}, keyPassword={2}")
public class TestPEMFileLoader extends AbstractTestX509Parameterized {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestPEMFileLoader.class);
+ public TestPEMFileLoader(X509KeyType caKeyType, X509KeyType certKeyType, char[] keyPassword) {
+ super(caKeyType, certKeyType, keyPassword);
+ }
- @Test
+ @TestTemplate
public void testLoadKeyStore() throws Exception {
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath();
KeyStore ks = new PEMFileLoader.Builder().setKeyStorePath(path)
.setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore();
- Assert.assertEquals(1, ks.size());
+ assertEquals(1, ks.size());
}
- @Test(expected = Exception.class)
- public void testLoadKeyStoreWithWrongPassword() throws Exception {
+ @TestTemplate
+ public void testLoadKeyStoreWithWrongPassword() throws IOException {
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath();
- new PEMFileLoader.Builder().setKeyStorePath(path)
- .setKeyStorePassword("wrong password".toCharArray()).build().loadKeyStore();
+ assertThrows(Exception.class, () -> {
+ new PEMFileLoader.Builder().setKeyStorePath(path)
+ .setKeyStorePassword("wrong password".toCharArray()).build().loadKeyStore();
+ });
}
- @Test(expected = IOException.class)
- public void testLoadKeyStoreWithWrongFilePath() throws Exception {
+ @TestTemplate
+ public void testLoadKeyStoreWithWrongFilePath() throws IOException {
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath();
- new PEMFileLoader.Builder().setKeyStorePath(path + ".does_not_exist")
- .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore();
+ assertThrows(IOException.class, () -> {
+ new PEMFileLoader.Builder().setKeyStorePath(path + ".does_not_exist")
+ .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore();
+ });
}
- @Test(expected = NullPointerException.class)
- public void testLoadKeyStoreWithNullFilePath() throws Exception {
- new PEMFileLoader.Builder().setKeyStorePassword(x509TestContext.getKeyStorePassword()).build()
- .loadKeyStore();
+ @TestTemplate
+ public void testLoadKeyStoreWithNullFilePath() {
+ assertThrows(NullPointerException.class, () -> {
+ new PEMFileLoader.Builder().setKeyStorePassword(x509TestContext.getKeyStorePassword()).build()
+ .loadKeyStore();
+ });
}
- @Test(expected = KeyStoreException.class)
- public void testLoadKeyStoreWithWrongFileType() throws Exception {
- // Trying to load a JKS file with PEM loader should fail
+ @TestTemplate
+ public void testLoadKeyStoreWithWrongFileType() throws IOException {
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS).getAbsolutePath();
- new PEMFileLoader.Builder().setKeyStorePath(path)
- .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore();
+ assertThrows(KeyStoreException.class, () -> {
+ // Trying to load a JKS file with PEM loader should fail
+ new PEMFileLoader.Builder().setKeyStorePath(path)
+ .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore();
+ });
}
- @Test
+ @TestTemplate
public void testLoadTrustStore() throws Exception {
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM).getAbsolutePath();
KeyStore ts = new PEMFileLoader.Builder().setTrustStorePath(path)
.setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore();
- Assert.assertEquals(1, ts.size());
+ assertEquals(1, ts.size());
}
- @Test(expected = IOException.class)
- public void testLoadTrustStoreWithWrongFilePath() throws Exception {
+ @TestTemplate
+ public void testLoadTrustStoreWithWrongFilePath() throws IOException {
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM).getAbsolutePath();
- new PEMFileLoader.Builder().setTrustStorePath(path + ".does_not_exist")
- .setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore();
+ assertThrows(IOException.class, () -> {
+ new PEMFileLoader.Builder().setTrustStorePath(path + ".does_not_exist")
+ .setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore();
+ });
}
- @Test(expected = NullPointerException.class)
- public void testLoadTrustStoreWithNullFilePath() throws Exception {
- new PEMFileLoader.Builder().setTrustStorePassword(x509TestContext.getTrustStorePassword())
- .build().loadTrustStore();
+ @TestTemplate
+ public void testLoadTrustStoreWithNullFilePath() {
+ assertThrows(NullPointerException.class, () -> {
+ new PEMFileLoader.Builder().setTrustStorePassword(x509TestContext.getTrustStorePassword())
+ .build().loadTrustStore();
+ });
}
- @Test
+ @TestTemplate
public void testLoadTrustStoreWithWrongFileType() throws Exception {
// Trying to load a JKS file with PEM loader should fail
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS).getAbsolutePath();
KeyStore ts = new PEMFileLoader.Builder().setTrustStorePath(path)
.setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore();
- Assert.assertEquals(0, ts.size());
+ assertEquals(0, ts.size());
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestPKCS12FileLoader.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestPKCS12FileLoader.java
index a0ff83833e2..fe8249356e6 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestPKCS12FileLoader.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestPKCS12FileLoader.java
@@ -17,17 +17,16 @@
*/
package org.apache.hadoop.hbase.io.crypto.tls;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
import java.io.IOException;
import java.security.KeyStore;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.testclassification.SecurityTests;
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.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
/**
* This file has been copied from the Apache ZooKeeper project.
@@ -35,83 +34,100 @@ import org.junit.runners.Parameterized;
* "https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/test/java/org/apache/zookeeper/common/PKCS12FileLoaderTest.java">Base
* revision</a>
*/
-@RunWith(Parameterized.class)
-@Category({ SecurityTests.class, SmallTests.class })
+@Tag(SecurityTests.TAG)
+@Tag(SmallTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: caKeyType={0}, certKeyType={1}, keyPassword={2}")
public class TestPKCS12FileLoader extends AbstractTestX509Parameterized {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestPKCS12FileLoader.class);
+ public TestPKCS12FileLoader(X509KeyType caKeyType, X509KeyType certKeyType, char[] keyPassword) {
+ super(caKeyType, certKeyType, keyPassword);
+ }
- @Test
+ @TestTemplate
public void testLoadKeyStore() throws Exception {
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath();
KeyStore ks = new PKCS12FileLoader.Builder().setKeyStorePath(path)
.setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore();
- Assert.assertEquals(1, ks.size());
+ assertEquals(1, ks.size());
}
- @Test(expected = Exception.class)
- public void testLoadKeyStoreWithWrongPassword() throws Exception {
+ @TestTemplate
+ public void testLoadKeyStoreWithWrongPassword() throws IOException {
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath();
- new PKCS12FileLoader.Builder().setKeyStorePath(path)
- .setKeyStorePassword("wrong password".toCharArray()).build().loadKeyStore();
+ assertThrows(IOException.class, () -> {
+ new PKCS12FileLoader.Builder().setKeyStorePath(path)
+ .setKeyStorePassword("wrong password".toCharArray()).build().loadKeyStore();
+ });
}
- @Test(expected = IOException.class)
- public void testLoadKeyStoreWithWrongFilePath() throws Exception {
+ @TestTemplate
+ public void testLoadKeyStoreWithWrongFilePath() throws IOException {
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath();
- new PKCS12FileLoader.Builder().setKeyStorePath(path + ".does_not_exist")
- .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore();
+ assertThrows(IOException.class, () -> {
+ new PKCS12FileLoader.Builder().setKeyStorePath(path + ".does_not_exist")
+ .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore();
+ });
}
- @Test(expected = NullPointerException.class)
- public void testLoadKeyStoreWithNullFilePath() throws Exception {
- new PKCS12FileLoader.Builder().setKeyStorePassword(x509TestContext.getKeyStorePassword())
- .build().loadKeyStore();
+ @TestTemplate
+ public void testLoadKeyStoreWithNullFilePath() {
+ assertThrows(NullPointerException.class, () -> {
+ new PKCS12FileLoader.Builder().setKeyStorePassword(x509TestContext.getKeyStorePassword())
+ .build().loadKeyStore();
+ });
}
- @Test(expected = IOException.class)
- public void testLoadKeyStoreWithWrongFileType() throws Exception {
- // Trying to load a PEM file with PKCS12 loader should fail
+ @TestTemplate
+ public void testLoadKeyStoreWithWrongFileType() throws IOException {
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath();
- new PKCS12FileLoader.Builder().setKeyStorePath(path)
- .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore();
+ assertThrows(IOException.class, () -> {
+ // Trying to load a PEM file with PKCS12 loader should fail
+ new PKCS12FileLoader.Builder().setKeyStorePath(path)
+ .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore();
+ });
}
- @Test
+ @TestTemplate
public void testLoadTrustStore() throws Exception {
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath();
KeyStore ts = new PKCS12FileLoader.Builder().setTrustStorePath(path)
.setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore();
- Assert.assertEquals(1, ts.size());
+ assertEquals(1, ts.size());
}
- @Test(expected = Exception.class)
- public void testLoadTrustStoreWithWrongPassword() throws Exception {
+ @TestTemplate
+ public void testLoadTrustStoreWithWrongPassword() throws IOException {
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath();
- new PKCS12FileLoader.Builder().setTrustStorePath(path)
- .setTrustStorePassword("wrong password".toCharArray()).build().loadTrustStore();
+ assertThrows(IOException.class, () -> {
+ new PKCS12FileLoader.Builder().setTrustStorePath(path)
+ .setTrustStorePassword("wrong password".toCharArray()).build().loadTrustStore();
+ });
}
- @Test(expected = IOException.class)
- public void testLoadTrustStoreWithWrongFilePath() throws Exception {
+ @TestTemplate
+ public void testLoadTrustStoreWithWrongFilePath() throws IOException {
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath();
- new PKCS12FileLoader.Builder().setTrustStorePath(path + ".does_not_exist")
- .setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore();
+ assertThrows(IOException.class, () -> {
+ new PKCS12FileLoader.Builder().setTrustStorePath(path + ".does_not_exist")
+ .setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore();
+ });
}
- @Test(expected = NullPointerException.class)
- public void testLoadTrustStoreWithNullFilePath() throws Exception {
- new PKCS12FileLoader.Builder().setTrustStorePassword(x509TestContext.getTrustStorePassword())
- .build().loadTrustStore();
+ @TestTemplate
+ public void testLoadTrustStoreWithNullFilePath() {
+ assertThrows(NullPointerException.class, () -> {
+ new PKCS12FileLoader.Builder().setTrustStorePassword(x509TestContext.getTrustStorePassword())
+ .build().loadTrustStore();
+ });
}
- @Test(expected = IOException.class)
- public void testLoadTrustStoreWithWrongFileType() throws Exception {
- // Trying to load a PEM file with PKCS12 loader should fail
- String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM).getAbsolutePath();
- new PKCS12FileLoader.Builder().setTrustStorePath(path)
- .setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore();
+ @TestTemplate
+ public void testLoadTrustStoreWithWrongFileType() {
+ assertThrows(IOException.class, () -> {
+ // Trying to load a PEM file with PKCS12 loader should fail
+ String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM).getAbsolutePath();
+ new PKCS12FileLoader.Builder().setTrustStorePath(path)
+ .setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore();
+ });
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestX509Util.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestX509Util.java
index dd43f8be5cb..7231d23c79e 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestX509Util.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestX509Util.java
@@ -19,29 +19,25 @@ package org.apache.hadoop.hbase.io.crypto.tls;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.equalTo;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeThat;
+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.Mockito.mock;
import java.security.Security;
import java.util.Arrays;
import java.util.Collections;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.exceptions.KeyManagerException;
import org.apache.hadoop.hbase.exceptions.SSLContextException;
import org.apache.hadoop.hbase.exceptions.TrustManagerException;
import org.apache.hadoop.hbase.testclassification.SecurityTests;
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.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
import org.apache.hbase.thirdparty.io.netty.buffer.ByteBufAllocator;
import org.apache.hbase.thirdparty.io.netty.handler.ssl.SslContext;
@@ -52,24 +48,25 @@ import org.apache.hbase.thirdparty.io.netty.handler.ssl.SslContext;
* "https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/test/java/org/apache/zookeeper/common/X509UtilTest.java">Base
* revision</a>
*/
-@RunWith(Parameterized.class)
-@Category({ SecurityTests.class, SmallTests.class })
+@Tag(SecurityTests.TAG)
+@Tag(SmallTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: caKeyType={0}, certKeyType={1}, keyPassword={2}")
public class TestX509Util extends AbstractTestX509Parameterized {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestX509Util.class);
-
private static final char[] EMPTY_CHAR_ARRAY = new char[0];
- @Test
+ public TestX509Util(X509KeyType caKeyType, X509KeyType certKeyType, char[] keyPassword) {
+ super(caKeyType, certKeyType, keyPassword);
+ }
+
+ @TestTemplate
public void testCreateSSLContextWithClientAuthDefault() throws Exception {
SslContext sslContext = X509Util.createSslContextForServer(conf);
ByteBufAllocator byteBufAllocatorMock = mock(ByteBufAllocator.class);
assertTrue(sslContext.newEngine(byteBufAllocatorMock).getNeedClientAuth());
}
- @Test
+ @TestTemplate
public void testCreateSSLContextWithClientAuthNEED() throws Exception {
conf.set(X509Util.HBASE_SERVER_NETTY_TLS_CLIENT_AUTH_MODE, X509Util.ClientAuth.NEED.name());
SslContext sslContext = X509Util.createSslContextForServer(conf);
@@ -77,7 +74,7 @@ public class TestX509Util extends AbstractTestX509Parameterized {
assertTrue(sslContext.newEngine(byteBufAllocatorMock).getNeedClientAuth());
}
- @Test
+ @TestTemplate
public void testCreateSSLContextWithClientAuthWANT() throws Exception {
conf.set(X509Util.HBASE_SERVER_NETTY_TLS_CLIENT_AUTH_MODE, X509Util.ClientAuth.WANT.name());
SslContext sslContext = X509Util.createSslContextForServer(conf);
@@ -85,7 +82,7 @@ public class TestX509Util extends AbstractTestX509Parameterized {
assertTrue(sslContext.newEngine(byteBufAllocatorMock).getWantClientAuth());
}
- @Test
+ @TestTemplate
public void testCreateSSLContextWithClientAuthNONE() throws Exception {
conf.set(X509Util.HBASE_SERVER_NETTY_TLS_CLIENT_AUTH_MODE, X509Util.ClientAuth.NONE.name());
SslContext sslContext = X509Util.createSslContextForServer(conf);
@@ -94,7 +91,7 @@ public class TestX509Util extends AbstractTestX509Parameterized {
assertFalse(sslContext.newEngine(byteBufAllocatorMock).getWantClientAuth());
}
- @Test
+ @TestTemplate
public void testCreateSSLContextWithoutCustomProtocol() throws Exception {
SslContext sslContext = X509Util.createSslContextForClient(conf);
ByteBufAllocator byteBufAllocatorMock = mock(ByteBufAllocator.class);
@@ -102,7 +99,7 @@ public class TestX509Util extends AbstractTestX509Parameterized {
sslContext.newEngine(byteBufAllocatorMock).getEnabledProtocols());
}
- @Test
+ @TestTemplate
public void testCreateSSLContextWithCustomProtocol() throws Exception {
final String protocol = "TLSv1.1";
conf.set(X509Util.TLS_CONFIG_PROTOCOL, protocol);
@@ -112,25 +109,27 @@ public class TestX509Util extends AbstractTestX509Parameterized {
Arrays.asList(sslContext.newEngine(byteBufAllocatorMock).getEnabledProtocols()));
}
- @Test(expected = SSLContextException.class)
- public void testCreateSSLContextWithoutKeyStoreLocationServer() throws Exception {
+ @TestTemplate
+ public void testCreateSSLContextWithoutKeyStoreLocationServer() {
conf.unset(X509Util.TLS_CONFIG_KEYSTORE_LOCATION);
- X509Util.createSslContextForServer(conf);
+ assertThrows(SSLContextException.class, () -> {
+ X509Util.createSslContextForServer(conf);
+ });
}
- @Test
+ @TestTemplate
public void testCreateSSLContextWithoutKeyStoreLocationClient() throws Exception {
conf.unset(X509Util.TLS_CONFIG_KEYSTORE_LOCATION);
X509Util.createSslContextForClient(conf);
}
- @Test
+ @TestTemplate
public void testCreateSSLContextWithoutTrustStoreLocationClient() throws Exception {
conf.unset(X509Util.TLS_CONFIG_TRUSTSTORE_LOCATION);
X509Util.createSslContextForClient(conf);
}
- @Test
+ @TestTemplate
public void testCreateSSLContextWithoutTrustStoreLocationServer() throws Exception {
conf.unset(X509Util.TLS_CONFIG_TRUSTSTORE_LOCATION);
X509Util.createSslContextForServer(conf);
@@ -138,7 +137,7 @@ public class TestX509Util extends AbstractTestX509Parameterized {
// It would be great to test the value of PKIXBuilderParameters#setRevocationEnabled,
// but it does not appear to be possible
- @Test
+ @TestTemplate
public void testCRLEnabled() throws Exception {
conf.setBoolean(X509Util.TLS_CONFIG_CLR, true);
X509Util.createSslContextForServer(conf);
@@ -147,7 +146,7 @@ public class TestX509Util extends AbstractTestX509Parameterized {
assertFalse(Boolean.valueOf(Security.getProperty("ocsp.enable")));
}
- @Test
+ @TestTemplate
public void testCRLDisabled() throws Exception {
X509Util.createSslContextForServer(conf);
assertFalse(Boolean.valueOf(System.getProperty("com.sun.net.ssl.checkRevocation")));
@@ -155,7 +154,7 @@ public class TestX509Util extends AbstractTestX509Parameterized {
assertFalse(Boolean.valueOf(Security.getProperty("ocsp.enable")));
}
- @Test
+ @TestTemplate
public void testLoadPEMKeyStore() throws Exception {
// Make sure we can instantiate a key manager from the PEM file on disk
X509Util.createKeyManager(
@@ -163,16 +162,16 @@ public class TestX509Util extends AbstractTestX509Parameterized {
x509TestContext.getKeyStorePassword(), KeyStoreFileType.PEM.getPropertyValue());
}
- @Test
+ @TestTemplate
public void testLoadPEMKeyStoreNullPassword() throws Exception {
- assumeThat(x509TestContext.getKeyStorePassword(), equalTo(EMPTY_CHAR_ARRAY));
+ assumeTrue(Arrays.equals(x509TestContext.getKeyStorePassword(), EMPTY_CHAR_ARRAY));
// Make sure that empty password and null password are treated the same
X509Util.createKeyManager(
x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath(), null,
KeyStoreFileType.PEM.getPropertyValue());
}
- @Test
+ @TestTemplate
public void testLoadPEMKeyStoreAutodetectStoreFileType() throws Exception {
// Make sure we can instantiate a key manager from the PEM file on disk
X509Util.createKeyManager(
@@ -181,16 +180,18 @@ public class TestX509Util extends AbstractTestX509Parameterized {
null /* null StoreFileType means 'autodetect from file extension' */);
}
- @Test(expected = KeyManagerException.class)
- public void testLoadPEMKeyStoreWithWrongPassword() throws Exception {
- // Attempting to load with the wrong key password should fail
- X509Util.createKeyManager(
- x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath(),
- "wrong password".toCharArray(), // intentionally use the wrong password
- KeyStoreFileType.PEM.getPropertyValue());
+ @TestTemplate
+ public void testLoadPEMKeyStoreWithWrongPassword() {
+ assertThrows(KeyManagerException.class, () -> {
+ // Attempting to load with the wrong key password should fail
+ X509Util.createKeyManager(
+ x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath(),
+ "wrong password".toCharArray(), // intentionally use the wrong password
+ KeyStoreFileType.PEM.getPropertyValue());
+ });
}
- @Test
+ @TestTemplate
public void testLoadPEMTrustStore() throws Exception {
// Make sure we can instantiate a trust manager from the PEM file on disk
X509Util.createTrustManager(
@@ -199,16 +200,16 @@ public class TestX509Util extends AbstractTestX509Parameterized {
false, true, true);
}
- @Test
+ @TestTemplate
public void testLoadPEMTrustStoreNullPassword() throws Exception {
- assumeThat(x509TestContext.getTrustStorePassword(), equalTo(EMPTY_CHAR_ARRAY));
+ assumeTrue(Arrays.equals(x509TestContext.getTrustStorePassword(), EMPTY_CHAR_ARRAY));
// Make sure that empty password and null password are treated the same
X509Util.createTrustManager(
x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM).getAbsolutePath(), null,
KeyStoreFileType.PEM.getPropertyValue(), false, false, true, true);
}
- @Test
+ @TestTemplate
public void testLoadPEMTrustStoreAutodetectStoreFileType() throws Exception {
// Make sure we can instantiate a trust manager from the PEM file on disk
X509Util.createTrustManager(
@@ -218,7 +219,7 @@ public class TestX509Util extends AbstractTestX509Parameterized {
false, false, true, true);
}
- @Test
+ @TestTemplate
public void testLoadJKSKeyStore() throws Exception {
// Make sure we can instantiate a key manager from the JKS file on disk
X509Util.createKeyManager(
@@ -226,16 +227,16 @@ public class TestX509Util extends AbstractTestX509Parameterized {
x509TestContext.getKeyStorePassword(), KeyStoreFileType.JKS.getPropertyValue());
}
- @Test
+ @TestTemplate
public void testLoadJKSKeyStoreNullPassword() throws Exception {
- assumeThat(x509TestContext.getKeyStorePassword(), equalTo(EMPTY_CHAR_ARRAY));
+ assumeTrue(Arrays.equals(x509TestContext.getKeyStorePassword(), EMPTY_CHAR_ARRAY));
// Make sure that empty password and null password are treated the same
X509Util.createKeyManager(
x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS).getAbsolutePath(), null,
KeyStoreFileType.JKS.getPropertyValue());
}
- @Test
+ @TestTemplate
public void testLoadJKSKeyStoreAutodetectStoreFileType() throws Exception {
// Make sure we can instantiate a key manager from the JKS file on disk
X509Util.createKeyManager(
@@ -244,7 +245,7 @@ public class TestX509Util extends AbstractTestX509Parameterized {
null /* null StoreFileType means 'autodetect from file extension' */);
}
- @Test
+ @TestTemplate
public void testLoadJKSKeyStoreWithWrongPassword() {
assertThrows(KeyManagerException.class, () -> {
// Attempting to load with the wrong key password should fail
@@ -254,7 +255,7 @@ public class TestX509Util extends AbstractTestX509Parameterized {
});
}
- @Test
+ @TestTemplate
public void testLoadJKSTrustStore() throws Exception {
// Make sure we can instantiate a trust manager from the JKS file on disk
X509Util.createTrustManager(
@@ -263,26 +264,25 @@ public class TestX509Util extends AbstractTestX509Parameterized {
true, true);
}
- @Test
+ @TestTemplate
public void testLoadJKSTrustStoreNullPassword() throws Exception {
- assumeThat(x509TestContext.getTrustStorePassword(), equalTo(EMPTY_CHAR_ARRAY));
+ assumeTrue(Arrays.equals(x509TestContext.getTrustStorePassword(), EMPTY_CHAR_ARRAY));
// Make sure that empty password and null password are treated the same
X509Util.createTrustManager(
x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS).getAbsolutePath(), null,
KeyStoreFileType.JKS.getPropertyValue(), false, false, true, true);
}
- @Test
+ @TestTemplate
public void testLoadJKSTrustStoreAutodetectStoreFileType() throws Exception {
// Make sure we can instantiate a trust manager from the JKS file on disk
+ // null StoreFileType means 'autodetect from file extension'
X509Util.createTrustManager(
x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS).getAbsolutePath(),
- x509TestContext.getTrustStorePassword(), null, // null StoreFileType means 'autodetect from
- // file extension'
- true, true, true, true);
+ x509TestContext.getTrustStorePassword(), null, true, true, true, true);
}
- @Test
+ @TestTemplate
public void testLoadJKSTrustStoreWithWrongPassword() {
assertThrows(TrustManagerException.class, () -> {
// Attempting to load with the wrong key password should fail
@@ -293,7 +293,7 @@ public class TestX509Util extends AbstractTestX509Parameterized {
});
}
- @Test
+ @TestTemplate
public void testLoadPKCS12KeyStore() throws Exception {
// Make sure we can instantiate a key manager from the PKCS12 file on disk
X509Util.createKeyManager(
@@ -301,16 +301,16 @@ public class TestX509Util extends AbstractTestX509Parameterized {
x509TestContext.getKeyStorePassword(), KeyStoreFileType.PKCS12.getPropertyValue());
}
- @Test
+ @TestTemplate
public void testLoadPKCS12KeyStoreNullPassword() throws Exception {
- assumeThat(x509TestContext.getKeyStorePassword(), equalTo(EMPTY_CHAR_ARRAY));
+ assumeTrue(Arrays.equals(x509TestContext.getKeyStorePassword(), EMPTY_CHAR_ARRAY));
// Make sure that empty password and null password are treated the same
X509Util.createKeyManager(
x509TestContext.getKeyStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath(), null,
KeyStoreFileType.PKCS12.getPropertyValue());
}
- @Test
+ @TestTemplate
public void testLoadPKCS12KeyStoreAutodetectStoreFileType() throws Exception {
// Make sure we can instantiate a key manager from the PKCS12 file on disk
X509Util.createKeyManager(
@@ -319,7 +319,7 @@ public class TestX509Util extends AbstractTestX509Parameterized {
null /* null StoreFileType means 'autodetect from file extension' */);
}
- @Test
+ @TestTemplate
public void testLoadPKCS12KeyStoreWithWrongPassword() {
assertThrows(KeyManagerException.class, () -> {
// Attempting to load with the wrong key password should fail
@@ -329,7 +329,7 @@ public class TestX509Util extends AbstractTestX509Parameterized {
});
}
- @Test
+ @TestTemplate
public void testLoadPKCS12TrustStore() throws Exception {
// Make sure we can instantiate a trust manager from the PKCS12 file on disk
X509Util.createTrustManager(
@@ -338,16 +338,16 @@ public class TestX509Util extends AbstractTestX509Parameterized {
true, true, true);
}
- @Test
+ @TestTemplate
public void testLoadPKCS12TrustStoreNullPassword() throws Exception {
- assumeThat(x509TestContext.getTrustStorePassword(), equalTo(EMPTY_CHAR_ARRAY));
+ assumeTrue(Arrays.equals(x509TestContext.getTrustStorePassword(), EMPTY_CHAR_ARRAY));
// Make sure that empty password and null password are treated the same
X509Util.createTrustManager(
x509TestContext.getTrustStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath(), null,
KeyStoreFileType.PKCS12.getPropertyValue(), false, false, true, true);
}
- @Test
+ @TestTemplate
public void testLoadPKCS12TrustStoreAutodetectStoreFileType() throws Exception {
// Make sure we can instantiate a trust manager from the PKCS12 file on disk
X509Util.createTrustManager(
@@ -357,7 +357,7 @@ public class TestX509Util extends AbstractTestX509Parameterized {
true, true, true, true);
}
- @Test
+ @TestTemplate
public void testLoadPKCS12TrustStoreWithWrongPassword() {
assertThrows(TrustManagerException.class, () -> {
// Attempting to load with the wrong key password should fail
@@ -368,42 +368,42 @@ public class TestX509Util extends AbstractTestX509Parameterized {
});
}
- @Test
+ @TestTemplate
public void testGetDefaultCipherSuitesJava8() {
String[] cipherSuites = X509Util.getDefaultCipherSuitesForJavaVersion("1.8");
// Java 8 default should have the CBC suites first
assertThat(cipherSuites[0], containsString("CBC"));
}
- @Test
+ @TestTemplate
public void testGetDefaultCipherSuitesJava9() {
String[] cipherSuites = X509Util.getDefaultCipherSuitesForJavaVersion("9");
// Java 9+ default should have the GCM suites first
assertEquals(cipherSuites[0], "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256");
}
- @Test
+ @TestTemplate
public void testGetDefaultCipherSuitesJava10() {
String[] cipherSuites = X509Util.getDefaultCipherSuitesForJavaVersion("10");
// Java 9+ default should have the GCM suites first
assertEquals(cipherSuites[0], "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256");
}
- @Test
+ @TestTemplate
public void testGetDefaultCipherSuitesJava11() {
String[] cipherSuites = X509Util.getDefaultCipherSuitesForJavaVersion("11");
// Java 11+ default should have the TLSv1.3 suites first
assertThat(cipherSuites[0], containsString("TLS_AES_128_GCM"));
}
- @Test
+ @TestTemplate
public void testGetDefaultCipherSuitesUnknownVersion() {
String[] cipherSuites = X509Util.getDefaultCipherSuitesForJavaVersion("notaversion");
// If version can't be parsed, use the more conservative Java 8 default
assertThat(cipherSuites[0], containsString("CBC"));
}
- @Test
+ @TestTemplate
public void testGetDefaultCipherSuitesNullVersion() {
assertThrows(NullPointerException.class, () -> {
X509Util.getDefaultCipherSuitesForJavaVersion(null);
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/hadoopbackport/TestThrottledInputStream.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/hadoopbackport/TestThrottledInputStream.java
index 24a0f630870..669ba8d0c99 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/hadoopbackport/TestThrottledInputStream.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/hadoopbackport/TestThrottledInputStream.java
@@ -17,22 +17,17 @@
*/
package org.apache.hadoop.hbase.io.hadoopbackport;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestThrottledInputStream {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestThrottledInputStream.class);
-
@Test
public void testCalSleepTimeMs() {
// case 0: initial - no read, no sleep
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/util/TestLRUDictionary.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/util/TestLRUDictionary.java
index 8fe9e5135ee..e2fe9d3624b 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/util/TestLRUDictionary.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/util/TestLRUDictionary.java
@@ -17,35 +17,31 @@
*/
package org.apache.hadoop.hbase.io.util;
-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.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.math.BigInteger;
import java.util.Arrays;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.testclassification.MiscTests;
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.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
/**
* Tests LRUDictionary
*/
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestLRUDictionary {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestLRUDictionary.class);
-
LRUDictionary testee;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
testee = new LRUDictionary();
testee.init(Short.MAX_VALUE);
@@ -72,8 +68,8 @@ public class TestLRUDictionary {
// works.
int len = HConstants.CATALOG_FAMILY.length;
int index = testee.addEntry(HConstants.CATALOG_FAMILY, 0, len);
- assertFalse(index == testee.addEntry(HConstants.CATALOG_FAMILY, 0, len));
- assertFalse(index == testee.addEntry(HConstants.CATALOG_FAMILY, 0, len));
+ assertNotEquals(index, testee.addEntry(HConstants.CATALOG_FAMILY, 0, len));
+ assertNotEquals(index, testee.addEntry(HConstants.CATALOG_FAMILY, 0, len));
}
@Test
@@ -93,7 +89,7 @@ public class TestLRUDictionary {
short t = testee.findEntry(testBytes, 0, testBytes.length);
// Making sure we do find what we're looking for
- assertTrue(t != -1);
+ assertNotEquals(t, -1);
byte[] testBytesCopy = new byte[20];
@@ -121,33 +117,31 @@ public class TestLRUDictionary {
}
// check we have the first element added
- assertTrue(
- testee.findEntry(BigInteger.ZERO.toByteArray(), 0, BigInteger.ZERO.toByteArray().length)
- != -1);
+ assertNotEquals(
+ testee.findEntry(BigInteger.ZERO.toByteArray(), 0, BigInteger.ZERO.toByteArray().length), -1);
// check for an element we know isn't there
- assertTrue(testee.findEntry(BigInteger.valueOf(Integer.MAX_VALUE).toByteArray(), 0,
- BigInteger.valueOf(Integer.MAX_VALUE).toByteArray().length) == -1);
+ assertEquals(testee.findEntry(BigInteger.valueOf(Integer.MAX_VALUE).toByteArray(), 0,
+ BigInteger.valueOf(Integer.MAX_VALUE).toByteArray().length), -1);
// since we just checked for this element, it should be there now.
- assertTrue(testee.findEntry(BigInteger.valueOf(Integer.MAX_VALUE).toByteArray(), 0,
- BigInteger.valueOf(Integer.MAX_VALUE).toByteArray().length) != -1);
+ assertNotEquals(testee.findEntry(BigInteger.valueOf(Integer.MAX_VALUE).toByteArray(), 0,
+ BigInteger.valueOf(Integer.MAX_VALUE).toByteArray().length), -1);
// test eviction, that the least recently added or looked at element is
// evicted. We looked at ZERO so it should be in the dictionary still.
- assertTrue(
- testee.findEntry(BigInteger.ZERO.toByteArray(), 0, BigInteger.ZERO.toByteArray().length)
- != -1);
+ assertNotEquals(
+ testee.findEntry(BigInteger.ZERO.toByteArray(), 0, BigInteger.ZERO.toByteArray().length), -1);
// Now go from beyond 1 to the end.
for (int i = 1; i < Short.MAX_VALUE; i++) {
- assertTrue(testee.findEntry(BigInteger.valueOf(i).toByteArray(), 0,
- BigInteger.valueOf(i).toByteArray().length) == -1);
+ assertEquals(testee.findEntry(BigInteger.valueOf(i).toByteArray(), 0,
+ BigInteger.valueOf(i).toByteArray().length), -1);
}
// check we can find all of these.
for (int i = 0; i < Short.MAX_VALUE; i++) {
- assertTrue(testee.findEntry(BigInteger.valueOf(i).toByteArray(), 0,
- BigInteger.valueOf(i).toByteArray().length) != -1);
+ assertNotEquals(testee.findEntry(BigInteger.valueOf(i).toByteArray(), 0,
+ BigInteger.valueOf(i).toByteArray().length), -1);
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/logging/TestJul2Slf4j.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/logging/TestJul2Slf4j.java
index 9d458f3a422..1e270ec6e1a 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/logging/TestJul2Slf4j.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/logging/TestJul2Slf4j.java
@@ -17,7 +17,7 @@
*/
package org.apache.hadoop.hbase.logging;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
@@ -30,11 +30,10 @@ import java.util.concurrent.atomic.AtomicReference;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MiscTests;
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.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -42,13 +41,10 @@ import org.mockito.stubbing.Answer;
* This should be in the hbase-logging module but the {@link HBaseClassTestRule} is in hbase-common
* so we can only put the class in hbase-common module for now...
*/
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestJul2Slf4j {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestJul2Slf4j.class);
-
static {
System.setProperty("java.util.logging.config.class", JulToSlf4jInitializer.class.getName());
}
@@ -57,7 +53,7 @@ public class TestJul2Slf4j {
private org.apache.logging.log4j.core.Appender mockAppender;
- @Before
+ @BeforeEach
public void setUp() {
mockAppender = mock(org.apache.logging.log4j.core.Appender.class);
when(mockAppender.getName()).thenReturn("mockAppender");
@@ -66,7 +62,7 @@ public class TestJul2Slf4j {
.getLogger(loggerName)).addAppender(mockAppender);
}
- @After
+ @AfterEach
public void tearDown() {
((org.apache.logging.log4j.core.Logger) org.apache.logging.log4j.LogManager
.getLogger(loggerName)).removeAppender(mockAppender);
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/logging/TestLog4jUtils.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/logging/TestLog4jUtils.java
index c5b0202ca3d..de8b169fb2d 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/logging/TestLog4jUtils.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/logging/TestLog4jUtils.java
@@ -17,28 +17,24 @@
*/
package org.apache.hadoop.hbase.logging;
-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 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;
/**
* This should be in the hbase-logging module but the {@link HBaseClassTestRule} is in hbase-common
* so we can only put the class in hbase-common module for now...
*/
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestLog4jUtils {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestLog4jUtils.class);
-
@Test
public void test() {
org.apache.logging.log4j.Logger zk =
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/net/BoundSocketMaker.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/net/BoundSocketMaker.java
index c8eb875ec0e..77d0c81356c 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/net/BoundSocketMaker.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/net/BoundSocketMaker.java
@@ -37,10 +37,6 @@ public final class BoundSocketMaker implements Closeable {
private static final Logger LOG = LoggerFactory.getLogger(BoundSocketMaker.class);
private final ServerSocket socket;
- private BoundSocketMaker() {
- this.socket = null;
- }
-
public BoundSocketMaker(Supplier<Integer> randomPortMaker) {
this(InetAddress.getLoopbackAddress().getHostName(), randomPortMaker);
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/net/TestAddress.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/net/TestAddress.java
index 75e0ed87faa..aed1fec9a93 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/net/TestAddress.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/net/TestAddress.java
@@ -17,21 +17,16 @@
*/
package org.apache.hadoop.hbase.net;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestAddress {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestAddress.class);
-
@Test
public void testGetHostWithoutDomain() {
assertEquals("a:123", Address.fromParts("a.b.c", 123).toStringWithoutDomain());
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/nio/TestMultiByteBuff.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/nio/TestMultiByteBuff.java
index 9ba774bfc02..0a3ba53a8e2 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/nio/TestMultiByteBuff.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/nio/TestMultiByteBuff.java
@@ -17,33 +17,28 @@
*/
package org.apache.hadoop.hbase.nio;
-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.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.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
import java.nio.BufferOverflowException;
import java.nio.BufferUnderflowException;
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.ByteBufferUtils;
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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestMultiByteBuff {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestMultiByteBuff.class);
-
/**
* Test right answer though we span many sub-buffers.
*/
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/nio/TestSingleByteBuff.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/nio/TestSingleByteBuff.java
index 9f21ed91d2d..8f5faa2cbfe 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/nio/TestSingleByteBuff.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/nio/TestSingleByteBuff.java
@@ -17,23 +17,18 @@
*/
package org.apache.hadoop.hbase.nio;
-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.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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestSingleByteBuff {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestSingleByteBuff.class);
-
@Test
public void testPositionalReads() {
// Off heap buffer
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestCopyOnWriteMaps.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestCopyOnWriteMaps.java
index 5487997afea..3cd2c09d8b2 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestCopyOnWriteMaps.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestCopyOnWriteMaps.java
@@ -17,36 +17,32 @@
*/
package org.apache.hadoop.hbase.types;
-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.util.Map;
import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.ThreadLocalRandom;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.MiscTests;
-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({ MiscTests.class, MediumTests.class })
+@Tag(MiscTests.TAG)
+@Tag(MediumTests.TAG)
public class TestCopyOnWriteMaps {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCopyOnWriteMaps.class);
private static final int MAX_INITIAL_ENTRIES = 10_000;
private static final int MAX_RAND = 10 * 1000 * 1000;
private ConcurrentNavigableMap<Long, Long> m;
private ConcurrentSkipListMap<Long, Long> csm;
- @Before
+ @BeforeEach
public void setUp() {
m = new CopyOnWriteArrayMap<>();
csm = new ConcurrentSkipListMap<>();
@@ -75,7 +71,7 @@ public class TestCopyOnWriteMaps {
@Test
public void testSize() {
- assertEquals("Size should always be equal", m.size(), csm.size());
+ assertEquals(m.size(), csm.size(), "Size should always be equal");
}
@Test
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestFixedLengthWrapper.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestFixedLengthWrapper.java
index 23056582f69..43abf538fb6 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestFixedLengthWrapper.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestFixedLengthWrapper.java
@@ -17,27 +17,23 @@
*/
package org.apache.hadoop.hbase.types;
-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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-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.apache.hadoop.hbase.util.Order;
import org.apache.hadoop.hbase.util.PositionedByteRange;
import org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange;
-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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestFixedLengthWrapper {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestFixedLengthWrapper.class);
-
static final byte[][] VALUES =
new byte[][] { Bytes.toBytes(""), Bytes.toBytes("1"), Bytes.toBytes("22"), Bytes.toBytes("333"),
Bytes.toBytes("4444"), Bytes.toBytes("55555"), Bytes.toBytes("666666"),
@@ -59,8 +55,8 @@ public class TestFixedLengthWrapper {
assertEquals(limit, type.encode(buff, val));
buff.setPosition(0);
byte[] actual = type.decode(buff);
- assertTrue("Decoding output differs from expected",
- Bytes.equals(val, 0, val.length, actual, 0, val.length));
+ assertTrue(Bytes.equals(val, 0, val.length, actual, 0, val.length),
+ "Decoding output differs from expected");
buff.setPosition(0);
assertEquals(limit, type.skip(buff));
}
@@ -68,24 +64,24 @@ public class TestFixedLengthWrapper {
}
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testInsufficientRemainingRead() {
PositionedByteRange buff = new SimplePositionedMutableByteRange(0);
- DataType<byte[]> type = new FixedLengthWrapper<>(new RawBytes(), 3);
- type.decode(buff);
+ DataType<byte[]> type = new FixedLengthWrapper<>(new RawBytes(Order.ASCENDING), 3);
+ assertThrows(IllegalArgumentException.class, () -> type.decode(buff));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testInsufficientRemainingWrite() {
PositionedByteRange buff = new SimplePositionedMutableByteRange(0);
- DataType<byte[]> type = new FixedLengthWrapper<>(new RawBytes(), 3);
- type.encode(buff, Bytes.toBytes(""));
+ DataType<byte[]> type = new FixedLengthWrapper<>(new RawBytes(Order.ASCENDING), 3);
+ assertThrows(IllegalArgumentException.class, () -> type.encode(buff, Bytes.toBytes("")));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testOverflowPassthrough() {
PositionedByteRange buff = new SimplePositionedMutableByteRange(3);
- DataType<byte[]> type = new FixedLengthWrapper<>(new RawBytes(), 0);
- type.encode(buff, Bytes.toBytes("foo"));
+ DataType<byte[]> type = new FixedLengthWrapper<>(new RawBytes(Order.ASCENDING), 0);
+ assertThrows(IllegalArgumentException.class, () -> type.encode(buff, Bytes.toBytes("foo")));
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedBlob.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedBlob.java
index 35e6625e3b7..69d8d27ceb3 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedBlob.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedBlob.java
@@ -17,26 +17,20 @@
*/
package org.apache.hadoop.hbase.types;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-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.apache.hadoop.hbase.util.PositionedByteRange;
import org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange;
-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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestOrderedBlob {
-
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestOrderedBlob.class);
-
- static final byte[][] VALUES =
+ private static final byte[][] VALUES =
new byte[][] { null, Bytes.toBytes(""), Bytes.toBytes("1"), Bytes.toBytes("22"),
Bytes.toBytes("333"), Bytes.toBytes("4444"), Bytes.toBytes("55555"), Bytes.toBytes("666666"),
Bytes.toBytes("7777777"), Bytes.toBytes("88888888"), Bytes.toBytes("999999999"), };
@@ -49,8 +43,8 @@ public class TestOrderedBlob {
for (byte[] val : VALUES) {
buff.setPosition(0);
type.encode(buff, val);
- assertEquals("encodedLength does not match actual, " + Bytes.toStringBinary(val),
- buff.getPosition(), type.encodedLength(val));
+ assertEquals(buff.getPosition(), type.encodedLength(val),
+ "encodedLength does not match actual, " + Bytes.toStringBinary(val));
}
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedBlobVar.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedBlobVar.java
index 6f1f028518e..3ef027557f9 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedBlobVar.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedBlobVar.java
@@ -17,26 +17,20 @@
*/
package org.apache.hadoop.hbase.types;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-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.apache.hadoop.hbase.util.PositionedByteRange;
import org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange;
-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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestOrderedBlobVar {
-
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestOrderedBlobVar.class);
-
- static final byte[][] VALUES =
+ private static final byte[][] VALUES =
new byte[][] { null, Bytes.toBytes(""), Bytes.toBytes("1"), Bytes.toBytes("22"),
Bytes.toBytes("333"), Bytes.toBytes("4444"), Bytes.toBytes("55555"), Bytes.toBytes("666666"),
Bytes.toBytes("7777777"), Bytes.toBytes("88888888"), Bytes.toBytes("999999999"), };
@@ -49,8 +43,8 @@ public class TestOrderedBlobVar {
for (byte[] val : VALUES) {
buff.setPosition(0);
type.encode(buff, val);
- assertEquals("encodedLength does not match actual, " + Bytes.toStringBinary(val),
- buff.getPosition(), type.encodedLength(val));
+ assertEquals(buff.getPosition(), type.encodedLength(val),
+ "encodedLength does not match actual, " + Bytes.toStringBinary(val));
}
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedString.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedString.java
index b12ee4a8c5a..fd7b6965ba0 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedString.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedString.java
@@ -17,25 +17,19 @@
*/
package org.apache.hadoop.hbase.types;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-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.PositionedByteRange;
import org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange;
-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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestOrderedString {
-
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestOrderedString.class);
-
- static final String[] VALUES = new String[] { null, "", "1", "22", "333", "4444", "55555",
+ private static final String[] VALUES = new String[] { null, "", "1", "22", "333", "4444", "55555",
"666666", "7777777", "88888888", "999999999" };
@Test
@@ -46,8 +40,8 @@ public class TestOrderedString {
for (String val : VALUES) {
buff.setPosition(0);
type.encode(buff, val);
- assertEquals("encodedLength does not match actual, " + val, buff.getPosition(),
- type.encodedLength(val));
+ assertEquals(buff.getPosition(), type.encodedLength(val),
+ "encodedLength does not match actual, " + val);
}
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestRawString.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestRawString.java
index d9a26c11033..a77da6d167b 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestRawString.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestRawString.java
@@ -17,29 +17,23 @@
*/
package org.apache.hadoop.hbase.types;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-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.apache.hadoop.hbase.util.Order;
import org.apache.hadoop.hbase.util.PositionedByteRange;
import org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange;
-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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestRawString {
-
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestRawString.class);
-
- static final String[] VALUES = new String[] { "", "1", "22", "333", "4444", "55555", "666666",
- "7777777", "88888888", "999999999", };
+ private static final String[] VALUES = new String[] { "", "1", "22", "333", "4444", "55555",
+ "666666", "7777777", "88888888", "999999999", };
@Test
public void testReadWrite() {
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStruct.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStruct.java
index 0f62e8b6b86..fea723b9da9 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStruct.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStruct.java
@@ -17,50 +17,49 @@
*/
package org.apache.hadoop.hbase.types;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.lang.reflect.Constructor;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Comparator;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import java.util.stream.Stream;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Order;
import org.apache.hadoop.hbase.util.PositionedByteRange;
import org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange;
-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;
/**
* This class both tests and demonstrates how to construct compound rowkeys from a POJO. The code
* under test is {@link Struct}. {@link SpecializedPojo1Type1} demonstrates how one might create
* their own custom data type extension for an application POJO.
*/
-@RunWith(Parameterized.class)
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
+@HBaseParameterizedTestTemplate(name = "[{index}]: generic = {0}, specialized = {1}")
public class TestStruct {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestStruct.class);
- @Parameterized.Parameter()
- public Struct generic;
+ private Struct generic;
@SuppressWarnings("rawtypes")
- @Parameterized.Parameter(value = 1)
- public DataType specialized;
+ private DataType specialized;
- @Parameterized.Parameter(value = 2)
- public Object[][] constructorArgs;
+ private Object[][] constructorArgs;
- @Parameters
- public static Collection<Object[]> params() {
+ @SuppressWarnings("rawtypes")
+ public TestStruct(Struct generic, DataType specialized, Object[][] constructorArgs) {
+ this.generic = generic;
+ this.specialized = specialized;
+ this.constructorArgs = constructorArgs;
+ }
+
+ public static Stream<Arguments> parameters() {
Object[][] pojo1Args = { new Object[] { "foo", 5, 10.001 }, new Object[] { "foo", 100, 7.0 },
new Object[] { "foo", 100, 10.001 }, new Object[] { "bar", 5, 10.001 },
new Object[] { "bar", 100, 10.001 }, new Object[] { "baz", 5, 10.001 }, };
@@ -72,10 +71,9 @@ public class TestStruct {
new Object[] { Bytes.toBytes("worst"), Bytes.toBytes("of"), "times,", new byte[0] },
new Object[] { new byte[0], new byte[0], "", new byte[0] }, };
- Object[][] params =
- new Object[][] { { SpecializedPojo1Type1.GENERIC, new SpecializedPojo1Type1(), pojo1Args },
- { SpecializedPojo2Type1.GENERIC, new SpecializedPojo2Type1(), pojo2Args }, };
- return Arrays.asList(params);
+ return Stream.of(
+ Arguments.of(SpecializedPojo1Type1.GENERIC, new SpecializedPojo1Type1(), pojo1Args),
+ Arguments.of(SpecializedPojo2Type1.GENERIC, new SpecializedPojo2Type1(), pojo2Args));
}
static final Comparator<byte[]> NULL_SAFE_BYTES_COMPARATOR = (o1, o2) -> {
@@ -407,7 +405,7 @@ public class TestStruct {
}
}
- @Test
+ @TestTemplate
@SuppressWarnings("unchecked")
public void testOrderPreservation() throws Exception {
Object[] vals = new Object[constructorArgs.length];
@@ -436,10 +434,10 @@ public class TestStruct {
Arrays.sort(encodedSpecialized);
for (int i = 0; i < vals.length; i++) {
- assertEquals("Struct encoder does not preserve sort order at position " + i, vals[i],
- ctor.newInstance(new Object[] { generic.decode(encodedGeneric[i]) }));
- assertEquals("Specialized encoder does not preserve sort order at position " + i, vals[i],
- specialized.decode(encodedSpecialized[i]));
+ assertEquals(vals[i], ctor.newInstance(new Object[] { generic.decode(encodedGeneric[i]) }),
+ "Struct encoder does not preserve sort order at position " + i);
+ assertEquals(vals[i], specialized.decode(encodedSpecialized[i]),
+ "Specialized encoder does not preserve sort order at position " + i);
}
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStructNullExtension.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStructNullExtension.java
index a0ee8e16349..6ce7abdbaf5 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStructNullExtension.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStructNullExtension.java
@@ -17,37 +17,35 @@
*/
package org.apache.hadoop.hbase.types;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+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 java.math.BigDecimal;
import java.util.Arrays;
-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.PositionedByteRange;
import org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange;
-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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestStructNullExtension {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestStructNullExtension.class);
-
/**
* Verify null extension respects the type's isNullable field.
*/
- @Test(expected = NullPointerException.class)
+ @Test
public void testNonNullableNullExtension() {
- Struct s = new StructBuilder().add(new RawStringTerminated("|")) // not nullable
- .toStruct();
+ // not nullable
+ Struct s = new StructBuilder().add(new RawStringTerminated("|")).toStruct();
PositionedByteRange buf = new SimplePositionedMutableByteRange(4);
- s.encode(buf, new Object[1]);
+ assertThrows(NullPointerException.class, () -> {
+ s.encode(buf, new Object[1]);
+ });
}
/**
@@ -66,8 +64,8 @@ public class TestStructNullExtension {
PositionedByteRange buf1 = new SimplePositionedMutableByteRange(7);
Object[] val1 = new Object[] { BigDecimal.ONE, "foo" }; // => 2 bytes + 5 bytes
- assertEquals("Encoding shorter value wrote a surprising number of bytes.", buf1.getLength(),
- shorter.encode(buf1, val1));
+ assertEquals(buf1.getLength(), shorter.encode(buf1, val1),
+ "Encoding shorter value wrote a surprising number of bytes.");
int shortLen = buf1.getLength();
// test iterator
@@ -75,71 +73,69 @@ public class TestStructNullExtension {
StructIterator it = longer.iterator(buf1);
it.skip();
it.skip();
- assertEquals("Position should be at end. Broken test.", buf1.getLength(), buf1.getPosition());
- assertEquals("Failed to skip null element with extended struct.", 0, it.skip());
- assertEquals("Failed to skip null element with extended struct.", 0, it.skip());
+ assertEquals(buf1.getLength(), buf1.getPosition(), "Position should be at end. Broken test.");
+ assertEquals(0, it.skip(), "Failed to skip null element with extended struct.");
+ assertEquals(0, it.skip(), "Failed to skip null element with extended struct.");
buf1.setPosition(0);
it = longer.iterator(buf1);
assertEquals(BigDecimal.ONE, it.next());
assertEquals("foo", it.next());
- assertEquals("Position should be at end. Broken test.", buf1.getLength(), buf1.getPosition());
- assertNull("Failed to skip null element with extended struct.", it.next());
- assertNull("Failed to skip null element with extended struct.", it.next());
+ assertEquals(buf1.getLength(), buf1.getPosition(), "Position should be at end. Broken test.");
+ assertNull(it.next(), "Failed to skip null element with extended struct.");
+ assertNull(it.next(), "Failed to skip null element with extended struct.");
// test Struct
buf1.setPosition(0);
- assertArrayEquals("Simple struct decoding is broken.", val1, shorter.decode(buf1));
+ assertArrayEquals(val1, shorter.decode(buf1), "Simple struct decoding is broken.");
buf1.setPosition(0);
- assertArrayEquals("Decoding short value with extended struct should append null elements.",
- Arrays.copyOf(val1, 4), longer.decode(buf1));
+ assertArrayEquals(Arrays.copyOf(val1, 4), longer.decode(buf1),
+ "Decoding short value with extended struct should append null elements.");
// test omission of trailing members
PositionedByteRange buf2 = new SimplePositionedMutableByteRange(7);
buf1.setPosition(0);
- assertEquals(
- "Encoding a short value with extended struct should have same result as using short struct.",
- shortLen, longer.encode(buf2, val1));
- assertArrayEquals(
- "Encoding a short value with extended struct should have same result as using short struct",
- buf1.getBytes(), buf2.getBytes());
+ assertEquals(shortLen, longer.encode(buf2, val1),
+ "Encoding a short value with extended struct should have same result as using short struct.");
+ assertArrayEquals(buf1.getBytes(), buf2.getBytes(),
+ "Encoding a short value with extended struct should have same result as using short struct");
// test null trailing members
// all fields are nullable, so nothing should hit the buffer.
val1 = new Object[] { null, null, null, null }; // => 0 bytes
buf1.set(0);
buf2.set(0);
- assertEquals("Encoding null-truncated value wrote a surprising number of bytes.",
- buf1.getLength(), longer.encode(buf1, new Object[0]));
- assertEquals("Encoding null-extended value wrote a surprising number of bytes.",
- buf1.getLength(), longer.encode(buf1, val1));
- assertArrayEquals("Encoded unexpected result.", buf1.getBytes(), buf2.getBytes());
- assertArrayEquals("Decoded unexpected result.", val1, longer.decode(buf2));
+ assertEquals(buf1.getLength(), longer.encode(buf1, new Object[0]),
+ "Encoding null-truncated value wrote a surprising number of bytes.");
+ assertEquals(buf1.getLength(), longer.encode(buf1, val1),
+ "Encoding null-extended value wrote a surprising number of bytes.");
+ assertArrayEquals(buf1.getBytes(), buf2.getBytes(), "Encoded unexpected result.");
+ assertArrayEquals(val1, longer.decode(buf2), "Decoded unexpected result.");
// all fields are nullable, so only 1 should hit the buffer.
Object[] val2 = new Object[] { BigDecimal.ONE, null, null, null }; // => 2 bytes
buf1.set(2);
buf2.set(2);
- assertEquals("Encoding null-truncated value wrote a surprising number of bytes.",
- buf1.getLength(), longer.encode(buf1, Arrays.copyOf(val2, 1)));
- assertEquals("Encoding null-extended value wrote a surprising number of bytes.",
- buf2.getLength(), longer.encode(buf2, val2));
- assertArrayEquals("Encoded unexpected result.", buf1.getBytes(), buf2.getBytes());
+ assertEquals(buf1.getLength(), longer.encode(buf1, Arrays.copyOf(val2, 1)),
+ "Encoding null-truncated value wrote a surprising number of bytes.");
+ assertEquals(buf2.getLength(), longer.encode(buf2, val2),
+ "Encoding null-extended value wrote a surprising number of bytes.");
+ assertArrayEquals(buf1.getBytes(), buf2.getBytes(), "Encoded unexpected result.");
buf2.setPosition(0);
- assertArrayEquals("Decoded unexpected result.", val2, longer.decode(buf2));
+ assertArrayEquals(val2, longer.decode(buf2), "Decoded unexpected result.");
// all fields are nullable, so only 1, null, "foo" should hit the buffer.
// => 2 bytes + 1 byte + 6 bytes
Object[] val3 = new Object[] { BigDecimal.ONE, null, "foo", null };
buf1.set(9);
buf2.set(9);
- assertEquals("Encoding null-truncated value wrote a surprising number of bytes.",
- buf1.getLength(), longer.encode(buf1, Arrays.copyOf(val3, 3)));
- assertEquals("Encoding null-extended value wrote a surprising number of bytes.",
- buf2.getLength(), longer.encode(buf2, val3));
- assertArrayEquals("Encoded unexpected result.", buf1.getBytes(), buf2.getBytes());
+ assertEquals(buf1.getLength(), longer.encode(buf1, Arrays.copyOf(val3, 3)),
+ "Encoding null-truncated value wrote a surprising number of bytes.");
+ assertEquals(buf2.getLength(), longer.encode(buf2, val3),
+ "Encoding null-extended value wrote a surprising number of bytes.");
+ assertArrayEquals(buf1.getBytes(), buf2.getBytes(), "Encoded unexpected result.");
buf2.setPosition(0);
- assertArrayEquals("Decoded unexpected result.", val3, longer.decode(buf2));
+ assertArrayEquals(val3, longer.decode(buf2), "Decoded unexpected result.");
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestTerminatedWrapper.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestTerminatedWrapper.java
index 8baaf29e82b..caf48a59da2 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestTerminatedWrapper.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestTerminatedWrapper.java
@@ -17,27 +17,23 @@
*/
package org.apache.hadoop.hbase.types;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
-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.apache.hadoop.hbase.util.Order;
import org.apache.hadoop.hbase.util.PositionedByteRange;
import org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange;
-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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestTerminatedWrapper {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestTerminatedWrapper.class);
-
static final String[] VALUES_STRINGS = new String[] { "", "1", "22", "333", "4444", "55555",
"666666", "7777777", "88888888", "999999999", };
@@ -50,22 +46,24 @@ public class TestTerminatedWrapper {
static final byte[][] TERMINATORS = new byte[][] { new byte[] { -2 }, Bytes.toBytes("foo") };
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testEmptyDelimiter() {
- new TerminatedWrapper<>(new RawBytes(), "");
+ assertThrows(IllegalArgumentException.class, () -> new TerminatedWrapper<>(new RawBytes(), ""));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testNullDelimiter() {
- new RawBytesTerminated((byte[]) null);
+ assertThrows(IllegalArgumentException.class, () -> new RawBytesTerminated((byte[]) null));
// new TerminatedWrapper<byte[]>(new RawBytes(), (byte[]) null);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testEncodedValueContainsTerm() {
DataType<byte[]> type = new TerminatedWrapper<>(new RawBytes(), "foo");
PositionedByteRange buff = new SimplePositionedMutableByteRange(16);
- type.encode(buff, Bytes.toBytes("hello foobar!"));
+ assertThrows(IllegalArgumentException.class, () -> {
+ type.encode(buff, Bytes.toBytes("hello foobar!"));
+ });
}
@Test
@@ -139,10 +137,12 @@ public class TestTerminatedWrapper {
}
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testInvalidSkip() {
PositionedByteRange buff = new SimplePositionedMutableByteRange(Bytes.toBytes("foo"));
DataType<byte[]> type = new TerminatedWrapper<>(new RawBytes(), new byte[] { 0x00 });
- type.skip(buff);
+ assertThrows(IllegalArgumentException.class, () -> {
+ type.skip(buff);
+ });
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestUnion2.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestUnion2.java
index d5bedeee307..a951efefc1b 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestUnion2.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestUnion2.java
@@ -17,23 +17,19 @@
*/
package org.apache.hadoop.hbase.types;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-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.Order;
import org.apache.hadoop.hbase.util.PositionedByteRange;
import org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange;
-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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestUnion2 {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestUnion2.class);
-
/**
* An example <code>Union</code>
*/
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/AbstractHBaseToolTest.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/AbstractHBaseToolTest.java
index 6cad94cd01a..32ead23dc24 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/AbstractHBaseToolTest.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/AbstractHBaseToolTest.java
@@ -19,20 +19,25 @@ package org.apache.hadoop.hbase.util;
import static org.apache.hadoop.hbase.util.AbstractHBaseTool.EXIT_FAILURE;
import static org.apache.hadoop.hbase.util.AbstractHBaseTool.EXIT_SUCCESS;
-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.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.util.ArrayList;
import java.util.List;
import org.apache.hadoop.hbase.HBaseConfiguration;
-import org.junit.Before;
-import org.junit.Test;
+import org.apache.hadoop.hbase.testclassification.MiscTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine;
import org.apache.hbase.thirdparty.org.apache.commons.cli.Option;
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class AbstractHBaseToolTest {
static final class Options {
static final Option REQUIRED = new Option(null, "required", true, "");
@@ -90,7 +95,7 @@ public class AbstractHBaseToolTest {
TestTool tool;
- @Before
+ @BeforeEach
public void setup() {
tool = new TestTool();
tool.setConf(HBaseConfiguration.create());
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/ByteBufferUtilsTestBase.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/ByteBufferUtilsTestBase.java
index 19491547577..0c7c00fbfd6 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/ByteBufferUtilsTestBase.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/ByteBufferUtilsTestBase.java
@@ -44,7 +44,6 @@ import java.util.stream.Collectors;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.nio.ByteBuff;
import org.apache.hadoop.io.WritableUtils;
-import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
@@ -59,8 +58,7 @@ public class ByteBufferUtilsTestBase {
private byte[] array;
- @BeforeAll
- public static void setUpBeforeAll() {
+ protected static void initialize() {
SortedSet<Long> a = new TreeSet<>();
for (int i = 0; i <= 63; ++i) {
long v = -1L << i;
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/ClassLoaderTestHelper.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/ClassLoaderTestHelper.java
index 2bfce990877..e11f98b3a51 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/ClassLoaderTestHelper.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/ClassLoaderTestHelper.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.util;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.BufferedWriter;
import java.io.File;
@@ -148,7 +148,7 @@ public final class ClassLoaderTestHelper {
LOG.debug("Setting classpath to: " + classpath);
JavaCompiler.CompilationTask task = compiler.getTask(null, fm, null, options, null, cu);
- assertTrue("Compile file " + sourceCodeFile + " failed.", task.call());
+ assertTrue(task.call(), "Compile file " + sourceCodeFile + " failed.");
// build a jar file by the classes files
String jarFileName = className + ".jar";
@@ -173,30 +173,29 @@ public final class ClassLoaderTestHelper {
*/
public static void addJarFilesToJar(File targetJar, String libPrefix, File... srcJars)
throws Exception {
- FileOutputStream stream = new FileOutputStream(targetJar);
- JarOutputStream out = new JarOutputStream(stream, new Manifest());
- byte[] buffer = new byte[BUFFER_SIZE];
-
- for (File jarFile : srcJars) {
- // Add archive entry
- JarEntry jarAdd = new JarEntry(libPrefix + jarFile.getName());
- jarAdd.setTime(jarFile.lastModified());
- out.putNextEntry(jarAdd);
-
- // Write file to archive
- FileInputStream in = new FileInputStream(jarFile);
- while (true) {
- int nRead = in.read(buffer, 0, buffer.length);
- if (nRead <= 0) {
- break;
- }
+ try (FileOutputStream stream = new FileOutputStream(targetJar);
+ JarOutputStream out = new JarOutputStream(stream, new Manifest())) {
+ byte[] buffer = new byte[BUFFER_SIZE];
+
+ for (File jarFile : srcJars) {
+ // Add archive entry
+ JarEntry jarAdd = new JarEntry(libPrefix + jarFile.getName());
+ jarAdd.setTime(jarFile.lastModified());
+ out.putNextEntry(jarAdd);
- out.write(buffer, 0, nRead);
+ // Write file to archive
+ try (FileInputStream in = new FileInputStream(jarFile)) {
+ while (true) {
+ int nRead = in.read(buffer, 0, buffer.length);
+ if (nRead <= 0) {
+ break;
+ }
+
+ out.write(buffer, 0, nRead);
+ }
+ }
}
- in.close();
}
- out.close();
- stream.close();
LOG.info("Adding jar file to outer jar file completed");
}
@@ -209,14 +208,14 @@ public final class ClassLoaderTestHelper {
String jarFileName = className + ".jar";
File file = new File(testDir, jarFileName);
file.delete();
- assertFalse("Should be deleted: " + file.getPath(), file.exists());
+ assertFalse(file.exists(), "Should be deleted: " + file.getPath());
file = new File(conf.get("hbase.dynamic.jars.dir"), jarFileName);
file.delete();
- assertFalse("Should be deleted: " + file.getPath(), file.exists());
+ assertFalse(file.exists(), "Should be deleted: " + file.getPath());
file = new File(ClassLoaderTestHelper.localDirPath(conf), jarFileName);
file.delete();
- assertFalse("Should be deleted: " + file.getPath(), file.exists());
+ assertFalse(file.exists(), "Should be deleted: " + file.getPath());
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestAvlUtil.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestAvlUtil.java
index 5cd99ecc6b3..040df460a8f 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestAvlUtil.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestAvlUtil.java
@@ -17,16 +17,15 @@
*/
package org.apache.hadoop.hbase.util;
-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.util.Random;
import java.util.TreeMap;
import java.util.concurrent.ThreadLocalRandom;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.util.AvlUtil.AvlIterableList;
@@ -36,17 +35,13 @@ import org.apache.hadoop.hbase.util.AvlUtil.AvlNode;
import org.apache.hadoop.hbase.util.AvlUtil.AvlNodeVisitor;
import org.apache.hadoop.hbase.util.AvlUtil.AvlTree;
import org.apache.hadoop.hbase.util.AvlUtil.AvlTreeIterator;
-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({ MiscTests.class, MediumTests.class })
+@Tag(MiscTests.TAG)
+@Tag(MediumTests.TAG)
public class TestAvlUtil {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestAvlUtil.class);
-
private static final TestAvlKeyComparator KEY_COMPARATOR = new TestAvlKeyComparator();
@Test
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferArray.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferArray.java
index 6d1a5ed3771..01149135f0e 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferArray.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferArray.java
@@ -17,31 +17,26 @@
*/
package org.apache.hadoop.hbase.util;
-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.nio.ByteBuffer;
import java.util.concurrent.ThreadLocalRandom;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.nio.ByteBuff;
import org.apache.hadoop.hbase.nio.MultiByteBuff;
import org.apache.hadoop.hbase.nio.SingleByteBuff;
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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestByteBufferArray {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestByteBufferArray.class);
-
private static final ByteBufferAllocator ALLOC = (size) -> ByteBuffer.allocateDirect((int) size);
@Test
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferUtils.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferUtils.java
index b451d71ed87..e38d74ed70a 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferUtils.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferUtils.java
@@ -19,10 +19,15 @@ package org.apache.hadoop.hbase.util;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
@Tag(MiscTests.TAG)
@Tag(SmallTests.TAG)
public class TestByteBufferUtils extends ByteBufferUtilsTestBase {
+ @BeforeAll
+ public static void setUpBeforeAll() {
+ initialize();
+ }
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferUtilsWoUnsafe.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferUtilsWoUnsafe.java
index c02db2142c1..b77cfe55dee 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferUtilsWoUnsafe.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferUtilsWoUnsafe.java
@@ -31,8 +31,7 @@ import org.mockito.MockedStatic;
@Tag(SmallTests.TAG)
public class TestByteBufferUtilsWoUnsafe extends ByteBufferUtilsTestBase {
- @BeforeAll
- public static void disableUnsafe() {
+ private static void disableUnsafe() {
try (MockedStatic<HBasePlatformDependent> mocked = mockStatic(HBasePlatformDependent.class)) {
mocked.when(HBasePlatformDependent::isUnsafeAvailable).thenReturn(false);
mocked.when(HBasePlatformDependent::unaligned).thenReturn(false);
@@ -40,4 +39,10 @@ public class TestByteBufferUtilsWoUnsafe extends ByteBufferUtilsTestBase {
assertFalse(ByteBufferUtils.UNSAFE_UNALIGNED);
}
}
+
+ @BeforeAll
+ public static void setUpBeforeClass() {
+ disableUnsafe();
+ initialize();
+ }
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteRangeUtils.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteRangeUtils.java
index b095808ad36..e5cb296cb6d 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteRangeUtils.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteRangeUtils.java
@@ -17,24 +17,20 @@
*/
package org.apache.hadoop.hbase.util;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import java.util.Arrays;
-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(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestByteRangeUtils {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestByteRangeUtils.class);
-
@Test
public void testNumEqualPrefixBytes() {
assertEquals(0, ByteRangeUtils.numEqualPrefixBytes(new SimpleByteRange(new byte[] { 1, 2, 3 }),
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteRangeWithKVSerialization.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteRangeWithKVSerialization.java
index f1d8a92cbed..2d670e2111f 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteRangeWithKVSerialization.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteRangeWithKVSerialization.java
@@ -17,26 +17,22 @@
*/
package org.apache.hadoop.hbase.util;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.util.ArrayList;
import java.util.List;
import org.apache.hadoop.hbase.ArrayBackedTag;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.Tag;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.Assert;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Test;
-@Category({ MiscTests.class, SmallTests.class })
+@org.junit.jupiter.api.Tag(MiscTests.TAG)
+@org.junit.jupiter.api.Tag(SmallTests.TAG)
public class TestByteRangeWithKVSerialization {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestByteRangeWithKVSerialization.class);
-
static void writeCell(PositionedByteRange pbr, KeyValue kv) throws Exception {
pbr.putInt(kv.getKeyLength());
pbr.putInt(kv.getValueLength());
@@ -88,12 +84,12 @@ public class TestByteRangeWithKVSerialization {
for (int i = 0; i < kvCount; i++) {
KeyValue kv = readCell(pbr1);
KeyValue kv1 = kvs.get(i);
- Assert.assertTrue(kv.equals(kv1));
- Assert.assertTrue(Bytes.equals(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength(),
+ assertTrue(kv.equals(kv1));
+ assertTrue(Bytes.equals(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength(),
kv1.getValueArray(), kv1.getValueOffset(), kv1.getValueLength()));
- Assert.assertTrue(Bytes.equals(kv.getTagsArray(), kv.getTagsOffset(), kv.getTagsLength(),
+ assertTrue(Bytes.equals(kv.getTagsArray(), kv.getTagsOffset(), kv.getTagsLength(),
kv1.getTagsArray(), kv1.getTagsOffset(), kv1.getTagsLength()));
- Assert.assertEquals(kv1.getSequenceId(), kv.getSequenceId());
+ assertEquals(kv1.getSequenceId(), kv.getSequenceId());
}
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestClasses.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestClasses.java
index 6a4bf6387ec..84b804c7df3 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestClasses.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestClasses.java
@@ -17,26 +17,16 @@
*/
package org.apache.hadoop.hbase.util;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category({ SmallTests.class })
+@Tag(SmallTests.TAG)
public class TestClasses {
- @Rule
- public final ExpectedException thrown = ExpectedException.none();
-
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestClasses.class);
-
@Test
public void testExtendedForName() throws ClassNotFoundException {
assertEquals(int.class, Classes.extendedForName("int"));
@@ -48,8 +38,7 @@ public class TestClasses {
assertEquals(double.class, Classes.extendedForName("double"));
assertEquals(boolean.class, Classes.extendedForName("boolean"));
- thrown.expect(ClassNotFoundException.class);
- Classes.extendedForName("foo");
+ assertThrows(ClassNotFoundException.class, () -> Classes.extendedForName("foo"));
}
@Test
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestCommonFSUtils.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestCommonFSUtils.java
index fd255fd2065..68224dff042 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestCommonFSUtils.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestCommonFSUtils.java
@@ -17,38 +17,34 @@
*/
package org.apache.hadoop.hbase.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.testclassification.MiscTests;
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;
/**
* Test {@link CommonFSUtils}.
*/
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestCommonFSUtils {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCommonFSUtils.class);
-
private HBaseCommonTestingUtility htu;
private Configuration conf;
- @Before
+ @BeforeEach
public void setUp() throws IOException {
htu = new HBaseCommonTestingUtility();
conf = htu.getConfiguration();
@@ -113,13 +109,15 @@ public class TestCommonFSUtils {
assertEquals(walRoot, CommonFSUtils.getWALRootDir(conf));
}
- @Test(expected = IllegalStateException.class)
+ @Test
public void testGetWALRootDirIllegalWALDir() throws IOException {
Path root = new Path("file:///hbase/root");
Path invalidWALDir = new Path("file:///hbase/root/logroot");
CommonFSUtils.setRootDir(conf, root);
CommonFSUtils.setWALRootDir(conf, invalidWALDir);
- CommonFSUtils.getWALRootDir(conf);
+ assertThrows(IllegalStateException.class, () -> {
+ CommonFSUtils.getWALRootDir(conf);
+ });
}
@Test
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestConcatenatedLists.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestConcatenatedLists.java
index aff879b7e1c..a47c67031ef 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestConcatenatedLists.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestConcatenatedLists.java
@@ -17,72 +17,40 @@
*/
package org.apache.hadoop.hbase.util;
-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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
-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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestConcatenatedLists {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestConcatenatedLists.class);
-
@Test
public void testUnsupportedOps() {
// If adding support, add tests.
ConcatenatedLists<Long> c = new ConcatenatedLists<>();
c.addSublist(Arrays.asList(0L, 1L));
- try {
- c.add(2L);
- fail("Should throw");
- } catch (UnsupportedOperationException ex) {
- }
- try {
- c.addAll(Arrays.asList(2L, 3L));
- fail("Should throw");
- } catch (UnsupportedOperationException ex) {
- }
- try {
- c.remove(0L);
- fail("Should throw");
- } catch (UnsupportedOperationException ex) {
- }
- try {
- c.removeAll(Arrays.asList(0L, 1L));
- fail("Should throw");
- } catch (UnsupportedOperationException ex) {
- }
- try {
- c.clear();
- fail("Should throw");
- } catch (UnsupportedOperationException ex) {
- }
- try {
- c.retainAll(Arrays.asList(0L, 2L));
- fail("Should throw");
- } catch (UnsupportedOperationException ex) {
- }
+ assertThrows(UnsupportedOperationException.class, () -> c.add(2L));
+ assertThrows(UnsupportedOperationException.class, () -> c.addAll(Arrays.asList(2L, 3L)));
+ assertThrows(UnsupportedOperationException.class, () -> c.remove(0L));
+ assertThrows(UnsupportedOperationException.class, () -> c.removeAll(Arrays.asList(0L, 1L)));
+ assertThrows(UnsupportedOperationException.class, () -> c.clear());
+ assertThrows(UnsupportedOperationException.class, () -> c.retainAll(Arrays.asList(0L, 2L)));
+
Iterator<Long> iter = c.iterator();
iter.next();
- try {
- iter.remove();
- fail("Should throw");
- } catch (UnsupportedOperationException ex) {
- }
+ assertThrows(UnsupportedOperationException.class, () -> iter.remove());
}
@Test
@@ -105,7 +73,6 @@ public class TestConcatenatedLists {
}
@Test
- @SuppressWarnings("unchecked")
public void testManyOne() {
ConcatenatedLists<Long> c = new ConcatenatedLists<>();
c.addSublist(Arrays.asList(0L));
@@ -143,11 +110,6 @@ public class TestConcatenatedLists {
}
assertTrue(c.containsAll(all));
assertFalse(iter.hasNext());
- try {
- iter.next();
- fail("Should have thrown");
- } catch (NoSuchElementException nsee) {
- // Expected
- }
+ assertThrows(NoSuchElementException.class, () -> iter.next());
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorClassLoader.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorClassLoader.java
index 615edc7dc84..68b9811b97d 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorClassLoader.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorClassLoader.java
@@ -17,35 +17,30 @@
*/
package org.apache.hadoop.hbase.util;
-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.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.io.IOUtils;
-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 TestCoprocessorClassLoader. More tests are in TestClassLoading
*/
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestCoprocessorClassLoader {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCoprocessorClassLoader.class);
-
private static final HBaseCommonTestingUtility TEST_UTIL = new HBaseCommonTestingUtility();
private static final Configuration conf = TEST_UTIL.getConfiguration();
static {
@@ -64,16 +59,16 @@ public class TestCoprocessorClassLoader {
tmpJarFile.delete();
}
- assertFalse("tmp jar file should not exist", tmpJarFile.exists());
+ assertFalse(tmpJarFile.exists(), "tmp jar file should not exist");
ClassLoader parent = TestCoprocessorClassLoader.class.getClassLoader();
CoprocessorClassLoader.getClassLoader(new Path(jarFile.getParent()), parent, "112", conf);
IOUtils.copyBytes(new FileInputStream(jarFile), new FileOutputStream(tmpJarFile), conf, true);
- assertTrue("tmp jar file should be created", tmpJarFile.exists());
+ assertTrue(tmpJarFile.exists(), "tmp jar file should be created");
Path path = new Path(jarFile.getAbsolutePath());
CoprocessorClassLoader.parentDirLockSet.clear(); // So that clean up can be triggered
ClassLoader classLoader = CoprocessorClassLoader.getClassLoader(path, parent, "111", conf);
- assertNotNull("Classloader should be created", classLoader);
- assertFalse("tmp jar file should be removed", tmpJarFile.exists());
+ assertNotNull(classLoader, "Classloader should be created");
+ assertFalse(tmpJarFile.exists(), "tmp jar file should be removed");
}
@Test
@@ -109,7 +104,7 @@ public class TestCoprocessorClassLoader {
Path path = new Path(targetJarFile.getAbsolutePath());
ClassLoader parent = TestCoprocessorClassLoader.class.getClassLoader();
ClassLoader classLoader = CoprocessorClassLoader.getClassLoader(path, parent, "112", conf);
- assertNotNull("Classloader should be created", classLoader);
+ assertNotNull(classLoader, "Classloader should be created");
String fileToLookFor = "." + className + ".jar";
String[] files = tmpFolder.list();
if (files != null) {
@@ -128,7 +123,6 @@ public class TestCoprocessorClassLoader {
public void testDirectoryAndWildcard() throws Exception {
String testClassName = "TestClass";
String dataTestDir = TEST_UTIL.getDataTestDir().toString();
- System.out.println(dataTestDir);
String localDirContainingJar = ClassLoaderTestHelper.localDirPath(conf);
ClassLoaderTestHelper.buildJar(dataTestDir, testClassName, null, localDirContainingJar);
ClassLoader parent = TestCoprocessorClassLoader.class.getClassLoader();
@@ -160,7 +154,7 @@ public class TestCoprocessorClassLoader {
*/
private void verifyCoprocessorClassLoader(CoprocessorClassLoader coprocessorClassLoader,
String className) throws ClassNotFoundException {
- assertNotNull("Classloader should be created and not null", coprocessorClassLoader);
+ assertNotNull(coprocessorClassLoader, "Classloader should be created and not null");
assertEquals(className, coprocessorClassLoader.loadClass(className).getName());
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestCounter.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestCounter.java
index 99bc4d6e0ac..34e089d932d 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestCounter.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestCounter.java
@@ -17,22 +17,18 @@
*/
package org.apache.hadoop.hbase.util;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
import java.util.concurrent.CountDownLatch;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.Assert;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestCounter {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCounter.class);
-
private static final int[] THREAD_COUNTS = { 1, 10, 100 };
private static final int DATA_COUNT = 1000000;
@@ -52,7 +48,7 @@ public class TestCounter {
}
}, threadCount);
- Assert.assertEquals(threadCount * (long) DATA_COUNT, counter.get());
+ assertEquals(threadCount * (long) DATA_COUNT, counter.get());
}
}
@@ -69,7 +65,7 @@ public class TestCounter {
}
}, threadCount);
- Assert.assertEquals(threadCount * (long) DATA_COUNT, counter.get());
+ assertEquals(threadCount * (long) DATA_COUNT, counter.get());
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestDynamicClassLoader.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestDynamicClassLoader.java
index 47632c7826e..614badcc609 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestDynamicClassLoader.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestDynamicClassLoader.java
@@ -17,32 +17,27 @@
*/
package org.apache.hadoop.hbase.util;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
import org.apache.hadoop.hbase.testclassification.MiscTests;
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;
/**
* Test TestDynamicClassLoader
*/
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestDynamicClassLoader {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestDynamicClassLoader.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestDynamicClassLoader.class);
private static final HBaseCommonTestingUtility TEST_UTIL = new HBaseCommonTestingUtility();
@@ -53,7 +48,7 @@ public class TestDynamicClassLoader {
TEST_UTIL.getDataTestDir().toString());
}
- @Before
+ @BeforeEach
public void initializeConfiguration() {
conf = new Configuration(TEST_UTIL.getConfiguration());
}
@@ -131,14 +126,14 @@ public class TestDynamicClassLoader {
String jarFileName = className + ".jar";
File file = new File(TEST_UTIL.getDataTestDir().toString(), jarFileName);
file.delete();
- assertFalse("Should be deleted: " + file.getPath(), file.exists());
+ assertFalse(file.exists(), "Should be deleted: " + file.getPath());
file = new File(conf.get("hbase.dynamic.jars.dir"), jarFileName);
file.delete();
- assertFalse("Should be deleted: " + file.getPath(), file.exists());
+ assertFalse(file.exists(), "Should be deleted: " + file.getPath());
file = new File(ClassLoaderTestHelper.localDirPath(conf), jarFileName);
file.delete();
- assertFalse("Should be deleted: " + file.getPath(), file.exists());
+ assertFalse(file.exists(), "Should be deleted: " + file.getPath());
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestEnvironmentEdgeManager.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestEnvironmentEdgeManager.java
index e740811cfa0..a0273da13a7 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestEnvironmentEdgeManager.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestEnvironmentEdgeManager.java
@@ -17,28 +17,23 @@
*/
package org.apache.hadoop.hbase.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestEnvironmentEdgeManager {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestEnvironmentEdgeManager.class);
-
@Test
public void testManageSingleton() {
EnvironmentEdgeManager.reset();
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestFastStringPool.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestFastStringPool.java
index dd0a8339334..a2448cf8bb6 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestFastStringPool.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestFastStringPool.java
@@ -26,12 +26,14 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+@Tag(MiscTests.TAG)
@Tag(SmallTests.TAG)
public class TestFastStringPool {
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestFutureUtils.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestFutureUtils.java
index a3d29ce7a2c..c6b99f60582 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestFutureUtils.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestFutureUtils.java
@@ -20,42 +20,37 @@ package org.apache.hadoop.hbase.util;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
-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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Stream;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseIOException;
import org.apache.hadoop.hbase.testclassification.MiscTests;
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.apache.hbase.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder;
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestFutureUtils {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestFutureUtils.class);
-
private ExecutorService executor;
- @Before
+ @BeforeEach
public void setUp() {
executor = Executors.newFixedThreadPool(1, new ThreadFactoryBuilder().setDaemon(true).build());
}
- @After
+ @AfterEach
public void tearDown() {
executor.shutdownNow();
}
@@ -64,25 +59,28 @@ public class TestFutureUtils {
public void testRecordStackTrace() throws IOException {
CompletableFuture<Void> future = new CompletableFuture<>();
executor.execute(() -> future.completeExceptionally(new HBaseIOException("Inject error!")));
- try {
- FutureUtils.get(future);
- fail("The future should have been completed exceptionally");
- } catch (HBaseIOException e) {
- assertEquals("Inject error!", e.getMessage());
- StackTraceElement[] elements = e.getStackTrace();
- assertThat(elements[0].toString(), containsString("java.lang.Thread.getStackTrace"));
- assertThat(elements[1].toString(),
- startsWith("org.apache.hadoop.hbase.util.FutureUtils.setStackTrace"));
- assertThat(elements[2].toString(),
- startsWith("org.apache.hadoop.hbase.util.FutureUtils.rethrow"));
- assertThat(elements[3].toString(),
- startsWith("org.apache.hadoop.hbase.util.FutureUtils.get"));
- assertThat(elements[4].toString(),
- startsWith("org.apache.hadoop.hbase.util.TestFutureUtils.testRecordStackTrace"));
- assertTrue(Stream.of(elements)
- .anyMatch(element -> element.toString().contains("--------Future.get--------")));
- } catch (Throwable t) {
- throw new AssertionError("Caught unexpected Throwable", t);
+ HBaseIOException e = assertThrows(HBaseIOException.class, () -> FutureUtils.get(future),
+ "The future should have been completed exceptionally");
+ assertEquals("Inject error!", e.getMessage());
+ StackTraceElement[] elements = e.getStackTrace();
+ assertThat(elements[0].toString(), containsString("java.lang.Thread.getStackTrace"));
+ assertThat(elements[1].toString(),
+ startsWith("org.apache.hadoop.hbase.util.FutureUtils.setStackTrace"));
+ assertThat(elements[2].toString(),
+ startsWith("org.apache.hadoop.hbase.util.FutureUtils.rethrow"));
+ assertThat(elements[3].toString(), startsWith("org.apache.hadoop.hbase.util.FutureUtils.get"));
+ assertThat(elements[4].toString(),
+ startsWith("org.apache.hadoop.hbase.util.TestFutureUtils.lambda"));
+ int i = 5;
+ for (;;) {
+ if (!elements[i].toString().contains("assertThrows")) {
+ break;
+ }
+ i++;
}
+ assertThat(elements[i].toString(),
+ startsWith("org.apache.hadoop.hbase.util.TestFutureUtils.testRecordStackTrace"));
+ assertTrue(Stream.of(elements)
+ .anyMatch(element -> element.toString().contains("--------Future.get--------")));
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestGsonUtil.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestGsonUtil.java
index 48652d67be6..2f59ff6d927 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestGsonUtil.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestGsonUtil.java
@@ -17,24 +17,19 @@
*/
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 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;
import org.apache.hbase.thirdparty.com.google.gson.Gson;
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestGsonUtil {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestGsonUtil.class);
-
private static final Gson GSON = GsonUtil.createGson().create();
private static final Gson DHE_GSON = GsonUtil.createGsonWithDisableHtmlEscaping().create();
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestJRubyFormat.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestJRubyFormat.java
index c5573910ea0..38bcaaf75be 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestJRubyFormat.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestJRubyFormat.java
@@ -17,25 +17,21 @@
*/
package org.apache.hadoop.hbase.util;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.LinkedHashMap;
import java.util.Map;
-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;
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
-@Category(SmallTests.class)
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestJRubyFormat {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestJRubyFormat.class);
-
@Test
public void testPrint() {
Map<String, Object> map = new LinkedHashMap<>();
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestKeyLocker.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestKeyLocker.java
index 34a000346e6..c6a8b404325 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestKeyLocker.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestKeyLocker.java
@@ -17,44 +17,42 @@
*/
package org.apache.hadoop.hbase.util;
+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.util.concurrent.locks.ReentrantLock;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.Assert;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestKeyLocker {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestKeyLocker.class);
-
@Test
public void testLocker() {
KeyLocker<String> locker = new KeyLocker<>();
ReentrantLock lock1 = locker.acquireLock("l1");
- Assert.assertTrue(lock1.isHeldByCurrentThread());
+ assertTrue(lock1.isHeldByCurrentThread());
ReentrantLock lock2 = locker.acquireLock("l2");
- Assert.assertTrue(lock2.isHeldByCurrentThread());
- Assert.assertTrue(lock1 != lock2);
+ assertTrue(lock2.isHeldByCurrentThread());
+ assertTrue(lock1 != lock2);
// same key = same lock
ReentrantLock lock20 = locker.acquireLock("l2");
- Assert.assertTrue(lock20 == lock2);
- Assert.assertTrue(lock2.isHeldByCurrentThread());
- Assert.assertTrue(lock20.isHeldByCurrentThread());
+ assertTrue(lock20 == lock2);
+ assertTrue(lock2.isHeldByCurrentThread());
+ assertTrue(lock20.isHeldByCurrentThread());
// Locks are still reentrant; so with 2 acquires we want two unlocks
lock20.unlock();
- Assert.assertTrue(lock20.isHeldByCurrentThread());
+ assertTrue(lock20.isHeldByCurrentThread());
lock2.unlock();
- Assert.assertFalse(lock20.isHeldByCurrentThread());
+ assertFalse(lock20.isHeldByCurrentThread());
// The lock object will be garbage-collected
// if you free its reference for a long time,
@@ -68,13 +66,13 @@ public class TestKeyLocker {
System.gc();
ReentrantLock lock200 = locker.acquireLock("l2");
- Assert.assertNotEquals(lock2Hash, System.identityHashCode(lock200));
+ assertNotEquals(lock2Hash, System.identityHashCode(lock200));
lock200.unlock();
- Assert.assertFalse(lock200.isHeldByCurrentThread());
+ assertFalse(lock200.isHeldByCurrentThread());
// first lock is still there
- Assert.assertTrue(lock1.isHeldByCurrentThread());
+ assertTrue(lock1.isHeldByCurrentThread());
lock1.unlock();
- Assert.assertFalse(lock1.isHeldByCurrentThread());
+ assertFalse(lock1.isHeldByCurrentThread());
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestLoadTestKVGenerator.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestLoadTestKVGenerator.java
index 1c35c7f0314..fea1c0bf850 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestLoadTestKVGenerator.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestLoadTestKVGenerator.java
@@ -17,26 +17,21 @@
*/
package org.apache.hadoop.hbase.util;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
-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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestLoadTestKVGenerator {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestLoadTestKVGenerator.class);
-
private static final int MIN_LEN = 10;
private static final int MAX_LEN = 20;
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestMovingAverage.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestMovingAverage.java
index 295afb9893e..563146d539d 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestMovingAverage.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestMovingAverage.java
@@ -17,140 +17,135 @@
*/
package org.apache.hadoop.hbase.util;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.Assert;
-import org.junit.ClassRule;
-import org.junit.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;
-@Category(SmallTests.class)
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestMovingAverage {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestMovingAverage.class);
-
- @Rule
- public TestName name = new TestName();
-
private long[] data = { 1, 12, 13, 24, 25, 26, 37, 38, 39, 40 };
private double delta = 0.1;
@Test
- public void testSimpleMovingAverage() throws Exception {
- MovingAverage<?> algorithm = new SimpleMovingAverage(name.getMethodName());
+ public void testSimpleMovingAverage(TestInfo testInfo) throws Exception {
+ MovingAverage<?> algorithm = new SimpleMovingAverage(testInfo.getTestMethod().get().getName());
int index = 0;
// [1, 12, 13, 24]
int bound = 4;
for (; index < bound; index++) {
algorithm.updateMostRecentTime(data[index]);
}
- Assert.assertEquals(12.5, algorithm.getAverageTime(), delta);
+ assertEquals(12.5, algorithm.getAverageTime(), delta);
// [1, 12, 13, 24, 25]
bound = 5;
for (; index < bound; index++) {
algorithm.updateMostRecentTime(data[index]);
}
- Assert.assertEquals(15.0, algorithm.getAverageTime(), delta);
+ assertEquals(15.0, algorithm.getAverageTime(), delta);
// [1, 12, 13, 24, 25, 26, 37, 38]
bound = 8;
for (; index < bound; index++) {
algorithm.updateMostRecentTime(data[index]);
}
- Assert.assertEquals(22.0, algorithm.getAverageTime(), delta);
+ assertEquals(22.0, algorithm.getAverageTime(), delta);
// [1, 12, 13, 24, 25, 26, 37, 38, 39, 40]
for (; index < data.length; index++) {
algorithm.updateMostRecentTime(data[index]);
}
- Assert.assertEquals(25.5, algorithm.getAverageTime(), delta);
+ assertEquals(25.5, algorithm.getAverageTime(), delta);
}
@Test
- public void testWindowMovingAverage() throws Exception {
+ public void testWindowMovingAverage(TestInfo testInfo) throws Exception {
// Default size is 5.
- MovingAverage<?> algorithm = new WindowMovingAverage(name.getMethodName());
+ MovingAverage<?> algorithm = new WindowMovingAverage(testInfo.getTestMethod().get().getName());
int index = 0;
// [1, 12, 13, 24]
int bound = 4;
for (; index < bound; index++) {
algorithm.updateMostRecentTime(data[index]);
}
- Assert.assertEquals(12.5, algorithm.getAverageTime(), delta);
+ assertEquals(12.5, algorithm.getAverageTime(), delta);
// [1, 12, 13, 24, 25]
bound = 5;
for (; index < bound; index++) {
algorithm.updateMostRecentTime(data[index]);
}
- Assert.assertEquals(15.0, algorithm.getAverageTime(), delta);
+ assertEquals(15.0, algorithm.getAverageTime(), delta);
// [24, 25, 26, 37, 38]
bound = 8;
for (; index < bound; index++) {
algorithm.updateMostRecentTime(data[index]);
}
- Assert.assertEquals(30.0, algorithm.getAverageTime(), delta);
+ assertEquals(30.0, algorithm.getAverageTime(), delta);
// [26, 37, 38, 39, 40]
for (; index < data.length; index++) {
algorithm.updateMostRecentTime(data[index]);
}
- Assert.assertEquals(36.0, algorithm.getAverageTime(), delta);
+ assertEquals(36.0, algorithm.getAverageTime(), delta);
}
@Test
- public void testWeightedMovingAverage() throws Exception {
+ public void testWeightedMovingAverage(TestInfo testInfo) throws Exception {
// Default size is 5.
- MovingAverage<?> algorithm = new WeightedMovingAverage(name.getMethodName());
+ MovingAverage<?> algorithm =
+ new WeightedMovingAverage(testInfo.getTestMethod().get().getName());
int index = 0;
// [1, 12, 13, 24]
int bound = 4;
for (; index < bound; index++) {
algorithm.updateMostRecentTime(data[index]);
}
- Assert.assertEquals(12.5, algorithm.getAverageTime(), delta);
+ assertEquals(12.5, algorithm.getAverageTime(), delta);
// [1, 12, 13, 24, 25]
bound = 5;
for (; index < bound; index++) {
algorithm.updateMostRecentTime(data[index]);
}
- Assert.assertEquals(15.0, algorithm.getAverageTime(), delta);
+ assertEquals(15.0, algorithm.getAverageTime(), delta);
// [24, 25, 26, 37, 38]
bound = 8;
for (; index < bound; index++) {
algorithm.updateMostRecentTime(data[index]);
}
- Assert.assertEquals(32.67, algorithm.getAverageTime(), delta);
+ assertEquals(32.67, algorithm.getAverageTime(), delta);
// [26, 37, 38, 39, 40]
for (; index < data.length; index++) {
algorithm.updateMostRecentTime(data[index]);
}
- Assert.assertEquals(38.0, algorithm.getAverageTime(), delta);
+ assertEquals(38.0, algorithm.getAverageTime(), delta);
}
@Test
- public void testExponentialMovingAverage() throws Exception {
+ public void testExponentialMovingAverage(TestInfo testInfo) throws Exception {
// [1, 12, 13, 24, 25, 26, 37, 38, 39, 40]
- MovingAverage<?> algorithm = new ExponentialMovingAverage(name.getMethodName());
+ MovingAverage<?> algorithm =
+ new ExponentialMovingAverage(testInfo.getTestMethod().get().getName());
int index = 0;
int bound = 5;
for (; index < bound; index++) {
algorithm.updateMostRecentTime(data[index]);
}
- Assert.assertEquals(15.0, algorithm.getAverageTime(), delta);
+ assertEquals(15.0, algorithm.getAverageTime(), delta);
bound = 6;
for (; index < bound; index++) {
algorithm.updateMostRecentTime(data[index]);
}
- Assert.assertEquals(18.67, algorithm.getAverageTime(), delta);
+ assertEquals(18.67, algorithm.getAverageTime(), delta);
bound = 8;
for (; index < bound; index++) {
algorithm.updateMostRecentTime(data[index]);
}
- Assert.assertEquals(29.16, algorithm.getAverageTime(), delta);
+ assertEquals(29.16, algorithm.getAverageTime(), delta);
for (; index < data.length; index++) {
algorithm.updateMostRecentTime(data[index]);
}
- Assert.assertEquals(34.97, algorithm.getAverageTime(), delta);
+ assertEquals(34.97, algorithm.getAverageTime(), delta);
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestOrder.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestOrder.java
index affe3ec067a..22c5b73b409 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestOrder.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestOrder.java
@@ -19,23 +19,19 @@ package org.apache.hadoop.hbase.util;
import static org.apache.hadoop.hbase.util.Order.ASCENDING;
import static org.apache.hadoop.hbase.util.Order.DESCENDING;
-import static org.junit.Assert.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import java.util.Arrays;
import java.util.Collections;
-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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestOrder {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestOrder.class);
-
byte[][] VALS = { Bytes.toBytes("foo"), Bytes.toBytes("bar"), Bytes.toBytes("baz") };
@Test
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestOrderedBytes.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestOrderedBytes.java
index 56645324c9a..a02c5b04829 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestOrderedBytes.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestOrderedBytes.java
@@ -17,29 +17,24 @@
*/
package org.apache.hadoop.hbase.util;
-import static org.junit.Assert.assertArrayEquals;
-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.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.ThreadLocalRandom;
-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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestOrderedBytes {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestOrderedBytes.class);
-
// integer constants for testing Numeric code paths
static final Long[] I_VALS =
{ 0L, 1L, 10L, 99L, 100L, 1234L, 9999L, 10000L, 10001L, 12345L, 123450L, Long.MAX_VALUE, -1L,
@@ -83,9 +78,8 @@ public class TestOrderedBytes {
for (int i = 0; i < I_VALS.length; i++) {
for (int d = 0; d < D_VALS.length; d++) {
if (Math.abs(I_VALS[i] - D_VALS[d]) < MIN_EPSILON) {
- assertEquals(
- "Test inconsistency detected: expected lengths for " + I_VALS[i] + " do not match.",
- I_LENGTHS[i], D_LENGTHS[d]);
+ assertEquals(I_LENGTHS[i], D_LENGTHS[d],
+ "Test inconsistency detected: expected lengths for " + I_VALS[i] + " do not match.");
}
}
}
@@ -117,7 +111,7 @@ public class TestOrderedBytes {
72057594037927934L, 72057594037927935L, Long.MAX_VALUE - 1, Long.MAX_VALUE,
Long.MIN_VALUE + 1, Long.MIN_VALUE, -2L, -1L };
int[] lens = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9 };
- assertEquals("Broken test!", vals.length, lens.length);
+ assertEquals(vals.length, lens.length, "Broken test!");
/*
* assert encoded values match decoded values. encode into target buffer starting at an offset
@@ -130,21 +124,21 @@ public class TestOrderedBytes {
PositionedByteRange buf = new SimplePositionedMutableByteRange(a, 1, lens[i]);
// verify encode
- assertEquals("Surprising return value.", lens[i],
- OrderedBytes.putVaruint64(buf, vals[i], comp));
- assertEquals("Surprising serialized length.", lens[i], buf.getPosition());
- assertEquals("Buffer underflow.", 0, a[0]);
- assertEquals("Buffer overflow.", 0, a[a.length - 1]);
+ assertEquals(lens[i], OrderedBytes.putVaruint64(buf, vals[i], comp),
+ "Surprising return value.");
+ assertEquals(lens[i], buf.getPosition(), "Surprising serialized length.");
+ assertEquals(0, a[0], "Buffer underflow.");
+ assertEquals(0, a[a.length - 1], "Buffer overflow.");
// verify skip
buf.setPosition(0);
- assertEquals("Surprising return value.", lens[i], OrderedBytes.skipVaruint64(buf, comp));
- assertEquals("Did not skip enough bytes.", lens[i], buf.getPosition());
+ assertEquals(lens[i], OrderedBytes.skipVaruint64(buf, comp), "Surprising return value.");
+ assertEquals(lens[i], buf.getPosition(), "Did not skip enough bytes.");
// verify decode
buf.setPosition(0);
- assertEquals("Deserialization failed.", vals[i], OrderedBytes.getVaruint64(buf, comp));
- assertEquals("Did not consume enough bytes.", lens[i], buf.getPosition());
+ assertEquals(vals[i], OrderedBytes.getVaruint64(buf, comp), "Deserialization failed.");
+ assertEquals(lens[i], buf.getPosition(), "Did not consume enough bytes.");
}
}
}
@@ -166,25 +160,25 @@ public class TestOrderedBytes {
buf1.setPosition(1);
// verify encode
- assertEquals("Surprising return value.", I_LENGTHS[i],
- OrderedBytes.encodeNumeric(buf1, I_VALS[i], ord));
- assertEquals("Broken test: serialization did not consume entire buffer.", buf1.getLength(),
- buf1.getPosition());
- assertEquals("Surprising serialized length.", I_LENGTHS[i], buf1.getPosition() - 1);
- assertEquals("Buffer underflow.", 0, a[0]);
- assertEquals("Buffer underflow.", 0, a[1]);
- assertEquals("Buffer overflow.", 0, a[a.length - 1]);
+ assertEquals(I_LENGTHS[i], OrderedBytes.encodeNumeric(buf1, I_VALS[i], ord),
+ "Surprising return value.");
+ assertEquals(buf1.getLength(), buf1.getPosition(),
+ "Broken test: serialization did not consume entire buffer.");
+ assertEquals(I_LENGTHS[i], buf1.getPosition() - 1, "Surprising serialized length.");
+ assertEquals(0, a[0], "Buffer underflow.");
+ assertEquals(0, a[1], "Buffer underflow.");
+ assertEquals(0, a[a.length - 1], "Buffer overflow.");
// verify skip
buf1.setPosition(1);
- assertEquals("Surprising return value.", I_LENGTHS[i], OrderedBytes.skip(buf1));
- assertEquals("Did not skip enough bytes.", I_LENGTHS[i], buf1.getPosition() - 1);
+ assertEquals(I_LENGTHS[i], OrderedBytes.skip(buf1), "Surprising return value.");
+ assertEquals(I_LENGTHS[i], buf1.getPosition() - 1, "Did not skip enough bytes.");
// verify decode
buf1.setPosition(1);
- assertEquals("Deserialization failed.", I_VALS[i].longValue(),
- OrderedBytes.decodeNumericAsLong(buf1));
- assertEquals("Did not consume enough bytes.", I_LENGTHS[i], buf1.getPosition() - 1);
+ assertEquals(I_VALS[i].longValue(), OrderedBytes.decodeNumericAsLong(buf1),
+ "Deserialization failed.");
+ assertEquals(I_LENGTHS[i], buf1.getPosition() - 1, "Did not consume enough bytes.");
}
}
@@ -211,10 +205,9 @@ public class TestOrderedBytes {
for (int i = 0; i < sortedVals.length; i++) {
pbr.set(encoded[i]);
long decoded = OrderedBytes.decodeNumericAsLong(pbr);
- assertEquals(
+ assertEquals(sortedVals[i].longValue(), decoded,
String.format("Encoded representations do not preserve natural order: <%s>, <%s>, %s",
- sortedVals[i], decoded, ord),
- sortedVals[i].longValue(), decoded);
+ sortedVals[i], decoded, ord));
}
}
}
@@ -236,25 +229,25 @@ public class TestOrderedBytes {
buf1.setPosition(1);
// verify encode
- assertEquals("Surprising return value.", D_LENGTHS[i],
- OrderedBytes.encodeNumeric(buf1, D_VALS[i], ord));
- assertEquals("Broken test: serialization did not consume entire buffer.", buf1.getLength(),
- buf1.getPosition());
- assertEquals("Surprising serialized length.", D_LENGTHS[i], buf1.getPosition() - 1);
- assertEquals("Buffer underflow.", 0, a[0]);
- assertEquals("Buffer underflow.", 0, a[1]);
- assertEquals("Buffer overflow.", 0, a[a.length - 1]);
+ assertEquals(D_LENGTHS[i], OrderedBytes.encodeNumeric(buf1, D_VALS[i], ord),
+ "Surprising return value.");
+ assertEquals(buf1.getLength(), buf1.getPosition(),
+ "Broken test: serialization did not consume entire buffer.");
+ assertEquals(D_LENGTHS[i], buf1.getPosition() - 1, "Surprising serialized length.");
+ assertEquals(0, a[0], "Buffer underflow.");
+ assertEquals(0, a[1], "Buffer underflow.");
+ assertEquals(0, a[a.length - 1], "Buffer overflow.");
// verify skip
buf1.setPosition(1);
- assertEquals("Surprising return value.", D_LENGTHS[i], OrderedBytes.skip(buf1));
- assertEquals("Did not skip enough bytes.", D_LENGTHS[i], buf1.getPosition() - 1);
+ assertEquals(D_LENGTHS[i], OrderedBytes.skip(buf1), "Surprising return value.");
+ assertEquals(D_LENGTHS[i], buf1.getPosition() - 1, "Did not skip enough bytes.");
// verify decode
buf1.setPosition(1);
- assertEquals("Deserialization failed.", D_VALS[i], OrderedBytes.decodeNumericAsDouble(buf1),
- MIN_EPSILON);
- assertEquals("Did not consume enough bytes.", D_LENGTHS[i], buf1.getPosition() - 1);
+ assertEquals(D_VALS[i], OrderedBytes.decodeNumericAsDouble(buf1), MIN_EPSILON,
+ "Deserialization failed.");
+ assertEquals(D_LENGTHS[i], buf1.getPosition() - 1, "Did not consume enough bytes.");
}
}
@@ -281,10 +274,9 @@ public class TestOrderedBytes {
for (int i = 0; i < sortedVals.length; i++) {
pbr.set(encoded[i]);
double decoded = OrderedBytes.decodeNumericAsDouble(pbr);
- assertEquals(
+ assertEquals(sortedVals[i], decoded, MIN_EPSILON,
String.format("Encoded representations do not preserve natural order: <%s>, <%s>, %s",
- sortedVals[i], decoded, ord),
- sortedVals[i], decoded, MIN_EPSILON);
+ sortedVals[i], decoded, ord));
}
}
}
@@ -306,19 +298,19 @@ public class TestOrderedBytes {
buf1.setPosition(1);
// verify encode
- assertEquals("Surprising return value.", BD_LENGTHS[i],
- OrderedBytes.encodeNumeric(buf1, BD_VALS[i], ord));
- assertEquals("Broken test: serialization did not consume entire buffer.", buf1.getLength(),
- buf1.getPosition());
- assertEquals("Surprising serialized length.", BD_LENGTHS[i], buf1.getPosition() - 1);
- assertEquals("Buffer underflow.", 0, a[0]);
- assertEquals("Buffer underflow.", 0, a[1]);
- assertEquals("Buffer overflow.", 0, a[a.length - 1]);
+ assertEquals(BD_LENGTHS[i], OrderedBytes.encodeNumeric(buf1, BD_VALS[i], ord),
+ "Surprising return value.");
+ assertEquals(buf1.getLength(), buf1.getPosition(),
+ "Broken test: serialization did not consume entire buffer.");
+ assertEquals(BD_LENGTHS[i], buf1.getPosition() - 1, "Surprising serialized length.");
+ assertEquals(0, a[0], "Buffer underflow.");
+ assertEquals(0, a[1], "Buffer underflow.");
+ assertEquals(0, a[a.length - 1], "Buffer overflow.");
// verify skip
buf1.setPosition(1);
- assertEquals("Surprising return value.", BD_LENGTHS[i], OrderedBytes.skip(buf1));
- assertEquals("Did not skip enough bytes.", BD_LENGTHS[i], buf1.getPosition() - 1);
+ assertEquals(BD_LENGTHS[i], OrderedBytes.skip(buf1), "Surprising return value.");
+ assertEquals(BD_LENGTHS[i], buf1.getPosition() - 1, "Did not skip enough bytes.");
// verify decode
buf1.setPosition(1);
@@ -329,10 +321,10 @@ public class TestOrderedBytes {
// The num will be rounded to a specific precision in the encoding phase.
// So that big value will lose precision here. Need to add a normalization here to
// make the test pass.
- assertEquals("Deserialization failed.", 0,
- OrderedBytes.normalize(BD_VALS[i]).compareTo(decoded));
+ assertEquals(0, OrderedBytes.normalize(BD_VALS[i]).compareTo(decoded),
+ "Deserialization failed.");
}
- assertEquals("Did not consume enough bytes.", BD_LENGTHS[i], buf1.getPosition() - 1);
+ assertEquals(BD_LENGTHS[i], buf1.getPosition() - 1, "Did not consume enough bytes.");
}
}
}
@@ -349,7 +341,7 @@ public class TestOrderedBytes {
PositionedByteRange pbrr = new SimplePositionedMutableByteRange(I_LENGTHS[i]);
OrderedBytes.encodeNumeric(pbri, I_VALS[i], ord);
OrderedBytes.encodeNumeric(pbrr, I_VALS[i], ord);
- assertArrayEquals("Integer and real encodings differ.", pbri.getBytes(), pbrr.getBytes());
+ assertArrayEquals(pbri.getBytes(), pbrr.getBytes(), "Integer and real encodings differ.");
pbri.setPosition(0);
pbrr.setPosition(0);
assertEquals((long) I_VALS[i], OrderedBytes.decodeNumericAsLong(pbri));
@@ -359,11 +351,11 @@ public class TestOrderedBytes {
BigDecimal bd = BigDecimal.valueOf(I_VALS[i]);
PositionedByteRange pbrbd = new SimplePositionedMutableByteRange(I_LENGTHS[i]);
OrderedBytes.encodeNumeric(pbrbd, bd, ord);
- assertArrayEquals("Integer and BigDecimal encodings differ.", pbri.getBytes(),
- pbrbd.getBytes());
+ assertArrayEquals(pbri.getBytes(), pbrbd.getBytes(),
+ "Integer and BigDecimal encodings differ.");
pbri.setPosition(0);
- assertEquals("Value not preserved when decoding as Long", 0,
- bd.compareTo(BigDecimal.valueOf(OrderedBytes.decodeNumericAsLong(pbri))));
+ assertEquals(0, bd.compareTo(BigDecimal.valueOf(OrderedBytes.decodeNumericAsLong(pbri))),
+ "Value not preserved when decoding as Long");
}
}
}
@@ -387,23 +379,23 @@ public class TestOrderedBytes {
buf1.setPosition(1);
// verify encode
- assertEquals("Surprising return value.", 2, OrderedBytes.encodeInt8(buf1, val, ord));
- assertEquals("Broken test: serialization did not consume entire buffer.", buf1.getLength(),
- buf1.getPosition());
- assertEquals("Surprising serialized length.", 2, buf1.getPosition() - 1);
- assertEquals("Buffer underflow.", 0, a[0]);
- assertEquals("Buffer underflow.", 0, a[1]);
- assertEquals("Buffer overflow.", 0, a[a.length - 1]);
+ assertEquals(2, OrderedBytes.encodeInt8(buf1, val, ord), "Surprising return value.");
+ assertEquals(buf1.getLength(), buf1.getPosition(),
+ "Broken test: serialization did not consume entire buffer.");
+ assertEquals(2, buf1.getPosition() - 1, "Surprising serialized length.");
+ assertEquals(0, a[0], "Buffer underflow.");
+ assertEquals(0, a[1], "Buffer underflow.");
+ assertEquals(0, a[a.length - 1], "Buffer overflow.");
// verify skip
buf1.setPosition(1);
- assertEquals("Surprising return value.", 2, OrderedBytes.skip(buf1));
- assertEquals("Did not skip enough bytes.", 2, buf1.getPosition() - 1);
+ assertEquals(2, OrderedBytes.skip(buf1), "Surprising return value.");
+ assertEquals(2, buf1.getPosition() - 1, "Did not skip enough bytes.");
// verify decode
buf1.setPosition(1);
- assertEquals("Deserialization failed.", val.byteValue(), OrderedBytes.decodeInt8(buf1));
- assertEquals("Did not consume enough bytes.", 2, buf1.getPosition() - 1);
+ assertEquals(val.byteValue(), OrderedBytes.decodeInt8(buf1), "Deserialization failed.");
+ assertEquals(2, buf1.getPosition() - 1, "Did not consume enough bytes.");
}
}
@@ -428,10 +420,9 @@ public class TestOrderedBytes {
for (int i = 0; i < sortedVals.length; i++) {
int decoded = OrderedBytes.decodeInt8(pbr.set(encoded[i]));
- assertEquals(
+ assertEquals(sortedVals[i].byteValue(), decoded,
String.format("Encoded representations do not preserve natural order: <%s>, <%s>, %s",
- sortedVals[i], decoded, ord),
- sortedVals[i].byteValue(), decoded);
+ sortedVals[i], decoded, ord));
}
}
}
@@ -456,23 +447,23 @@ public class TestOrderedBytes {
buf1.setPosition(1);
// verify encode
- assertEquals("Surprising return value.", 3, OrderedBytes.encodeInt16(buf1, val, ord));
- assertEquals("Broken test: serialization did not consume entire buffer.", buf1.getLength(),
- buf1.getPosition());
- assertEquals("Surprising serialized length.", 3, buf1.getPosition() - 1);
- assertEquals("Buffer underflow.", 0, a[0]);
- assertEquals("Buffer underflow.", 0, a[1]);
- assertEquals("Buffer overflow.", 0, a[a.length - 1]);
+ assertEquals(3, OrderedBytes.encodeInt16(buf1, val, ord), "Surprising return value.");
+ assertEquals(buf1.getLength(), buf1.getPosition(),
+ "Broken test: serialization did not consume entire buffer.");
+ assertEquals(3, buf1.getPosition() - 1, "Surprising serialized length.");
+ assertEquals(0, a[0], "Buffer underflow.");
+ assertEquals(0, a[1], "Buffer underflow.");
+ assertEquals(0, a[a.length - 1], "Buffer overflow.");
// verify skip
buf1.setPosition(1);
- assertEquals("Surprising return value.", 3, OrderedBytes.skip(buf1));
- assertEquals("Did not skip enough bytes.", 3, buf1.getPosition() - 1);
+ assertEquals(3, OrderedBytes.skip(buf1), "Surprising return value.");
+ assertEquals(3, buf1.getPosition() - 1, "Did not skip enough bytes.");
// verify decode
buf1.setPosition(1);
- assertEquals("Deserialization failed.", val.shortValue(), OrderedBytes.decodeInt16(buf1));
- assertEquals("Did not consume enough bytes.", 3, buf1.getPosition() - 1);
+ assertEquals(val.shortValue(), OrderedBytes.decodeInt16(buf1), "Deserialization failed.");
+ assertEquals(3, buf1.getPosition() - 1, "Did not consume enough bytes.");
}
}
@@ -497,10 +488,9 @@ public class TestOrderedBytes {
for (int i = 0; i < sortedVals.length; i++) {
int decoded = OrderedBytes.decodeInt16(pbr.set(encoded[i]));
- assertEquals(
+ assertEquals(sortedVals[i].shortValue(), decoded,
String.format("Encoded representations do not preserve natural order: <%s>, <%s>, %s",
- sortedVals[i], decoded, ord),
- sortedVals[i].shortValue(), decoded);
+ sortedVals[i], decoded, ord));
}
}
}
@@ -525,23 +515,23 @@ public class TestOrderedBytes {
buf1.setPosition(1);
// verify encode
- assertEquals("Surprising return value.", 5, OrderedBytes.encodeInt32(buf1, val, ord));
- assertEquals("Broken test: serialization did not consume entire buffer.", buf1.getLength(),
- buf1.getPosition());
- assertEquals("Surprising serialized length.", 5, buf1.getPosition() - 1);
- assertEquals("Buffer underflow.", 0, a[0]);
- assertEquals("Buffer underflow.", 0, a[1]);
- assertEquals("Buffer overflow.", 0, a[a.length - 1]);
+ assertEquals(5, OrderedBytes.encodeInt32(buf1, val, ord), "Surprising return value.");
+ assertEquals(buf1.getLength(), buf1.getPosition(),
+ "Broken test: serialization did not consume entire buffer.");
+ assertEquals(5, buf1.getPosition() - 1, "Surprising serialized length.");
+ assertEquals(0, a[0], "Buffer underflow.");
+ assertEquals(0, a[1], "Buffer underflow.");
+ assertEquals(0, a[a.length - 1], "Buffer overflow.");
// verify skip
buf1.setPosition(1);
- assertEquals("Surprising return value.", 5, OrderedBytes.skip(buf1));
- assertEquals("Did not skip enough bytes.", 5, buf1.getPosition() - 1);
+ assertEquals(5, OrderedBytes.skip(buf1), "Surprising return value.");
+ assertEquals(5, buf1.getPosition() - 1, "Did not skip enough bytes.");
// verify decode
buf1.setPosition(1);
- assertEquals("Deserialization failed.", val.intValue(), OrderedBytes.decodeInt32(buf1));
- assertEquals("Did not consume enough bytes.", 5, buf1.getPosition() - 1);
+ assertEquals(val.intValue(), OrderedBytes.decodeInt32(buf1), "Deserialization failed.");
+ assertEquals(5, buf1.getPosition() - 1, "Did not consume enough bytes.");
}
}
@@ -566,10 +556,9 @@ public class TestOrderedBytes {
for (int i = 0; i < sortedVals.length; i++) {
int decoded = OrderedBytes.decodeInt32(pbr.set(encoded[i]));
- assertEquals(
+ assertEquals(sortedVals[i].intValue(), decoded,
String.format("Encoded representations do not preserve natural order: <%s>, <%s>, %s",
- sortedVals[i], decoded, ord),
- sortedVals[i].intValue(), decoded);
+ sortedVals[i], decoded, ord));
}
}
}
@@ -593,23 +582,23 @@ public class TestOrderedBytes {
buf1.setPosition(1);
// verify encode
- assertEquals("Surprising return value.", 9, OrderedBytes.encodeInt64(buf1, val, ord));
- assertEquals("Broken test: serialization did not consume entire buffer.", buf1.getLength(),
- buf1.getPosition());
- assertEquals("Surprising serialized length.", 9, buf1.getPosition() - 1);
- assertEquals("Buffer underflow.", 0, a[0]);
- assertEquals("Buffer underflow.", 0, a[1]);
- assertEquals("Buffer overflow.", 0, a[a.length - 1]);
+ assertEquals(9, OrderedBytes.encodeInt64(buf1, val, ord), "Surprising return value.");
+ assertEquals(buf1.getLength(), buf1.getPosition(),
+ "Broken test: serialization did not consume entire buffer.");
+ assertEquals(9, buf1.getPosition() - 1, "Surprising serialized length.");
+ assertEquals(0, a[0], "Buffer underflow.");
+ assertEquals(0, a[1], "Buffer underflow.");
+ assertEquals(0, a[a.length - 1], "Buffer overflow.");
// verify skip
buf1.setPosition(1);
- assertEquals("Surprising return value.", 9, OrderedBytes.skip(buf1));
- assertEquals("Did not skip enough bytes.", 9, buf1.getPosition() - 1);
+ assertEquals(9, OrderedBytes.skip(buf1), "Surprising return value.");
+ assertEquals(9, buf1.getPosition() - 1, "Did not skip enough bytes.");
// verify decode
buf1.setPosition(1);
- assertEquals("Deserialization failed.", val.longValue(), OrderedBytes.decodeInt64(buf1));
- assertEquals("Did not consume enough bytes.", 9, buf1.getPosition() - 1);
+ assertEquals(val.longValue(), OrderedBytes.decodeInt64(buf1), "Deserialization failed.");
+ assertEquals(9, buf1.getPosition() - 1, "Did not consume enough bytes.");
}
}
@@ -634,10 +623,9 @@ public class TestOrderedBytes {
for (int i = 0; i < sortedVals.length; i++) {
long decoded = OrderedBytes.decodeInt64(pbr.set(encoded[i]));
- assertEquals(
+ assertEquals(sortedVals[i].longValue(), decoded,
String.format("Encoded representations do not preserve natural order: <%s>, <%s>, %s",
- sortedVals[i], decoded, ord),
- sortedVals[i].longValue(), decoded);
+ sortedVals[i], decoded, ord));
}
}
}
@@ -662,24 +650,24 @@ public class TestOrderedBytes {
buf1.setPosition(1);
// verify encode
- assertEquals("Surprising return value.", 5, OrderedBytes.encodeFloat32(buf1, val, ord));
- assertEquals("Broken test: serialization did not consume entire buffer.", buf1.getLength(),
- buf1.getPosition());
- assertEquals("Surprising serialized length.", 5, buf1.getPosition() - 1);
- assertEquals("Buffer underflow.", 0, a[0]);
- assertEquals("Buffer underflow.", 0, a[1]);
- assertEquals("Buffer overflow.", 0, a[a.length - 1]);
+ assertEquals(5, OrderedBytes.encodeFloat32(buf1, val, ord), "Surprising return value.");
+ assertEquals(buf1.getLength(), buf1.getPosition(),
+ "Broken test: serialization did not consume entire buffer.");
+ assertEquals(5, buf1.getPosition() - 1, "Surprising serialized length.");
+ assertEquals(0, a[0], "Buffer underflow.");
+ assertEquals(0, a[1], "Buffer underflow.");
+ assertEquals(0, a[a.length - 1], "Buffer overflow.");
// verify skip
buf1.setPosition(1);
- assertEquals("Surprising return value.", 5, OrderedBytes.skip(buf1));
- assertEquals("Did not skip enough bytes.", 5, buf1.getPosition() - 1);
+ assertEquals(5, OrderedBytes.skip(buf1), "Surprising return value.");
+ assertEquals(5, buf1.getPosition() - 1, "Did not skip enough bytes.");
// verify decode
buf1.setPosition(1);
- assertEquals("Deserialization failed.", Float.floatToIntBits(val),
- Float.floatToIntBits(OrderedBytes.decodeFloat32(buf1)));
- assertEquals("Did not consume enough bytes.", 5, buf1.getPosition() - 1);
+ assertEquals(Float.floatToIntBits(val),
+ Float.floatToIntBits(OrderedBytes.decodeFloat32(buf1)), "Deserialization failed.");
+ assertEquals(5, buf1.getPosition() - 1, "Did not consume enough bytes.");
}
}
@@ -704,10 +692,9 @@ public class TestOrderedBytes {
for (int i = 0; i < sortedVals.length; i++) {
float decoded = OrderedBytes.decodeFloat32(pbr.set(encoded[i]));
- assertEquals(
+ assertEquals(Float.floatToIntBits(sortedVals[i]), Float.floatToIntBits(decoded),
String.format("Encoded representations do not preserve natural order: <%s>, <%s>, %s",
- sortedVals[i], decoded, ord),
- Float.floatToIntBits(sortedVals[i]), Float.floatToIntBits(decoded));
+ sortedVals[i], decoded, ord));
}
}
}
@@ -732,24 +719,24 @@ public class TestOrderedBytes {
buf1.setPosition(1);
// verify encode
- assertEquals("Surprising return value.", 9, OrderedBytes.encodeFloat64(buf1, val, ord));
- assertEquals("Broken test: serialization did not consume entire buffer.", buf1.getLength(),
- buf1.getPosition());
- assertEquals("Surprising serialized length.", 9, buf1.getPosition() - 1);
- assertEquals("Buffer underflow.", 0, a[0]);
- assertEquals("Buffer underflow.", 0, a[1]);
- assertEquals("Buffer overflow.", 0, a[a.length - 1]);
+ assertEquals(9, OrderedBytes.encodeFloat64(buf1, val, ord), "Surprising return value.");
+ assertEquals(buf1.getLength(), buf1.getPosition(),
+ "Broken test: serialization did not consume entire buffer.");
+ assertEquals(9, buf1.getPosition() - 1, "Surprising serialized length.");
+ assertEquals(0, a[0], "Buffer underflow.");
+ assertEquals(0, a[1], "Buffer underflow.");
+ assertEquals(0, a[a.length - 1], "Buffer overflow.");
// verify skip
buf1.setPosition(1);
- assertEquals("Surprising return value.", 9, OrderedBytes.skip(buf1));
- assertEquals("Did not skip enough bytes.", 9, buf1.getPosition() - 1);
+ assertEquals(9, OrderedBytes.skip(buf1), "Surprising return value.");
+ assertEquals(9, buf1.getPosition() - 1, "Did not skip enough bytes.");
// verify decode
buf1.setPosition(1);
- assertEquals("Deserialization failed.", Double.doubleToLongBits(val),
- Double.doubleToLongBits(OrderedBytes.decodeFloat64(buf1)));
- assertEquals("Did not consume enough bytes.", 9, buf1.getPosition() - 1);
+ assertEquals(Double.doubleToLongBits(val),
+ Double.doubleToLongBits(OrderedBytes.decodeFloat64(buf1)), "Deserialization failed.");
+ assertEquals(9, buf1.getPosition() - 1, "Did not consume enough bytes.");
}
}
@@ -774,10 +761,9 @@ public class TestOrderedBytes {
for (int i = 0; i < sortedVals.length; i++) {
double decoded = OrderedBytes.decodeFloat64(pbr.set(encoded[i]));
- assertEquals(
+ assertEquals(Double.doubleToLongBits(sortedVals[i]), Double.doubleToLongBits(decoded),
String.format("Encoded representations do not preserve natural order: <%s>, <%s>, %s",
- sortedVals[i], decoded, ord),
- Double.doubleToLongBits(sortedVals[i]), Double.doubleToLongBits(decoded));
+ sortedVals[i], decoded, ord));
}
}
}
@@ -803,24 +789,24 @@ public class TestOrderedBytes {
buf1.setPosition(1);
// verify encode
- assertEquals("Surprising return value.", expectedLengths[i],
- OrderedBytes.encodeString(buf1, vals[i], ord));
- assertEquals("Broken test: serialization did not consume entire buffer.", buf1.getLength(),
- buf1.getPosition());
- assertEquals("Surprising serialized length.", expectedLengths[i], buf1.getPosition() - 1);
- assertEquals("Buffer underflow.", 0, a[0]);
- assertEquals("Buffer underflow.", 0, a[1]);
- assertEquals("Buffer overflow.", 0, a[a.length - 1]);
+ assertEquals(expectedLengths[i], OrderedBytes.encodeString(buf1, vals[i], ord),
+ "Surprising return value.");
+ assertEquals(buf1.getLength(), buf1.getPosition(),
+ "Broken test: serialization did not consume entire buffer.");
+ assertEquals(expectedLengths[i], buf1.getPosition() - 1, "Surprising serialized length.");
+ assertEquals(0, a[0], "Buffer underflow.");
+ assertEquals(0, a[1], "Buffer underflow.");
+ assertEquals(0, a[a.length - 1], "Buffer overflow.");
// verify skip
buf1.setPosition(1);
- assertEquals("Surprising return value.", expectedLengths[i], OrderedBytes.skip(buf1));
- assertEquals("Did not skip enough bytes.", expectedLengths[i], buf1.getPosition() - 1);
+ assertEquals(expectedLengths[i], OrderedBytes.skip(buf1), "Surprising return value.");
+ assertEquals(expectedLengths[i], buf1.getPosition() - 1, "Did not skip enough bytes.");
// verify decode
buf1.setPosition(1);
- assertEquals("Deserialization failed.", vals[i], OrderedBytes.decodeString(buf1));
- assertEquals("Did not consume enough bytes.", expectedLengths[i], buf1.getPosition() - 1);
+ assertEquals(vals[i], OrderedBytes.decodeString(buf1), "Deserialization failed.");
+ assertEquals(expectedLengths[i], buf1.getPosition() - 1, "Did not consume enough bytes.");
}
}
@@ -847,18 +833,19 @@ public class TestOrderedBytes {
for (int i = 0; i < sortedVals.length; i++) {
pbr.set(encoded[i]);
String decoded = OrderedBytes.decodeString(pbr);
- assertEquals(
+ assertEquals(sortedVals[i], decoded,
String.format("Encoded representations do not preserve natural order: <%s>, <%s>, %s",
- sortedVals[i], decoded, ord),
- sortedVals[i], decoded);
+ sortedVals[i], decoded, ord));
}
}
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testStringNoNullChars() {
- PositionedByteRange buff = new SimplePositionedMutableByteRange(3);
- OrderedBytes.encodeString(buff, "\u0000", Order.ASCENDING);
+ assertThrows(IllegalArgumentException.class, () -> {
+ PositionedByteRange buff = new SimplePositionedMutableByteRange(3);
+ OrderedBytes.encodeString(buff, "\u0000", Order.ASCENDING);
+ });
}
/**
@@ -917,24 +904,24 @@ public class TestOrderedBytes {
buf1.setPosition(1);
// verify encode
- assertEquals("Surprising return value.", expectedLen,
- OrderedBytes.encodeBlobVar(buf1, val, ord));
- assertEquals("Broken test: serialization did not consume entire buffer.", buf1.getLength(),
- buf1.getPosition());
- assertEquals("Surprising serialized length.", expectedLen, buf1.getPosition() - 1);
- assertEquals("Buffer underflow.", 0, a[0]);
- assertEquals("Buffer underflow.", 0, a[1]);
- assertEquals("Buffer overflow.", 0, a[a.length - 1]);
+ assertEquals(expectedLen, OrderedBytes.encodeBlobVar(buf1, val, ord),
+ "Surprising return value.");
+ assertEquals(buf1.getLength(), buf1.getPosition(),
+ "Broken test: serialization did not consume entire buffer.");
+ assertEquals(expectedLen, buf1.getPosition() - 1, "Surprising serialized length.");
+ assertEquals(0, a[0], "Buffer underflow.");
+ assertEquals(0, a[1], "Buffer underflow.");
+ assertEquals(0, a[a.length - 1], "Buffer overflow.");
// verify skip
buf1.setPosition(1);
- assertEquals("Surprising return value.", expectedLen, OrderedBytes.skip(buf1));
- assertEquals("Did not skip enough bytes.", expectedLen, buf1.getPosition() - 1);
+ assertEquals(expectedLen, OrderedBytes.skip(buf1), "Surprising return value.");
+ assertEquals(expectedLen, buf1.getPosition() - 1, "Did not skip enough bytes.");
// verify decode
buf1.setPosition(1);
- assertArrayEquals("Deserialization failed.", val, OrderedBytes.decodeBlobVar(buf1));
- assertEquals("Did not consume enough bytes.", expectedLen, buf1.getPosition() - 1);
+ assertArrayEquals(val, OrderedBytes.decodeBlobVar(buf1), "Deserialization failed.");
+ assertEquals(expectedLen, buf1.getPosition() - 1, "Did not consume enough bytes.");
}
}
@@ -961,10 +948,9 @@ public class TestOrderedBytes {
for (int i = 0; i < sortedVals.length; i++) {
pbr.set(encoded[i]);
byte[] decoded = OrderedBytes.decodeBlobVar(pbr);
- assertArrayEquals(
+ assertArrayEquals(sortedVals[i], decoded,
String.format("Encoded representations do not preserve natural order: <%s>, <%s>, %s",
- Arrays.toString(sortedVals[i]), Arrays.toString(decoded), ord),
- sortedVals[i], decoded);
+ Arrays.toString(sortedVals[i]), Arrays.toString(decoded), ord));
}
}
}
@@ -993,24 +979,24 @@ public class TestOrderedBytes {
buf1.setPosition(1);
// verify encode
- assertEquals("Surprising return value.", expectedLen,
- OrderedBytes.encodeBlobCopy(buf1, val, ord));
- assertEquals("Broken test: serialization did not consume entire buffer.", buf1.getLength(),
- buf1.getPosition());
- assertEquals("Surprising serialized length.", expectedLen, buf1.getPosition() - 1);
- assertEquals("Buffer underflow.", 0, a[0]);
- assertEquals("Buffer underflow.", 0, a[1]);
- assertEquals("Buffer overflow.", 0, a[a.length - 1]);
+ assertEquals(expectedLen, OrderedBytes.encodeBlobCopy(buf1, val, ord),
+ "Surprising return value.");
+ assertEquals(buf1.getLength(), buf1.getPosition(),
+ "Broken test: serialization did not consume entire buffer.");
+ assertEquals(expectedLen, buf1.getPosition() - 1, "Surprising serialized length.");
+ assertEquals(0, a[0], "Buffer underflow.");
+ assertEquals(0, a[1], "Buffer underflow.");
+ assertEquals(0, a[a.length - 1], "Buffer overflow.");
// verify skip
buf1.setPosition(1);
- assertEquals("Surprising return value.", expectedLen, OrderedBytes.skip(buf1));
- assertEquals("Did not skip enough bytes.", expectedLen, buf1.getPosition() - 1);
+ assertEquals(expectedLen, OrderedBytes.skip(buf1), "Surprising return value.");
+ assertEquals(expectedLen, buf1.getPosition() - 1, "Did not skip enough bytes.");
// verify decode
buf1.setPosition(1);
- assertArrayEquals("Deserialization failed.", val, OrderedBytes.decodeBlobCopy(buf1));
- assertEquals("Did not consume enough bytes.", expectedLen, buf1.getPosition() - 1);
+ assertArrayEquals(val, OrderedBytes.decodeBlobCopy(buf1), "Deserialization failed.");
+ assertEquals(expectedLen, buf1.getPosition() - 1, "Did not consume enough bytes.");
}
}
@@ -1037,10 +1023,9 @@ public class TestOrderedBytes {
for (int i = 0; i < sortedVals.length; i++) {
pbr.set(encoded[i]);
byte[] decoded = OrderedBytes.decodeBlobCopy(pbr);
- assertArrayEquals(
+ assertArrayEquals(sortedVals[i], decoded,
String.format("Encoded representations do not preserve natural order: <%s>, <%s>, %s",
- Arrays.toString(sortedVals[i]), Arrays.toString(decoded), ord),
- sortedVals[i], decoded);
+ Arrays.toString(sortedVals[i]), Arrays.toString(decoded), ord));
}
}
@@ -1060,7 +1045,7 @@ public class TestOrderedBytes {
/**
* Assert invalid input byte[] are rejected by BlobCopy
*/
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testBlobCopyNoZeroBytes() {
byte[] val = { 0x01, 0x02, 0x00, 0x03 };
// TODO: implementation detail leaked here.
@@ -1069,8 +1054,8 @@ public class TestOrderedBytes {
OrderedBytes.encodeBlobCopy(buf, val, Order.ASCENDING);
assertArrayEquals(ascExpected, buf.getBytes());
buf.set(val.length + 2);
- OrderedBytes.encodeBlobCopy(buf, val, Order.DESCENDING);
- fail("test should never get here.");
+ assertThrows(IllegalArgumentException.class,
+ () -> OrderedBytes.encodeBlobCopy(buf, val, Order.DESCENDING));
}
/**
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestReservoirSample.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestReservoirSample.java
index d7ea0c5ac0c..42abb566281 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestReservoirSample.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestReservoirSample.java
@@ -17,25 +17,20 @@
*/
package org.apache.hadoop.hbase.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.stream.IntStream;
-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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestReservoirSample {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestReservoirSample.class);
-
@Test
public void test() {
int round = 100000;
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestRetryCounter.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestRetryCounter.java
index 08dcc6396aa..df0b57d432c 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestRetryCounter.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestRetryCounter.java
@@ -17,25 +17,21 @@
*/
package org.apache.hadoop.hbase.util;
-import static junit.framework.TestCase.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Basic test for some old functionality we don't seem to have used but that looks nice.
*/
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestRetryCounter {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestRetryCounter.class);
private static final Logger LOG = LoggerFactory.getLogger(TestRetryCounter.class);
@Test
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestShowProperties.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestShowProperties.java
index 41416f7cd5d..e24916b1a7f 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestShowProperties.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestShowProperties.java
@@ -18,12 +18,10 @@
package org.apache.hadoop.hbase.util;
import java.util.Properties;
-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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -31,13 +29,10 @@ import org.slf4j.LoggerFactory;
* This test is there to dump the properties. It allows to detect possible env issues when executing
* the tests on various environment.
*/
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestShowProperties {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestShowProperties.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestShowProperties.class);
@Test
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestSimpleKdcServerUtil.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestSimpleKdcServerUtil.java
index e8f227576ec..cac9547a1a5 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestSimpleKdcServerUtil.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestSimpleKdcServerUtil.java
@@ -19,21 +19,17 @@ package org.apache.hadoop.hbase.util;
import java.io.File;
import java.io.IOException;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.kerby.kerberos.kerb.KrbException;
import org.apache.kerby.kerberos.kerb.server.SimpleKdcServer;
-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({ MiscTests.class, MediumTests.class })
+@Tag(MiscTests.TAG)
+@Tag(MediumTests.TAG)
public class TestSimpleKdcServerUtil {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestSimpleKdcServerUtil.class);
private static final HBaseCommonTestingUtility UTIL = new HBaseCommonTestingUtility();
/**
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestSimpleMutableByteRange.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestSimpleMutableByteRange.java
index 0088919da18..4518645e6a5 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestSimpleMutableByteRange.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestSimpleMutableByteRange.java
@@ -17,63 +17,63 @@
*/
package org.apache.hadoop.hbase.util;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+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.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.Assert;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestSimpleMutableByteRange {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestSimpleMutableByteRange.class);
-
@Test
public void testEmpty() {
- Assert.assertTrue(SimpleMutableByteRange.isEmpty(null));
+ assertTrue(SimpleMutableByteRange.isEmpty(null));
ByteRange r = new SimpleMutableByteRange();
- Assert.assertTrue(SimpleMutableByteRange.isEmpty(r));
- Assert.assertTrue(r.isEmpty());
+ assertTrue(SimpleMutableByteRange.isEmpty(r));
+ assertTrue(r.isEmpty());
r.set(new byte[0]);
- Assert.assertEquals(0, r.getBytes().length);
- Assert.assertEquals(0, r.getOffset());
- Assert.assertEquals(0, r.getLength());
- Assert.assertTrue(Bytes.equals(new byte[0], r.deepCopyToNewArray()));
- Assert.assertEquals(0, r.compareTo(new SimpleMutableByteRange(new byte[0], 0, 0)));
- Assert.assertEquals(0, r.hashCode());
+ assertEquals(0, r.getBytes().length);
+ assertEquals(0, r.getOffset());
+ assertEquals(0, r.getLength());
+ assertTrue(Bytes.equals(new byte[0], r.deepCopyToNewArray()));
+ assertEquals(0, r.compareTo(new SimpleMutableByteRange(new byte[0], 0, 0)));
+ assertEquals(0, r.hashCode());
}
@Test
public void testBasics() {
ByteRange r = new SimpleMutableByteRange(new byte[] { 1, 3, 2 });
- Assert.assertFalse(SimpleMutableByteRange.isEmpty(r));
- Assert.assertNotNull(r.getBytes());// should be empty byte[], but could change this behavior
- Assert.assertEquals(3, r.getBytes().length);
- Assert.assertEquals(0, r.getOffset());
- Assert.assertEquals(3, r.getLength());
+ assertFalse(SimpleMutableByteRange.isEmpty(r));
+ assertNotNull(r.getBytes());// should be empty byte[], but could change this behavior
+ assertEquals(3, r.getBytes().length);
+ assertEquals(0, r.getOffset());
+ assertEquals(3, r.getLength());
// cloning (deep copying)
- Assert.assertTrue(Bytes.equals(new byte[] { 1, 3, 2 }, r.deepCopyToNewArray()));
- Assert.assertNotSame(r.getBytes(), r.deepCopyToNewArray());
+ assertTrue(Bytes.equals(new byte[] { 1, 3, 2 }, r.deepCopyToNewArray()));
+ assertNotSame(r.getBytes(), r.deepCopyToNewArray());
// hash code
- Assert.assertTrue(r.hashCode() > 0);
- Assert.assertEquals(r.hashCode(), r.deepCopy().hashCode());
+ assertTrue(r.hashCode() > 0);
+ assertEquals(r.hashCode(), r.deepCopy().hashCode());
// copying to arrays
byte[] destination = new byte[] { -59 };// junk
r.deepCopySubRangeTo(2, 1, destination, 0);
- Assert.assertTrue(Bytes.equals(new byte[] { 2 }, destination));
+ assertTrue(Bytes.equals(new byte[] { 2 }, destination));
// set length
r.setLength(1);
- Assert.assertTrue(Bytes.equals(new byte[] { 1 }, r.deepCopyToNewArray()));
+ assertTrue(Bytes.equals(new byte[] { 1 }, r.deepCopyToNewArray()));
r.setLength(2);// verify we retained the 2nd byte, but dangerous in real code
- Assert.assertTrue(Bytes.equals(new byte[] { 1, 3 }, r.deepCopyToNewArray()));
+ assertTrue(Bytes.equals(new byte[] { 1, 3 }, r.deepCopyToNewArray()));
}
@Test
@@ -100,20 +100,20 @@ public class TestSimpleMutableByteRange {
r.putVLong(offset, Long.MIN_VALUE);
offset = 0;
- Assert.assertEquals(i1, r.getInt(offset));
+ assertEquals(i1, r.getInt(offset));
offset += Bytes.SIZEOF_INT;
- Assert.assertEquals(i2, r.getInt(offset));
+ assertEquals(i2, r.getInt(offset));
offset += Bytes.SIZEOF_INT;
- Assert.assertEquals(s1, r.getShort(offset));
+ assertEquals(s1, r.getShort(offset));
offset += Bytes.SIZEOF_SHORT;
- Assert.assertEquals(l1, r.getLong(offset));
+ assertEquals(l1, r.getLong(offset));
offset += Bytes.SIZEOF_LONG;
- Assert.assertEquals(l1, r.getVLong(offset));
+ assertEquals(l1, r.getVLong(offset));
offset += SimpleByteRange.getVLongSize(l1);
- Assert.assertEquals(l2, r.getVLong(offset));
+ assertEquals(l2, r.getVLong(offset));
offset += SimpleByteRange.getVLongSize(l2);
- Assert.assertEquals(Long.MAX_VALUE, r.getVLong(offset));
+ assertEquals(Long.MAX_VALUE, r.getVLong(offset));
offset += SimpleByteRange.getVLongSize(Long.MAX_VALUE);
- Assert.assertEquals(Long.MIN_VALUE, r.getVLong(offset));
+ assertEquals(Long.MIN_VALUE, r.getVLong(offset));
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestSimplePositionedMutableByteRange.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestSimplePositionedMutableByteRange.java
index 5cd0ac6d7ab..2adee33f287 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestSimplePositionedMutableByteRange.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestSimplePositionedMutableByteRange.java
@@ -17,55 +17,52 @@
*/
package org.apache.hadoop.hbase.util;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
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.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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestSimplePositionedMutableByteRange {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestSimplePositionedMutableByteRange.class);
-
@Test
public void testPosition() {
PositionedByteRange r = new SimplePositionedMutableByteRange(new byte[5], 1, 3);
// exercise single-byte put
r.put(Bytes.toBytes("f")[0]).put(Bytes.toBytes("o")[0]).put(Bytes.toBytes("o")[0]);
- Assert.assertEquals(3, r.getPosition());
- Assert.assertArrayEquals(
+ assertEquals(3, r.getPosition());
+ assertArrayEquals(
new byte[] { 0, Bytes.toBytes("f")[0], Bytes.toBytes("o")[0], Bytes.toBytes("o")[0], 0 },
r.getBytes());
// exercise multi-byte put
r.setPosition(0);
r.put(Bytes.toBytes("f")).put(Bytes.toBytes("o")).put(Bytes.toBytes("o"));
- Assert.assertEquals(3, r.getPosition());
- Assert.assertArrayEquals(
+ assertEquals(3, r.getPosition());
+ assertArrayEquals(
new byte[] { 0, Bytes.toBytes("f")[0], Bytes.toBytes("o")[0], Bytes.toBytes("o")[0], 0 },
r.getBytes());
// exercise single-byte get
r.setPosition(0);
- Assert.assertEquals(Bytes.toBytes("f")[0], r.get());
- Assert.assertEquals(Bytes.toBytes("o")[0], r.get());
- Assert.assertEquals(Bytes.toBytes("o")[0], r.get());
+ assertEquals(Bytes.toBytes("f")[0], r.get());
+ assertEquals(Bytes.toBytes("o")[0], r.get());
+ assertEquals(Bytes.toBytes("o")[0], r.get());
r.setPosition(1);
- Assert.assertEquals(Bytes.toBytes("o")[0], r.get());
+ assertEquals(Bytes.toBytes("o")[0], r.get());
// exercise multi-byte get
r.setPosition(0);
byte[] dst = new byte[3];
r.get(dst);
- Assert.assertArrayEquals(Bytes.toBytes("foo"), dst);
+ assertArrayEquals(Bytes.toBytes("foo"), dst);
// set position to the end of the range; this should not throw.
r.setPosition(3);
@@ -87,14 +84,14 @@ public class TestSimplePositionedMutableByteRange {
pbr.putVLong(Long.MIN_VALUE);
// rewind
pbr.setPosition(0);
- Assert.assertEquals(i1, pbr.getInt());
- Assert.assertEquals(i2, pbr.getInt());
- Assert.assertEquals(s1, pbr.getShort());
- Assert.assertEquals(l1, pbr.getLong());
- Assert.assertEquals(0, pbr.getVLong());
- Assert.assertEquals(l1, pbr.getVLong());
- Assert.assertEquals(Long.MAX_VALUE, pbr.getVLong());
- Assert.assertEquals(Long.MIN_VALUE, pbr.getVLong());
+ assertEquals(i1, pbr.getInt());
+ assertEquals(i2, pbr.getInt());
+ assertEquals(s1, pbr.getShort());
+ assertEquals(l1, pbr.getLong());
+ assertEquals(0, pbr.getVLong());
+ assertEquals(l1, pbr.getVLong());
+ assertEquals(Long.MAX_VALUE, pbr.getVLong());
+ assertEquals(Long.MIN_VALUE, pbr.getVLong());
}
@Test
@@ -110,15 +107,15 @@ public class TestSimplePositionedMutableByteRange {
pbr.putLong(l1);
// rewind
pbr.setPosition(0);
- Assert.assertEquals(i1, pbr.getInt());
- Assert.assertEquals(s1, pbr.getShort());
- Assert.assertEquals(i2, pbr.getInt());
- Assert.assertEquals(l1, pbr.getLong());
+ assertEquals(i1, pbr.getInt());
+ assertEquals(s1, pbr.getShort());
+ assertEquals(i2, pbr.getInt());
+ assertEquals(l1, pbr.getLong());
// Read back using BB APIs
ByteBuffer bb = ByteBuffer.wrap(pbr.getBytes());
- Assert.assertEquals(i1, bb.getInt());
- Assert.assertEquals(s1, bb.getShort());
- Assert.assertEquals(i2, bb.getInt());
- Assert.assertEquals(l1, bb.getLong());
+ assertEquals(i1, bb.getInt());
+ assertEquals(s1, bb.getShort());
+ assertEquals(i2, bb.getInt());
+ assertEquals(l1, bb.getLong());
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestStrings.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestStrings.java
index 8528fd88beb..da388fda9b2 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestStrings.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestStrings.java
@@ -17,29 +17,25 @@
*/
package org.apache.hadoop.hbase.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.net.URI;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import org.apache.hadoop.conf.Configuration;
-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(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestStrings {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestStrings.class);
-
@Test
public void testAppendKeyValue() {
assertEquals("foo, bar=baz",
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestThreads.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestThreads.java
index 57f44d1d1ac..10f7932b6f5 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestThreads.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestThreads.java
@@ -17,25 +17,20 @@
*/
package org.apache.hadoop.hbase.util;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.concurrent.atomic.AtomicBoolean;
-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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestThreads {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestThreads.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestThreads.class);
private static final int SLEEP_TIME_MS = 3000;
@@ -72,13 +67,13 @@ public class TestThreads {
sleeper.interrupt();
sleeper.join();
- assertTrue("sleepWithoutInterrupt did not preserve the thread's " + "interrupted status",
- wasInterrupted.get());
+ assertTrue(wasInterrupted.get(),
+ "sleepWithoutInterrupt did not preserve the thread's " + "interrupted status");
long timeElapsed = EnvironmentEdgeManager.currentTime() - startTime;
// We expect to wait at least SLEEP_TIME_MS, but we can wait more if there is a GC.
- assertTrue("Elapsed time " + timeElapsed + " ms is out of the expected " + " sleep time of "
- + SLEEP_TIME_MS, SLEEP_TIME_MS - timeElapsed < TOLERANCE_MS);
+ assertTrue(SLEEP_TIME_MS - timeElapsed < TOLERANCE_MS, "Elapsed time " + timeElapsed
+ + " ms is out of the expected " + " sleep time of " + SLEEP_TIME_MS);
LOG.debug("Target sleep time: " + SLEEP_TIME_MS + ", time elapsed: " + timeElapsed);
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestVersionInfo.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestVersionInfo.java
index 93ec6878e2e..2e98cc08801 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestVersionInfo.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestVersionInfo.java
@@ -17,21 +17,17 @@
*/
package org.apache.hadoop.hbase.util;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-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(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestVersionInfo {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestVersionInfo.class);
-
@Test
public void testCompareVersion() {
assertTrue(VersionInfo.compareVersion("1.0.0", "0.98.11") > 0);
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestWeakObjectPool.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestWeakObjectPool.java
index 348bbaa5d29..6fe28b5de93 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestWeakObjectPool.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestWeakObjectPool.java
@@ -17,28 +17,28 @@
*/
package org.apache.hadoop.hbase.util;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.fail;
+
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-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({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestWeakObjectPool {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestWeakObjectPool.class);
-
ObjectPool<String, Object> pool;
- @Before
+ @BeforeEach
public void setUp() {
pool = new WeakObjectPool<>(new ObjectPool.ObjectFactory<String, Object>() {
@Override
@@ -53,11 +53,11 @@ public class TestWeakObjectPool {
Object obj1 = pool.get("a");
Object obj2 = pool.get(new String("a"));
- Assert.assertSame(obj1, obj2);
+ assertSame(obj1, obj2);
Object obj3 = pool.get("b");
- Assert.assertNotSame(obj1, obj3);
+ assertNotSame(obj1, obj3);
}
@Test
@@ -73,10 +73,10 @@ public class TestWeakObjectPool {
// Sleep a while because references newly becoming stale
// may still remain when calling the {@code purge} method.
pool.purge();
- Assert.assertEquals(1, pool.size());
+ assertEquals(1, pool.size());
Object obj2 = pool.get("a");
- Assert.assertSame(obj1, obj2);
+ assertSame(obj1, obj2);
obj1 = null;
obj2 = null;
@@ -87,10 +87,10 @@ public class TestWeakObjectPool {
Thread.sleep(10);
pool.purge();
- Assert.assertEquals(0, pool.size());
+ assertEquals(0, pool.size());
Object obj3 = pool.get("a");
- Assert.assertNotEquals(hash1, System.identityHashCode(obj3));
+ assertNotEquals(hash1, System.identityHashCode(obj3));
}
@Test
@@ -132,7 +132,7 @@ public class TestWeakObjectPool {
endLatch.await();
if (assertionFailed.get()) {
- Assert.fail();
+ fail();
}
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKConfig.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKConfig.java
index b5d52f44f81..ecddfbf0a1f 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKConfig.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKConfig.java
@@ -17,32 +17,27 @@
*/
package org.apache.hadoop.hbase.zookeeper;
-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.Properties;
import java.util.Set;
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.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.zookeeper.client.ZKClientConfig;
-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.ImmutableSet;
-@Category({ MiscTests.class, SmallTests.class })
+@Tag(MiscTests.TAG)
+@Tag(SmallTests.TAG)
public class TestZKConfig {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestZKConfig.class);
-
/** Supported ZooKeeper client TLS properties */
private static final Set<String> ZOOKEEPER_CLIENT_TLS_PROPERTIES = ImmutableSet.of(
"client.secure", "clientCnxnSocket", "ssl.keyStore.location", "ssl.keyStore.password",
@@ -56,8 +51,8 @@ public class TestZKConfig {
// (i.e. via hbase-default.xml and hbase-site.xml)
conf.setInt(HConstants.ZOOKEEPER_CLIENT_PORT, 2181);
Properties props = ZKConfig.makeZKProps(conf);
- assertEquals("Property client port should have been default from the HBase config", "2181",
- props.getProperty("clientPort"));
+ assertEquals("2181", props.getProperty("clientPort"),
+ "Property client port should have been default from the HBase config");
}
@Test
@@ -115,8 +110,8 @@ public class TestZKConfig {
// Assert
for (String p : ZOOKEEPER_CLIENT_TLS_PROPERTIES) {
- assertEquals("Invalid or unset system property: " + p, p,
- zkClientConfig.getProperty("zookeeper." + p));
+ assertEquals(p, zkClientConfig.getProperty("zookeeper." + p),
+ "Invalid or unset system property: " + p);
}
}
@@ -135,7 +130,7 @@ public class TestZKConfig {
// Assert
for (String p : ZOOKEEPER_CLIENT_TLS_PROPERTIES) {
- assertEquals("Invalid or unset system property: " + p, p, zkProps.getProperty(p));
+ assertEquals(p, zkProps.getProperty(p), "Invalid or unset system property: " + p);
}
}