コード例 #1
0
  public void testExclude() throws Exception {
    LOG.info("Starting testExlude");
    JobConf conf = new JobConf();
    // Start with an empty excludes file.
    File excludesFile = new File(TEST_DIR, "excludes");
    conf.set(CoronaConf.EXCLUDE_HOSTS_FILE, excludesFile.getAbsolutePath());
    excludesFile.delete();
    excludesFile.createNewFile();

    corona = new MiniCoronaCluster.Builder().conf(conf).numTaskTrackers(1).build();

    // 0 excluded nodes at first.
    NodeManager nm = corona.getClusterManager().nodeManager;
    assertEquals(0, nm.getExcludedNodeCount());

    // Wait for 1 node to be alive.
    long start = System.currentTimeMillis();
    while (System.currentTimeMillis() - start < 30 * 1000 && nm.getAliveNodeCount() < 1) {
      Thread.sleep(100);
    }
    List<String> aliveNodes = nm.getAliveNodes();
    assertEquals(1, aliveNodes.size());

    // Exclude the only host.
    PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(excludesFile)));
    writer.println(aliveNodes.get(0));
    writer.close();

    conf.set(CoronaConf.CM_ADDRESS, "localhost:" + corona.getClusterManagerPort());
    CoronaAdmin coronaAdmin = new CoronaAdmin();
    coronaAdmin.setConf(conf);
    String[] args = {"-refreshNodes"};
    int ret = ToolRunner.run(coronaAdmin, args);
    assertEquals("Refresh nodes failed", 0, ret);

    // Should have 1 excluded host now.
    assertEquals(1, nm.getExcludedNodes().size());
  }
コード例 #2
0
 @Override
 protected void tearDown() {
   if (corona != null) {
     corona.shutdown();
   }
 }