Пример #1
0
 @Test
 public void testNodeHealthScriptShouldRun() throws IOException {
   // Node health script should not start if there is no property called
   // node health script path.
   Assert.assertFalse(
       "By default Health script should not have started",
       NodeHealthScriptRunner.shouldRun(new Configuration()));
   Configuration conf = getConfForNodeHealthScript();
   // Node health script should not start if the node health script does not
   // exists
   Assert.assertFalse("Node health script should start", NodeHealthScriptRunner.shouldRun(conf));
   // Create script path.
   conf.writeXml(new FileOutputStream(nodeHealthConfigFile));
   conf.addResource(nodeHealthConfigFile.getName());
   writeNodeHealthScriptFile("", false);
   // Node health script should not start if the node health script is not
   // executable.
   Assert.assertFalse("Node health script should start", NodeHealthScriptRunner.shouldRun(conf));
   writeNodeHealthScriptFile("", true);
   Assert.assertTrue("Node health script should start", NodeHealthScriptRunner.shouldRun(conf));
 }
Пример #2
0
  @Test
  public void testNodeHealthScript() throws Exception {
    RecordFactory factory = RecordFactoryProvider.getRecordFactory(null);
    NodeHealthStatus healthStatus = factory.newRecordInstance(NodeHealthStatus.class);
    String errorScript = "echo ERROR\n echo \"Tracker not healthy\"";
    String normalScript = "echo \"I am all fine\"";
    String timeOutScript =
        Shell.WINDOWS
            ? "@echo off\nping -n 4 127.0.0.1 >nul\necho \"I am fine\""
            : "sleep 4\necho \"I am fine\"";
    Configuration conf = getConfForNodeHealthScript();
    conf.writeXml(new FileOutputStream(nodeHealthConfigFile));
    conf.addResource(nodeHealthConfigFile.getName());

    writeNodeHealthScriptFile(normalScript, true);
    NodeHealthCheckerService nodeHealthChecker = new NodeHealthCheckerService();
    nodeHealthChecker.init(conf);
    NodeHealthScriptRunner nodeHealthScriptRunner = nodeHealthChecker.getNodeHealthScriptRunner();
    TimerTask timerTask = nodeHealthScriptRunner.getTimerTask();

    timerTask.run();

    setHealthStatus(
        healthStatus,
        nodeHealthChecker.isHealthy(),
        nodeHealthChecker.getHealthReport(),
        nodeHealthChecker.getLastHealthReportTime());
    LOG.info("Checking initial healthy condition");
    // Check proper report conditions.
    Assert.assertTrue("Node health status reported unhealthy", healthStatus.getIsNodeHealthy());
    Assert.assertTrue(
        "Node health status reported unhealthy",
        healthStatus.getHealthReport().equals(nodeHealthChecker.getHealthReport()));

    // write out error file.
    // Healthy to unhealthy transition
    writeNodeHealthScriptFile(errorScript, true);
    // Run timer
    timerTask.run();
    // update health status
    setHealthStatus(
        healthStatus,
        nodeHealthChecker.isHealthy(),
        nodeHealthChecker.getHealthReport(),
        nodeHealthChecker.getLastHealthReportTime());
    LOG.info("Checking Healthy--->Unhealthy");
    Assert.assertFalse("Node health status reported healthy", healthStatus.getIsNodeHealthy());
    Assert.assertTrue(
        "Node health status reported healthy",
        healthStatus.getHealthReport().equals(nodeHealthChecker.getHealthReport()));

    // Check unhealthy to healthy transitions.
    writeNodeHealthScriptFile(normalScript, true);
    timerTask.run();
    setHealthStatus(
        healthStatus,
        nodeHealthChecker.isHealthy(),
        nodeHealthChecker.getHealthReport(),
        nodeHealthChecker.getLastHealthReportTime());
    LOG.info("Checking UnHealthy--->healthy");
    // Check proper report conditions.
    Assert.assertTrue("Node health status reported unhealthy", healthStatus.getIsNodeHealthy());
    Assert.assertTrue(
        "Node health status reported unhealthy",
        healthStatus.getHealthReport().equals(nodeHealthChecker.getHealthReport()));

    // Healthy to timeout transition.
    writeNodeHealthScriptFile(timeOutScript, true);
    timerTask.run();
    setHealthStatus(
        healthStatus,
        nodeHealthChecker.isHealthy(),
        nodeHealthChecker.getHealthReport(),
        nodeHealthChecker.getLastHealthReportTime());
    LOG.info("Checking Healthy--->timeout");
    Assert.assertFalse(
        "Node health status reported healthy even after timeout", healthStatus.getIsNodeHealthy());
    Assert.assertTrue(
        "Node script time out message not propogated",
        healthStatus
            .getHealthReport()
            .equals(
                NodeHealthScriptRunner.NODE_HEALTH_SCRIPT_TIMED_OUT_MSG
                    + NodeHealthCheckerService.SEPARATOR
                    + nodeHealthChecker.getDiskHandler().getDisksHealthReport()));
  }