Skip to content

Commit 9cf568e

Browse files
committed
New tests should be JUnit 5
1 parent b0bcdd7 commit 9cf568e

2 files changed

Lines changed: 39 additions & 48 deletions

File tree

hbase-server/src/test/java/org/apache/hadoop/hbase/io/devsim/TestEBSDeviceLayer.java

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
*/
1818
package org.apache.hadoop.hbase.io.devsim;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2222

2323
import java.io.IOException;
2424
import org.apache.hadoop.conf.Configuration;
25-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2625
import org.apache.hadoop.hbase.HBaseConfiguration;
2726
import org.apache.hadoop.hbase.HBaseTestingUtil;
2827
import org.apache.hadoop.hbase.HConstants;
@@ -41,11 +40,10 @@
4140
import org.apache.hadoop.hbase.testclassification.MediumTests;
4241
import org.apache.hadoop.hbase.util.Bytes;
4342
import org.apache.hadoop.hdfs.MiniDFSCluster;
44-
import org.junit.AfterClass;
45-
import org.junit.BeforeClass;
46-
import org.junit.ClassRule;
47-
import org.junit.Test;
48-
import org.junit.experimental.categories.Category;
43+
import org.junit.jupiter.api.AfterAll;
44+
import org.junit.jupiter.api.BeforeAll;
45+
import org.junit.jupiter.api.Tag;
46+
import org.junit.jupiter.api.Test;
4947
import org.slf4j.Logger;
5048
import org.slf4j.LoggerFactory;
5149

@@ -58,13 +56,10 @@
5856
* device latency disabled. Writes data through HBase, flushes, reads it back via scan and get, and
5957
* asserts that the device layer metrics reflect the IO.
6058
*/
61-
@Category({ IOTests.class, MediumTests.class })
59+
@Tag(IOTests.TAG)
60+
@Tag(MediumTests.TAG)
6261
public class TestEBSDeviceLayer {
6362

64-
@ClassRule
65-
public static final HBaseClassTestRule CLASS_RULE =
66-
HBaseClassTestRule.forClass(TestEBSDeviceLayer.class);
67-
6863
private static final Logger LOG = LoggerFactory.getLogger(TestEBSDeviceLayer.class);
6964

7065
private static final TableName TABLE_NAME = TableName.valueOf("TestEBSDeviceLayer");
@@ -76,7 +71,7 @@ public class TestEBSDeviceLayer {
7671

7772
private static HBaseTestingUtil UTIL;
7873

79-
@BeforeClass
74+
@BeforeAll
8075
public static void setUp() throws Exception {
8176
Configuration conf = HBaseConfiguration.create();
8277
conf.set(HConstants.HBASE_REGION_SPLIT_POLICY_KEY,
@@ -93,7 +88,7 @@ public static void setUp() throws Exception {
9388
UTIL.startMiniCluster(1);
9489
}
9590

96-
@AfterClass
91+
@AfterAll
9792
public static void tearDown() throws Exception {
9893
EBSDevice.shutdown();
9994
if (UTIL != null) {
@@ -103,9 +98,9 @@ public static void tearDown() throws Exception {
10398

10499
@Test
105100
public void testDeviceLayerInterceptsIO() throws Exception {
106-
assertEquals("Expected 1 DataNode registered with EBSDevice", 1, EBSDevice.getNumDataNodes());
101+
assertEquals(1, EBSDevice.getNumDataNodes(), "Expected 1 DataNode registered with EBSDevice");
107102
EBSDevice.DataNodeContext dnCtx = EBSDevice.getDataNodeContext(0);
108-
assertEquals("Expected " + NUM_VOLUMES + " volumes", NUM_VOLUMES, dnCtx.getNumVolumes());
103+
assertEquals(NUM_VOLUMES, dnCtx.getNumVolumes(), "Expected " + NUM_VOLUMES + " volumes");
109104

110105
TableDescriptor desc = TableDescriptorBuilder.newBuilder(TABLE_NAME).setColumnFamily(
111106
ColumnFamilyDescriptorBuilder.newBuilder(FAMILY).setBlocksize(64 * 1024).build()).build();
@@ -132,23 +127,23 @@ public void testDeviceLayerInterceptsIO() throws Exception {
132127
LOG.info("After write+flush: bytesWritten={}, writeIntercepts={}, deviceWriteOps={}",
133128
writeBytesAfterFlush, writeInterceptsAfterFlush, EBSDevice.getDeviceWriteOps());
134129

135-
assertTrue("Expected write intercepts after flush, got " + writeInterceptsAfterFlush,
136-
writeInterceptsAfterFlush > 0);
137-
assertTrue("Expected bytes written > 0 after flush, got " + writeBytesAfterFlush,
138-
writeBytesAfterFlush > 0);
130+
assertTrue(writeInterceptsAfterFlush > 0,
131+
"Expected write intercepts after flush, got " + writeInterceptsAfterFlush);
132+
assertTrue(writeBytesAfterFlush > 0,
133+
"Expected bytes written > 0 after flush, got " + writeBytesAfterFlush);
139134

140135
EBSDevice.resetMetrics();
141136
int rowCount = 0;
142137
try (Table table = UTIL.getConnection().getTable(TABLE_NAME)) {
143138
try (ResultScanner scanner = table.getScanner(new Scan())) {
144139
Result result;
145140
while ((result = scanner.next()) != null) {
146-
assertTrue("Row should not be empty", !result.isEmpty());
141+
assertTrue(!result.isEmpty(), "Row should not be empty");
147142
rowCount++;
148143
}
149144
}
150145
}
151-
assertEquals("Expected to read back all rows", NUM_ROWS, rowCount);
146+
assertEquals(NUM_ROWS, rowCount, "Expected to read back all rows");
152147

153148
long readBytes = EBSDevice.getTotalBytesRead();
154149
long readIntercepts = EBSDevice.getReadInterceptCount();
@@ -157,28 +152,29 @@ public void testDeviceLayerInterceptsIO() throws Exception {
157152
LOG.info("After scan: bytesRead={}, readIntercepts={}, appReadOps={}, deviceReadOps={}",
158153
readBytes, readIntercepts, readOps, deviceReadOps);
159154

160-
assertTrue("Expected read intercepts after scan, got " + readIntercepts, readIntercepts > 0);
161-
assertTrue("Expected bytes read > 0 after scan, got " + readBytes, readBytes > 0);
162-
assertTrue("Expected device read ops > 0 (IOPS coalescing should still produce ops), got "
163-
+ deviceReadOps, deviceReadOps > 0);
155+
assertTrue(readIntercepts > 0, "Expected read intercepts after scan, got " + readIntercepts);
156+
assertTrue(readBytes > 0, "Expected bytes read > 0 after scan, got " + readBytes);
157+
assertTrue(deviceReadOps > 0,
158+
"Expected device read ops > 0 (IOPS coalescing should still produce ops), got "
159+
+ deviceReadOps);
164160

165161
EBSDevice.resetMetrics();
166162
try (Table table = UTIL.getConnection().getTable(TABLE_NAME)) {
167163
Result result = table.get(new Get(Bytes.toBytes("row-00050")));
168-
assertTrue("Get should return data", !result.isEmpty());
164+
assertTrue(!result.isEmpty(), "Get should return data");
169165
}
170166
long getReadIntercepts = EBSDevice.getReadInterceptCount();
171167
LOG.info("After get: readIntercepts={}, bytesRead={}", getReadIntercepts,
172168
EBSDevice.getTotalBytesRead());
173-
assertTrue("Expected read intercepts after get, got " + getReadIntercepts,
174-
getReadIntercepts > 0);
169+
assertTrue(getReadIntercepts > 0,
170+
"Expected read intercepts after get, got " + getReadIntercepts);
175171

176172
long totalIntercepts = EBSDevice.getReadInterceptCount() + EBSDevice.getWriteInterceptCount();
177173
long unresolved = EBSDevice.getUnresolvedVolumeCount();
178174
if (totalIntercepts > 0) {
179175
double unresolvedRatio = (double) unresolved / totalIntercepts;
180-
assertTrue("Unresolved volume ratio too high: " + unresolvedRatio + " (unresolved="
181-
+ unresolved + ", total=" + totalIntercepts + ")", unresolvedRatio <= 0.01);
176+
assertTrue(unresolvedRatio <= 0.01, "Unresolved volume ratio too high: " + unresolvedRatio
177+
+ " (unresolved=" + unresolved + ", total=" + totalIntercepts + ")");
182178
}
183179

184180
LOG.info("Per-volume stats: {}", EBSDevice.getPerVolumeStats());

hbase-server/src/test/java/org/apache/hadoop/hbase/io/devsim/TestIOBudget.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,17 @@
1717
*/
1818
package org.apache.hadoop.hbase.io.devsim;
1919

20-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
2121

22-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2322
import org.apache.hadoop.hbase.testclassification.IOTests;
2423
import org.apache.hadoop.hbase.testclassification.SmallTests;
25-
import org.junit.ClassRule;
26-
import org.junit.Test;
27-
import org.junit.experimental.categories.Category;
24+
import org.junit.jupiter.api.Tag;
25+
import org.junit.jupiter.api.Test;
2826

29-
@Category({ IOTests.class, SmallTests.class })
27+
@Tag(IOTests.TAG)
28+
@Tag(SmallTests.TAG)
3029
public class TestIOBudget {
3130

32-
@ClassRule
33-
public static final HBaseClassTestRule CLASS_RULE =
34-
HBaseClassTestRule.forClass(TestIOBudget.class);
35-
3631
@Test
3732
public void testLowRateModeDoesNotDeadlock() {
3833
IOBudget budget = new IOBudget(2, 100);
@@ -43,18 +38,18 @@ public void testLowRateModeDoesNotDeadlock() {
4338
long elapsedSecondTokenMs = System.currentTimeMillis() - t1;
4439

4540
// At 2 tokens/sec, second token should require waiting roughly 500ms.
46-
assertTrue("Expected low-rate budget to throttle second token, elapsed=" + elapsedSecondTokenMs,
47-
elapsedSecondTokenMs >= 300);
48-
assertTrue("Unexpectedly long low-rate throttle delay, elapsed=" + elapsedSecondTokenMs,
49-
elapsedSecondTokenMs < 3000);
50-
assertTrue("Clock sanity check", t1 >= t0);
41+
assertTrue(elapsedSecondTokenMs >= 300,
42+
"Expected low-rate budget to throttle second token, elapsed=" + elapsedSecondTokenMs);
43+
assertTrue(elapsedSecondTokenMs < 3000,
44+
"Unexpectedly long low-rate throttle delay, elapsed=" + elapsedSecondTokenMs);
45+
assertTrue(t1 >= t0, "Clock sanity check");
5146
}
5247

5348
@Test
5449
public void testRegularWindowModeStillThrottles() {
5550
// 100 tokens/sec with 100ms windows -> 10 tokens/window
5651
IOBudget budget = new IOBudget(100, 100);
5752
long elapsedMs = budget.consume(15);
58-
assertTrue("Expected consume to sleep when exceeding window budget", elapsedMs > 0);
53+
assertTrue(elapsedMs > 0, "Expected consume to sleep when exceeding window budget");
5954
}
6055
}

0 commit comments

Comments
 (0)