HDFS-11834. Ozone: Fix TestArchive#testArchive. Contributed by Xiaoyu Yao.

This commit is contained in:
Anu Engineer 2017-08-29 14:14:14 -07:00 committed by Owen O'Malley
parent 2e2e30373c
commit 91a8f134b7

View File

@ -18,7 +18,7 @@
package org.apache.hadoop.scm; package org.apache.hadoop.scm;
import org.apache.commons.io.FileUtils; 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.apache.hadoop.fs.FileUtil;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
@ -43,6 +43,10 @@ public class TestArchive {
private static final int DIR_COUNT = 10; private static final int DIR_COUNT = 10;
private static final int SUB_DIR_COUNT = 3; private static final int SUB_DIR_COUNT = 3;
private static final int FILE_COUNT = 10; private static final int FILE_COUNT = 10;
private long checksumWrite = 0L;
private long checksumRead = 0L;
private long tmp = 0L;
@Rule @Rule
public TemporaryFolder folder = new TemporaryFolder(); public TemporaryFolder folder = new TemporaryFolder();
@ -68,10 +72,12 @@ public void setUp() throws Exception {
for (int z = 0; z < FILE_COUNT; z++) { for (int z = 0; z < FILE_COUNT; z++) {
Path temp = Paths.get(targetDir.getPath().concat(File.separator) Path temp = Paths.get(targetDir.getPath().concat(File.separator)
.concat(String.format("File%d.txt", z))); .concat(String.format("File%d.txt", z)));
byte[] buf = RandomStringUtils.randomAlphanumeric(r.nextInt(megaByte)) byte[] buf = RandomUtils.nextBytes(r.nextInt(megaByte));
.getBytes("UTF-8");
Files.write(temp, buf); Files.write(temp, buf);
crc.reset();
crc.update(buf, 0, buf.length); crc.update(buf, 0, buf.length);
tmp = crc.getValue();
checksumWrite +=tmp;
} }
} }
} }
@ -79,7 +85,6 @@ public void setUp() throws Exception {
@Test @Test
public void testArchive() throws Exception { public void testArchive() throws Exception {
Checksum readCrc = new Adler32();
File archiveFile = new File(outputFolder.getRoot() + File.separator File archiveFile = new File(outputFolder.getRoot() + File.separator
+ "test.container.zip"); + "test.container.zip");
long zipCheckSum = FileUtil.zip(folder.getRoot(), archiveFile); long zipCheckSum = FileUtil.zip(folder.getRoot(), archiveFile);
@ -98,9 +103,12 @@ public void testArchive() throws Exception {
while (iter.hasNext()) { while (iter.hasNext()) {
count++; count++;
byte[] buf = Files.readAllBytes(iter.next().toPath()); 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(DIR_COUNT * SUB_DIR_COUNT * FILE_COUNT, count);
Assert.assertEquals(crc.getValue(), readCrc.getValue()); Assert.assertEquals(checksumWrite, checksumRead);
} }
} }