From c1e178caee798da4ed946d5a03ec67246c99726f Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Mon, 11 May 2026 18:45:51 +0800 Subject: [PATCH] HBASE-30153 Upgrade hbase-common to junit5 --- hbase-common/pom.xml | 5 + .../hadoop/hbase/TestByteBufferKeyValue.java | 19 +- .../apache/hadoop/hbase/TestCellBuilder.java | 16 +- .../hadoop/hbase/TestCellComparator.java | 21 +- .../org/apache/hadoop/hbase/TestCellUtil.java | 112 +++-- .../apache/hadoop/hbase/TestChoreService.java | 105 +++-- .../apache/hadoop/hbase/TestClassFinder.java | 74 ++-- .../hadoop/hbase/TestHBaseConfiguration.java | 31 +- .../hbase/TestHDFSBlocksDistribution.java | 62 ++- .../hbase/TestIndividualBytesFieldCell.java | 87 ++-- .../org/apache/hadoop/hbase/TestKeyValue.java | 27 +- .../apache/hadoop/hbase/TestServerName.java | 24 +- .../hadoop/hbase/TestSystemExitInTest.java | 20 +- .../apache/hadoop/hbase/TestTableName.java | 21 +- .../apache/hadoop/hbase/TestTagBuilder.java | 19 +- .../org/apache/hadoop/hbase/TestTagUtil.java | 15 +- .../org/apache/hadoop/hbase/TestTimeout.java | 17 +- .../hadoop/hbase/codec/TestCellCodec.java | 22 +- .../hbase/codec/TestCellCodecWithTags.java | 21 +- .../codec/TestKeyValueCodecWithTags.java | 21 +- .../hadoop/hbase/conf/TestConfigKey.java | 18 +- .../hbase/conf/TestConfigurationManager.java | 20 +- .../hbase/io/TestByteBuffAllocator.java | 60 ++- .../TestByteBuffAllocatorLeakDetection.java | 20 +- .../io/TestByteBufferListOutputStream.java | 20 +- .../hbase/io/TestFileChangeWatcher.java | 12 +- .../io/TestMultiByteBuffInputStream.java | 18 +- .../hbase/io/TestTagCompressionContext.java | 17 +- .../hbase/io/compress/TestCodecPool.java | 62 ++- .../hbase/io/crypto/TestCipherProvider.java | 22 +- .../hbase/io/crypto/TestEncryption.java | 25 +- .../hbase/io/crypto/TestKeyProvider.java | 34 +- .../io/crypto/TestKeyStoreKeyProvider.java | 24 +- .../hadoop/hbase/io/crypto/aes/TestAES.java | 29 +- .../hbase/io/crypto/aes/TestCommonsAES.java | 30 +- .../tls/AbstractTestX509Parameterized.java | 53 ++- .../io/crypto/tls/TestBCFKSFileLoader.java | 133 +++--- ...TestFileKeyStoreLoaderBuilderProvider.java | 31 +- .../crypto/tls/TestHBaseHostnameVerifier.java | 25 +- .../io/crypto/tls/TestHBaseTrustManager.java | 35 +- .../io/crypto/tls/TestJKSFileLoader.java | 133 +++--- .../io/crypto/tls/TestKeyStoreFileType.java | 100 ++--- .../io/crypto/tls/TestPEMFileLoader.java | 111 +++-- .../io/crypto/tls/TestPKCS12FileLoader.java | 133 +++--- .../hbase/io/crypto/tls/TestX509Util.java | 146 +++--- .../io/encoding/TestEncodedDataBlock.java | 43 +- .../TestThrottledInputStream.java | 18 +- .../hbase/io/util/TestLRUDictionary.java | 26 +- .../hadoop/hbase/logging/TestJul2Slf4j.java | 26 +- .../hadoop/hbase/logging/TestLog4jUtils.java | 20 +- .../apache/hadoop/hbase/net/TestAddress.java | 18 +- .../hadoop/hbase/nio/TestMultiByteBuff.java | 26 +- .../hadoop/hbase/nio/TestSingleByteBuff.java | 18 +- .../hbase/types/TestFixedLengthWrapper.java | 37 +- .../hadoop/hbase/types/TestOrderedBlob.java | 24 +- .../hbase/types/TestOrderedBlobVar.java | 22 +- .../hbase/types/TestOrderedFloat32.java | 39 +- .../hbase/types/TestOrderedFloat64.java | 39 +- .../hadoop/hbase/types/TestOrderedInt16.java | 39 +- .../hadoop/hbase/types/TestOrderedInt32.java | 39 +- .../hadoop/hbase/types/TestOrderedInt64.java | 39 +- .../hadoop/hbase/types/TestOrderedInt8.java | 39 +- .../hbase/types/TestOrderedNumeric.java | 47 +- .../hadoop/hbase/types/TestOrderedString.java | 22 +- .../hadoop/hbase/types/TestRawBytes.java | 31 +- .../hadoop/hbase/types/TestRawString.java | 24 +- .../apache/hadoop/hbase/types/TestStruct.java | 62 +-- .../hbase/types/TestStructNullExtension.java | 103 +++-- .../hbase/types/TestTerminatedWrapper.java | 52 ++- .../apache/hadoop/hbase/types/TestUnion2.java | 17 +- .../apache/hadoop/hbase/util/TestAvlUtil.java | 26 +- .../hbase/util/TestByteBufferArray.java | 24 +- .../hadoop/hbase/util/TestByteRangeUtils.java | 19 +- .../TestByteRangeWithKVSerialization.java | 27 +- .../apache/hadoop/hbase/util/TestClasses.java | 26 +- .../hadoop/hbase/util/TestCommonFSUtils.java | 41 +- .../hbase/util/TestConcatenatedLists.java | 24 +- .../util/TestCoprocessorClassLoader.java | 38 +- .../hbase/util/TestDynamicClassLoader.java | 30 +- .../util/TestEnvironmentEdgeManager.java | 24 +- .../hadoop/hbase/util/TestFutureUtils.java | 30 +- .../hadoop/hbase/util/TestGsonUtil.java | 18 +- .../hadoop/hbase/util/TestJRubyFormat.java | 17 +- .../hadoop/hbase/util/TestKeyLocker.java | 45 +- .../hadoop/hbase/util/TestMovingAverage.java | 74 ++-- .../apache/hadoop/hbase/util/TestOrder.java | 17 +- .../hadoop/hbase/util/TestOrderedBytes.java | 414 +++++++++--------- .../hbase/util/TestReservoirSample.java | 22 +- .../hadoop/hbase/util/TestRetryCounter.java | 17 +- .../hadoop/hbase/util/TestShowProperties.java | 16 +- .../hbase/util/TestSimpleKdcServerUtil.java | 15 +- .../util/TestSimpleMutableByteRange.java | 81 ++-- .../TestSimplePositionedMutableByteRange.java | 70 +-- .../apache/hadoop/hbase/util/TestStrings.java | 23 +- .../apache/hadoop/hbase/util/TestThreads.java | 26 +- .../hadoop/hbase/util/TestVersionInfo.java | 17 +- .../hadoop/hbase/util/TestWeakObjectPool.java | 43 +- .../hadoop/hbase/zookeeper/TestZKConfig.java | 30 +- 98 files changed, 2033 insertions(+), 2141 deletions(-) diff --git a/hbase-common/pom.xml b/hbase-common/pom.xml index 9a30ae406d09..ea58c0327c78 100644 --- a/hbase-common/pom.xml +++ b/hbase-common/pom.xml @@ -156,6 +156,11 @@ mockito-inline test + + org.mockito + mockito-junit-jupiter + test + org.slf4j jcl-over-slf4j 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 dcf7d9e52569..c2db9716fdad 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,14 @@ 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@org.junit.jupiter.api.Tag(MiscTests.TAG) +@org.junit.jupiter.api.Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 7860b62dfa70..0b90ba1decfe 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 553b39311369..1de240d1f1ce 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,15 @@ 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 +263,8 @@ public void testBinaryKeys() throws Exception { 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 3ff63ef6ff65..fbea47242481 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.IOException; import java.math.BigDecimal; @@ -32,17 +32,15 @@ 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.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestCellUtil { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestCellUtil.class); /** * CellScannable used in test. Returns a {@link TestCellScanner} @@ -269,7 +267,7 @@ private void consume(final CellScanner scanner, final int expected) throws IOExc while (scanner.advance()) { count++; } - Assert.assertEquals(expected, count); + assertEquals(expected, count); } @Test @@ -281,43 +279,43 @@ public void testOverlappingKeys() { 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 @@ -325,32 +323,32 @@ public void testFindCommonPrefixInFlatKey() { // 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)); @@ -358,18 +356,18 @@ public void testFindCommonPrefixInFlatKey() { 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)); @@ -423,10 +421,10 @@ public void testToString1() { System.out.println("nonVerbose=" + nonVerbose); System.out.println("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 8828ac7bd1b5..685c00dd0422 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,37 @@ 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.junit.jupiter.api.extension.ExtendWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MiscTests.class, MediumTests.class }) +@Tag(MiscTests.TAG) +@Tag(MediumTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 +283,10 @@ protected void chore() { } }; - 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 +296,8 @@ protected void chore() { } }; - 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 +337,10 @@ public void testFrequencyOfChores() throws InterruptedException { 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 +356,7 @@ public void testForceTrigger() throws InterruptedException { 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 +371,19 @@ public void testForceTrigger() throws InterruptedException { 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 +395,22 @@ public void testCorePoolIncrease() throws InterruptedException { 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 +427,20 @@ public void testCorePoolDecrease() throws InterruptedException { 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 +493,21 @@ public void testNumberOfRunningChores() throws InterruptedException { 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 +593,10 @@ public void testMaximumChoreServiceThreads() throws InterruptedException { } @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 043ee3a3049e..7fcd15245547 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 @@ 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,22 @@ 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.junit.jupiter.api.extension.ExtendWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 HBaseCommonTestingUtil testUtil = new HBaseCommonTestingUtil(); private static final String BASEPKG = "tfcpkg"; private static final String PREFIX = "Prefix"; @@ -75,7 +71,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 +88,7 @@ public static void createTestDir() throws IOException { classLoader = new CustomClassloader(new URL[0], ClassLoader.getSystemClassLoader()); } - @AfterClass + @AfterAll public static void deleteTestDir() { testUtil.cleanupTestDir(TestClassFinder.class.getSimpleName()); } @@ -125,10 +121,10 @@ public void testClassFinderHandlesConflicts() throws Exception { } @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 +143,9 @@ public void testClassFinderHandlesNestedPackages() throws Exception { } @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 +158,9 @@ public void testClassFinderFiltersByNameInJar() throws Exception { } @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 +180,8 @@ private static String createAndLoadJar(final String packageNameSuffix, } @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 +203,17 @@ public void testClassFinderFiltersByPathInJar() throws Exception { } @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> 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 +228,12 @@ private static boolean contains(final Set> classes, final String simple } @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 +241,7 @@ public void testClassFinderFiltersByNameInDirs() throws Exception { String pkgName = makePackageName(pkgNameSuffix, counter); ClassFinder allClassesFinder = new ClassFinder(classLoader); Set> 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> notAllClasses = notThisClassFinder.findClasses(pkgName, false); assertFalse(contains(notAllClasses, classNameToFilterOut)); @@ -253,19 +249,19 @@ public void testClassFinderFiltersByNameInDirs() throws Exception { } @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> 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> notAllClasses = notThisClassFinder.findClasses(pkgName, false); assertFalse(contains(notAllClasses, clazz.getSimpleName())); 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 e959f77a7220..2def5dcb2772 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,25 @@ 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.junit.jupiter.api.extension.ExtendWith; 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) +@ExtendWith(HBaseJupiterExtension.class) 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 HBaseCommonTestingUtil UTIL = new HBaseCommonTestingUtil(); - @AfterClass + @AfterAll public static void tearDown() throws IOException { UTIL.cleanupTestDir(); } @@ -104,13 +103,13 @@ public void testGetPassword() throws Exception { 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/TestHDFSBlocksDistribution.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestHDFSBlocksDistribution.java index 62011f13ffc0..74a0910e5047 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestHDFSBlocksDistribution.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestHDFSBlocksDistribution.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import java.util.HashMap; import java.util.Map; @@ -26,39 +26,37 @@ import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.DNS; -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 TestHDFSBlocksDistribution { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestHDFSBlocksDistribution.class); - @Test public void testAddHostsAndBlockWeight() throws Exception { HDFSBlocksDistribution distribution = new HDFSBlocksDistribution(); distribution.addHostsAndBlockWeight(null, 100); - assertEquals("Expecting no hosts weights", 0, distribution.getHostAndWeights().size()); + assertEquals(0, distribution.getHostAndWeights().size(), "Expecting no hosts weights"); distribution.addHostsAndBlockWeight(new String[0], 100); - assertEquals("Expecting no hosts weights", 0, distribution.getHostAndWeights().size()); + assertEquals(0, distribution.getHostAndWeights().size(), "Expecting no hosts weights"); distribution.addHostsAndBlockWeight(new String[] { "test" }, 101); - assertEquals("Should be one host", 1, distribution.getHostAndWeights().size()); + assertEquals(1, distribution.getHostAndWeights().size(), "Should be one host"); distribution.addHostsAndBlockWeight(new String[] { "test" }, 202); - assertEquals("Should be one host", 1, distribution.getHostAndWeights().size()); - assertEquals("test host should have weight 303", 303, - distribution.getHostAndWeights().get("test").getWeight()); + assertEquals(1, distribution.getHostAndWeights().size(), "Should be one host"); + assertEquals(303, distribution.getHostAndWeights().get("test").getWeight(), + "test host should have weight 303"); distribution.addHostsAndBlockWeight(new String[] { "testTwo" }, 222); - assertEquals("Should be two hosts", 2, distribution.getHostAndWeights().size()); - assertEquals("Total weight should be 525", 525, distribution.getUniqueBlocksTotalWeight()); + assertEquals(2, distribution.getHostAndWeights().size(), "Should be two hosts"); + assertEquals(525, distribution.getUniqueBlocksTotalWeight(), "Total weight should be 525"); distribution.addHostsAndBlockWeight(new String[] { "test" }, 100, new StorageType[] { StorageType.SSD }); - assertEquals("test host should have weight 403", 403, - distribution.getHostAndWeights().get("test").getWeight()); - assertEquals("test host should have weight for ssd 100", 100, - distribution.getHostAndWeights().get("test").getWeightForSsd()); + assertEquals(403, distribution.getHostAndWeights().get("test").getWeight(), + "test host should have weight 403"); + assertEquals(100, distribution.getHostAndWeights().get("test").getWeightForSsd(), + "test host should have weight for ssd 100"); } private static final class MockHDFSBlocksDistribution extends HDFSBlocksDistribution { @@ -75,25 +73,25 @@ public Map getHostAndWeights() { public void testAdd() throws Exception { HDFSBlocksDistribution distribution = new HDFSBlocksDistribution(); distribution.add(new MockHDFSBlocksDistribution()); - assertEquals("Expecting no hosts weights", 0, distribution.getHostAndWeights().size()); + assertEquals(0, distribution.getHostAndWeights().size(), "Expecting no hosts weights"); distribution.addHostsAndBlockWeight(new String[] { "test" }, 10); - assertEquals("Should be one host", 1, distribution.getHostAndWeights().size()); + assertEquals(1, distribution.getHostAndWeights().size(), "Should be one host"); distribution.add(new MockHDFSBlocksDistribution()); - assertEquals("Should be one host", 1, distribution.getHostAndWeights().size()); - assertEquals("Total weight should be 10", 10, distribution.getUniqueBlocksTotalWeight()); + assertEquals(1, distribution.getHostAndWeights().size(), "Should be one host"); + assertEquals(10, distribution.getUniqueBlocksTotalWeight(), "Total weight should be 10"); } @Test public void testLocalHostCompatibility() throws Exception { String currentHost = DNS.getDefaultHost("default", "default"); HDFSBlocksDistribution distribution = new HDFSBlocksDistribution(); - assertEquals("Locality should be 0.0", 0.0, distribution.getBlockLocalityIndex(currentHost), - 0.01); + assertEquals(0.0, distribution.getBlockLocalityIndex(currentHost), 0.01, + "Locality should be 0.0"); distribution.addHostsAndBlockWeight(new String[] { "localhost" }, 10); - assertEquals("Should be one host", 1, distribution.getHostAndWeights().size()); - assertEquals("Locality should be 0.0", 0.0, distribution.getBlockLocalityIndex("test"), 0.01); - assertNotEquals("Locality should be 0.0", 0.0, distribution.getBlockLocalityIndex(currentHost), - 0.01); + assertEquals(1, distribution.getHostAndWeights().size(), "Should be one host"); + assertEquals(0.0, distribution.getBlockLocalityIndex("test"), 0.01, "Locality should be 0.0"); + assertNotEquals(0.0, distribution.getBlockLocalityIndex(currentHost), 0.01, + "Locality should be 0.0"); } } 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 0a1cf713fea9..9fe4fc2fb80f 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,20 @@ 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; - -@Category({ MiscTests.class, SmallTests.class }) +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 +184,58 @@ public void testIfExtendedCellImplemented() { 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 1644a6f1fce7..b49d8d467946 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; @@ -38,17 +38,14 @@ 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.junit.jupiter.api.extension.ExtendWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category(SmallTests.class) +@org.junit.jupiter.api.Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 void testCheckKeyValueBytesFailureCase() throws Exception { fail("Should fail when parse key value from an invalid bytes for 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 c37d0c25d888..9b9f0896799b 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,15 @@ 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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/TestSystemExitInTest.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestSystemExitInTest.java index c8438bc77d16..ce7dec7f9afb 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,22 @@ */ 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 d9281d8953e8..1318ba176f05 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,17 @@ 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.junit.jupiter.api.extension.ExtendWith; /** * Tests for various kinds of TableNames. */ -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 a0c8aea937a2..f7cf31a797c8 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,21 @@ */ 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@org.junit.jupiter.api.Tag(MiscTests.TAG) +@org.junit.jupiter.api.Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 9ac858e99141..e089c174822a 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,19 @@ */ 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@org.junit.jupiter.api.Tag(MiscTests.TAG) +@org.junit.jupiter.api.Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 557bd14f67a1..ee7ca99a7687 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 @@ -18,18 +18,15 @@ package org.apache.hadoop.hbase; 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category(SmallTests.class) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 void run1() throws InterruptedException { * 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/codec/TestCellCodec.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodec.java index 3508419cea78..4b11ac21f737 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; @@ -27,26 +27,24 @@ import java.io.DataOutputStream; import java.io.IOException; import org.apache.hadoop.hbase.ExtendedCell; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseJupiterExtension; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.PrivateCellUtil; 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.junit.jupiter.api.extension.ExtendWith; 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) +@ExtendWith(HBaseJupiterExtension.class) 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 17c95eb2c729..9fe403fc8a3f 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,7 @@ import org.apache.hadoop.hbase.ArrayBackedTag; import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.ExtendedCell; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseJupiterExtension; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.PrivateCellUtil; @@ -38,19 +38,16 @@ 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.junit.jupiter.api.extension.ExtendWith; 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) +@ExtendWith(HBaseJupiterExtension.class) 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/TestKeyValueCodecWithTags.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestKeyValueCodecWithTags.java index e2bdecbf7c6b..e30c18281220 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,7 @@ import org.apache.hadoop.hbase.ArrayBackedTag; import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.ExtendedCell; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseJupiterExtension; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.PrivateCellUtil; @@ -38,19 +38,16 @@ 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.junit.jupiter.api.extension.ExtendWith; 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) +@ExtendWith(HBaseJupiterExtension.class) 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 eedf0964f2a3..8feb8f4f8514 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,24 @@ */ package org.apache.hadoop.hbase.conf; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; +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.HBaseJupiterExtension; 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 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 d38a4ee5efc9..149065cde8ed 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,24 @@ */ 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.HBaseJupiterExtension; 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.junit.jupiter.api.extension.ExtendWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ SmallTests.class, ClientTests.class }) +@Tag(SmallTests.TAG) +@Tag(ClientTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 8dcb1465684e..56f116de66b2 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,30 @@ 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.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ RPCTests.class, SmallTests.class }) +@Tag(RPCTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestByteBuffAllocator { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestByteBuffAllocator.class); - @Test public void testRecycleOnlyPooledBuffers() { int maxBuffersInPool = 10; @@ -364,25 +361,25 @@ public void testDeprecatedConfigs() { 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 +388,30 @@ public void testHeapAllocationRatio() { 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 ffc0292902e4..f1e912aba5fc 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,17 @@ */ 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.HBaseJupiterExtension; 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.junit.jupiter.api.extension.ExtendWith; import org.apache.hbase.thirdparty.io.netty.util.ResourceLeakDetector; import org.apache.hbase.thirdparty.io.netty.util.internal.logging.InternalLogLevel; @@ -35,13 +35,11 @@ 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) +@ExtendWith(HBaseJupiterExtension.class) 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 4f9ec7d09f84..a278b5c2091f 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,26 @@ */ 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.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ IOTests.class, SmallTests.class }) +@Tag(IOTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 358ea172e143..4b822c9d402d 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 @@ 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 void testNoFalseNotifications() throws Exception { 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 void testCallbackWorksOnFileChanges() throws IOException, InterruptedExce 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 a82441f9509e..c9666bb58351 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,26 @@ */ 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.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ IOTests.class, SmallTests.class }) +@Tag(IOTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 4c80d0de0413..ab5ca5693bbf 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,7 @@ 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.HBaseJupiterExtension; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.Tag; import org.apache.hadoop.hbase.io.util.LRUDictionary; @@ -37,17 +37,14 @@ 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@org.junit.jupiter.api.Tag(MiscTests.TAG) +@org.junit.jupiter.api.Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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/TestCodecPool.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/compress/TestCodecPool.java index 6ce7850273da..fa856dbd2a40 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,7 @@ 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.HBaseJupiterExtension; import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.io.compress.AlreadyClosedException; @@ -42,55 +42,53 @@ 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; +import org.junit.jupiter.api.extension.ExtendWith; /** * 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) +@ExtendWith(HBaseJupiterExtension.class) 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); @@ -105,24 +103,24 @@ public void testCompressorNotReturnSameInstance() { } } - @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); @@ -156,10 +154,10 @@ public Boolean call() throws Exception { 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); @@ -193,10 +191,10 @@ public Boolean call() throws Exception { 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); @@ -211,7 +209,7 @@ public void testDecompressorNotReturnSameInstance() { } } - @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 1cafaaf7ecb3..4a03d03d8716 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,21 @@ 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.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 4e67c814c2aa..c9552d7fbe71 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,30 @@ */ 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.HBaseJupiterExtension; 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.junit.jupiter.api.extension.ExtendWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 +134,9 @@ private void checkTransformSymmetry(byte[] keyBytes, byte[] iv, byte[] plaintext 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 741cf05744d8..856cf3e2063a 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,40 @@ */ 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.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.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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, MockAesKeyProvider.class.getName()); KeyProvider provider = Encryption.getKeyProvider(conf); - assertNotNull("Null returned for provider", provider); - assertTrue("Provider is not the expected type", provider instanceof MockAesKeyProvider); + assertNotNull(provider, "Null returned for provider"); + assertTrue(provider instanceof MockAesKeyProvider, "Provider is not the expected type"); 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 581681988c28..723449a048f7 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,21 @@ import java.security.MessageDigest; import java.util.Properties; import javax.crypto.spec.SecretKeySpec; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseCommonTestingUtil; +import org.apache.hadoop.hbase.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestKeyStoreKeyProvider { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestKeyStoreKeyProvider.class); - static final HBaseCommonTestingUtil TEST_UTIL = new HBaseCommonTestingUtil(); static final String ALIAS = "test"; static final String PASSWORD = "password"; @@ -53,7 +51,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 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 c50da383dc93..75300c9edb1b 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,8 +32,8 @@ 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.HBaseJupiterExtension; import org.apache.hadoop.hbase.io.crypto.Cipher; import org.apache.hadoop.hbase.io.crypto.DefaultCipherProvider; import org.apache.hadoop.hbase.io.crypto.Encryption; @@ -41,16 +41,15 @@ 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.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 +73,13 @@ public void testAESAlgorithm() throws Exception { 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 +92,7 @@ public void testAlternateRNG() throws Exception { 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 2114ebbfb140..c9fe2037d9d0 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,8 +32,8 @@ 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.HBaseJupiterExtension; import org.apache.hadoop.hbase.io.crypto.Cipher; import org.apache.hadoop.hbase.io.crypto.DefaultCipherProvider; import org.apache.hadoop.hbase.io.crypto.Encryption; @@ -41,17 +41,15 @@ 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.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 +73,13 @@ public void testAESAlgorithm() throws Exception { 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 +92,7 @@ public void testAlternateRNG() throws Exception { 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 821a68541358..359731a3461c 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.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.HBaseCommonTestingUtil; 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,34 @@ public abstract class AbstractTestX509Parameterized { private static final HBaseCommonTestingUtil UTIL = new HBaseCommonTestingUtil(); private static X509TestContextProvider PROVIDER; - @Parameterized.Parameter() - public X509KeyType caKeyType; + private X509KeyType caKeyType; + private X509KeyType certKeyType; + private char[] keyPassword; + private Integer paramIndex; - @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, Integer paramIndex) { + this.caKeyType = caKeyType; + this.certKeyType = certKeyType; + this.keyPassword = keyPassword; + this.paramIndex = paramIndex; + } /** * 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 defaultParams() { - List result = new ArrayList<>(); + public static Stream parameters() { + List result = new ArrayList<>(); int paramIndex = 0; 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, paramIndex++)); } } } - return result; + return result.stream(); } /** @@ -92,7 +91,7 @@ public static Collection defaultParams() { 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 +100,20 @@ public static void setUpBaseClass() throws Exception { 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 060c60a7a0ca..81c8bb5925ff 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,18 @@ */ 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.HBaseJupiterExtension; +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; +import org.junit.jupiter.api.extension.ExtendWith; /** * This file has been copied from the Apache ZooKeeper project. @@ -35,84 +36,104 @@ * "https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/test/java/org/apache/zookeeper/common/BCFKSFileLoaderTest.java">Base * revision */ -@RunWith(Parameterized.class) -@Category({ SecurityTests.class, SmallTests.class }) +@Tag(SecurityTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) +@HBaseParameterizedTestTemplate( + name = "{index}: caKeyType={0}, certKeyType={1}, keyPassword={2}, paramIndex={3}") public class TestBCFKSFileLoader extends AbstractTestX509Parameterized { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestBCFKSFileLoader.class); + public TestBCFKSFileLoader(X509KeyType caKeyType, X509KeyType certKeyType, char[] keyPassword, + Integer paramIndex) { + super(caKeyType, certKeyType, keyPassword, paramIndex); + } - @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 { - String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.BCFKS).getAbsolutePath(); - new BCFKSFileLoader.Builder().setKeyStorePath(path) - .setKeyStorePassword("wrong password".toCharArray()).build().loadKeyStore(); + @TestTemplate + public void testLoadKeyStoreWithWrongPassword() { + assertThrows(Exception.class, () -> { + String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.BCFKS).getAbsolutePath(); + new BCFKSFileLoader.Builder().setKeyStorePath(path) + .setKeyStorePassword("wrong password".toCharArray()).build().loadKeyStore(); + }); } - @Test(expected = IOException.class) - public void testLoadKeyStoreWithWrongFilePath() throws Exception { - String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.BCFKS).getAbsolutePath(); - new BCFKSFileLoader.Builder().setKeyStorePath(path + ".does_not_exist") - .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore(); + @TestTemplate + public void testLoadKeyStoreWithWrongFilePath() { + assertThrows(IOException.class, () -> { + String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.BCFKS).getAbsolutePath(); + 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 - String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath(); - new BCFKSFileLoader.Builder().setKeyStorePath(path) - .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore(); + @TestTemplate + public void testLoadKeyStoreWithWrongFileType() { + assertThrows(IOException.class, () -> { + // Trying to load a PEM file with BCFKS loader should fail + String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath(); + 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 { - String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.BCFKS).getAbsolutePath(); - new BCFKSFileLoader.Builder().setTrustStorePath(path) - .setTrustStorePassword("wrong password".toCharArray()).build().loadTrustStore(); + @TestTemplate + public void testLoadTrustStoreWithWrongPassword() { + assertThrows(Exception.class, () -> { + String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.BCFKS).getAbsolutePath(); + new BCFKSFileLoader.Builder().setTrustStorePath(path) + .setTrustStorePassword("wrong password".toCharArray()).build().loadTrustStore(); + }); } - @Test(expected = IOException.class) - public void testLoadTrustStoreWithWrongFilePath() throws Exception { - String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.BCFKS).getAbsolutePath(); - new BCFKSFileLoader.Builder().setTrustStorePath(path + ".does_not_exist") - .setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore(); + @TestTemplate + public void testLoadTrustStoreWithWrongFilePath() { + assertThrows(IOException.class, () -> { + String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.BCFKS).getAbsolutePath(); + 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 - String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM).getAbsolutePath(); - new BCFKSFileLoader.Builder().setTrustStorePath(path) - .setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore(); + @TestTemplate + public void testLoadTrustStoreWithWrongFileType() { + assertThrows(IOException.class, () -> { + // Trying to load a PEM file with BCFKS loader should fail + String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM).getAbsolutePath(); + 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 a80103483345..037718d07287 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,15 @@ */ package org.apache.hadoop.hbase.io.crypto.tls; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.apache.hadoop.hbase.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; /** * This file has been copied from the Apache ZooKeeper project. @@ -31,36 +33,35 @@ * "https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/test/java/org/apache/zookeeper/common/FileKeyStoreLoaderBuilderProviderTest.java">Base * revision */ -@Category({ SecurityTests.class, SmallTests.class }) +@Tag(SecurityTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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); + assertTrue(builder instanceof JKSFileLoader.Builder); } @Test public void testGetBuilderForPEMFileType() { FileKeyStoreLoader.Builder builder = FileKeyStoreLoaderBuilderProvider.getBuilderForKeyStoreFileType(KeyStoreFileType.PEM); - Assert.assertTrue(builder instanceof PEMFileLoader.Builder); + assertTrue(builder instanceof PEMFileLoader.Builder); } @Test public void testGetBuilderForPKCS12FileType() { FileKeyStoreLoader.Builder builder = FileKeyStoreLoaderBuilderProvider.getBuilderForKeyStoreFileType(KeyStoreFileType.PKCS12); - Assert.assertTrue(builder instanceof PKCS12FileLoader.Builder); + assertTrue(builder instanceof PKCS12FileLoader.Builder); } - @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 12de61758360..f4570670a490 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.fail; import java.io.ByteArrayInputStream; import java.io.InputStream; @@ -27,7 +27,7 @@ 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.HBaseJupiterExtension; import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.bouncycastle.asn1.x500.X500Name; @@ -36,11 +36,11 @@ 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.junit.jupiter.api.extension.ExtendWith; import org.apache.hbase.thirdparty.com.google.common.net.InetAddresses; @@ -50,15 +50,14 @@ * "https://github.com/apache/zookeeper/blob/5820d10d9dc58c8e12d2e25386fdf92acb360359/zookeeper-server/src/test/java/org/apache/zookeeper/common/ZKHostnameVerifierTest.java">Base * revision */ -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 +68,7 @@ public static void setupClass() throws Exception { certificateCreator = new CertificateCreator(keyPair, caCert); } - @Before + @BeforeEach public void setup() { impl = new HBaseHostnameVerifier(); } 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 31a443758f91..0a4e611369c1 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,7 @@ 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.HBaseJupiterExtension; import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.bouncycastle.asn1.x500.X500NameBuilder; @@ -55,12 +55,12 @@ 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.junit.jupiter.api.extension.ExtendWith; import org.mockito.stubbing.Answer; // @@ -71,13 +71,11 @@ * "https://github.com/apache/zookeeper/blob/c74658d398cdc1d207aa296cb6e20de00faec03e/zookeeper-server/src/test/java/org/apache/zookeeper/common/HBaseTrustManagerTest.java">Base * revision */ -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestHBaseTrustManager { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestHBaseTrustManager.class); - private static KeyPair keyPair; private X509ExtendedTrustManager mockX509ExtendedTrustManager; @@ -91,7 +89,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 +98,12 @@ public static void createKeyPair() throws Exception { 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); @@ -370,12 +368,13 @@ public void testClientTrustedSslEngineWithPeerHostReverseLookup() throws Excepti 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 6640e3b22f98..ab6c4f532ede 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,18 @@ */ 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.HBaseJupiterExtension; +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; +import org.junit.jupiter.api.extension.ExtendWith; /** * This file has been copied from the Apache ZooKeeper project. @@ -35,83 +36,103 @@ * "https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/test/java/org/apache/zookeeper/common/JKSFileLoaderTest.java">Base * revision */ -@RunWith(Parameterized.class) -@Category({ SecurityTests.class, SmallTests.class }) +@Tag(SecurityTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) +@HBaseParameterizedTestTemplate( + name = "{index}: caKeyType={0}, certKeyType={1}, keyPassword={2}, paramIndex={3}") public class TestJKSFileLoader extends AbstractTestX509Parameterized { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestJKSFileLoader.class); + public TestJKSFileLoader(X509KeyType caKeyType, X509KeyType certKeyType, char[] keyPassword, + Integer paramIndex) { + super(caKeyType, certKeyType, keyPassword, paramIndex); + } - @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 { - String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS).getAbsolutePath(); - new JKSFileLoader.Builder().setKeyStorePath(path) - .setKeyStorePassword("wrong password".toCharArray()).build().loadKeyStore(); + @TestTemplate + public void testLoadKeyStoreWithWrongPassword() { + assertThrows(Exception.class, () -> { + String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS).getAbsolutePath(); + new JKSFileLoader.Builder().setKeyStorePath(path) + .setKeyStorePassword("wrong password".toCharArray()).build().loadKeyStore(); + }); } - @Test(expected = IOException.class) - public void testLoadKeyStoreWithWrongFilePath() throws Exception { - String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS).getAbsolutePath(); - new JKSFileLoader.Builder().setKeyStorePath(path + ".does_not_exist") - .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore(); + @TestTemplate + public void testLoadKeyStoreWithWrongFilePath() { + assertThrows(IOException.class, () -> { + String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS).getAbsolutePath(); + 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 - String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath(); - new JKSFileLoader.Builder().setKeyStorePath(path) - .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore(); + @TestTemplate + public void testLoadKeyStoreWithWrongFileType() { + assertThrows(IOException.class, () -> { + // Trying to load a PEM file with JKS loader should fail + String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath(); + 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 { - String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS).getAbsolutePath(); - new JKSFileLoader.Builder().setTrustStorePath(path) - .setTrustStorePassword("wrong password".toCharArray()).build().loadTrustStore(); + @TestTemplate + public void testLoadTrustStoreWithWrongPassword() { + assertThrows(Exception.class, () -> { + String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS).getAbsolutePath(); + new JKSFileLoader.Builder().setTrustStorePath(path) + .setTrustStorePassword("wrong password".toCharArray()).build().loadTrustStore(); + }); } - @Test(expected = IOException.class) - public void testLoadTrustStoreWithWrongFilePath() throws Exception { - String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS).getAbsolutePath(); - new JKSFileLoader.Builder().setTrustStorePath(path + ".does_not_exist") - .setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore(); + @TestTemplate + public void testLoadTrustStoreWithWrongFilePath() { + assertThrows(IOException.class, () -> { + String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS).getAbsolutePath(); + 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 d3f457fb4d33..08cafa0e0617 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,16 @@ */ 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.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; /** * This file has been copied from the Apache ZooKeeper project. @@ -31,90 +34,89 @@ * "https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/test/java/org/apache/zookeeper/common/KeyStoreFileTypeTest.java">Base * revision */ -@Category({ SecurityTests.class, SmallTests.class }) +@Tag(SecurityTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 0c9924f09075..b094dd30af37 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,19 @@ */ 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.HBaseJupiterExtension; +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; +import org.junit.jupiter.api.extension.ExtendWith; /** * This file has been copied from the Apache ZooKeeper project. @@ -36,77 +37,93 @@ * "https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/test/java/org/apache/zookeeper/common/PEMFileLoaderTest.java">Base * revision */ -@RunWith(Parameterized.class) -@Category({ SecurityTests.class, SmallTests.class }) +@Tag(SecurityTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) +@HBaseParameterizedTestTemplate( + name = "{index}: caKeyType={0}, certKeyType={1}, keyPassword={2}, paramIndex={3}") public class TestPEMFileLoader extends AbstractTestX509Parameterized { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestPEMFileLoader.class); + public TestPEMFileLoader(X509KeyType caKeyType, X509KeyType certKeyType, char[] keyPassword, + Integer paramIndex) { + super(caKeyType, certKeyType, keyPassword, paramIndex); + } - @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 { - String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath(); - new PEMFileLoader.Builder().setKeyStorePath(path) - .setKeyStorePassword("wrong password".toCharArray()).build().loadKeyStore(); + @TestTemplate + public void testLoadKeyStoreWithWrongPassword() { + assertThrows(Exception.class, () -> { + String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath(); + new PEMFileLoader.Builder().setKeyStorePath(path) + .setKeyStorePassword("wrong password".toCharArray()).build().loadKeyStore(); + }); } - @Test(expected = IOException.class) - public void testLoadKeyStoreWithWrongFilePath() throws Exception { - String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath(); - new PEMFileLoader.Builder().setKeyStorePath(path + ".does_not_exist") - .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore(); + @TestTemplate + public void testLoadKeyStoreWithWrongFilePath() { + assertThrows(IOException.class, () -> { + String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath(); + 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 - String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS).getAbsolutePath(); - new PEMFileLoader.Builder().setKeyStorePath(path) - .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore(); + @TestTemplate + public void testLoadKeyStoreWithWrongFileType() { + assertThrows(KeyStoreException.class, () -> { + // Trying to load a JKS file with PEM loader should fail + String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS).getAbsolutePath(); + 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 { - String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM).getAbsolutePath(); - new PEMFileLoader.Builder().setTrustStorePath(path + ".does_not_exist") - .setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore(); + @TestTemplate + public void testLoadTrustStoreWithWrongFilePath() { + assertThrows(IOException.class, () -> { + String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM).getAbsolutePath(); + 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 a0ff83833e22..1fef3cc9279b 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,18 @@ */ 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.HBaseJupiterExtension; +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; +import org.junit.jupiter.api.extension.ExtendWith; /** * This file has been copied from the Apache ZooKeeper project. @@ -35,83 +36,103 @@ * "https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/test/java/org/apache/zookeeper/common/PKCS12FileLoaderTest.java">Base * revision */ -@RunWith(Parameterized.class) -@Category({ SecurityTests.class, SmallTests.class }) +@Tag(SecurityTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) +@HBaseParameterizedTestTemplate( + name = "{index}: caKeyType={0}, certKeyType={1}, keyPassword={2}, paramIndex={3}") public class TestPKCS12FileLoader extends AbstractTestX509Parameterized { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestPKCS12FileLoader.class); + public TestPKCS12FileLoader(X509KeyType caKeyType, X509KeyType certKeyType, char[] keyPassword, + Integer paramIndex) { + super(caKeyType, certKeyType, keyPassword, paramIndex); + } - @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 { - String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath(); - new PKCS12FileLoader.Builder().setKeyStorePath(path) - .setKeyStorePassword("wrong password".toCharArray()).build().loadKeyStore(); + @TestTemplate + public void testLoadKeyStoreWithWrongPassword() { + assertThrows(Exception.class, () -> { + String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath(); + new PKCS12FileLoader.Builder().setKeyStorePath(path) + .setKeyStorePassword("wrong password".toCharArray()).build().loadKeyStore(); + }); } - @Test(expected = IOException.class) - public void testLoadKeyStoreWithWrongFilePath() throws Exception { - String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath(); - new PKCS12FileLoader.Builder().setKeyStorePath(path + ".does_not_exist") - .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore(); + @TestTemplate + public void testLoadKeyStoreWithWrongFilePath() { + assertThrows(IOException.class, () -> { + String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath(); + 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 - String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath(); - new PKCS12FileLoader.Builder().setKeyStorePath(path) - .setKeyStorePassword(x509TestContext.getKeyStorePassword()).build().loadKeyStore(); + @TestTemplate + public void testLoadKeyStoreWithWrongFileType() { + assertThrows(IOException.class, () -> { + // Trying to load a PEM file with PKCS12 loader should fail + String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath(); + 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 { - String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath(); - new PKCS12FileLoader.Builder().setTrustStorePath(path) - .setTrustStorePassword("wrong password".toCharArray()).build().loadTrustStore(); + @TestTemplate + public void testLoadTrustStoreWithWrongPassword() { + assertThrows(Exception.class, () -> { + String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath(); + new PKCS12FileLoader.Builder().setTrustStorePath(path) + .setTrustStorePassword("wrong password".toCharArray()).build().loadTrustStore(); + }); } - @Test(expected = IOException.class) - public void testLoadTrustStoreWithWrongFilePath() throws Exception { - String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath(); - new PKCS12FileLoader.Builder().setTrustStorePath(path + ".does_not_exist") - .setTrustStorePassword(x509TestContext.getTrustStorePassword()).build().loadTrustStore(); + @TestTemplate + public void testLoadTrustStoreWithWrongFilePath() { + assertThrows(IOException.class, () -> { + String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath(); + 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 bc70b844e05c..56fe6f2ec6f2 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 @@ -17,29 +17,27 @@ */ package org.apache.hadoop.hbase.io.crypto.tls; -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.HBaseJupiterExtension; +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.junit.jupiter.api.extension.ExtendWith; import org.apache.hbase.thirdparty.io.netty.buffer.ByteBufAllocator; import org.apache.hbase.thirdparty.io.netty.handler.ssl.SslContext; @@ -50,24 +48,28 @@ * "https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/test/java/org/apache/zookeeper/common/X509UtilTest.java">Base * revision */ -@RunWith(Parameterized.class) -@Category({ SecurityTests.class, SmallTests.class }) +@Tag(SecurityTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) +@HBaseParameterizedTestTemplate( + name = "{index}: caKeyType={0}, certKeyType={1}, keyPassword={2}, paramIndex={3}") 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, + Integer paramIndex) { + super(caKeyType, certKeyType, keyPassword, paramIndex); + } + + @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); @@ -75,7 +77,7 @@ public void testCreateSSLContextWithClientAuthNEED() throws Exception { 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); @@ -83,7 +85,7 @@ public void testCreateSSLContextWithClientAuthWANT() throws Exception { 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); @@ -92,7 +94,7 @@ public void testCreateSSLContextWithClientAuthNONE() throws Exception { assertFalse(sslContext.newEngine(byteBufAllocatorMock).getWantClientAuth()); } - @Test + @TestTemplate public void testCreateSSLContextWithoutCustomProtocol() throws Exception { SslContext sslContext = X509Util.createSslContextForClient(conf); ByteBufAllocator byteBufAllocatorMock = mock(ByteBufAllocator.class); @@ -100,7 +102,7 @@ public void testCreateSSLContextWithoutCustomProtocol() throws Exception { sslContext.newEngine(byteBufAllocatorMock).getEnabledProtocols()); } - @Test + @TestTemplate public void testCreateTcNativeSSLContextWithoutCustomProtocol() throws Exception { conf.set(X509Util.TLS_USE_OPENSSL, "true"); SslContext sslContext = X509Util.createSslContextForClient(conf); @@ -109,7 +111,7 @@ public void testCreateTcNativeSSLContextWithoutCustomProtocol() throws Exception sslContext.newEngine(byteBufAllocatorMock).getEnabledProtocols()); } - @Test + @TestTemplate public void testCreateSSLContextWithCustomProtocol() throws Exception { final String protocol = "TLSv1.1"; conf.set(X509Util.TLS_CONFIG_PROTOCOL, protocol); @@ -119,25 +121,27 @@ public void testCreateSSLContextWithCustomProtocol() throws Exception { Arrays.asList(sslContext.newEngine(byteBufAllocatorMock).getEnabledProtocols())); } - @Test(expected = SSLContextException.class) - public void testCreateSSLContextWithoutKeyStoreLocationServer() throws Exception { - conf.unset(X509Util.TLS_CONFIG_KEYSTORE_LOCATION); - X509Util.createSslContextForServer(conf); + @TestTemplate + public void testCreateSSLContextWithoutKeyStoreLocationServer() { + assertThrows(SSLContextException.class, () -> { + conf.unset(X509Util.TLS_CONFIG_KEYSTORE_LOCATION); + 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); @@ -145,7 +149,7 @@ public void testCreateSSLContextWithoutTrustStoreLocationServer() throws Excepti // 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); @@ -154,7 +158,7 @@ public void testCRLEnabled() throws Exception { 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"))); @@ -162,7 +166,7 @@ public void testCRLDisabled() throws Exception { 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( @@ -170,16 +174,16 @@ public void testLoadPEMKeyStore() throws Exception { 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( @@ -188,16 +192,18 @@ public void testLoadPEMKeyStoreAutodetectStoreFileType() throws Exception { 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( @@ -206,16 +212,16 @@ public void testLoadPEMTrustStore() throws Exception { 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( @@ -225,7 +231,7 @@ public void testLoadPEMTrustStoreAutodetectStoreFileType() throws Exception { 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( @@ -233,16 +239,16 @@ public void testLoadJKSKeyStore() throws Exception { 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( @@ -251,7 +257,7 @@ public void testLoadJKSKeyStoreAutodetectStoreFileType() throws Exception { 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 @@ -261,7 +267,7 @@ public void testLoadJKSKeyStoreWithWrongPassword() { }); } - @Test + @TestTemplate public void testLoadJKSTrustStore() throws Exception { // Make sure we can instantiate a trust manager from the JKS file on disk X509Util.createTrustManager( @@ -270,16 +276,16 @@ public void testLoadJKSTrustStore() throws Exception { 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 X509Util.createTrustManager( @@ -289,7 +295,7 @@ public void testLoadJKSTrustStoreAutodetectStoreFileType() throws Exception { true, true, true, true); } - @Test + @TestTemplate public void testLoadJKSTrustStoreWithWrongPassword() { assertThrows(TrustManagerException.class, () -> { // Attempting to load with the wrong key password should fail @@ -300,7 +306,7 @@ public void testLoadJKSTrustStoreWithWrongPassword() { }); } - @Test + @TestTemplate public void testLoadPKCS12KeyStore() throws Exception { // Make sure we can instantiate a key manager from the PKCS12 file on disk X509Util.createKeyManager( @@ -308,16 +314,16 @@ public void testLoadPKCS12KeyStore() throws Exception { 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( @@ -326,7 +332,7 @@ public void testLoadPKCS12KeyStoreAutodetectStoreFileType() throws Exception { 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 @@ -336,7 +342,7 @@ public void testLoadPKCS12KeyStoreWithWrongPassword() { }); } - @Test + @TestTemplate public void testLoadPKCS12TrustStore() throws Exception { // Make sure we can instantiate a trust manager from the PKCS12 file on disk X509Util.createTrustManager( @@ -345,16 +351,16 @@ public void testLoadPKCS12TrustStore() throws Exception { 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( @@ -364,7 +370,7 @@ public void testLoadPKCS12TrustStoreAutodetectStoreFileType() throws Exception { true, true, true, true); } - @Test + @TestTemplate public void testLoadPKCS12TrustStoreWithWrongPassword() { assertThrows(TrustManagerException.class, () -> { // Attempting to load with the wrong key password should fail diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/encoding/TestEncodedDataBlock.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/encoding/TestEncodedDataBlock.java index b9319ffacbca..e4ff473e8d28 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/encoding/TestEncodedDataBlock.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/encoding/TestEncodedDataBlock.java @@ -17,38 +17,28 @@ */ package org.apache.hadoop.hbase.io.encoding; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mockStatic; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseJupiterExtension; import org.apache.hadoop.hbase.io.compress.Compression.Algorithm; import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.util.ReflectionUtils; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.mockito.Mock; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.MockedStatic; -import org.mockito.junit.MockitoJUnitRunner; /** * Test for HBASE-23342 */ -@RunWith(MockitoJUnitRunner.class) -@Category({ MiscTests.class, SmallTests.class }) +@ExtendWith(HBaseJupiterExtension.class) +@org.junit.jupiter.api.Tag(MiscTests.TAG) +@org.junit.jupiter.api.Tag(SmallTests.TAG) public class TestEncodedDataBlock { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestEncodedDataBlock.class); - - // for generating exception - @Mock - private MockedStatic mockedReflectionUtils; - private static final byte[] INPUT_BYTES = new byte[] { 0, 1, 0, 0, 1, 2, 3, 0, 0, 1, 0, 0, 1, 2, 3, 0, 0, 1, 0, 0, 1, 2, 3, 0, 0, 1, 0, 0, 1, 2, 3, 0 }; @@ -56,12 +46,13 @@ public class TestEncodedDataBlock { @Test public void testGetCompressedSize() throws Exception { RuntimeException inject = new RuntimeException("inject error"); - mockedReflectionUtils.when(() -> ReflectionUtils.newInstance(any(Class.class), any())) - .thenThrow(inject); - RuntimeException error = assertThrows(RuntimeException.class, - () -> EncodedDataBlock.getCompressedSize(Algorithm.GZ, null, INPUT_BYTES, 0, 0)); - // make sure we get the injected error instead of NPE - assertSame(inject, error); + try (MockedStatic mockedReflectionUtils = mockStatic(ReflectionUtils.class)) { + mockedReflectionUtils.when(() -> ReflectionUtils.newInstance(any(Class.class), any())) + .thenThrow(inject); + RuntimeException error = assertThrows(RuntimeException.class, + () -> EncodedDataBlock.getCompressedSize(Algorithm.GZ, null, INPUT_BYTES, 0, 0)); + // make sure we get the injected error instead of NPE + assertSame(inject, error); + } } - } 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 24a0f630870f..12e8effb8d3e 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,20 @@ */ 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.HBaseJupiterExtension; 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 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 8fe9e5135ee6..bd8c12a02103 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,33 @@ */ 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.assertTrue; import java.math.BigInteger; import java.util.Arrays; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; /** * Tests LRUDictionary */ -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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); 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 9d458f3a422f..f92bce9fa062 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; @@ -27,14 +27,14 @@ import java.io.IOException; import java.util.concurrent.atomic.AtomicReference; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseJupiterExtension; 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.junit.jupiter.api.extension.ExtendWith; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -42,13 +42,11 @@ * 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) +@ExtendWith(HBaseJupiterExtension.class) 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 +55,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 +64,7 @@ public void setUp() { .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 c5b0202ca3d2..9edc1a3d0dc3 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,26 @@ */ 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.HBaseJupiterExtension; 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; /** * 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) +@ExtendWith(HBaseJupiterExtension.class) 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/TestAddress.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/net/TestAddress.java index 75e0ed87faa3..166eb01e5427 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,19 @@ */ 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.HBaseJupiterExtension; 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 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 9ba774bfc028..02859d0b438a 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,31 @@ */ 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.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 9f21ed91d2d4..6a11de719335 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,21 @@ */ 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.HBaseJupiterExtension; 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 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/TestFixedLengthWrapper.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestFixedLengthWrapper.java index 5d1eb9d803c4..54f06bb7840f 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,26 @@ */ 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.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 +58,8 @@ public void testReadWrite() { 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 +67,24 @@ public void testReadWrite() { } } - @Test(expected = IllegalArgumentException.class) + @Test public void testInsufficientRemainingRead() { final PositionedByteRange buff = new SimplePositionedMutableByteRange(0); final DataType type = new FixedLengthWrapper<>(new RawBytes(Order.ASCENDING), 3); - type.decode(buff); + assertThrows(IllegalArgumentException.class, () -> type.decode(buff)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInsufficientRemainingWrite() { final PositionedByteRange buff = new SimplePositionedMutableByteRange(0); final DataType type = new FixedLengthWrapper<>(new RawBytes(Order.ASCENDING), 3); - type.encode(buff, Bytes.toBytes("")); + assertThrows(IllegalArgumentException.class, () -> type.encode(buff, Bytes.toBytes(""))); } - @Test(expected = IllegalArgumentException.class) + @Test public void testOverflowPassthrough() { final PositionedByteRange buff = new SimplePositionedMutableByteRange(3); final DataType type = new FixedLengthWrapper<>(new RawBytes(Order.ASCENDING), 0); - type.encode(buff, Bytes.toBytes("foo")); + 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 81a785606d7a..fae1a30c8f16 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,24 @@ */ package org.apache.hadoop.hbase.types; -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 org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestOrderedBlob { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestOrderedBlob.class); - 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"), @@ -57,8 +55,8 @@ public void testEncodedLength() { for (final 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 b9a83f199a8e..9d0bcb187c49 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,25 +17,23 @@ */ 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.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestOrderedBlobVar { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestOrderedBlobVar.class); - 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"), @@ -49,8 +47,8 @@ public void testEncodedLength() { for (final 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/TestOrderedFloat32.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedFloat32.java index f6177f30e0c5..279aa2f07927 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedFloat32.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedFloat32.java @@ -17,33 +17,27 @@ */ package org.apache.hadoop.hbase.types; -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.assertThrows; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseJupiterExtension; 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.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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestOrderedFloat32 { private static final Float[] VALUES = new Float[] { Float.NaN, 1f, 22f, 333f, 4444f, 55555f, 666666f, 7777777f, 8888888f, 9999999f }; - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestOrderedFloat32.class); - - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test public void testIsNullableIsFalse() { final DataType type = new OrderedFloat32(Order.ASCENDING); @@ -66,19 +60,18 @@ public void testEncodedLength() { for (final Float val : VALUES) { buffer.setPosition(0); type.encode(buffer, val); - assertEquals("encodedLength does not match actual, " + val, buffer.getPosition(), - type.encodedLength(val)); + assertEquals(buffer.getPosition(), type.encodedLength(val), + "encodedLength does not match actual, " + val); } } } @Test public void testEncodeNoSupportForNull() { - exception.expect(IllegalArgumentException.class); - final DataType type = new OrderedFloat32(Order.ASCENDING); - type.encode(new SimplePositionedMutableByteRange(20), null); + assertThrows(IllegalArgumentException.class, + () -> type.encode(new SimplePositionedMutableByteRange(20), null)); } @Test @@ -89,8 +82,8 @@ public void testEncodedFloatLength() { for (final Float val : VALUES) { buffer.setPosition(0); type.encodeFloat(buffer, val); - assertEquals("encodedLength does not match actual, " + val, buffer.getPosition(), - type.encodedLength(val)); + assertEquals(buffer.getPosition(), type.encodedLength(val), + "encodedLength does not match actual, " + val); } } } diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedFloat64.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedFloat64.java index 2622760f8c3f..ed5965c71748 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedFloat64.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedFloat64.java @@ -17,33 +17,27 @@ */ package org.apache.hadoop.hbase.types; -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.assertThrows; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseJupiterExtension; 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.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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestOrderedFloat64 { private static final Double[] VALUES = new Double[] { Double.NaN, 1.1, 22.2, 333.3, 4444.4, 55555.5, 666666.6, 7777777.7, 88888888.8, 999999999.9 }; - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestOrderedFloat64.class); - - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test public void testIsNullableIsFalse() { final DataType type = new OrderedFloat64(Order.ASCENDING); @@ -66,19 +60,18 @@ public void testEncodedLength() { for (final Double val : VALUES) { buffer.setPosition(0); type.encode(buffer, val); - assertEquals("encodedLength does not match actual, " + val, buffer.getPosition(), - type.encodedLength(val)); + assertEquals(buffer.getPosition(), type.encodedLength(val), + "encodedLength does not match actual, " + val); } } } @Test public void testEncodeNoSupportForNull() { - exception.expect(IllegalArgumentException.class); - final DataType type = new OrderedFloat64(Order.ASCENDING); - type.encode(new SimplePositionedMutableByteRange(20), null); + assertThrows(IllegalArgumentException.class, + () -> type.encode(new SimplePositionedMutableByteRange(20), null)); } @Test @@ -89,8 +82,8 @@ public void testEncodedFloatLength() { for (final Double val : VALUES) { buffer.setPosition(0); type.encodeDouble(buffer, val); - assertEquals("encodedLength does not match actual, " + val, buffer.getPosition(), - type.encodedLength(val)); + assertEquals(buffer.getPosition(), type.encodedLength(val), + "encodedLength does not match actual, " + val); } } } diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt16.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt16.java index 1df67b77a215..27c8a8114794 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt16.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt16.java @@ -17,32 +17,26 @@ */ package org.apache.hadoop.hbase.types; -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.assertThrows; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseJupiterExtension; 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.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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestOrderedInt16 { private static final Short[] VALUES = new Short[] { 1, 22, 333, 4444 }; - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestOrderedInt16.class); - - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test public void testIsNullableIsFalse() { final DataType type = new OrderedInt16(Order.ASCENDING); @@ -65,19 +59,18 @@ public void testEncodedLength() { for (final Short val : VALUES) { buffer.setPosition(0); type.encode(buffer, val); - assertEquals("encodedLength does not match actual, " + val, buffer.getPosition(), - type.encodedLength(val)); + assertEquals(buffer.getPosition(), type.encodedLength(val), + "encodedLength does not match actual, " + val); } } } @Test public void testEncodeNoSupportForNull() { - exception.expect(IllegalArgumentException.class); - final DataType type = new OrderedInt16(Order.ASCENDING); - type.encode(new SimplePositionedMutableByteRange(20), null); + assertThrows(IllegalArgumentException.class, + () -> type.encode(new SimplePositionedMutableByteRange(20), null)); } @Test @@ -88,8 +81,8 @@ public void testEncodedFloatLength() { for (final Short val : VALUES) { buffer.setPosition(0); type.encodeShort(buffer, val); - assertEquals("encodedLength does not match actual, " + val, buffer.getPosition(), - type.encodedLength(val)); + assertEquals(buffer.getPosition(), type.encodedLength(val), + "encodedLength does not match actual, " + val); } } } diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt32.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt32.java index 32520687c133..76f4b389042b 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt32.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt32.java @@ -17,33 +17,27 @@ */ package org.apache.hadoop.hbase.types; -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.assertThrows; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseJupiterExtension; 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.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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestOrderedInt32 { private static final Integer[] VALUES = new Integer[] { 1, 22, 333, 4444, 55555, 666666, 7777777, 88888888, 999999999 }; - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestOrderedInt32.class); - - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test public void testIsNullableIsFalse() { final DataType type = new OrderedInt32(Order.ASCENDING); @@ -66,19 +60,18 @@ public void testEncodedLength() { for (final Integer val : VALUES) { buffer.setPosition(0); type.encode(buffer, val); - assertEquals("encodedLength does not match actual, " + val, buffer.getPosition(), - type.encodedLength(val)); + assertEquals(buffer.getPosition(), type.encodedLength(val), + "encodedLength does not match actual, " + val); } } } @Test public void testEncodeNoSupportForNull() { - exception.expect(IllegalArgumentException.class); - final DataType type = new OrderedInt32(Order.ASCENDING); - type.encode(new SimplePositionedMutableByteRange(20), null); + assertThrows(IllegalArgumentException.class, + () -> type.encode(new SimplePositionedMutableByteRange(20), null)); } @Test @@ -89,8 +82,8 @@ public void testEncodedFloatLength() { for (final Integer val : VALUES) { buffer.setPosition(0); type.encodeInt(buffer, val); - assertEquals("encodedLength does not match actual, " + val, buffer.getPosition(), - type.encodedLength(val)); + assertEquals(buffer.getPosition(), type.encodedLength(val), + "encodedLength does not match actual, " + val); } } } diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt64.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt64.java index 9d08aa919799..03385e0126d9 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt64.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt64.java @@ -17,33 +17,27 @@ */ package org.apache.hadoop.hbase.types; -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.assertThrows; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseJupiterExtension; 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.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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestOrderedInt64 { private static final Long[] VALUES = new Long[] { 1L, 22L, 333L, 4444L, 55555L, 666666L, 7777777L, 88888888L, 999999999L }; - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestOrderedInt64.class); - - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test public void testIsNullableIsFalse() { final DataType type = new OrderedInt64(Order.ASCENDING); @@ -66,19 +60,18 @@ public void testEncodedLength() { for (final Long val : VALUES) { buffer.setPosition(0); type.encode(buffer, val); - assertEquals("encodedLength does not match actual, " + val, buffer.getPosition(), - type.encodedLength(val)); + assertEquals(buffer.getPosition(), type.encodedLength(val), + "encodedLength does not match actual, " + val); } } } @Test public void testEncodeNoSupportForNull() { - exception.expect(IllegalArgumentException.class); - final DataType type = new OrderedInt64(Order.ASCENDING); - type.encode(new SimplePositionedMutableByteRange(20), null); + assertThrows(IllegalArgumentException.class, + () -> type.encode(new SimplePositionedMutableByteRange(20), null)); } @Test @@ -89,8 +82,8 @@ public void testEncodedFloatLength() { for (final Long val : VALUES) { buffer.setPosition(0); type.encodeLong(buffer, val); - assertEquals("encodedLength does not match actual, " + val, buffer.getPosition(), - type.encodedLength(val)); + assertEquals(buffer.getPosition(), type.encodedLength(val), + "encodedLength does not match actual, " + val); } } } diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt8.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt8.java index 947e1fb69124..ba3d4fa48d80 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt8.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedInt8.java @@ -17,32 +17,26 @@ */ package org.apache.hadoop.hbase.types; -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.assertThrows; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseJupiterExtension; 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.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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestOrderedInt8 { private static final Byte[] VALUES = new Byte[] { 1, 22 }; - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestOrderedInt8.class); - - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test public void testIsNullableIsFalse() { final DataType type = new OrderedInt8(Order.ASCENDING); @@ -65,19 +59,18 @@ public void testEncodedLength() { for (final Byte val : VALUES) { buffer.setPosition(0); type.encode(buffer, val); - assertEquals("encodedLength does not match actual, " + val, buffer.getPosition(), - type.encodedLength(val)); + assertEquals(buffer.getPosition(), type.encodedLength(val), + "encodedLength does not match actual, " + val); } } } @Test public void testEncodeNoSupportForNull() { - exception.expect(IllegalArgumentException.class); - final DataType type = new OrderedInt8(Order.ASCENDING); - type.encode(new SimplePositionedMutableByteRange(20), null); + assertThrows(IllegalArgumentException.class, + () -> type.encode(new SimplePositionedMutableByteRange(20), null)); } @Test @@ -88,8 +81,8 @@ public void testEncodedFloatLength() { for (final Byte val : VALUES) { buffer.setPosition(0); type.encodeByte(buffer, val); - assertEquals("encodedLength does not match actual, " + val, buffer.getPosition(), - type.encodedLength(val)); + assertEquals(buffer.getPosition(), type.encodedLength(val), + "encodedLength does not match actual, " + val); } } } diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedNumeric.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedNumeric.java index 700ca0ca007b..b8f9f9e3345c 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedNumeric.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestOrderedNumeric.java @@ -17,23 +17,23 @@ */ package org.apache.hadoop.hbase.types; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.math.BigDecimal; import java.math.BigInteger; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseJupiterExtension; 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.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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestOrderedNumeric { private static final Long[] LONG_VALUES = new Long[] { 1L, 22L, 333L, 4444L, 55555L, 666666L, 7777777L, 88888888L, 999999999L }; @@ -51,13 +51,6 @@ public class TestOrderedNumeric { new BigInteger("4444"), new BigInteger("55555"), new BigInteger("666666"), new BigInteger("7777777"), new BigInteger("88888888"), new BigInteger("999999999") }; - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestOrderedNumeric.class); - - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test public void testEncodedClassIsNumber() { final DataType type = new OrderedNumeric(Order.ASCENDING); @@ -73,8 +66,8 @@ public void testEncodedLength() { for (final Number val : DOUBLE_VALUES) { buffer.setPosition(0); type.encode(buffer, val); - assertEquals("encodedLength does not match actual, " + val, buffer.getPosition(), - type.encodedLength(val)); + assertEquals(buffer.getPosition(), type.encodedLength(val), + "encodedLength does not match actual, " + val); } } } @@ -87,8 +80,8 @@ public void testEncodedBigDecimalLength() { for (final Number val : BIG_DECIMAL_VALUES) { buffer.setPosition(0); type.encode(buffer, val); - assertEquals("encodedLength does not match actual, " + val, buffer.getPosition(), - type.encodedLength(val)); + assertEquals(buffer.getPosition(), type.encodedLength(val), + "encodedLength does not match actual, " + val); } } } @@ -101,8 +94,8 @@ public void testEncodedBigIntegerLength() { for (final Number val : BIG_INTEGER_VALUES) { buffer.setPosition(0); type.encode(buffer, val); - assertEquals("encodedLength does not match actual, " + val, buffer.getPosition(), - type.encodedLength(val)); + assertEquals(buffer.getPosition(), type.encodedLength(val), + "encodedLength does not match actual, " + val); } } } @@ -116,8 +109,8 @@ public void testEncodedNullLength() { type.encode(buffer, null); type.encode(new SimplePositionedMutableByteRange(20), null); - assertEquals("encodedLength does not match actual, " + null, buffer.getPosition(), - type.encodedLength(null)); + assertEquals(buffer.getPosition(), type.encodedLength(null), + "encodedLength does not match actual, " + null); } @Test @@ -128,8 +121,8 @@ public void testEncodedLongLength() { for (final Long val : LONG_VALUES) { buffer.setPosition(0); type.encodeLong(buffer, val); - assertEquals("encodedLength does not match actual, " + val, buffer.getPosition(), - type.encodedLength(val)); + assertEquals(buffer.getPosition(), type.encodedLength(val), + "encodedLength does not match actual, " + val); } } } @@ -142,8 +135,8 @@ public void testEncodedDoubleLength() { for (final Double val : DOUBLE_VALUES) { buffer.setPosition(0); type.encodeDouble(buffer, val); - assertEquals("encodedLength does not match actual, " + val, buffer.getPosition(), - type.encodedLength(val)); + assertEquals(buffer.getPosition(), type.encodedLength(val), + "encodedLength does not match actual, " + 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 e23792fb529c..99a73c6b42e7 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,24 +17,22 @@ */ 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.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestOrderedString { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestOrderedString.class); - private static final String[] VALUES = new String[] { null, "", "1", "22", "333", "4444", "55555", "666666", "7777777", "88888888", "999999999" }; @@ -46,8 +44,8 @@ public void testEncodedLength() { for (final 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/TestRawBytes.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestRawBytes.java index 6c48a73628e0..d730456b864b 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestRawBytes.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestRawBytes.java @@ -17,38 +17,31 @@ */ package org.apache.hadoop.hbase.types; -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.util.Arrays; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseJupiterExtension; 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.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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestRawBytes { private 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"), Bytes.toBytes("7777777"), Bytes.toBytes("88888888"), Bytes.toBytes("999999999"), }; - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRawBytes.class); - - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test public void testIsOrderPreservingIsTrue() { final DataType type = new RawBytes(Order.ASCENDING); @@ -92,8 +85,8 @@ public void testEncodedLength() { for (final byte[] val : VALUES) { buffer.setPosition(0); type.encode(buffer, val); - assertEquals("encodedLength does not match actual, " + Arrays.toString(val), - buffer.getPosition(), type.encodedLength(val)); + assertEquals(buffer.getPosition(), type.encodedLength(val), + "encodedLength does not match actual, " + Arrays.toString(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 8b3b86ff1710..d320dd00c829 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,28 +17,26 @@ */ package org.apache.hadoop.hbase.types; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.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.assertTrue; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestRawString { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRawString.class); - private static final String[] VALUES = new String[] { "", "1", "22", "333", "4444", "55555", "666666", "7777777", "88888888", "999999999", }; 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 685bcd7fe485..21ba9765993a 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,51 @@ */ 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.HBaseJupiterExtension; +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.api.extension.ExtendWith; +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) +@ExtendWith(HBaseJupiterExtension.class) +@HBaseParameterizedTestTemplate 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 params() { + public TestStruct(Struct generic, DataType specialized, Object[][] constructorArgs) { + this.generic = generic; + this.specialized = specialized; + this.constructorArgs = constructorArgs; + } + + public static Stream 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 +73,9 @@ public static Collection params() { 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 NULL_SAFE_BYTES_COMPARATOR = (o1, o2) -> { @@ -407,7 +407,7 @@ public int encode(PositionedByteRange dst, Pojo2 val) { } } - @Test + @TestTemplate @SuppressWarnings("unchecked") public void testOrderPreservation() throws Exception { Object[] vals = new Object[constructorArgs.length]; @@ -436,10 +436,10 @@ public void testOrderPreservation() throws Exception { 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 3d4c76db31e0..772538f88350 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,38 +17,39 @@ */ 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.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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(); - PositionedByteRange buf = new SimplePositionedMutableByteRange(4); - s.encode(buf, new Object[1]); + assertThrows(NullPointerException.class, () -> { + Struct s = new StructBuilder().add(new RawStringTerminated("|")) // not nullable + .toStruct(); + PositionedByteRange buf = new SimplePositionedMutableByteRange(4); + s.encode(buf, new Object[1]); + }); } /** @@ -67,8 +68,8 @@ public void testNullableNullExtension() { 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 @@ -76,71 +77,69 @@ public void testNullableNullExtension() { 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 600a488146df..391f13f12334 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,26 @@ */ 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.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 +49,25 @@ 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(Order.ASCENDING), ""); + assertThrows(IllegalArgumentException.class, + () -> new TerminatedWrapper<>(new RawBytes(Order.ASCENDING), "")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testNullDelimiter() { - new RawBytesTerminated((byte[]) null); + assertThrows(IllegalArgumentException.class, () -> new RawBytesTerminated((byte[]) null)); // new TerminatedWrapper(new RawBytes(), (byte[]) null); } - @Test(expected = IllegalArgumentException.class) + @Test public void testEncodedValueContainsTerm() { - final DataType type = new TerminatedWrapper<>(new RawBytes(Order.ASCENDING), "foo"); - final PositionedByteRange buff = new SimplePositionedMutableByteRange(16); - type.encode(buff, Bytes.toBytes("hello foobar!")); + assertThrows(IllegalArgumentException.class, () -> { + final DataType type = new TerminatedWrapper<>(new RawBytes(Order.ASCENDING), "foo"); + final PositionedByteRange buff = new SimplePositionedMutableByteRange(16); + type.encode(buff, Bytes.toBytes("hello foobar!")); + }); } @Test @@ -139,11 +141,13 @@ public void testSkipNonSkippable() { } } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidSkip() { - final PositionedByteRange buff = new SimplePositionedMutableByteRange(Bytes.toBytes("foo")); - final DataType type = - new TerminatedWrapper<>(new RawBytes(Order.ASCENDING), new byte[] { 0x00 }); - type.skip(buff); + assertThrows(IllegalArgumentException.class, () -> { + final PositionedByteRange buff = new SimplePositionedMutableByteRange(Bytes.toBytes("foo")); + final DataType type = + new TerminatedWrapper<>(new RawBytes(Order.ASCENDING), new byte[] { 0x00 }); + 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 d5bedeee3075..e08ec7e5dbbc 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,22 @@ */ 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.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestUnion2 { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestUnion2.class); - /** * An example Union */ 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 5cd99ecc6b3d..34e262eb3af5 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,16 @@ */ 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.HBaseJupiterExtension; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.util.AvlUtil.AvlIterableList; @@ -36,17 +36,15 @@ 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, MediumTests.class }) +@Tag(MiscTests.TAG) +@Tag(MediumTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 6d1a5ed3771e..57a4c9ada11c 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,29 @@ */ 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.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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/TestByteRangeUtils.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteRangeUtils.java index b095808ad365..adb3f55b3e97 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,21 @@ */ 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.HBaseJupiterExtension; 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({ SmallTests.class }) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 f1d8a92cbedc..f463e556cf49 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,25 @@ */ 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.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@org.junit.jupiter.api.Tag(MiscTests.TAG) +@org.junit.jupiter.api.Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 +87,12 @@ public void testWritingAndReadingCells() throws Exception { 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 6a4bf6387ecc..8d8402c790dd 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,19 @@ */ 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.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ SmallTests.class }) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 +41,7 @@ public void testExtendedForName() throws ClassNotFoundException { 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 4ce0ff5054c9..d1c415613660 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,37 @@ */ 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.HBaseCommonTestingUtil; +import org.apache.hadoop.hbase.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; /** * Test {@link CommonFSUtils}. */ -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestCommonFSUtils { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestCommonFSUtils.class); - private HBaseCommonTestingUtil htu; private Configuration conf; - @Before + @BeforeEach public void setUp() throws IOException { htu = new HBaseCommonTestingUtil(); conf = htu.getConfiguration(); @@ -113,13 +112,15 @@ public void testGetWALRootDirUsingUri() throws IOException { 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, () -> { + 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); + }); } @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 aff879b7e1c4..e6d25cb20792 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,30 +17,28 @@ */ 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.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.HBaseJupiterExtension; 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 TestConcatenatedLists { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestConcatenatedLists.class); - @Test public void testUnsupportedOps() { // If adding support, add tests. 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 d0926b71436d..298c648174cc 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,33 @@ */ 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.HBaseCommonTestingUtil; +import org.apache.hadoop.hbase.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; /** * Test TestCoprocessorClassLoader. More tests are in TestClassLoading */ -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestCoprocessorClassLoader { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestCoprocessorClassLoader.class); - private static final HBaseCommonTestingUtil TEST_UTIL = new HBaseCommonTestingUtil(); private static final Configuration conf = TEST_UTIL.getConfiguration(); static { @@ -64,16 +62,16 @@ public void testCleanupOldJars() throws Exception { 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 +107,7 @@ private void checkingLibJarName(String jarName, String libPrefix) throws Excepti 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) { @@ -160,7 +158,7 @@ public void testDirectoryAndWildcard() throws Exception { */ 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/TestDynamicClassLoader.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestDynamicClassLoader.java index 1485a3bca56a..6faa85998429 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,30 @@ */ 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.HBaseCommonTestingUtil; +import org.apache.hadoop.hbase.HBaseJupiterExtension; 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.junit.jupiter.api.extension.ExtendWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Test TestDynamicClassLoader */ -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 HBaseCommonTestingUtil TEST_UTIL = new HBaseCommonTestingUtil(); @@ -53,7 +51,7 @@ public class TestDynamicClassLoader { TEST_UTIL.getDataTestDir().toString()); } - @Before + @BeforeEach public void initializeConfiguration() { conf = new Configuration(TEST_UTIL.getConfiguration()); } @@ -131,14 +129,14 @@ private void deleteClass(String className) throws Exception { 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 e740811cfa07..13800532103a 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,26 @@ */ 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.HBaseJupiterExtension; 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 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/TestFutureUtils.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestFutureUtils.java index a3d29ce7a2cc..77edf8a6ab1c 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,40 @@ 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.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; 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.HBaseJupiterExtension; 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.junit.jupiter.api.extension.ExtendWith; import org.apache.hbase.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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(); } 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 48652d67be62..061577e41d84 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,22 @@ */ 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.HBaseJupiterExtension; 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; import org.apache.hbase.thirdparty.com.google.gson.Gson; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 c5573910ea04..645bc890510a 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,22 @@ */ 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.HBaseJupiterExtension; 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; import org.apache.hbase.thirdparty.com.google.common.collect.Lists; -@Category(SmallTests.class) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestJRubyFormat { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestJRubyFormat.class); - @Test public void testPrint() { Map 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 34a000346e6c..7c6aa2e91ed2 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,45 @@ */ 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.HBaseJupiterExtension; import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.SmallTests; -import org.junit.Assert; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestKeyLocker { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestKeyLocker.class); - @Test public void testLocker() { KeyLocker 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 +69,13 @@ public void testLocker() { 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/TestMovingAverage.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestMovingAverage.java index 295afb9893e2..4b9c70e2b9af 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,136 @@ */ 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.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category(SmallTests.class) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 affe3ec067ad..67493786cb06 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,22 @@ 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.HBaseJupiterExtension; 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 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 56645324c9a2..8135d10df38e 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,27 @@ */ 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.HBaseJupiterExtension; 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 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 +81,8 @@ public void testVerifyTestIntegrity() { 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 +114,7 @@ public void testVaruint64Boundaries() { 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 +127,21 @@ public void testVaruint64Boundaries() { 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 +163,25 @@ public void testNumericInt() { 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 +208,9 @@ public void testNumericInt() { 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 +232,25 @@ public void testNumericReal() { 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 +277,9 @@ public void testNumericReal() { 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 +301,19 @@ public void testNumericOther() { 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 +324,10 @@ public void testNumericOther() { // 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 +344,7 @@ public void testNumericIntRealCompatibility() { 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 +354,11 @@ public void testNumericIntRealCompatibility() { 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 +382,23 @@ public void testInt8() { 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 +423,9 @@ public void testInt8() { 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 +450,23 @@ public void testInt16() { 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 +491,9 @@ public void testInt16() { 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 +518,23 @@ public void testInt32() { 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 +559,9 @@ public void testInt32() { 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 +585,23 @@ public void testInt64() { 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 +626,9 @@ public void testInt64() { 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 +653,24 @@ public void testFloat32() { 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 +695,9 @@ public void testFloat32() { 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 +722,24 @@ public void testFloat64() { 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 +764,9 @@ public void testFloat64() { 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 +792,24 @@ public void testString() { 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 +836,19 @@ public void testString() { 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 +907,24 @@ public void testBlobVar() { 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 +951,9 @@ public void testBlobVar() { 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 +982,24 @@ public void testBlobCopy() { 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 +1026,9 @@ public void testBlobCopy() { 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 +1048,7 @@ public void testBlobCopy() { /** * 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 +1057,8 @@ public void testBlobCopyNoZeroBytes() { 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 d7ea0c5ac0cb..3835928e636c 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,23 @@ */ 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.HBaseJupiterExtension; 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 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 08dcc6396aa3..f42f92615b3d 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,24 @@ */ 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.HBaseJupiterExtension; 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; 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) +@ExtendWith(HBaseJupiterExtension.class) 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 41416f7cd5d4..ad41089343f9 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,12 @@ package org.apache.hadoop.hbase.util; import java.util.Properties; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseJupiterExtension; 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; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,13 +31,11 @@ * 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) +@ExtendWith(HBaseJupiterExtension.class) 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 1036c00502b9..073c3ea18d58 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,20 @@ import java.io.File; import java.io.IOException; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseCommonTestingUtil; +import org.apache.hadoop.hbase.HBaseJupiterExtension; 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; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, MediumTests.class }) +@Tag(MiscTests.TAG) +@Tag(MediumTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestSimpleKdcServerUtil { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestSimpleKdcServerUtil.class); private static final HBaseCommonTestingUtil UTIL = new HBaseCommonTestingUtil(); /** 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 0088919da18d..83c8dca9defd 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,66 @@ */ 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.HBaseJupiterExtension; import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.SmallTests; -import org.junit.Assert; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 +103,20 @@ public void testPutandGetPrimitiveTypes() throws Exception { 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 5cd0ac6d7ab5..5ae34323a494 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,55 @@ */ 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.HBaseJupiterExtension; import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.SmallTests; -import org.junit.Assert; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 +87,14 @@ public void testPutAndGetPrimitiveTypes() { 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 +110,15 @@ public void testPutGetAPIsCompareWithBBAPIs() { 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 8528fd88beb1..85ef9d980a16 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,26 @@ */ 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.HBaseJupiterExtension; 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({ SmallTests.class }) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 57f44d1d1ac7..957f5c1cbed1 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,23 @@ */ 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.HBaseJupiterExtension; 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; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 +70,13 @@ public void run() { 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 93ec6878e2e0..52d63f4214d1 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,18 @@ */ 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.HBaseJupiterExtension; 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(SmallTests.class) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) 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 348bbaa5d297..7707d4fa559d 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,31 @@ */ 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.HBaseJupiterExtension; 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; - -@Category({ MiscTests.class, SmallTests.class }) +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestWeakObjectPool { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestWeakObjectPool.class); - ObjectPool pool; - @Before + @BeforeEach public void setUp() { pool = new WeakObjectPool<>(new ObjectPool.ObjectFactory() { @Override @@ -53,11 +56,11 @@ public void testKeys() { 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 +76,10 @@ public void testWeakReference() throws Exception { // 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 +90,10 @@ public void testWeakReference() throws Exception { 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 +135,7 @@ public void run() { 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 b5d52f44f810..b29436f05a2a 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,30 @@ */ 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.HBaseJupiterExtension; 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.junit.jupiter.api.extension.ExtendWith; import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableSet; -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(HBaseJupiterExtension.class) public class TestZKConfig { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestZKConfig.class); - /** Supported ZooKeeper client TLS properties */ private static final Set ZOOKEEPER_CLIENT_TLS_PROPERTIES = ImmutableSet.of( "client.secure", "clientCnxnSocket", "ssl.keyStore.location", "ssl.keyStore.password", @@ -56,8 +54,8 @@ public void testZKConfigLoading() throws Exception { // (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 +113,8 @@ public void testZooKeeperTlsProperties() { // 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 +133,7 @@ public void testZooKeeperTlsPropertiesHQuorumPeer() { // 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); } }