Java 类org.apache.hadoop.hdfs.server.namenode.NameNodeResourceChecker 实例源码

项目:hadoop    文件:TestNNHealthCheck.java   
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));
  }
}
项目:aliyun-oss-hadoop-fs    文件:TestNNHealthCheck.java   
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));
  }
}
项目:aliyun-oss-hadoop-fs    文件:TestDFSZKFailoverController.java   
/**
 * 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);
  }
}
项目:big-c    文件:TestNNHealthCheck.java   
@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();
    }
  }
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestNNHealthCheck.java   
@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();
    }
  }
}
项目:hadoop-plus    文件:TestNNHealthCheck.java   
@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();
    }
  }
}
项目:FlexMap    文件:TestNNHealthCheck.java   
@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();
    }
  }
}
项目:hadoop-TCP    文件:TestNNHealthCheck.java   
@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();
    }
  }
}
项目:hardfs    文件:TestNNHealthCheck.java   
@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();
    }
  }
}
项目:hadoop-on-lustre2    文件:TestNNHealthCheck.java   
@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();
    }
  }
}