[Check static addition] Fix TestFileStatus.

Change-Id: I7c583eb61f72f7ba020d8f149c6574110fe9af06
This commit is contained in:
Siyao Meng 2021-08-19 22:47:36 -07:00
parent e724af14b8
commit 6f54c9ecde
1 changed files with 18 additions and 18 deletions

View File

@ -30,12 +30,12 @@ import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.RemoteIterator; import org.apache.hadoop.fs.RemoteIterator;
import org.apache.hadoop.fs.contract.ContractTestUtils;
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus; import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem; import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
import org.apache.hadoop.ipc.RemoteException; import org.apache.hadoop.ipc.RemoteException;
import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.GenericTestUtils;
import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.slf4j.event.Level; import org.slf4j.event.Level;
@ -44,7 +44,7 @@ import org.slf4j.event.Level;
* This class tests the FileStatus API. * This class tests the FileStatus API.
*/ */
public class TestFileStatus { public class TestFileStatus {
{ static {
GenericTestUtils.setLogLevel(FSNamesystem.LOG, Level.TRACE); GenericTestUtils.setLogLevel(FSNamesystem.LOG, Level.TRACE);
GenericTestUtils.setLogLevel(FileSystem.LOG, Level.TRACE); GenericTestUtils.setLogLevel(FileSystem.LOG, Level.TRACE);
} }
@ -95,11 +95,11 @@ public class TestFileStatus {
Path path = new Path("/"); Path path = new Path("/");
assertTrue( assertTrue(
fs.getFileStatus(path).isDirectory(), "/ should be a directory"); fs.getFileStatus(path).isDirectory(), "/ should be a directory");
Assertions.assertNotErasureCoded(fs, path); ContractTestUtils.assertNotErasureCoded(fs, path);
// Make sure getFileInfo returns null for files which do not exist // Make sure getFileInfo returns null for files which do not exist
HdfsFileStatus fileInfo = dfsClient.getFileInfo("/noSuchFile"); HdfsFileStatus fileInfo = dfsClient.getFileInfo("/noSuchFile");
assertEquals(null, fileInfo, "Non-existant file should result in null"); assertNull(fileInfo, "Non-existant file should result in null");
Path path1 = new Path("/name1"); Path path1 = new Path("/name1");
Path path2 = new Path("/name1/name2"); Path path2 = new Path("/name1/name2");
@ -132,7 +132,7 @@ public class TestFileStatus {
assertEquals(blockSize, status.getBlockSize()); assertEquals(blockSize, status.getBlockSize());
assertEquals(1, status.getReplication()); assertEquals(1, status.getReplication());
assertEquals(fileSize, status.getLen()); assertEquals(fileSize, status.getLen());
Assertions.assertNotErasureCoded(fs, file1); ContractTestUtils.assertNotErasureCoded(fs, file1);
assertEquals(file1.makeQualified(fs.getUri(), assertEquals(file1.makeQualified(fs.getUri(),
fs.getWorkingDirectory()).toString(), fs.getWorkingDirectory()).toString(),
status.getPath().toString()); status.getPath().toString());
@ -151,7 +151,7 @@ public class TestFileStatus {
assertEquals(blockSize, status.getBlockSize()); assertEquals(blockSize, status.getBlockSize());
assertEquals(1, status.getReplication()); assertEquals(1, status.getReplication());
assertEquals(fileSize, status.getLen()); assertEquals(fileSize, status.getLen());
Assertions.assertNotErasureCoded(fs, file1); ContractTestUtils.assertNotErasureCoded(fs, file1);
assertEquals(file1.makeQualified(fs.getUri(), assertEquals(file1.makeQualified(fs.getUri(),
fs.getWorkingDirectory()).toString(), fs.getWorkingDirectory()).toString(),
status.getPath().toString()); status.getPath().toString());
@ -199,23 +199,23 @@ public class TestFileStatus {
// test getFileStatus on an empty directory // test getFileStatus on an empty directory
FileStatus status = fs.getFileStatus(dir); FileStatus status = fs.getFileStatus(dir);
assertTrue(status.isDirectory(), dir + " should be a directory"); assertTrue(status.isDirectory(), dir + " should be a directory");
assertTrue(status.getLen() == 0, dir + " should be zero size "); assertEquals(0, status.getLen(), dir + " should be zero size ");
Assertions.assertNotErasureCoded(fs, dir); ContractTestUtils.assertNotErasureCoded(fs, dir);
assertEquals(dir.makeQualified(fs.getUri(), assertEquals(dir.makeQualified(fs.getUri(),
fs.getWorkingDirectory()).toString(), fs.getWorkingDirectory()).toString(),
status.getPath().toString()); status.getPath().toString());
// test listStatus on an empty directory // test listStatus on an empty directory
FileStatus[] stats = fs.listStatus(dir); FileStatus[] stats = fs.listStatus(dir);
assertEquals(0, stats.length, dir + " should be empty"); assertEquals(0, stats.length, dir + " should be empty");
assertEquals( assertEquals(
0, fs.getContentSummary(dir).getLength(), dir + " should be zero size "); 0, fs.getContentSummary(dir).getLength(), dir + " should be zero size ");
RemoteIterator<FileStatus> itor = fc.listStatus(dir); RemoteIterator<FileStatus> itor = fc.listStatus(dir);
assertFalse(itor.hasNext(), dir + " should be empty"); assertFalse(itor.hasNext(), dir + " should be empty");
itor = fs.listStatusIterator(dir); itor = fs.listStatusIterator(dir);
assertFalse(itor.hasNext(), dir + " should be empty"); assertFalse(itor.hasNext(), dir + " should be empty");
// create another file that is smaller than a block. // create another file that is smaller than a block.
Path file2 = new Path(dir, "filestatus2.dat"); Path file2 = new Path(dir, "filestatus2.dat");
@ -245,19 +245,19 @@ public class TestFileStatus {
// Test listStatus on a non-empty directory // Test listStatus on a non-empty directory
stats = fs.listStatus(dir); stats = fs.listStatus(dir);
assertEquals(2, stats.length, dir + " should have two entries"); assertEquals(2, stats.length, dir + " should have two entries");
assertEquals(file2.toString(), stats[0].getPath().toString()); assertEquals(file2.toString(), stats[0].getPath().toString());
assertEquals(file3.toString(), stats[1].getPath().toString()); assertEquals(file3.toString(), stats[1].getPath().toString());
itor = fc.listStatus(dir); itor = fc.listStatus(dir);
assertEquals(file2.toString(), itor.next().getPath().toString()); assertEquals(file2.toString(), itor.next().getPath().toString());
assertEquals(file3.toString(), itor.next().getPath().toString()); assertEquals(file3.toString(), itor.next().getPath().toString());
assertFalse(itor.hasNext(), "Unexpected addtional file"); assertFalse(itor.hasNext(), "Unexpected addtional file");
itor = fs.listStatusIterator(dir); itor = fs.listStatusIterator(dir);
assertEquals(file2.toString(), itor.next().getPath().toString()); assertEquals(file2.toString(), itor.next().getPath().toString());
assertEquals(file3.toString(), itor.next().getPath().toString()); assertEquals(file3.toString(), itor.next().getPath().toString());
assertFalse(itor.hasNext(), "Unexpected addtional file"); assertFalse(itor.hasNext(), "Unexpected addtional file");
// Test iterative listing. Now dir has 2 entries, create one more. // Test iterative listing. Now dir has 2 entries, create one more.
@ -322,7 +322,7 @@ public class TestFileStatus {
try { try {
itor.hasNext(); itor.hasNext();
fail("FileNotFoundException expected"); fail("FileNotFoundException expected");
} catch (FileNotFoundException fnfe) { } catch (FileNotFoundException ignored) {
} }
fs.mkdirs(file2); fs.mkdirs(file2);
@ -337,7 +337,7 @@ public class TestFileStatus {
count++; count++;
} }
fail("FileNotFoundException expected"); fail("FileNotFoundException expected");
} catch (FileNotFoundException fnfe) { } catch (FileNotFoundException ignored) {
} }
assertEquals(2, count); assertEquals(2, count);
} }