EditLogFileOutputStream extends EditLogOutputStream { @Override public void close() throws IOException { if (fp == null) { throw new IOException("Trying to use aborted output stream"); } try { if (doubleBuf != null) { doubleBuf.close(); doubleBuf = null; } if (fc != null && fc.isOpen()) { fc.truncate(fc.position()); fc.close(); fc = null; } fp.close(); fp = null; } finally { IOUtils.cleanup(LOG, fc, fp); doubleBuf = null; fc = null; fp = null; } fp = null; } EditLogFileOutputStream(Configuration conf, File name, int size); @Override void write(FSEditLogOp op); @Override void writeRaw(byte[] bytes, int offset, int length); @Override void create(int layoutVersion); @VisibleForTesting static void writeHeader(int layoutVersion, DataOutputStream out); @Override void close(); @Override void abort(); @Override void setReadyToFlush(); @Override void flushAndSync(boolean durable); @Override boolean shouldForceSync(); @Override String toString(); boolean isOpen(); @VisibleForTesting void setFileChannelForTesting(FileChannel fc); @VisibleForTesting FileChannel getFileChannelForTesting(); @VisibleForTesting static void setShouldSkipFsyncForTesting(boolean skip); static final int MIN_PREALLOCATION_LENGTH; }
@Test public void testEditLogFileOutputStreamCloseClose() throws IOException { EditLogFileOutputStream editLogStream = new EditLogFileOutputStream(conf, TEST_EDITS, 0); editLogStream.close(); try { editLogStream.close(); } catch (IOException ioe) { String msg = StringUtils.stringifyException(ioe); assertTrue(msg, msg.contains("Trying to use aborted output stream")); } }