@@ -330,86 +330,93 @@ public void testForcedRegistration() throws Exception {
330330 conf .setInt (DFSConfigKeys .DFS_NAMENODE_HANDLER_COUNT_KEY , 4 );
331331 conf .setLong (DFSConfigKeys .DFS_BLOCKREPORT_INTERVAL_MSEC_KEY , Integer .MAX_VALUE );
332332
333- final MiniDFSCluster cluster =
334- new MiniDFSCluster .Builder (conf ).numDataNodes (1 ).build ();
335- cluster .waitActive ();
336- cluster .getHttpUri (0 );
337- FSNamesystem fsn = cluster .getNamesystem ();
338- String bpId = fsn .getBlockPoolId ();
333+ MiniDFSCluster cluster = null ;
334+ try {
335+ cluster = new MiniDFSCluster .Builder (conf ).numDataNodes (1 ).build ();
336+ cluster .waitActive ();
337+ cluster .getHttpUri (0 );
338+ FSNamesystem fsn = cluster .getNamesystem ();
339+ String bpId = fsn .getBlockPoolId ();
339340
340- DataNode dn = cluster .getDataNodes ().get (0 );
341- DatanodeDescriptor dnd =
342- NameNodeAdapter .getDatanode (fsn , dn .getDatanodeId ());
343- DataNodeTestUtils .setHeartbeatsDisabledForTests (dn , true );
344- DatanodeStorageInfo storage = dnd .getStorageInfos ()[0 ];
341+ DataNode dn = cluster .getDataNodes ().get (0 );
342+ DatanodeDescriptor dnd =
343+ NameNodeAdapter .getDatanode (fsn , dn .getDatanodeId ());
344+ DataNodeTestUtils .setHeartbeatsDisabledForTests (dn , true );
345+ DatanodeStorageInfo storage = dnd .getStorageInfos ()[0 ];
345346
346- // registration should not change after heartbeat.
347- assertTrue (dnd .isRegistered ());
348- DatanodeRegistration lastReg = dn .getDNRegistrationForBP (bpId );
349- waitForHeartbeat (dn , dnd );
350- assertSame (lastReg , dn .getDNRegistrationForBP (bpId ));
347+ // registration should not change after heartbeat.
348+ assertTrue (dnd .isRegistered ());
349+ DatanodeRegistration lastReg = dn .getDNRegistrationForBP (bpId );
350+ waitForHeartbeat (dn , dnd );
351+ assertSame (lastReg , dn .getDNRegistrationForBP (bpId ));
351352
352- // force a re-registration on next heartbeat.
353- dnd .setForceRegistration (true );
354- assertFalse (dnd .isRegistered ());
355- waitForHeartbeat (dn , dnd );
356- assertTrue (dnd .isRegistered ());
357- DatanodeRegistration newReg = dn .getDNRegistrationForBP (bpId );
358- assertNotSame (lastReg , newReg );
359- lastReg = newReg ;
353+ // force a re-registration on next heartbeat.
354+ dnd .setForceRegistration (true );
355+ assertFalse (dnd .isRegistered ());
356+ waitForHeartbeat (dn , dnd );
357+ assertTrue (dnd .isRegistered ());
358+ DatanodeRegistration newReg = dn .getDNRegistrationForBP (bpId );
359+ assertNotSame (lastReg , newReg );
360+ lastReg = newReg ;
360361
361- // registration should not change on subsequent heartbeats.
362- waitForHeartbeat (dn , dnd );
363- assertTrue (dnd .isRegistered ());
364- assertSame (lastReg , dn .getDNRegistrationForBP (bpId ));
365- assertTrue (waitForBlockReport (dn , dnd ));
366- assertTrue (dnd .isRegistered ());
367- assertSame (lastReg , dn .getDNRegistrationForBP (bpId ));
362+ // registration should not change on subsequent heartbeats.
363+ waitForHeartbeat (dn , dnd );
364+ assertTrue (dnd .isRegistered ());
365+ assertSame (lastReg , dn .getDNRegistrationForBP (bpId ));
366+ assertTrue (waitForBlockReport (dn , dnd ));
367+ assertTrue (dnd .isRegistered ());
368+ assertSame (lastReg , dn .getDNRegistrationForBP (bpId ));
368369
369- // check that block report is not processed and registration didn't change.
370- dnd .setForceRegistration (true );
371- assertFalse (waitForBlockReport (dn , dnd ));
372- assertFalse (dnd .isRegistered ());
373- assertSame (lastReg , dn .getDNRegistrationForBP (bpId ));
370+ // check that block report is not processed and registration didn't
371+ // change.
372+ dnd .setForceRegistration (true );
373+ assertFalse (waitForBlockReport (dn , dnd ));
374+ assertFalse (dnd .isRegistered ());
375+ assertSame (lastReg , dn .getDNRegistrationForBP (bpId ));
374376
375- // heartbeat should trigger re-registration, and next block report should
376- // not change registration.
377- waitForHeartbeat (dn , dnd );
378- assertTrue (dnd .isRegistered ());
379- newReg = dn .getDNRegistrationForBP (bpId );
380- assertNotSame (lastReg , newReg );
381- lastReg = newReg ;
382- assertTrue (waitForBlockReport (dn , dnd ));
383- assertTrue (dnd .isRegistered ());
384- assertSame (lastReg , dn .getDNRegistrationForBP (bpId ));
377+ // heartbeat should trigger re-registration, and next block report
378+ // should not change registration.
379+ waitForHeartbeat (dn , dnd );
380+ assertTrue (dnd .isRegistered ());
381+ newReg = dn .getDNRegistrationForBP (bpId );
382+ assertNotSame (lastReg , newReg );
383+ lastReg = newReg ;
384+ assertTrue (waitForBlockReport (dn , dnd ));
385+ assertTrue (dnd .isRegistered ());
386+ assertSame (lastReg , dn .getDNRegistrationForBP (bpId ));
385387
386- // registration doesn't change.
387- ExtendedBlock eb = new ExtendedBlock (bpId , 1234 );
388- dn .notifyNamenodeDeletedBlock (eb , storage .getStorageID ());
389- DataNodeTestUtils .triggerDeletionReport (dn );
390- assertTrue (dnd .isRegistered ());
391- assertSame (lastReg , dn .getDNRegistrationForBP (bpId ));
388+ // registration doesn't change.
389+ ExtendedBlock eb = new ExtendedBlock (bpId , 1234 );
390+ dn .notifyNamenodeDeletedBlock (eb , storage .getStorageID ());
391+ DataNodeTestUtils .triggerDeletionReport (dn );
392+ assertTrue (dnd .isRegistered ());
393+ assertSame (lastReg , dn .getDNRegistrationForBP (bpId ));
392394
393- // a failed IBR will effectively unregister the node.
394- boolean failed = false ;
395- try {
396- // pass null to cause a failure since there aren't any easy failure
397- // modes since it shouldn't happen.
398- fsn .processIncrementalBlockReport (lastReg , null );
399- } catch (NullPointerException npe ) {
400- failed = true ;
401- }
402- assertTrue ("didn't fail" , failed );
403- assertFalse (dnd .isRegistered ());
395+ // a failed IBR will effectively unregister the node.
396+ boolean failed = false ;
397+ try {
398+ // pass null to cause a failure since there aren't any easy failure
399+ // modes since it shouldn't happen.
400+ fsn .processIncrementalBlockReport (lastReg , null );
401+ } catch (NullPointerException npe ) {
402+ failed = true ;
403+ }
404+ assertTrue ("didn't fail" , failed );
405+ assertFalse (dnd .isRegistered ());
404406
405- // should remain unregistered until next heartbeat.
406- dn .notifyNamenodeDeletedBlock (eb , storage .getStorageID ());
407- DataNodeTestUtils .triggerDeletionReport (dn );
408- assertFalse (dnd .isRegistered ());
409- assertSame (lastReg , dn .getDNRegistrationForBP (bpId ));
410- waitForHeartbeat (dn , dnd );
411- assertTrue (dnd .isRegistered ());
412- assertNotSame (lastReg , dn .getDNRegistrationForBP (bpId ));
407+ // should remain unregistered until next heartbeat.
408+ dn .notifyNamenodeDeletedBlock (eb , storage .getStorageID ());
409+ DataNodeTestUtils .triggerDeletionReport (dn );
410+ assertFalse (dnd .isRegistered ());
411+ assertSame (lastReg , dn .getDNRegistrationForBP (bpId ));
412+ waitForHeartbeat (dn , dnd );
413+ assertTrue (dnd .isRegistered ());
414+ assertNotSame (lastReg , dn .getDNRegistrationForBP (bpId ));
415+ } finally {
416+ if (cluster != null ) {
417+ cluster .shutdown ();
418+ }
419+ }
413420 }
414421
415422 private void waitForHeartbeat (final DataNode dn , final DatanodeDescriptor dnd )
0 commit comments