From 5604c3788fa0029c665d6d21138c15dff204d19b Mon Sep 17 00:00:00 2001 From: Weiwei Yang Date: Tue, 18 Jul 2017 12:12:20 +0800 Subject: [PATCH] HDFS-11996. Ozone : add an UT to test partial read of chunks. Contributed by Chen Liang. --- .../common/impl/TestContainerPersistence.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/common/impl/TestContainerPersistence.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/common/impl/TestContainerPersistence.java index 7a23b87a4d..b33ee86ed7 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/common/impl/TestContainerPersistence.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/common/impl/TestContainerPersistence.java @@ -57,6 +57,7 @@ import java.nio.file.Paths; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.Arrays; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -72,6 +73,8 @@ import static org.apache.hadoop.ozone.container.ContainerTestHelper.getData; import static org.apache.hadoop.ozone.container.ContainerTestHelper .setDataChecksum; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** @@ -454,6 +457,41 @@ public void testWritReadManyChunks() throws IOException, } } + /** + * Test partial within a single chunk. + * + * @throws IOException + */ + @Test + public void testPartialRead() throws Exception { + final int datalen = 1024; + final int start = datalen/4; + final int length = datalen/2; + + String containerName = OzoneUtils.getRequestID(); + String keyName = OzoneUtils.getRequestID(); + Pipeline pipeline = createSingleNodePipeline(containerName); + + pipeline.setContainerName(containerName); + ContainerData cData = new ContainerData(containerName); + cData.addMetadata("VOLUME", "shire"); + cData.addMetadata("owner)", "bilbo"); + containerManager.createContainer(pipeline, cData); + ChunkInfo info = getChunk(keyName, 0, 0, datalen); + byte[] data = getData(datalen); + setDataChecksum(info, data); + chunkManager.writeChunk(pipeline, keyName, info, data); + + byte[] readData = chunkManager.readChunk(pipeline, keyName, info); + assertTrue(Arrays.equals(data, readData)); + + ChunkInfo info2 = getChunk(keyName, 0, start, length); + byte[] readData2 = chunkManager.readChunk(pipeline, keyName, info2); + assertEquals(length, readData2.length); + assertTrue(Arrays.equals( + Arrays.copyOfRange(data, start, start + length), readData2)); + } + /** * Writes a single chunk and tries to overwrite that chunk without over write * flag then re-tries with overwrite flag.