hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/node/TestNodeManager.java
@Test
  public void testScmHeartbeatAfterRestart() throws Exception {
    OzoneConfiguration conf = getConf();
    conf.getTimeDuration(ScmConfigKeys.OZONE_SCM_HEARTBEAT_PROCESS_INTERVAL,
        100, TimeUnit.MILLISECONDS);
    DatanodeDetails datanodeDetails = TestUtils.getDatanodeDetails();
    try (SCMNodeManager nodemanager = createNodeManager(conf)) {
      nodemanager.register(datanodeDetails.getProtoBufMessage());
      List<SCMCommand> command = nodemanager.sendHeartbeat(
          datanodeDetails.getProtoBufMessage(),
          null, reportState);
      Assert.assertTrue(nodemanager.getAllNodes().contains(datanodeDetails));
      Assert.assertTrue("On regular HB calls, SCM responses a "
          + "datanode with an empty command list", command.isEmpty());
    }

    // Sends heartbeat without registering to SCM.
    // This happens when SCM restarts.
    try (SCMNodeManager nodemanager = createNodeManager(conf)) {
      Assert.assertFalse(nodemanager
          .getAllNodes().contains(datanodeDetails));
      try {
        // SCM handles heartbeat asynchronously.
        // It may need more than one heartbeat processing to
        // send the notification.
        GenericTestUtils.waitFor(new Supplier<Boolean>() {
          @Override public Boolean get() {
            List<SCMCommand> command =
                nodemanager.sendHeartbeat(datanodeDetails.getProtoBufMessage(),
                    null, reportState);
            return command.size() == 1 && command.get(0).getType()
                .equals(SCMCmdType.reregisterCommand);
          }
        }, 100, 3 * 1000);
      } catch (TimeoutException e) {
        Assert.fail("Times out to verify that scm informs "
            + "datanode to re-register itself.");
      }
    }
  }
/**
   * Asserts scm informs datanodes to re-register with the nodemanager
   * on a restart.
   *
   * @throws Exception
   */
Asserts scm informs datanodes to re-register with the nodemanager
on a restart.

@throws Exception
Asserts scm informs datanodes to re - register with the nodemanager on a restart . @throws Exception
@Test
  public void testScmHeartbeatAfterRestart() throws Exception {
    OzoneConfiguration conf = getConf();
    conf.getTimeDuration(ScmConfigKeys.OZONE_SCM_HEARTBEAT_PROCESS_INTERVAL,
        100, TimeUnit.MILLISECONDS);
    DatanodeDetails datanodeDetails = TestUtils.getDatanodeDetails();
    try (SCMNodeManager nodemanager = createNodeManager(conf)) {
      nodemanager.register(datanodeDetails.getProtoBufMessage());
      List<SCMCommand> command = nodemanager.sendHeartbeat(
          datanodeDetails.getProtoBufMessage(),
          null, reportState);
      Assert.assertTrue(nodemanager.getAllNodes().contains(datanodeDetails));
      Assert.assertTrue("On regular HB calls, SCM responses a "
          + "datanode with an empty command list", command.isEmpty());
    }
    try (SCMNodeManager nodemanager = createNodeManager(conf)) {
      Assert.assertFalse(nodemanager
          .getAllNodes().contains(datanodeDetails));
      try {
        GenericTestUtils.waitFor(new Supplier<Boolean>() {
          @Override public Boolean get() {
            List<SCMCommand> command =
                nodemanager.sendHeartbeat(datanodeDetails.getProtoBufMessage(),
                    null, reportState);
            return command.size() == 1 && command.get(0).getType()
                .equals(SCMCmdType.reregisterCommand);
          }
        }, 100, 3 * 1000);
      } catch (TimeoutException e) {
        Assert.fail("Times out to verify that scm informs "
            + "datanode to re-register itself.");
      }
    }
  }
@ Test public void testScmHeartbeatAfterRestart ( ) throws Exception { OzoneConfiguration conf = getConf ( ) ; conf . getTimeDuration ( ScmConfigKeys . OZONE_SCM_HEARTBEAT_PROCESS_INTERVAL , 100 , TimeUnit . MILLISECONDS ) ; DatanodeDetails datanodeDetails = TestUtils . getDatanodeDetails ( ) ; try ( SCMNodeManager nodemanager = createNodeManager ( conf ) ) { nodemanager . register ( datanodeDetails . getProtoBufMessage ( ) ) ; List < SCMCommand > command = nodemanager . sendHeartbeat ( datanodeDetails . getProtoBufMessage ( ) , null , reportState ) ; Assert . assertTrue ( nodemanager . getAllNodes ( ) . contains ( datanodeDetails ) ) ; Assert . assertTrue ( "On regular HB calls, SCM responses a " + "datanode with an empty command list" , command . isEmpty ( ) ) ; } try ( SCMNodeManager nodemanager = createNodeManager ( conf ) ) { Assert . assertFalse ( nodemanager . getAllNodes ( ) . contains ( datanodeDetails ) ) ; try { GenericTestUtils . waitFor ( new Supplier < Boolean > ( ) { @ Override public Boolean get ( ) { List < SCMCommand > command = nodemanager . sendHeartbeat ( datanodeDetails . getProtoBufMessage ( ) , null , reportState ) ; return command . size ( ) == 1 && command . get ( 0 ) . getType ( ) . equals ( SCMCmdType . reregisterCommand ) ; } } , 100 , 3 * 1000 ) ; } catch ( TimeoutException e ) { Assert . fail ( "Times out to verify that scm informs " + "datanode to re-register itself." ) ; } } }
Asserts scm informs datanodes to re-register with the nodemanager
 on a restart.
Asserts scm informs datanodes to re - register with the nodemanager on a restart .
// Sends heartbeat without registering to SCM. // This happens when SCM restarts. // SCM handles heartbeat asynchronously. // It may need more than one heartbeat processing to // send the notification.