private void doNNHealthCheckTest() throws IOException { NameNodeResourceChecker mockResourceChecker = Mockito.mock( NameNodeResourceChecker.class); Mockito.doReturn(true).when(mockResourceChecker).hasAvailableDiskSpace(); cluster.getNameNode(0).getNamesystem() .setNNResourceChecker(mockResourceChecker); NNHAServiceTarget haTarget = new NNHAServiceTarget(conf, DFSUtil.getNamenodeNameServiceId(conf), "nn1"); HAServiceProtocol rpc = haTarget.getHealthMonitorProxy(conf, conf.getInt( HA_HM_RPC_TIMEOUT_KEY, HA_HM_RPC_TIMEOUT_DEFAULT)); // Should not throw error, which indicates healthy. rpc.monitorHealth(); Mockito.doReturn(false).when(mockResourceChecker).hasAvailableDiskSpace(); try { // Should throw error - NN is unhealthy. rpc.monitorHealth(); fail("Should not have succeeded in calling monitorHealth"); } catch (HealthCheckFailedException hcfe) { GenericTestUtils.assertExceptionContains( "The NameNode has no resources available", hcfe); } catch (RemoteException re) { GenericTestUtils.assertExceptionContains( "The NameNode has no resources available", re.unwrapRemoteException(HealthCheckFailedException.class)); } }
/** * Test that thread dump is captured after NN state changes. */ @Test(timeout=60000) public void testThreadDumpCaptureAfterNNStateChange() throws Exception { NameNodeResourceChecker mockResourceChecker = Mockito.mock( NameNodeResourceChecker.class); Mockito.doReturn(false).when(mockResourceChecker).hasAvailableDiskSpace(); cluster.getNameNode(0).getNamesystem() .setNNResourceChecker(mockResourceChecker); waitForHAState(0, HAServiceState.STANDBY); while (!thr1.zkfc.isThreadDumpCaptured()) { Thread.sleep(1000); } }
@Test public void testNNHealthCheck() throws IOException { MiniDFSCluster cluster = null; try { Configuration conf = new Configuration(); cluster = new MiniDFSCluster.Builder(conf) .numDataNodes(0) .nnTopology(MiniDFSNNTopology.simpleHATopology()) .build(); NameNodeResourceChecker mockResourceChecker = Mockito.mock( NameNodeResourceChecker.class); Mockito.doReturn(true).when(mockResourceChecker).hasAvailableDiskSpace(); cluster.getNameNode(0).getNamesystem() .setNNResourceChecker(mockResourceChecker); NamenodeProtocols rpc = cluster.getNameNodeRpc(0); // Should not throw error, which indicates healthy. rpc.monitorHealth(); Mockito.doReturn(false).when(mockResourceChecker).hasAvailableDiskSpace(); try { // Should throw error - NN is unhealthy. rpc.monitorHealth(); fail("Should not have succeeded in calling monitorHealth"); } catch (HealthCheckFailedException hcfe) { GenericTestUtils.assertExceptionContains( "The NameNode has no resources available", hcfe); } } finally { if (cluster != null) { cluster.shutdown(); } } }