FileJournalManager implements JournalManager { @Override public void doPreUpgrade() throws IOException { LOG.info("Starting upgrade of edits directory " + sd.getRoot()); try { NNUpgradeUtil.doPreUpgrade(conf, sd); } catch (IOException ioe) { LOG.error("Failed to move aside pre-upgrade storage " + "in image directory " + sd.getRoot(), ioe); throw ioe; } } FileJournalManager(Configuration conf, StorageDirectory sd,
      StorageErrorReporter errorReporter); @Override void close(); @Override void format(NamespaceInfo ns); @Override boolean hasSomeData(); @Override synchronized EditLogOutputStream startLogSegment(long txid,
      int layoutVersion); @Override synchronized void finalizeLogSegment(long firstTxId, long lastTxId); @VisibleForTesting StorageDirectory getStorageDirectory(); @Override synchronized void setOutputBufferCapacity(int size); @Override void purgeLogsOlderThan(long minTxIdToKeep); List<RemoteEditLog> getRemoteEditLogs(long firstTxId,
      boolean inProgressOk); static List<EditLogFile> matchEditLogs(File logDir); @Override synchronized void selectInputStreams(
      Collection<EditLogInputStream> streams, long fromTxId,
      boolean inProgressOk); @Override synchronized void recoverUnfinalizedSegments(); List<EditLogFile> getLogFiles(long fromTxId); EditLogFile getLogFile(long startTxId); static EditLogFile getLogFile(File dir, long startTxId); @Override String toString(); @Override void discardSegments(long startTxid); @Override void doPreUpgrade(); @Override void doUpgrade(Storage storage); @Override void doFinalize(); @Override boolean canRollBack(StorageInfo storage, StorageInfo prevStorage,
      int targetLayoutVersion); @Override void doRollback(); @Override long getJournalCTime();  }
@Test public void testDoPreUpgradeIOError() throws IOException { File storageDir = new File(TestEditLog.TEST_DIR, "preupgradeioerror"); List<URI> editUris = Collections.singletonList(storageDir.toURI()); NNStorage storage = setupEdits(editUris, 5); StorageDirectory sd = storage.dirIterator(NameNodeDirType.EDITS).next(); assertNotNull(sd); FileUtil.setWritable(storageDir, false); FileJournalManager jm = null; try { jm = new FileJournalManager(conf, sd, storage); exception.expect(IOException.class); if (NativeCodeLoader.isNativeCodeLoaded()) { exception.expectMessage("failure in native rename"); } jm.doPreUpgrade(); } finally { IOUtils.cleanup(LOG, jm); FileUtil.setWritable(storageDir, true); FileUtil.fullyDelete(storageDir); } }