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();
}
}
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();
}
}
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();
}
}
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());
}
}
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));
}
Aggregations