Search in sources :

Example 6 with EndOfStreamException

use of org.apache.distributedlog.exceptions.EndOfStreamException in project bookkeeper by apache.

the class TestAsyncReaderWriter method testMarkEndOfStreamAtBeginningOfSegment.

@Test(timeout = 60000)
public void testMarkEndOfStreamAtBeginningOfSegment() throws Exception {
    String name = runtime.getMethodName();
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.addConfiguration(testConf);
    confLocal.setOutputBufferSize(0);
    confLocal.setImmediateFlushEnabled(true);
    confLocal.setPeriodicFlushFrequencyMilliSeconds(0);
    DistributedLogManager dlm = createNewDLM(confLocal, name);
    BKAsyncLogWriter writer = (BKAsyncLogWriter) dlm.startAsyncLogSegmentNonPartitioned();
    Utils.ioResult(writer.markEndOfStream());
    try {
        Utils.ioResult(writer.write(DLMTestUtil.getLogRecordInstance(1)));
        fail("Should have thrown");
    } catch (EndOfStreamException ex) {
    }
    writer.close();
    BKAsyncLogReader reader = (BKAsyncLogReader) dlm.getAsyncLogReader(DLSN.InitialDLSN);
    try {
        LogRecord record = Utils.ioResult(reader.readNext());
        fail("Should have thrown");
    } catch (EndOfStreamException ex) {
    }
    Utils.close(reader);
}
Also used : DynamicDistributedLogConfiguration(org.apache.distributedlog.config.DynamicDistributedLogConfiguration) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) EndOfStreamException(org.apache.distributedlog.exceptions.EndOfStreamException) Test(org.junit.Test)

Example 7 with EndOfStreamException

use of org.apache.distributedlog.exceptions.EndOfStreamException in project incubator-pulsar by apache.

the class DLInputStreamTest method testReadEos.

/**
 * Test Case: reader hits eos (end of stream)
 */
@Test
public void testReadEos() throws Exception {
    DistributedLogManager dlm = mock(DistributedLogManager.class);
    LogReader reader = mock(LogReader.class);
    when(dlm.getInputStream(any(DLSN.class))).thenReturn(reader);
    when(reader.readNext(anyBoolean())).thenThrow(new EndOfStreamException("eos"));
    byte[] b = new byte[1];
    DLInputStream in = new DLInputStream(dlm);
    assertEquals("Should return 0 when reading an empty eos stream", 0, in.read(b, 0, 1));
    assertEquals("Should return -1 when reading an empty eos stream", -1, in.read(b, 0, 1));
}
Also used : LogRecordWithDLSN(org.apache.distributedlog.LogRecordWithDLSN) DLSN(org.apache.distributedlog.DLSN) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) EndOfStreamException(org.apache.distributedlog.exceptions.EndOfStreamException) LogReader(org.apache.distributedlog.api.LogReader) Test(org.testng.annotations.Test)

Example 8 with EndOfStreamException

use of org.apache.distributedlog.exceptions.EndOfStreamException in project incubator-pulsar by apache.

the class DLInputStreamTest method testRead.

/**
 * Test Case: read records from the input stream.
 */
@Test
public void testRead() throws Exception {
    DistributedLogManager dlm = mock(DistributedLogManager.class);
    LogReader reader = mock(LogReader.class);
    when(dlm.getInputStream(any(DLSN.class))).thenReturn(reader);
    byte[] data = "test-read".getBytes(UTF_8);
    LogRecordWithDLSN record = mock(LogRecordWithDLSN.class);
    when(record.getPayLoadInputStream()).thenReturn(new ByteArrayInputStream(data));
    when(reader.readNext(anyBoolean())).thenReturn(record).thenThrow(new EndOfStreamException("eos"));
    DLInputStream in = new DLInputStream(dlm);
    int numReads = 0;
    int readByte;
    while ((readByte = in.read()) != -1) {
        assertEquals(data[numReads], readByte);
        ++numReads;
    }
    assertEquals(data.length, numReads);
}
Also used : LogRecordWithDLSN(org.apache.distributedlog.LogRecordWithDLSN) DLSN(org.apache.distributedlog.DLSN) LogRecordWithDLSN(org.apache.distributedlog.LogRecordWithDLSN) ByteArrayInputStream(java.io.ByteArrayInputStream) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) EndOfStreamException(org.apache.distributedlog.exceptions.EndOfStreamException) LogReader(org.apache.distributedlog.api.LogReader) Test(org.testng.annotations.Test)

Example 9 with EndOfStreamException

use of org.apache.distributedlog.exceptions.EndOfStreamException in project incubator-heron by apache.

the class DLInputStreamTest method testReadEos.

/**
 * Test Case: reader hits eos (end of stream)
 */
@Test
public void testReadEos() throws Exception {
    DistributedLogManager dlm = mock(DistributedLogManager.class);
    LogReader reader = mock(LogReader.class);
    when(dlm.getInputStream(any(DLSN.class))).thenReturn(reader);
    when(reader.readNext(anyBoolean())).thenThrow(new EndOfStreamException("eos"));
    byte[] b = new byte[1];
    DLInputStream in = new DLInputStream(dlm);
    assertEquals("Should return 0 when reading an empty eos stream", 0, in.read(b, 0, 1));
    assertEquals("Should return -1 when reading an empty eos stream", -1, in.read(b, 0, 1));
}
Also used : LogRecordWithDLSN(org.apache.distributedlog.LogRecordWithDLSN) DLSN(org.apache.distributedlog.DLSN) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) EndOfStreamException(org.apache.distributedlog.exceptions.EndOfStreamException) LogReader(org.apache.distributedlog.api.LogReader) Test(org.junit.Test)

Example 10 with EndOfStreamException

use of org.apache.distributedlog.exceptions.EndOfStreamException in project incubator-heron by apache.

the class DLInputStreamTest method testRead.

/**
 * Test Case: read records from the input stream.
 */
@Test
public void testRead() throws Exception {
    DistributedLogManager dlm = mock(DistributedLogManager.class);
    LogReader reader = mock(LogReader.class);
    when(dlm.getInputStream(any(DLSN.class))).thenReturn(reader);
    byte[] data = "test-read".getBytes(UTF_8);
    LogRecordWithDLSN record = mock(LogRecordWithDLSN.class);
    when(record.getPayLoadInputStream()).thenReturn(new ByteArrayInputStream(data));
    when(reader.readNext(anyBoolean())).thenReturn(record).thenThrow(new EndOfStreamException("eos"));
    DLInputStream in = new DLInputStream(dlm);
    int numReads = 0;
    int readByte;
    while ((readByte = in.read()) != -1) {
        assertEquals(data[numReads], readByte);
        ++numReads;
    }
    assertEquals(data.length, numReads);
}
Also used : LogRecordWithDLSN(org.apache.distributedlog.LogRecordWithDLSN) DLSN(org.apache.distributedlog.DLSN) LogRecordWithDLSN(org.apache.distributedlog.LogRecordWithDLSN) ByteArrayInputStream(java.io.ByteArrayInputStream) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) EndOfStreamException(org.apache.distributedlog.exceptions.EndOfStreamException) LogReader(org.apache.distributedlog.api.LogReader) Test(org.junit.Test)

Aggregations

EndOfStreamException (org.apache.distributedlog.exceptions.EndOfStreamException)15 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)11 Test (org.junit.Test)9 LogReader (org.apache.distributedlog.api.LogReader)7 DLSN (org.apache.distributedlog.DLSN)4 LogRecordWithDLSN (org.apache.distributedlog.LogRecordWithDLSN)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 AsyncLogReader (org.apache.distributedlog.api.AsyncLogReader)2 DynamicDistributedLogConfiguration (org.apache.distributedlog.config.DynamicDistributedLogConfiguration)2 Test (org.testng.annotations.Test)2 Stopwatch (com.google.common.base.Stopwatch)1 DLInputStream (com.twitter.heron.dlog.DLInputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 Path (java.nio.file.Path)1 DistributedLogConfiguration (org.apache.distributedlog.DistributedLogConfiguration)1 AsyncLogWriter (org.apache.distributedlog.api.AsyncLogWriter)1 LogWriter (org.apache.distributedlog.api.LogWriter)1