You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by si...@apache.org on 2022/06/09 16:43:52 UTC
[ozone] branch master updated: HDDS-6839. Migrate tests in hdds-client to JUnit5 (#3490)
This is an automated email from the ASF dual-hosted git repository.
siyao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 18ea216615 HDDS-6839. Migrate tests in hdds-client to JUnit5 (#3490)
18ea216615 is described below
commit 18ea2166150241f25e9ba3731e443a143e3e89ad
Author: Kaijie Chen <ch...@kaijie.org>
AuthorDate: Fri Jun 10 00:43:47 2022 +0800
HDDS-6839. Migrate tests in hdds-client to JUnit5 (#3490)
* HDDS-6839. Migrate tests in hdds-client to JUnit5
* simplify assertions
---
.../client/io/TestBlockInputStreamFactoryImpl.java | 16 +--
.../ozone/client/io/TestECBlockInputStream.java | 115 ++++++++++-----------
.../client/io/TestECBlockInputStreamProxy.java | 77 +++++++-------
.../io/TestECBlockReconstructedInputStream.java | 48 ++++-----
4 files changed, 123 insertions(+), 133 deletions(-)
diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java
index 16c34b56ea..abd69e5118 100644
--- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java
+++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestBlockInputStreamFactoryImpl.java
@@ -29,8 +29,8 @@ import org.apache.hadoop.hdds.scm.pipeline.PipelineID;
import org.apache.hadoop.hdds.scm.storage.BlockExtendedInputStream;
import org.apache.hadoop.hdds.scm.storage.BlockInputStream;
import org.apache.hadoop.hdds.scm.storage.BlockLocationInfo;
-import org.junit.Test;
-import org.junit.Assert;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Assertions;
import java.util.ArrayList;
import java.util.HashMap;
@@ -53,9 +53,9 @@ public class TestBlockInputStreamFactoryImpl {
BlockExtendedInputStream stream =
factory.create(repConfig, blockInfo, blockInfo.getPipeline(),
blockInfo.getToken(), true, null, null);
- Assert.assertTrue(stream instanceof BlockInputStream);
- Assert.assertEquals(stream.getBlockID(), blockInfo.getBlockID());
- Assert.assertEquals(stream.getLength(), blockInfo.getLength());
+ Assertions.assertTrue(stream instanceof BlockInputStream);
+ Assertions.assertEquals(stream.getBlockID(), blockInfo.getBlockID());
+ Assertions.assertEquals(stream.getLength(), blockInfo.getLength());
}
@Test
@@ -70,9 +70,9 @@ public class TestBlockInputStreamFactoryImpl {
BlockExtendedInputStream stream =
factory.create(repConfig, blockInfo, blockInfo.getPipeline(),
blockInfo.getToken(), true, null, null);
- Assert.assertTrue(stream instanceof ECBlockInputStreamProxy);
- Assert.assertEquals(stream.getBlockID(), blockInfo.getBlockID());
- Assert.assertEquals(stream.getLength(), blockInfo.getLength());
+ Assertions.assertTrue(stream instanceof ECBlockInputStreamProxy);
+ Assertions.assertEquals(stream.getBlockID(), blockInfo.getBlockID());
+ Assertions.assertEquals(stream.getLength(), blockInfo.getLength());
}
private BlockLocationInfo createKeyLocationInfo(ReplicationConfig repConf,
diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestECBlockInputStream.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestECBlockInputStream.java
index e2de82fa0e..536f618f7d 100644
--- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestECBlockInputStream.java
+++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestECBlockInputStream.java
@@ -29,9 +29,9 @@ import org.apache.hadoop.hdds.scm.storage.BlockLocationInfo;
import org.apache.hadoop.hdds.scm.storage.ByteReaderStrategy;
import org.apache.hadoop.hdds.security.token.OzoneBlockTokenIdentifier;
import org.apache.hadoop.security.token.Token;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.io.EOFException;
import java.io.IOException;
@@ -42,6 +42,8 @@ import java.util.List;
import java.util.Map;
import java.util.function.Function;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
/**
* Tests for ECBlockInputStream.
*/
@@ -52,7 +54,7 @@ public class TestECBlockInputStream {
private ECReplicationConfig repConfig;
private TestBlockInputStreamFactory streamFactory;
- @Before
+ @BeforeEach
public void setup() {
repConfig = new ECReplicationConfig(3, 2,
ECReplicationConfig.EcCodec.RS, ONEMB);
@@ -66,14 +68,14 @@ public class TestECBlockInputStream {
.createKeyInfo(repConfig, 5, 5 * ONEMB);
try (ECBlockInputStream ecb = new ECBlockInputStream(repConfig,
keyInfo, true, null, null, new TestBlockInputStreamFactory())) {
- Assert.assertTrue(ecb.hasSufficientLocations());
+ Assertions.assertTrue(ecb.hasSufficientLocations());
}
// EC-3-2, very large block, so all 3 data locations are needed
keyInfo = ECStreamTestUtil.createKeyInfo(repConfig, 5, 5000 * ONEMB);
try (ECBlockInputStream ecb = new ECBlockInputStream(repConfig,
keyInfo, true, null, null, new TestBlockInputStreamFactory())) {
- Assert.assertTrue(ecb.hasSufficientLocations());
+ Assertions.assertTrue(ecb.hasSufficientLocations());
}
Map<DatanodeDetails, Integer> dnMap = new HashMap<>();
@@ -83,7 +85,7 @@ public class TestECBlockInputStream {
keyInfo = ECStreamTestUtil.createKeyInfo(repConfig, ONEMB - 1, dnMap);
try (ECBlockInputStream ecb = new ECBlockInputStream(repConfig,
keyInfo, true, null, null, new TestBlockInputStreamFactory())) {
- Assert.assertTrue(ecb.hasSufficientLocations());
+ Assertions.assertTrue(ecb.hasSufficientLocations());
}
// EC-3-2, 5MB blocks, only 2 locations passed so we do not have sufficient
@@ -93,7 +95,7 @@ public class TestECBlockInputStream {
keyInfo = ECStreamTestUtil.createKeyInfo(repConfig, 5 * ONEMB, dnMap);
try (ECBlockInputStream ecb = new ECBlockInputStream(repConfig,
keyInfo, true, null, null, new TestBlockInputStreamFactory())) {
- Assert.assertFalse(ecb.hasSufficientLocations());
+ Assertions.assertFalse(ecb.hasSufficientLocations());
}
// EC-3-2, 5MB blocks, only 1 data and 2 parity locations present. For now
@@ -105,7 +107,7 @@ public class TestECBlockInputStream {
keyInfo = ECStreamTestUtil.createKeyInfo(repConfig, 5 * ONEMB, dnMap);
try (ECBlockInputStream ecb = new ECBlockInputStream(repConfig,
keyInfo, true, null, null, new TestBlockInputStreamFactory())) {
- Assert.assertFalse(ecb.hasSufficientLocations());
+ Assertions.assertFalse(ecb.hasSufficientLocations());
}
}
@@ -122,7 +124,7 @@ public class TestECBlockInputStream {
// We expect only 1 block stream and it should have a length passed of
// ONEMB - 100.
List<TestBlockInputStream> streams = streamFactory.getBlockStreams();
- Assert.assertEquals(ONEMB - 100, streams.get(0).getLength());
+ Assertions.assertEquals(ONEMB - 100, streams.get(0).getLength());
}
}
@@ -137,8 +139,8 @@ public class TestECBlockInputStream {
keyInfo, true, null, null, streamFactory)) {
ecb.read(buf);
List<TestBlockInputStream> streams = streamFactory.getBlockStreams();
- Assert.assertEquals(ONEMB, streams.get(0).getLength());
- Assert.assertEquals(100, streams.get(1).getLength());
+ Assertions.assertEquals(ONEMB, streams.get(0).getLength());
+ Assertions.assertEquals(100, streams.get(1).getLength());
}
}
@@ -153,9 +155,9 @@ public class TestECBlockInputStream {
keyInfo, true, null, null, streamFactory)) {
ecb.read(buf);
List<TestBlockInputStream> streams = streamFactory.getBlockStreams();
- Assert.assertEquals(ONEMB, streams.get(0).getLength());
- Assert.assertEquals(ONEMB, streams.get(1).getLength());
- Assert.assertEquals(100, streams.get(2).getLength());
+ Assertions.assertEquals(ONEMB, streams.get(0).getLength());
+ Assertions.assertEquals(ONEMB, streams.get(1).getLength());
+ Assertions.assertEquals(100, streams.get(2).getLength());
}
}
@@ -170,9 +172,9 @@ public class TestECBlockInputStream {
keyInfo, true, null, null, streamFactory)) {
ecb.read(buf);
List<TestBlockInputStream> streams = streamFactory.getBlockStreams();
- Assert.assertEquals(4 * ONEMB, streams.get(0).getLength());
- Assert.assertEquals(3 * ONEMB + 100, streams.get(1).getLength());
- Assert.assertEquals(3 * ONEMB, streams.get(2).getLength());
+ Assertions.assertEquals(4 * ONEMB, streams.get(0).getLength());
+ Assertions.assertEquals(3 * ONEMB + 100, streams.get(1).getLength());
+ Assertions.assertEquals(3 * ONEMB, streams.get(2).getLength());
}
}
@@ -187,7 +189,7 @@ public class TestECBlockInputStream {
keyInfo, true, null, null, streamFactory)) {
ecb.read(buf);
List<TestBlockInputStream> streams = streamFactory.getBlockStreams();
- Assert.assertEquals(ONEMB, streams.get(0).getLength());
+ Assertions.assertEquals(ONEMB, streams.get(0).getLength());
}
}
@@ -202,9 +204,9 @@ public class TestECBlockInputStream {
keyInfo, true, null, null, streamFactory)) {
ecb.read(buf);
List<TestBlockInputStream> streams = streamFactory.getBlockStreams();
- Assert.assertEquals(3 * ONEMB, streams.get(0).getLength());
- Assert.assertEquals(3 * ONEMB, streams.get(1).getLength());
- Assert.assertEquals(3 * ONEMB, streams.get(2).getLength());
+ Assertions.assertEquals(3 * ONEMB, streams.get(0).getLength());
+ Assertions.assertEquals(3 * ONEMB, streams.get(1).getLength());
+ Assertions.assertEquals(3 * ONEMB, streams.get(2).getLength());
}
}
@@ -218,12 +220,12 @@ public class TestECBlockInputStream {
ByteBuffer buf = ByteBuffer.allocate(100);
int read = ecb.read(buf);
- Assert.assertEquals(100, read);
+ Assertions.assertEquals(100, read);
validateBufferContents(buf, 0, 100, (byte) 0);
- Assert.assertEquals(100, ecb.getPos());
+ Assertions.assertEquals(100, ecb.getPos());
}
for (TestBlockInputStream s : streamFactory.getBlockStreams()) {
- Assert.assertTrue(s.isClosed());
+ Assertions.assertTrue(s.isClosed());
}
}
@@ -241,12 +243,12 @@ public class TestECBlockInputStream {
ByteBuffer buf = ByteBuffer.allocate(100);
int read = ecb.read(buf);
- Assert.assertEquals(100, read);
+ Assertions.assertEquals(100, read);
validateBufferContents(buf, 0, 100, (byte) 0);
- Assert.assertEquals(100, ecb.getPos());
+ Assertions.assertEquals(100, ecb.getPos());
}
for (TestBlockInputStream s : streamFactory.getBlockStreams()) {
- Assert.assertTrue(s.isClosed());
+ Assertions.assertTrue(s.isClosed());
}
}
@@ -260,9 +262,9 @@ public class TestECBlockInputStream {
ByteBuffer buf = ByteBuffer.allocate(100);
int read = ecb.read(buf);
- Assert.assertEquals(50, read);
+ Assertions.assertEquals(50, read);
read = ecb.read(buf);
- Assert.assertEquals(read, -1);
+ Assertions.assertEquals(read, -1);
}
}
@@ -280,7 +282,7 @@ public class TestECBlockInputStream {
// so 350
ByteBuffer buf = ByteBuffer.allocate(350);
int read = ecb.read(buf);
- Assert.assertEquals(350, read);
+ Assertions.assertEquals(350, read);
validateBufferContents(buf, 0, 100, (byte) 0);
validateBufferContents(buf, 100, 200, (byte) 1);
@@ -289,7 +291,7 @@ public class TestECBlockInputStream {
buf.clear();
read = ecb.read(buf);
- Assert.assertEquals(350, read);
+ Assertions.assertEquals(350, read);
validateBufferContents(buf, 0, 50, (byte) 0);
validateBufferContents(buf, 50, 150, (byte) 1);
@@ -298,11 +300,11 @@ public class TestECBlockInputStream {
}
for (TestBlockInputStream s : streamFactory.getBlockStreams()) {
- Assert.assertTrue(s.isClosed());
+ Assertions.assertTrue(s.isClosed());
}
}
- @Test(expected = EOFException.class)
+ @Test
public void testSeekPastBlockLength() throws IOException {
repConfig = new ECReplicationConfig(3, 2, ECReplicationConfig.EcCodec.RS,
ONEMB);
@@ -310,11 +312,11 @@ public class TestECBlockInputStream {
ECStreamTestUtil.createKeyInfo(repConfig, 5, 100);
try (ECBlockInputStream ecb = new ECBlockInputStream(repConfig,
keyInfo, true, null, null, streamFactory)) {
- ecb.seek(1000);
+ assertThrows(EOFException.class, () -> ecb.seek(1000));
}
}
- @Test(expected = EOFException.class)
+ @Test
public void testSeekToLength() throws IOException {
repConfig = new ECReplicationConfig(3, 2, ECReplicationConfig.EcCodec.RS,
ONEMB);
@@ -322,7 +324,7 @@ public class TestECBlockInputStream {
ECStreamTestUtil.createKeyInfo(repConfig, 5, 100);
try (ECBlockInputStream ecb = new ECBlockInputStream(repConfig,
keyInfo, true, null, null, streamFactory)) {
- ecb.seek(100);
+ assertThrows(EOFException.class, () -> ecb.seek(100));
}
}
@@ -335,8 +337,8 @@ public class TestECBlockInputStream {
try (ECBlockInputStream ecb = new ECBlockInputStream(repConfig,
keyInfo, true, null, null, streamFactory)) {
ecb.seek(0);
- Assert.assertEquals(0, ecb.getPos());
- Assert.assertEquals(0, ecb.getRemaining());
+ Assertions.assertEquals(0, ecb.getPos());
+ Assertions.assertEquals(0, ecb.getRemaining());
}
}
@@ -349,23 +351,23 @@ public class TestECBlockInputStream {
try (ECBlockInputStream ecb = new ECBlockInputStream(repConfig,
keyInfo, true, null, null, streamFactory)) {
ecb.seek(ONEMB - 1);
- Assert.assertEquals(ONEMB - 1, ecb.getPos());
- Assert.assertEquals(ONEMB * 4 + 1, ecb.getRemaining());
+ Assertions.assertEquals(ONEMB - 1, ecb.getPos());
+ Assertions.assertEquals(ONEMB * 4 + 1, ecb.getRemaining());
// First read should read the last byte of the first chunk
- Assert.assertEquals(0, ecb.read());
- Assert.assertEquals(ONEMB,
+ Assertions.assertEquals(0, ecb.read());
+ Assertions.assertEquals(ONEMB,
streamFactory.getBlockStreams().get(0).position);
// Second read should be the first byte of the second chunk.
- Assert.assertEquals(1, ecb.read());
+ Assertions.assertEquals(1, ecb.read());
// Seek to the end of the file minus one byte
ecb.seek(ONEMB * 5 - 1);
- Assert.assertEquals(1, ecb.read());
- Assert.assertEquals(ONEMB * 2,
+ Assertions.assertEquals(1, ecb.read());
+ Assertions.assertEquals(ONEMB * 2,
streamFactory.getBlockStreams().get(1).position);
// Second read should be EOF as there is no data left
- Assert.assertEquals(-1, ecb.read());
- Assert.assertEquals(0, ecb.getRemaining());
+ Assertions.assertEquals(-1, ecb.read());
+ Assertions.assertEquals(0, ecb.getRemaining());
}
}
@@ -381,26 +383,21 @@ public class TestECBlockInputStream {
// factory
ByteBuffer buf = ByteBuffer.allocate(3 * ONEMB);
int read = ecb.read(buf);
- Assert.assertEquals(3 * ONEMB, read);
+ Assertions.assertEquals(3 * ONEMB, read);
// Now make replication index 2 error on the next read
streamFactory.getBlockStreams().get(1).setThrowException(true);
buf.clear();
- try {
- ecb.read(buf);
- Assert.fail("Exception should be thrown");
- } catch (IOException e) {
- Assert.assertTrue(e instanceof BadDataLocationException);
- Assert.assertEquals(2,
- keyInfo.getPipeline().getReplicaIndex(
- ((BadDataLocationException) e).getFailedLocation()));
- }
+ BadDataLocationException e =
+ assertThrows(BadDataLocationException.class, () -> ecb.read(buf));
+ Assertions.assertEquals(2,
+ keyInfo.getPipeline().getReplicaIndex(e.getFailedLocation()));
}
}
private void validateBufferContents(ByteBuffer buf, int from, int to,
byte val) {
for (int i = from; i < to; i++) {
- Assert.assertEquals(val, buf.get(i));
+ Assertions.assertEquals(val, buf.get(i));
}
}
diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestECBlockInputStreamProxy.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestECBlockInputStreamProxy.java
index fc1b3fb92f..89ac7a831e 100644
--- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestECBlockInputStreamProxy.java
+++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestECBlockInputStreamProxy.java
@@ -25,9 +25,9 @@ import org.apache.hadoop.hdds.scm.XceiverClientFactory;
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
import org.apache.hadoop.hdds.scm.storage.BlockExtendedInputStream;
import org.apache.hadoop.hdds.scm.storage.BlockLocationInfo;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,6 +40,8 @@ import java.util.SplittableRandom;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Function;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
/**
* Unit tests for the ECBlockInputStreamProxy class.
*/
@@ -56,7 +58,7 @@ public class TestECBlockInputStreamProxy {
private ThreadLocalRandom random = ThreadLocalRandom.current();
private SplittableRandom dataGenerator;
- @Before
+ @BeforeEach
public void setup() {
repConfig = new ECReplicationConfig(3, 2);
streamFactory = new TestECBlockInputStreamFactory();
@@ -66,23 +68,23 @@ public class TestECBlockInputStreamProxy {
@Test
public void testExpectedDataLocations() {
- Assert.assertEquals(1,
+ Assertions.assertEquals(1,
ECBlockInputStreamProxy.expectedDataLocations(repConfig, 1));
- Assert.assertEquals(2,
+ Assertions.assertEquals(2,
ECBlockInputStreamProxy.expectedDataLocations(repConfig, ONEMB + 1));
- Assert.assertEquals(3,
+ Assertions.assertEquals(3,
ECBlockInputStreamProxy.expectedDataLocations(repConfig, 3 * ONEMB));
- Assert.assertEquals(3,
+ Assertions.assertEquals(3,
ECBlockInputStreamProxy.expectedDataLocations(repConfig, 10 * ONEMB));
repConfig = new ECReplicationConfig(6, 3);
- Assert.assertEquals(1,
+ Assertions.assertEquals(1,
ECBlockInputStreamProxy.expectedDataLocations(repConfig, 1));
- Assert.assertEquals(2,
+ Assertions.assertEquals(2,
ECBlockInputStreamProxy.expectedDataLocations(repConfig, ONEMB + 1));
- Assert.assertEquals(3,
+ Assertions.assertEquals(3,
ECBlockInputStreamProxy.expectedDataLocations(repConfig, 3 * ONEMB));
- Assert.assertEquals(6,
+ Assertions.assertEquals(6,
ECBlockInputStreamProxy.expectedDataLocations(repConfig, 10 * ONEMB));
}
@@ -92,21 +94,21 @@ public class TestECBlockInputStreamProxy {
ECStreamTestUtil.createIndexMap(1, 2, 3, 4, 5);
BlockLocationInfo blockInfo =
ECStreamTestUtil.createKeyInfo(repConfig, 1024, dnMap);
- Assert.assertEquals(1, ECBlockInputStreamProxy.availableDataLocations(
+ Assertions.assertEquals(1, ECBlockInputStreamProxy.availableDataLocations(
blockInfo.getPipeline(), 1));
- Assert.assertEquals(2, ECBlockInputStreamProxy.availableDataLocations(
+ Assertions.assertEquals(2, ECBlockInputStreamProxy.availableDataLocations(
blockInfo.getPipeline(), 2));
- Assert.assertEquals(3, ECBlockInputStreamProxy.availableDataLocations(
+ Assertions.assertEquals(3, ECBlockInputStreamProxy.availableDataLocations(
blockInfo.getPipeline(), 3));
dnMap = ECStreamTestUtil.createIndexMap(1, 4, 5);
blockInfo = ECStreamTestUtil.createKeyInfo(repConfig, 1024, dnMap);
- Assert.assertEquals(1, ECBlockInputStreamProxy.availableDataLocations(
+ Assertions.assertEquals(1, ECBlockInputStreamProxy.availableDataLocations(
blockInfo.getPipeline(), 3));
dnMap = ECStreamTestUtil.createIndexMap(2, 3, 4, 5);
blockInfo = ECStreamTestUtil.createKeyInfo(repConfig, 1024, dnMap);
- Assert.assertEquals(0, ECBlockInputStreamProxy.availableDataLocations(
+ Assertions.assertEquals(0, ECBlockInputStreamProxy.availableDataLocations(
blockInfo.getPipeline(), 1));
}
@@ -121,7 +123,7 @@ public class TestECBlockInputStreamProxy {
ECStreamTestUtil.createKeyInfo(repConfig, blockLength, dnMap);
try (ECBlockInputStreamProxy bis = createBISProxy(repConfig, blockInfo)) {
- Assert.assertEquals(blockInfo.getBlockID(), bis.getBlockID());
+ Assertions.assertEquals(blockInfo.getBlockID(), bis.getBlockID());
}
}
@@ -136,7 +138,7 @@ public class TestECBlockInputStreamProxy {
ECStreamTestUtil.createKeyInfo(repConfig, blockLength, dnMap);
try (ECBlockInputStreamProxy bis = createBISProxy(repConfig, blockInfo)) {
- Assert.assertEquals(1234, bis.getLength());
+ Assertions.assertEquals(1234, bis.getLength());
}
}
@@ -153,11 +155,11 @@ public class TestECBlockInputStreamProxy {
dataGenerator = new SplittableRandom(randomSeed);
ByteBuffer readBuffer = ByteBuffer.allocate(100);
try (ECBlockInputStreamProxy bis = createBISProxy(repConfig, blockInfo)) {
- Assert.assertEquals(12345, bis.getRemaining());
- Assert.assertEquals(0, bis.getPos());
+ Assertions.assertEquals(12345, bis.getRemaining());
+ Assertions.assertEquals(0, bis.getPos());
bis.read(readBuffer);
- Assert.assertEquals(12345 - 100, bis.getRemaining());
- Assert.assertEquals(100, bis.getPos());
+ Assertions.assertEquals(12345 - 100, bis.getRemaining());
+ Assertions.assertEquals(100, bis.getPos());
}
}
@@ -175,8 +177,8 @@ public class TestECBlockInputStreamProxy {
try (ECBlockInputStreamProxy bis = createBISProxy(repConfig, blockInfo)) {
// Not all locations present, so we expect on;y the "missing=true" stream
// to be present.
- Assert.assertTrue(streamFactory.getStreams().containsKey(false));
- Assert.assertFalse(streamFactory.getStreams().containsKey(true));
+ Assertions.assertTrue(streamFactory.getStreams().containsKey(false));
+ Assertions.assertFalse(streamFactory.getStreams().containsKey(true));
}
streamFactory = new TestECBlockInputStreamFactory();
@@ -187,8 +189,8 @@ public class TestECBlockInputStreamProxy {
try (ECBlockInputStreamProxy bis = createBISProxy(repConfig, blockInfo)) {
// Not all locations present, so we expect on;y the "missing=true" stream
// to be present.
- Assert.assertFalse(streamFactory.getStreams().containsKey(false));
- Assert.assertTrue(streamFactory.getStreams().containsKey(true));
+ Assertions.assertFalse(streamFactory.getStreams().containsKey(false));
+ Assertions.assertTrue(streamFactory.getStreams().containsKey(true));
}
}
@@ -216,7 +218,7 @@ public class TestECBlockInputStreamProxy {
}
readBuffer.clear();
int read = bis.read(readBuffer);
- Assert.assertEquals(-1, read);
+ Assertions.assertEquals(-1, read);
}
}
@@ -244,7 +246,7 @@ public class TestECBlockInputStreamProxy {
}
readBuffer.clear();
int read = bis.read(readBuffer);
- Assert.assertEquals(-1, read);
+ Assertions.assertEquals(-1, read);
}
}
@@ -266,7 +268,7 @@ public class TestECBlockInputStreamProxy {
try (ECBlockInputStreamProxy bis = createBISProxy(repConfig, blockInfo)) {
// Perform one read to get the stream created
int read = bis.read(readBuffer);
- Assert.assertEquals(100, read);
+ Assertions.assertEquals(100, read);
ECStreamTestUtil.assertBufferMatches(readBuffer, dataGenerator);
// Setup an error to be thrown part through a read, so the dataBuffer
// will have been advanced by 50 bytes before the error. This tests it
@@ -284,10 +286,10 @@ public class TestECBlockInputStreamProxy {
}
readBuffer.clear();
read = bis.read(readBuffer);
- Assert.assertEquals(-1, read);
+ Assertions.assertEquals(-1, read);
// Ensure the bad location was passed into the factory to create the
// reconstruction reader
- Assert.assertEquals(badDN, streamFactory.getFailedLocations().get(0));
+ Assertions.assertEquals(badDN, streamFactory.getFailedLocations().get(0));
}
}
@@ -306,14 +308,14 @@ public class TestECBlockInputStreamProxy {
try (ECBlockInputStreamProxy bis = createBISProxy(repConfig, blockInfo)) {
// Perform one read to get the stream created
int read = bis.read(readBuffer);
- Assert.assertEquals(100, read);
+ Assertions.assertEquals(100, read);
bis.seek(1024);
readBuffer.clear();
resetAndAdvanceDataGenerator(1024);
bis.read(readBuffer);
ECStreamTestUtil.assertBufferMatches(readBuffer, dataGenerator);
- Assert.assertEquals(1124, bis.getPos());
+ Assertions.assertEquals(1124, bis.getPos());
// Set the non-reconstruction reader to thrown an exception on seek
streamFactory.getStreams().get(false).setShouldErrorOnSeek(true);
@@ -325,12 +327,7 @@ public class TestECBlockInputStreamProxy {
// Finally, set the recon reader to fail on seek.
streamFactory.getStreams().get(true).setShouldErrorOnSeek(true);
- try {
- bis.seek(1024);
- Assert.fail("Seek should have raised an exception");
- } catch (IOException e) {
- // expected
- }
+ assertThrows(IOException.class, () -> bis.seek(1024));
}
}
diff --git a/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestECBlockReconstructedInputStream.java b/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestECBlockReconstructedInputStream.java
index 4fc237f34a..e39acaf9d2 100644
--- a/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestECBlockReconstructedInputStream.java
+++ b/hadoop-hdds/client/src/test/java/org/apache/hadoop/ozone/client/io/TestECBlockReconstructedInputStream.java
@@ -23,10 +23,10 @@ import org.apache.hadoop.hdds.protocol.DatanodeDetails;
import org.apache.hadoop.hdds.scm.storage.BlockLocationInfo;
import org.apache.hadoop.io.ByteBufferPool;
import org.apache.hadoop.io.ElasticByteBufferPool;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.ByteBuffer;
@@ -39,6 +39,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ThreadLocalRandom;
import static org.apache.hadoop.ozone.client.io.ECStreamTestUtil.generateParity;
+import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Test for the ECBlockReconstructedInputStream class.
@@ -54,7 +55,7 @@ public class TestECBlockReconstructedInputStream {
private ExecutorService ecReconstructExecutor =
Executors.newFixedThreadPool(3);
- @Before
+ @BeforeEach
public void setup() throws IOException {
repConfig = new ECReplicationConfig(3, 2);
streamFactory = new ECStreamTestUtil.TestBlockInputStreamFactory();
@@ -63,7 +64,7 @@ public class TestECBlockReconstructedInputStream {
dataGenerator = new SplittableRandom(randomSeed);
}
- @After
+ @AfterEach
public void teardown() {
ecReconstructExecutor.shutdownNow();
}
@@ -86,7 +87,7 @@ public class TestECBlockReconstructedInputStream {
try (ECBlockReconstructedInputStream stream =
new ECBlockReconstructedInputStream(repConfig, bufferPool,
stripeStream)) {
- Assert.assertEquals(12345L, stream.getLength());
+ Assertions.assertEquals(12345L, stream.getLength());
}
}
}
@@ -100,7 +101,7 @@ public class TestECBlockReconstructedInputStream {
try (ECBlockReconstructedInputStream stream =
new ECBlockReconstructedInputStream(repConfig, bufferPool,
stripeStream)) {
- Assert.assertEquals(new BlockID(1, 1), stream.getBlockID());
+ Assertions.assertEquals(new BlockID(1, 1), stream.getBlockID());
}
}
}
@@ -132,19 +133,19 @@ public class TestECBlockReconstructedInputStream {
int expectedRead = Math.min(blockLength - totalRead, readBufferSize);
long read = stream.read(b);
totalRead += read;
- Assert.assertEquals(expectedRead, read);
+ Assertions.assertEquals(expectedRead, read);
ECStreamTestUtil.assertBufferMatches(b, dataGenerator);
b.clear();
}
// Next read should be EOF
b.clear();
long read = stream.read(b);
- Assert.assertEquals(-1, read);
+ Assertions.assertEquals(-1, read);
// Seek back to zero and read again to ensure the buffers are
// re-allocated after being freed at the end of block.
stream.seek(0);
read = stream.read(b);
- Assert.assertEquals(readBufferSize, read);
+ Assertions.assertEquals(readBufferSize, read);
dataGenerator = new SplittableRandom(randomSeed);
ECStreamTestUtil.assertBufferMatches(b, dataGenerator);
}
@@ -180,7 +181,7 @@ public class TestECBlockReconstructedInputStream {
int expectedRead = Math.min(blockLength - totalRead, readBufferSize);
long read = stream.read(b);
totalRead += read;
- Assert.assertEquals(expectedRead, read);
+ Assertions.assertEquals(expectedRead, read);
ECStreamTestUtil.assertBufferMatches(b, dataGenerator);
b.clear();
stream.unbuffer();
@@ -188,7 +189,7 @@ public class TestECBlockReconstructedInputStream {
// Next read should be EOF
b.clear();
long read = stream.read(b);
- Assert.assertEquals(-1, read);
+ Assertions.assertEquals(-1, read);
}
}
}
@@ -215,12 +216,12 @@ public class TestECBlockReconstructedInputStream {
ByteBuffer b = ByteBuffer.allocate(readBufferSize);
dataGenerator = new SplittableRandom(randomSeed);
long read = stream.read(b);
- Assert.assertEquals(blockLength, read);
+ Assertions.assertEquals(blockLength, read);
ECStreamTestUtil.assertBufferMatches(b, dataGenerator);
b.clear();
// Next read should be EOF
read = stream.read(b);
- Assert.assertEquals(-1, read);
+ Assertions.assertEquals(-1, read);
}
}
}
@@ -252,10 +253,10 @@ public class TestECBlockReconstructedInputStream {
if (val == -1) {
break;
}
- Assert.assertEquals(dataGenerator.nextInt(255), val);
+ Assertions.assertEquals(dataGenerator.nextInt(255), val);
totalRead += 1;
}
- Assert.assertEquals(blockLength, totalRead);
+ Assertions.assertEquals(blockLength, totalRead);
}
}
}
@@ -286,13 +287,13 @@ public class TestECBlockReconstructedInputStream {
int expectedRead = Math.min(blockLength - totalRead, 1024);
long read = stream.read(buf, 0, buf.length);
totalRead += read;
- Assert.assertEquals(expectedRead, read);
+ Assertions.assertEquals(expectedRead, read);
ECStreamTestUtil.assertBufferMatches(
ByteBuffer.wrap(buf, 0, (int)read), dataGenerator);
}
// Next read should be EOF
long read = stream.read(buf, 0, buf.length);
- Assert.assertEquals(-1, read);
+ Assertions.assertEquals(-1, read);
}
}
}
@@ -324,19 +325,14 @@ public class TestECBlockReconstructedInputStream {
resetAndAdvanceDataGenerator(seekPosition);
long expectedRead = Math.min(stream.getRemaining(), readBufferSize);
long read = stream.read(b);
- Assert.assertEquals(expectedRead, read);
+ Assertions.assertEquals(expectedRead, read);
ECStreamTestUtil.assertBufferMatches(b, dataGenerator);
seekPosition = random.nextInt(blockLength);
stream.seek(seekPosition);
b.clear();
}
// Seeking beyond EOF should give an error
- try {
- stream.seek(blockLength + 1);
- Assert.fail("Seek beyond EOF should error");
- } catch (IOException e) {
- // expected
- }
+ assertThrows(IOException.class, () -> stream.seek(blockLength + 1));
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@ozone.apache.org
For additional commands, e-mail: commits-help@ozone.apache.org