public static NameNodeConnector getNameNodeConnector(Configuration conf)
      throws InterruptedException {
    final Collection<URI> namenodes = DFSUtil.getInternalNsRpcUris(conf);
    final Path externalSPSPathId = HdfsServerConstants.MOVER_ID_PATH;
    String serverName = ExternalStoragePolicySatisfier.class.getSimpleName();
    while (true) {
      try {
        final List<NameNodeConnector> nncs = NameNodeConnector
            .newNameNodeConnectors(namenodes,
                serverName,
                externalSPSPathId, conf,
                NameNodeConnector.DEFAULT_MAX_IDLE_ITERATIONS);
        return nncs.get(0);
      } catch (IOException e) {
        LOG.warn("Failed to connect with namenode", e);
        if (e.getMessage().equals("Another " + serverName + " is running.")) {
          ExitUtil.terminate(-1,
              "Exit immediately because another " + serverName + " is running");
        }
        Thread.sleep(3000); // retry the connection after few secs
      }
    }
  }
@Test(timeout = 300000)
  public void testInfiniteStartWhenAnotherSPSRunning()
      throws Exception {

    try {
      // Create cluster and create mover path when get NameNodeConnector.
      createCluster(true);

      // Disable system exit for assert.
      ExitUtil.disableSystemExit();

      // Get NameNodeConnector one more time to simulate starting other sps process.
      // It should exit immediately when another sps is running.
      LambdaTestUtils.intercept(ExitUtil.ExitException.class,
          "Exit immediately because another ExternalStoragePolicySatisfier is running",
          () -> ExternalStoragePolicySatisfier.getNameNodeConnector(config));
    } finally {
      // Reset first exit exception to avoid AssertionError in MiniDFSCluster#shutdown.
      // This has no effect on functionality.
      ExitUtil.resetFirstExitException();
      shutdownCluster();
    }
  }