@Test
  public void testOverwrite() throws IOException {
    Path file = new Path("/" + name.getMethodName());
    FSDataOutputStream out1 = FS.create(file);
    FSDataOutputStream out2 = FS.create(file, true);
    out1.write(2);
    out2.write(1);
    try {
      out1.close();
      // a successful close is also OK for us so no assertion here, we just need to confirm that the
      // data in the file are correct.
    } catch (FileNotFoundException fnfe) {
      // hadoop3 throws one of these.
    } catch (RemoteException e) {
      // expected
      assertThat(e.unwrapRemoteException(), instanceOf(LeaseExpiredException.class));
    }
    out2.close();
    try (FSDataInputStream in = FS.open(file)) {
      assertEquals(1, in.read());
      assertEquals(-1, in.read());
    }
  }
Used to confirm that it is OK to overwrite a file which is being written currently.
hbase-asyncfs/src/test/java/org/apache/hadoop/hbase/io/asyncfs/TestOverwriteFileUnderConstruction.java