Skip to content

Commit 73aa5fa

Browse files
HDFS-15322. Few checkstyle fixups.
1 parent 47b2de5 commit 73aa5fa

File tree

1 file changed

+41
-48
lines changed

1 file changed

+41
-48
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemOverloadSchemeWithHdfsScheme.java

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -452,27 +452,27 @@ public void testViewFsOverloadSchemeWithNoInnerCacheAndLocalSchemeTargets()
452452
/**
453453
* Tests the rename with nfly mount link.
454454
*/
455-
@Test
455+
@Test(timeout = 3000)
456456
public void testNflyRename() throws Exception {
457457
final Path hdfsTargetPath1 = new Path(defaultFSURI + HDFS_USER_FOLDER);
458458
final Path hdfsTargetPath2 = new Path(defaultFSURI + HDFS_USER_FOLDER + 1);
459459
final URI uri1 = hdfsTargetPath1.toUri();
460460
final URI uri2 = hdfsTargetPath2.toUri();
461461
final Path nflyRoot = new Path("/nflyroot");
462462

463-
addMountLinks(defaultFSURI.getAuthority(),
464-
new String[] {Constants.CONFIG_VIEWFS_LINK_NFLY + "."
465-
+ "minReplication=2" + "." + nflyRoot.toString() },
463+
final String nflyLinkKey = Constants.CONFIG_VIEWFS_LINK_NFLY
464+
+ ".minReplication=2." + nflyRoot.toString();
465+
addMountLinks(defaultFSURI.getAuthority(), new String[] {nflyLinkKey },
466466
new String[] {uri1.toString() + "," + uri2.toString() }, conf);
467467
final FileSystem nfly = FileSystem.get(defaultFSURI, conf);
468468

469469
final Path testDir = new Path("/nflyroot/testdir1/sub1/sub3");
470-
final Path testDir_tmp = new Path("/nflyroot/testdir1/sub1/sub3_temp");
470+
final Path testDirTmp = new Path("/nflyroot/testdir1/sub1/sub3_temp");
471471
assertTrue(testDir + ": Failed to create!", nfly.mkdirs(testDir));
472472

473473
// Test renames
474-
assertTrue(nfly.rename(testDir, testDir_tmp));
475-
assertTrue(nfly.rename(testDir_tmp, testDir));
474+
assertTrue(nfly.rename(testDir, testDirTmp));
475+
assertTrue(nfly.rename(testDirTmp, testDir));
476476

477477
final URI[] testUris = new URI[] {uri1, uri2 };
478478
for (final URI testUri : testUris) {
@@ -484,24 +484,25 @@ public void testNflyRename() throws Exception {
484484
/**
485485
* Tests the write and read contents with nfly mount link.
486486
*/
487-
@Test
487+
@Test(timeout = 3000)
488488
public void testNflyWriteRead() throws Exception {
489489
final Path hdfsTargetPath1 = new Path(defaultFSURI + HDFS_USER_FOLDER);
490490
final Path hdfsTargetPath2 = new Path(defaultFSURI + HDFS_USER_FOLDER + 1);
491491
final URI uri1 = hdfsTargetPath1.toUri();
492492
final URI uri2 = hdfsTargetPath2.toUri();
493493
final Path nflyRoot = new Path("/nflyroot");
494-
addMountLinks(defaultFSURI.getAuthority(),
495-
new String[] {Constants.CONFIG_VIEWFS_LINK_NFLY + "."
496-
+ "minReplication=2" + "." + nflyRoot.toString() },
494+
final String nflyLinkKey = Constants.CONFIG_VIEWFS_LINK_NFLY
495+
+ ".minReplication=2." + nflyRoot.toString();
496+
addMountLinks(defaultFSURI.getAuthority(), new String[] {nflyLinkKey },
497497
new String[] {uri1.toString() + "," + uri2.toString() }, conf);
498498
final FileSystem nfly = FileSystem.get(defaultFSURI, conf);
499499
final Path testFile = new Path("/nflyroot/test.txt");
500500
writeString(nfly, TEST_STRING, testFile);
501501
final URI[] testUris = new URI[] {uri1, uri2 };
502502
for (final URI testUri : testUris) {
503-
final FileSystem fs = FileSystem.get(testUri, conf);
504-
readString(fs, testFile, TEST_STRING, testUri);
503+
try (FileSystem fs = FileSystem.get(testUri, conf)) {
504+
readString(fs, testFile, TEST_STRING, testUri);
505+
}
505506
}
506507
}
507508

@@ -510,60 +511,52 @@ public void testNflyWriteRead() throws Exception {
510511
* target file. 3. Tests the read works with repairOnRead flag. 4. Tests that
511512
* previously deleted file fully recovered and exists.
512513
*/
513-
@Test
514+
@Test(timeout = 3000)
514515
public void testNflyRepair() throws Exception {
515516
final NflyFSystem.NflyKey repairKey = NflyFSystem.NflyKey.repairOnRead;
516517
final Path hdfsTargetPath1 = new Path(defaultFSURI + HDFS_USER_FOLDER);
517518
final Path hdfsTargetPath2 = new Path(defaultFSURI + HDFS_USER_FOLDER + 1);
518519
final URI uri1 = hdfsTargetPath1.toUri();
519520
final URI uri2 = hdfsTargetPath2.toUri();
520521
final Path nflyRoot = new Path("/nflyroot");
521-
addMountLinks(defaultFSURI.getAuthority(),
522-
new String[] {
523-
Constants.CONFIG_VIEWFS_LINK_NFLY + "." + "minReplication=2,"
524-
+ repairKey + "=true" + "." + nflyRoot.toString() },
522+
final String nflyLinkKey = Constants.CONFIG_VIEWFS_LINK_NFLY
523+
+ ".minReplication=2," + repairKey + "=true." + nflyRoot.toString();
524+
addMountLinks(defaultFSURI.getAuthority(), new String[] {nflyLinkKey },
525525
new String[] {uri1.toString() + "," + uri2.toString() }, conf);
526-
527-
final FileSystem nfly = FileSystem.get(defaultFSURI, conf);
528-
529-
// write contents to nfly
530-
final Path testFilePath = new Path("/nflyroot/test.txt");
531-
writeString(nfly, TEST_STRING, testFilePath);
532-
533-
final URI[] testUris = new URI[] {uri1, uri2 };
534-
// both nodes are up again, test repair
535-
FsGetter getter = new ViewFileSystemOverloadScheme.ChildFsGetter("hdfs");
536-
FileSystem fs1 = getter.getNewInstance(testUris[0], conf);
537-
538-
// Delete a file from one target URI
539-
String testFile = "/test.txt";
540-
assertTrue(fs1.delete(new Path(testUris[0].toString() + testFile), false));
541-
assertFalse(fs1.exists(new Path(testUris[0].toString() + testFile)));
542-
543-
// Verify read success.
544-
readString(nfly, testFilePath, TEST_STRING, testUris[0]);
545-
// Verify file recovered.
546-
assertTrue(fs1.exists(new Path(testUris[0].toString() + testFile)));
526+
try (FileSystem nfly = FileSystem.get(defaultFSURI, conf)) {
527+
// write contents to nfly
528+
final Path testFilePath = new Path("/nflyroot/test.txt");
529+
writeString(nfly, TEST_STRING, testFilePath);
530+
531+
final URI[] testUris = new URI[] {uri1, uri2 };
532+
// both nodes are up again, test repair
533+
FsGetter getter = new ViewFileSystemOverloadScheme.ChildFsGetter("hdfs");
534+
try (FileSystem fs1 = getter.getNewInstance(testUris[0], conf)) {
535+
// Delete a file from one target URI
536+
String testFile = "/test.txt";
537+
assertTrue(
538+
fs1.delete(new Path(testUris[0].toString() + testFile), false));
539+
assertFalse(fs1.exists(new Path(testUris[0].toString() + testFile)));
540+
541+
// Verify read success.
542+
readString(nfly, testFilePath, TEST_STRING, testUris[0]);
543+
// Verify file recovered.
544+
assertTrue(fs1.exists(new Path(testUris[0].toString() + testFile)));
545+
}
546+
}
547547
}
548548

549549
private void writeString(final FileSystem nfly, final String testString,
550550
final Path testFile) throws IOException {
551-
final FSDataOutputStream fsDos = nfly.create(testFile);
552-
try {
551+
try (FSDataOutputStream fsDos = nfly.create(testFile)) {
553552
fsDos.writeUTF(testString);
554-
} finally {
555-
fsDos.close();
556553
}
557554
}
558555

559556
private void readString(final FileSystem nfly, final Path testFile,
560557
final String testString, final URI testUri) throws IOException {
561-
FSDataInputStream fsDis = null;
562-
try {
563-
fsDis = nfly.open(testFile);
558+
try (FSDataInputStream fsDis = nfly.open(testFile)) {
564559
assertEquals("Wrong file content", testString, fsDis.readUTF());
565-
} finally {
566-
IOUtils.cleanupWithLogger(null, fsDis);
567560
}
568561
}
569562

0 commit comments

Comments
 (0)