Search in sources :

Example 1 with EntryOutputStream

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();
}
Also used : FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) EntryOutputStream(alluxio.master.journal.JournalWriter.EntryOutputStream) OutputStream(java.io.OutputStream) EntryOutputStream(alluxio.master.journal.JournalWriter.EntryOutputStream) IOException(java.io.IOException) UnderFileSystem(alluxio.underfs.UnderFileSystem) CreateOptions(alluxio.underfs.options.CreateOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with EntryOutputStream

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();
}
Also used : EntryOutputStream(alluxio.master.journal.JournalWriter.EntryOutputStream) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) IOException(java.io.IOException) UnderFileSystem(alluxio.underfs.UnderFileSystem) CreateOptions(alluxio.underfs.options.CreateOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with EntryOutputStream

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();
}
Also used : EntryOutputStream(alluxio.master.journal.JournalWriter.EntryOutputStream) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) IOException(java.io.IOException) UnderFileSystem(alluxio.underfs.UnderFileSystem) CreateOptions(alluxio.underfs.options.CreateOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

EntryOutputStream (alluxio.master.journal.JournalWriter.EntryOutputStream)3 UnderFileSystem (alluxio.underfs.UnderFileSystem)3 CreateOptions (alluxio.underfs.options.CreateOptions)3 IOException (java.io.IOException)3 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 OutputStream (java.io.OutputStream)1