Fix TestFileStatusWithDefaultECPolicy.

Change-Id: I5980792c534bdbdafab787552c467cf45e9336fe
This commit is contained in:
Siyao Meng 2021-08-19 22:28:19 -07:00
parent 991fd8d746
commit 6a05d93de5
1 changed files with 17 additions and 14 deletions

View File

@ -17,21 +17,24 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.jupiter.api.Assertions.*;
import java.io.IOException;
import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.contract.ContractTestUtils;
import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy; import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy;
import org.junit.Rule; import org.junit.Rule;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.rules.Timeout; import org.junit.rules.Timeout;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* This test ensures the statuses of EC files with the default policy. * This test ensures the statuses of EC files with the default policy.
*/ */
@ -71,23 +74,23 @@ public class TestFileStatusWithDefaultECPolicy {
// test directory doesn't have an EC policy // test directory doesn't have an EC policy
final Path dir = new Path("/foo"); final Path dir = new Path("/foo");
assertTrue(fs.mkdir(dir, FsPermission.getDirDefault())); assertTrue(fs.mkdir(dir, FsPermission.getDirDefault()));
Assertions.assertNotErasureCoded(fs, dir); ContractTestUtils.assertNotErasureCoded(fs, dir);
assertNull(client.getFileInfo(dir.toString()).getErasureCodingPolicy()); assertNull(client.getFileInfo(dir.toString()).getErasureCodingPolicy());
// test file doesn't have an EC policy // test file doesn't have an EC policy
final Path file = new Path(dir, "foo"); final Path file = new Path(dir, "foo");
fs.create(file).close(); fs.create(file).close();
assertNull(client.getFileInfo(file.toString()).getErasureCodingPolicy()); assertNull(client.getFileInfo(file.toString()).getErasureCodingPolicy());
Assertions.assertNotErasureCoded(fs, file); ContractTestUtils.assertNotErasureCoded(fs, file);
fs.delete(file, true); fs.delete(file, true);
final ErasureCodingPolicy ecPolicy1 = getEcPolicy(); final ErasureCodingPolicy ecPolicy1 = getEcPolicy();
// set EC policy on dir // set EC policy on dir
fs.setErasureCodingPolicy(dir, ecPolicy1.getName()); fs.setErasureCodingPolicy(dir, ecPolicy1.getName());
Assertions.assertErasureCoded(fs, dir); ContractTestUtils.assertErasureCoded(fs, dir);
final ErasureCodingPolicy ecPolicy2 = final ErasureCodingPolicy ecPolicy2 =
client.getFileInfo(dir.toUri().getPath()).getErasureCodingPolicy(); client.getFileInfo(dir.toUri().getPath()).getErasureCodingPolicy();
assertNotNull(ecPolicy2); assertNotNull(ecPolicy2);
assertTrue(ecPolicy1.equals(ecPolicy2)); assertEquals(ecPolicy1, ecPolicy2);
// test file with EC policy // test file with EC policy
fs.create(file).close(); fs.create(file).close();
@ -95,11 +98,11 @@ public class TestFileStatusWithDefaultECPolicy {
fs.getClient().getFileInfo(file.toUri().getPath()) fs.getClient().getFileInfo(file.toUri().getPath())
.getErasureCodingPolicy(); .getErasureCodingPolicy();
assertNotNull(ecPolicy3); assertNotNull(ecPolicy3);
assertTrue(ecPolicy1.equals(ecPolicy3)); assertEquals(ecPolicy1, ecPolicy3);
Assertions.assertErasureCoded(fs, file); ContractTestUtils.assertErasureCoded(fs, file);
FileStatus status = fs.getFileStatus(file); FileStatus status = fs.getFileStatus(file);
assertTrue( assertTrue(status.toString().contains("isErasureCoded=true"),
status.toString().contains("isErasureCoded=true"), file + " should have erasure coding set in " + file + " should have erasure coding set in "
"FileStatus#toString(): " + status); + "FileStatus#toString(): " + status);
} }
} }