Skip to content

Commit e2b1133

Browse files
author
Steve Vaughan Jr
committed
Use try-with-resources for mini clusters
This update ensures that tests are cleaned-up correctly.
1 parent a228eed commit e2b1133

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgrade.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,7 @@ private static void checkMxBean() throws Exception {
307307
public void testRollback() throws Exception {
308308
// start a cluster
309309
final Configuration conf = new HdfsConfiguration();
310-
MiniDFSCluster cluster = null;
311-
try {
312-
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
310+
try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build()) {
313311
cluster.waitActive();
314312

315313
final Path foo = new Path("/foo");
@@ -349,8 +347,6 @@ public void testRollback() throws Exception {
349347

350348
startRollingUpgrade(foo, bar, file, data, cluster);
351349
rollbackRollingUpgrade(foo, bar, file, data, cluster);
352-
} finally {
353-
if(cluster != null) cluster.shutdown();
354350
}
355351
}
356352

@@ -558,9 +554,7 @@ private void testQuery(int nnCount) throws Exception{
558554
@Test (timeout = 300000)
559555
public void testQueryAfterRestart() throws IOException, InterruptedException {
560556
final Configuration conf = new Configuration();
561-
MiniDFSCluster cluster = null;
562-
try {
563-
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build();
557+
try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build()) {
564558
cluster.waitActive();
565559
DistributedFileSystem dfs = cluster.getFileSystem();
566560

@@ -574,10 +568,6 @@ public void testQueryAfterRestart() throws IOException, InterruptedException {
574568

575569
cluster.restartNameNodes();
576570
dfs.rollingUpgrade(RollingUpgradeAction.QUERY);
577-
} finally {
578-
if (cluster != null) {
579-
cluster.shutdown();
580-
}
581571
}
582572
}
583573

0 commit comments

Comments
 (0)