@VisibleForTesting
  static Configuration getConfiguration() {
    Configuration conf = new HdfsConfiguration();
    conf.addResource(FedBalance.FED_BALANCE_DEFAULT_XML);
    conf.addResource(FedBalance.FED_BALANCE_SITE_XML);
    return conf;
  }
@Test
  public void testClearStaleNamespacesInRouterStateIdContext() throws Exception {
    Router testRouter = new Router();
    Configuration routerConfig = DFSRouter.getConfiguration();
    routerConfig.set(FEDERATION_STORE_MEMBERSHIP_EXPIRATION_MS, "2000");
    routerConfig.set(RBFConfigKeys.DFS_ROUTER_SAFEMODE_ENABLE, "false");
    // Mock resolver classes
    routerConfig.setClass(RBFConfigKeys.FEDERATION_NAMENODE_RESOLVER_CLIENT_CLASS,
        MockResolver.class, ActiveNamenodeResolver.class);
    routerConfig.setClass(RBFConfigKeys.FEDERATION_FILE_RESOLVER_CLIENT_CLASS,
        MockResolver.class, FileSubclusterResolver.class);

    testRouter.init(routerConfig);
    String nsID1 = "ns0";
    String nsID2 = "ns1";
    MockResolver resolver = (MockResolver)testRouter.getNamenodeResolver();
    resolver.registerNamenode(createNamenodeReport(nsID1, "nn1",
        HAServiceProtocol.HAServiceState.ACTIVE));
    resolver.registerNamenode(createNamenodeReport(nsID2, "nn1",
        HAServiceProtocol.HAServiceState.ACTIVE));

    RouterRpcServer rpcServer = testRouter.getRpcServer();

    rpcServer.getRouterStateIdContext().getNamespaceStateId(nsID1);
    rpcServer.getRouterStateIdContext().getNamespaceStateId(nsID2);

    resolver.disableNamespace(nsID1);
    Thread.sleep(3000);
    RouterStateIdContext context = rpcServer.getRouterStateIdContext();
    assertEquals(2, context.getNamespaceIdMap().size());

    testRouter.start();
    Thread.sleep(3000);
    // wait clear stale namespaces
    RouterStateIdContext routerStateIdContext = rpcServer.getRouterStateIdContext();
    int size = routerStateIdContext.getNamespaceIdMap().size();
    assertEquals(1, size);
    rpcServer.stop();
    rpcServer.close();
    testRouter.close();
  }