@Test
public void testCloseTwice() throws IOException {

  DistributedFileSystem fs = cluster.getFileSystem();
  FSDataOutputStream os = fs.create(new Path("/test"));
  DFSOutputStream dos = (DFSOutputStream) Whitebox.getInternalState(os,
      "wrappedStream");
  @SuppressWarnings("unchecked")
  AtomicReference<IOException> ex = (AtomicReference<IOException>) Whitebox
      .getInternalState(dos, "lastException");
  Assert.assertEquals(null, ex.get());
  dos.close();
  IOException dummy = new IOException("dummy");
  ex.set(dummy);
  try {
    dos.close();
  } catch (IOException e) {
    Assert.assertEquals(e, dummy);
  }
  Assert.assertEquals(null, ex.get());
  dos.close();
}