@Override
    protected Writer createWriterInstance(FileSystem fs, Path path) throws IOException {
      final Writer w = super.createWriterInstance(fs, path);
      return new Writer() {
        @Override
        public void close() throws IOException {
          w.close();
        }

        @Override
        public void sync(boolean forceSync) throws IOException {
          if (throwSyncException) {
            throw new IOException("FAKE! Failed to replace a bad datanode...");
          }
          w.sync(forceSync);
        }

        @Override
        public void append(Entry entry) throws IOException {
          if (throwAppendException) {
            throw new IOException("FAKE! Failed to replace a bad datanode...");
          }
          w.append(entry);
        }

        @Override
        public long getLength() {
          return w.getLength();
        }

        @Override
        public long getSyncedLength() {
          return w.getSyncedLength();
        }
      };
    }
Testing sync/append failures. Copied from TestHRegion.
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFailedAppendAndSync.java