@Test
public void testStorageWithRemainingCapacity() throws Exception {

  final Configuration conf = new HdfsConfiguration();
  final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build();
  FileSystem fs = FileSystem.get(conf);
  Path file1 = null;
  try {
    cluster.waitActive();
    final FSNamesystem namesystem = cluster.getNamesystem();
    final String poolId = namesystem.getBlockPoolId();
    final DatanodeRegistration nodeReg =
      DataNodeTestUtils.getDNRegistrationForBP(cluster.getDataNodes().
      		get(0), poolId);
    final DatanodeDescriptor dd = NameNodeAdapter.getDatanode(namesystem,
  		  nodeReg);
    // By default, MiniDFSCluster will create 1 datanode with 2 storages.
    // Assigning 64k for remaining storage capacity and will 
    //create a file with 100k.
    for(DatanodeStorageInfo storage:  dd.getStorageInfos()) { 
  	  storage.setUtilizationForTesting(65536, 0, 65536, 0);
    }
    //sum of the remaining capacity of both the storages
    dd.setRemaining(131072);
    file1 = new Path("testRemainingStorage.dat");
    try {
      DFSTestUtil.createFile(fs, file1, 102400, 102400, 102400, (short)1,
      		0x1BAD5EED);
    }
    catch (RemoteException re) {
  	  GenericTestUtils.assertExceptionContains("nodes instead of "
  	  		+ "minReplication", re);
    }
  }
  finally {
    // Clean up
    assertTrue(fs.exists(file1));
    fs.delete(file1, true);
    assertTrue(!fs.exists(file1));
    cluster.shutdown();
  }
}