use of alluxio.master.journal.JournalWriter.EntryOutputStream in project alluxio by Alluxio.
the class JournalWriterTest method rotateLogOnFlushIOException.
@Test
public void rotateLogOnFlushIOException() throws Exception {
// Setup so that we can trigger an IOException when flush is called on the underlying stream.
JournalWriter mockJournalWriter = PowerMockito.mock(JournalWriter.class);
OutputStream mockOutStream = mock(OutputStream.class);
UnderFileSystem mockUfs = mock(UnderFileSystem.class);
doReturn(mockOutStream).when(mockUfs).create(eq(mJournal.getCurrentLogFilePath()), any(CreateOptions.class));
EntryOutputStream entryOutStream = new EntryOutputStream(mockUfs, mJournal.getCurrentLogFilePath(), mJournal.getJournalFormatter(), mockJournalWriter);
entryOutStream.writeEntry(JournalEntry.newBuilder().build());
doThrow(new IOException("flush failed")).when(mockOutStream).flush();
try {
entryOutStream.flush();
Assert.fail("Should have thrown an exception");
} catch (IOException ignored) {
// expected
}
// Undo the earlier mocking so that the writeEntry doesn't fail.
doNothing().when(mockOutStream).flush();
// The rotation happens the next time an entry is written.
entryOutStream.writeEntry(JournalEntry.newBuilder().build());
verify(mockJournalWriter).completeCurrentLog();
}
use of alluxio.master.journal.JournalWriter.EntryOutputStream in project alluxio by Alluxio.
the class JournalWriterTest method rotateLogOnWriteException.
@Test
public void rotateLogOnWriteException() throws Exception {
// Setup so that we can trigger an IOException when a write is performed on the underlying
// stream.
JournalWriter mockJournalWriter = PowerMockito.mock(JournalWriter.class);
FSDataOutputStream mockOutStream = mock(FSDataOutputStream.class);
UnderFileSystem mockUfs = mock(UnderFileSystem.class);
doReturn(mockOutStream).when(mockUfs).create(eq(mJournal.getCurrentLogFilePath()), any(CreateOptions.class));
EntryOutputStream entryOutStream = new EntryOutputStream(mockUfs, mJournal.getCurrentLogFilePath(), mJournal.getJournalFormatter(), mockJournalWriter);
doThrow(new IOException("write failed")).when(mockOutStream).write(any(byte[].class), anyInt(), anyInt());
try {
entryOutStream.writeEntry(JournalEntry.newBuilder().setSequenceNumber(10).build());
Assert.fail("Should have thrown an exception");
} catch (IOException ignored) {
// expected
}
// Undo the earlier mocking so that the writeEntry doesn't fail.
doNothing().when(mockOutStream).write(any(byte[].class), anyInt(), anyInt());
// The rotation happens the next time an entry is written.
entryOutStream.writeEntry(JournalEntry.newBuilder().build());
verify(mockJournalWriter).completeCurrentLog();
}
use of alluxio.master.journal.JournalWriter.EntryOutputStream in project alluxio by Alluxio.
the class JournalWriterTest method rotateLogOnSyncException.
@Test
public void rotateLogOnSyncException() throws Exception {
// Setup so that we can trigger an IOException when sync is called on the underlying stream.
JournalWriter mockJournalWriter = PowerMockito.mock(JournalWriter.class);
FSDataOutputStream mockOutStream = mock(FSDataOutputStream.class);
UnderFileSystem mockUfs = mock(UnderFileSystem.class);
doReturn(mockOutStream).when(mockUfs).create(eq(mJournal.getCurrentLogFilePath()), any(CreateOptions.class));
EntryOutputStream entryOutStream = new EntryOutputStream(mockUfs, mJournal.getCurrentLogFilePath(), mJournal.getJournalFormatter(), mockJournalWriter);
entryOutStream.writeEntry(JournalEntry.newBuilder().build());
doThrow(new IOException("sync failed")).when(mockOutStream).sync();
try {
entryOutStream.flush();
Assert.fail("Should have thrown an exception");
} catch (IOException ignored) {
// expected
}
// Undo the earlier mocking so that the writeEntry doesn't fail.
doNothing().when(mockOutStream).sync();
// The rotation happens the next time an entry is written.
entryOutStream.writeEntry(JournalEntry.newBuilder().build());
verify(mockJournalWriter).completeCurrentLog();
}
Aggregations