Example #1
0
  @Test
  public void testStatusManagerHeartbeats() throws IOException {
    StatusManager stats = new StatusManager();

    FlumeConfiguration cfg = FlumeConfiguration.createTestableConfiguration();
    Clock.resetDefault();
    cfg.set(FlumeConfiguration.WEBAPPS_PATH, "build/webapps");
    cfg.set(FlumeConfiguration.MASTER_STORE, "memory");

    // avoiding gossip ack manager until it shuts down cleanly.
    ConfigStore cfgStore = FlumeMaster.createConfigStore(cfg);
    FlumeMaster fm =
        new FlumeMaster(
            new CommandManager(), new ConfigManager(cfgStore), stats, new MasterAckManager(), cfg);

    fm.getSpecMan().addLogicalNode("physnode", "foo");

    // foo is in state HELLO and has configuration numbered 0
    long prev = Clock.unixTime();
    boolean needsRefresh =
        stats.updateHeartbeatStatus(NetUtils.localhost(), "physnode", "foo", NodeState.HELLO, 0);
    LOG.info(stats.getNodeStatuses());
    assertTrue(needsRefresh);

    StatusManager.NodeStatus ns = stats.getNodeStatuses().get("foo");
    assertEquals(0, ns.version);
    assertTrue(prev <= ns.lastseen);
    assertEquals(NodeState.HELLO, ns.state);
    prev = ns.lastseen;

    needsRefresh =
        stats.updateHeartbeatStatus(NetUtils.localhost(), "physnode", "foo", NodeState.IDLE, 0);
    LOG.info(stats.getNodeStatuses());
    assertFalse(needsRefresh); // no new data flow version
    assertEquals(0, ns.version);
    assertTrue(prev <= ns.lastseen);
    assertEquals(NodeState.IDLE, ns.state);
    prev = ns.lastseen;

    needsRefresh =
        stats.updateHeartbeatStatus(NetUtils.localhost(), "physnode", "foo", NodeState.ACTIVE, 10);
    LOG.info(stats.getNodeStatuses());
    assertFalse(needsRefresh); // node has updated version number, but master
    // has not
    assertEquals(10, ns.version);
    assertTrue(prev <= ns.lastseen);
    assertEquals(NodeState.ACTIVE, ns.state);
    prev = ns.lastseen;

    // same message, no refresh
    needsRefresh =
        stats.updateHeartbeatStatus(NetUtils.localhost(), "physnode", "foo", NodeState.ACTIVE, 10);
    LOG.info(stats.getNodeStatuses());
    assertFalse(needsRefresh); // this is wierd, is this right?
    assertEquals(10, ns.version);
    assertTrue(prev <= ns.lastseen);
    assertEquals(NodeState.ACTIVE, ns.state);
    prev = ns.lastseen;

    // regress to an older version,
    needsRefresh =
        stats.updateHeartbeatStatus(NetUtils.localhost(), "physnode", "foo", NodeState.ACTIVE, 5);
    LOG.info(stats.getNodeStatuses());
    assertFalse(needsRefresh);
    assertEquals(5, ns.version);
    assertTrue(prev <= ns.lastseen);
    assertEquals(NodeState.ACTIVE, ns.state);
    prev = ns.lastseen;

    LOG.info(stats.getReport());
    LOG.info(stats.getName());
  }