@@ -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