@Test(timeout=100000)
public void testBalancerWithPinnedBlocks() throws Exception {

  // This test assumes stick-bit based block pin mechanism available only
  // in Linux/Unix. It can be unblocked on Windows when HDFS-7759 is ready to
  // provide a different mechanism for Windows.
  assumeNotWindows();
  final Configuration conf = new HdfsConfiguration();
  initConf(conf);
  conf.setBoolean(DFS_DATANODE_BLOCK_PINNING_ENABLED, true);
  long[] capacities =  new long[] { CAPACITY, CAPACITY };
  String[] hosts = {"host0", "host1"};
  String[] racks = { RACK0, RACK1 };
  int numOfDatanodes = capacities.length;
  cluster = new MiniDFSCluster.Builder(conf).numDataNodes(capacities.length)
      .hosts(hosts).racks(racks).simulatedCapacities(capacities).build();
  cluster.waitActive();
  client = NameNodeProxies.createProxy(conf,
      cluster.getFileSystem(0).getUri(), ClientProtocol.class).getProxy();
  // fill up the cluster to be 80% full
  long totalCapacity = sum(capacities);
  long totalUsedSpace = totalCapacity * 8 / 10;
  InetSocketAddress[] favoredNodes = new InetSocketAddress[numOfDatanodes];
  for (int i = 0; i < favoredNodes.length; i++) {
    // DFSClient will attempt reverse lookup. In case it resolves
    // "127.0.0.1" to "localhost", we manually specify the hostname.
    int port = cluster.getDataNodes().get(i).getXferAddress().getPort();
    favoredNodes[i] = new InetSocketAddress(hosts[i], port);
  }
  DFSTestUtil.createFile(cluster.getFileSystem(0), filePath, false, 1024,
      totalUsedSpace / numOfDatanodes, DEFAULT_BLOCK_SIZE,
      (short) numOfDatanodes, 0, false, favoredNodes);
  // start up an empty node with the same capacity
  cluster.startDataNodes(conf, 1, true, null, new String[] { RACK2 },
      new long[] { CAPACITY });
  totalCapacity += CAPACITY;
  // run balancer and validate results
  waitForHeartBeat(totalUsedSpace, totalCapacity, client, cluster);
  // start rebalancing
  Collection<URI> namenodes = DFSUtil.getInternalNsRpcUris(conf);
  int r = Balancer.run(namenodes, BalancerParameters.DEFAULT, conf);
  assertEquals(ExitStatus.NO_MOVE_PROGRESS.getExitCode(), r);
}