Search in sources :

Example 16 with LogReader

use of org.apache.distributedlog.api.LogReader in project bookkeeper by apache.

the class TestNonBlockingReads method testHandleInconsistentMetadata.

@Test(timeout = 60000)
public void testHandleInconsistentMetadata() throws Exception {
    String name = "distrlog-inconsistent-metadata-blocking-read";
    long numRecordsWritten = createStreamWithInconsistentMetadata(name);
    DistributedLogManager dlm = createNewDLM(conf, name);
    try {
        LogReader reader = dlm.getInputStream(45);
        long numRecordsRead = 0;
        LogRecord record = reader.readNext(false);
        long lastTxId = -1;
        while (numRecordsRead < numRecordsWritten / 2) {
            if (null != record) {
                DLMTestUtil.verifyLogRecord(record);
                Assert.assertTrue(lastTxId < record.getTransactionId());
                lastTxId = record.getTransactionId();
                numRecordsRead++;
            } else {
                Thread.sleep(1);
            }
            record = reader.readNext(false);
        }
        reader.close();
        assertEquals(numRecordsWritten / 2, numRecordsRead);
    } finally {
        dlm.close();
    }
}
Also used : DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) LogReader(org.apache.distributedlog.api.LogReader) Test(org.junit.Test)

Example 17 with LogReader

use of org.apache.distributedlog.api.LogReader in project bookkeeper by apache.

the class TestNonBlockingReads method testHandleInconsistentMetadataNonBlocking.

@Test(timeout = 15000)
public void testHandleInconsistentMetadataNonBlocking() throws Exception {
    String name = "distrlog-inconsistent-metadata-nonblocking-read";
    long numRecordsWritten = createStreamWithInconsistentMetadata(name);
    DistributedLogManager dlm = createNewDLM(conf, name);
    try {
        LogReader reader = dlm.getInputStream(45);
        long numRecordsRead = 0;
        long lastTxId = -1;
        while (numRecordsRead < (numRecordsWritten / 2)) {
            LogRecord record = reader.readNext(false);
            if (record != null) {
                DLMTestUtil.verifyLogRecord(record);
                Assert.assertTrue(lastTxId < record.getTransactionId());
                lastTxId = record.getTransactionId();
                numRecordsRead++;
            } else {
                Thread.sleep(1);
            }
        }
        reader.close();
    } finally {
        dlm.close();
    }
}
Also used : DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) LogReader(org.apache.distributedlog.api.LogReader) Test(org.junit.Test)

Example 18 with LogReader

use of org.apache.distributedlog.api.LogReader in project bookkeeper by apache.

the class TestNonBlockingReads method testHandleInconsistentMetadataDLSNNonBlocking.

@Test(timeout = 15000)
public void testHandleInconsistentMetadataDLSNNonBlocking() throws Exception {
    String name = "distrlog-inconsistent-metadata-nonblocking-read-dlsn";
    long numRecordsWritten = createStreamWithInconsistentMetadata(name);
    DistributedLogManager dlm = createNewDLM(conf, name);
    try {
        LogReader reader = dlm.getInputStream(DLSN.InitialDLSN);
        long numRecordsRead = 0;
        long lastTxId = -1;
        while (numRecordsRead < numRecordsWritten) {
            LogRecord record = reader.readNext(false);
            if (record != null) {
                DLMTestUtil.verifyLogRecord(record);
                Assert.assertTrue(lastTxId < record.getTransactionId());
                lastTxId = record.getTransactionId();
                numRecordsRead++;
            } else {
                Thread.sleep(1);
            }
        }
        reader.close();
    } finally {
        dlm.close();
    }
}
Also used : DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) LogReader(org.apache.distributedlog.api.LogReader) Test(org.junit.Test)

Example 19 with LogReader

use of org.apache.distributedlog.api.LogReader in project bookkeeper by apache.

the class DLFileSystem method open.

@Override
public FSDataInputStream open(Path path, int bufferSize) throws IOException {
    try {
        DistributedLogManager dlm = namespace.openLog(getStreamName(path));
        LogReader reader;
        try {
            reader = dlm.openLogReader(DLSN.InitialDLSN);
        } catch (LogNotFoundException lnfe) {
            throw new FileNotFoundException(path.toString());
        } catch (LogEmptyException lee) {
            throw new FileNotFoundException(path.toString());
        }
        return new FSDataInputStream(new BufferedFSInputStream(new DLInputStream(dlm, reader, 0L), bufferSize));
    } catch (LogNotFoundException e) {
        throw new FileNotFoundException(path.toString());
    }
}
Also used : LogEmptyException(org.apache.distributedlog.exceptions.LogEmptyException) BufferedFSInputStream(org.apache.hadoop.fs.BufferedFSInputStream) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) LogReader(org.apache.distributedlog.api.LogReader) FileNotFoundException(java.io.FileNotFoundException) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) LogNotFoundException(org.apache.distributedlog.exceptions.LogNotFoundException)

Example 20 with LogReader

use of org.apache.distributedlog.api.LogReader 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)

Aggregations

LogReader (org.apache.distributedlog.api.LogReader)36 Test (org.junit.Test)27 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)26 AsyncLogReader (org.apache.distributedlog.api.AsyncLogReader)9 DLSN (org.apache.distributedlog.DLSN)7 LogRecordWithDLSN (org.apache.distributedlog.LogRecordWithDLSN)7 EndOfStreamException (org.apache.distributedlog.exceptions.EndOfStreamException)7 URI (java.net.URI)3 Namespace (org.apache.distributedlog.api.namespace.Namespace)3 LogNotFoundException (org.apache.distributedlog.exceptions.LogNotFoundException)3 Test (org.testng.annotations.Test)3 DLInputStream (com.twitter.heron.dlog.DLInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 DistributedLogConfiguration (org.apache.distributedlog.DistributedLogConfiguration)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1