From 91a8f134b7a10ae0c9ec9f589b24a261d0cd2d8f Mon Sep 17 00:00:00 2001 From: Anu Engineer Date: Tue, 29 Aug 2017 14:14:14 -0700 Subject: [PATCH] HDFS-11834. Ozone: Fix TestArchive#testArchive. Contributed by Xiaoyu Yao. --- .../org/apache/hadoop/scm/TestArchive.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/scm/TestArchive.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/scm/TestArchive.java index 6fff47ecf1..30305758cf 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/scm/TestArchive.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/scm/TestArchive.java @@ -18,7 +18,7 @@ package org.apache.hadoop.scm; import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.lang3.RandomUtils; import org.apache.hadoop.fs.FileUtil; import org.junit.Assert; import org.junit.Before; @@ -43,6 +43,10 @@ public class TestArchive { private static final int DIR_COUNT = 10; private static final int SUB_DIR_COUNT = 3; private static final int FILE_COUNT = 10; + private long checksumWrite = 0L; + private long checksumRead = 0L; + private long tmp = 0L; + @Rule public TemporaryFolder folder = new TemporaryFolder(); @@ -68,10 +72,12 @@ public void setUp() throws Exception { for (int z = 0; z < FILE_COUNT; z++) { Path temp = Paths.get(targetDir.getPath().concat(File.separator) .concat(String.format("File%d.txt", z))); - byte[] buf = RandomStringUtils.randomAlphanumeric(r.nextInt(megaByte)) - .getBytes("UTF-8"); + byte[] buf = RandomUtils.nextBytes(r.nextInt(megaByte)); Files.write(temp, buf); + crc.reset(); crc.update(buf, 0, buf.length); + tmp = crc.getValue(); + checksumWrite +=tmp; } } } @@ -79,7 +85,6 @@ public void setUp() throws Exception { @Test public void testArchive() throws Exception { - Checksum readCrc = new Adler32(); File archiveFile = new File(outputFolder.getRoot() + File.separator + "test.container.zip"); long zipCheckSum = FileUtil.zip(folder.getRoot(), archiveFile); @@ -98,9 +103,12 @@ public void testArchive() throws Exception { while (iter.hasNext()) { count++; byte[] buf = Files.readAllBytes(iter.next().toPath()); - readCrc.update(buf, 0, buf.length); + crc.reset(); + crc.update(buf, 0, buf.length); + tmp = crc.getValue(); + checksumRead += tmp; } Assert.assertEquals(DIR_COUNT * SUB_DIR_COUNT * FILE_COUNT, count); - Assert.assertEquals(crc.getValue(), readCrc.getValue()); + Assert.assertEquals(checksumWrite, checksumRead); } }