use of org.apache.distributedlog.LogRecordWithDLSN in project bookkeeper by apache.
the class TestBKLogSegmentEntryReader method testReadEntriesFromCompleteLogSegment.
@Test(timeout = 60000)
public void testReadEntriesFromCompleteLogSegment() throws Exception {
DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.addConfiguration(conf);
confLocal.setOutputBufferSize(0);
confLocal.setPeriodicFlushFrequencyMilliSeconds(0);
confLocal.setImmediateFlushEnabled(false);
confLocal.setNumPrefetchEntriesPerLogSegment(10);
confLocal.setMaxPrefetchEntriesPerLogSegment(10);
DistributedLogManager dlm = createNewDLM(confLocal, runtime.getMethodName());
generateCompletedLogSegments(dlm, confLocal, 1, 20);
List<LogSegmentMetadata> segments = dlm.getLogSegments();
assertEquals(segments.size() + " log segments found, expected to be only one", 1, segments.size());
BKLogSegmentEntryReader reader = createEntryReader(segments.get(0), 0, confLocal);
reader.start();
boolean done = false;
long txId = 1L;
long entryId = 0L;
while (!done) {
Entry.Reader entryReader;
try {
entryReader = Utils.ioResult(reader.readNext(1)).get(0);
} catch (EndOfLogSegmentException eol) {
done = true;
continue;
}
LogRecordWithDLSN record = entryReader.nextRecord();
while (null != record) {
if (!record.isControl()) {
DLMTestUtil.verifyLogRecord(record);
assertEquals(txId, record.getTransactionId());
++txId;
}
DLSN dlsn = record.getDlsn();
assertEquals(1L, dlsn.getLogSegmentSequenceNo());
assertEquals(entryId, dlsn.getEntryId());
record = entryReader.nextRecord();
}
++entryId;
}
assertEquals(21, txId);
assertFalse(reader.hasCaughtUpOnInprogress());
Utils.close(reader);
}
use of org.apache.distributedlog.LogRecordWithDLSN in project bookkeeper by apache.
the class TestDistributedLogTool method testToolTruncateStream.
@Test(timeout = 60000)
public void testToolTruncateStream() throws Exception {
DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.addConfiguration(conf);
confLocal.setLogSegmentCacheEnabled(false);
DistributedLogManager dlm = DLMTestUtil.createNewDLM("testToolTruncateStream", confLocal, defaultUri);
DLMTestUtil.generateCompletedLogSegments(dlm, confLocal, 3, 1000);
DLSN dlsn = new DLSN(2, 1, 0);
TruncateStreamCommand cmd = new TruncateStreamCommand();
cmd.setDlsn(dlsn);
cmd.setUri(defaultUri);
cmd.setStreamName("testToolTruncateStream");
cmd.setForce(true);
assertEquals(0, cmd.runCmd());
LogReader reader = dlm.getInputStream(0);
LogRecordWithDLSN record = reader.readNext(false);
assertEquals(dlsn, record.getDlsn());
reader.close();
dlm.close();
}
use of org.apache.distributedlog.LogRecordWithDLSN in project bookkeeper by apache.
the class MVCCStoreFactoryImplTest method setup.
@Before
public void setup() throws IOException {
this.namespace = mock(Namespace.class);
DistributedLogManager dlm = mock(DistributedLogManager.class);
when(dlm.asyncClose()).thenReturn(FutureUtils.Void());
when(namespace.openLog(anyString())).thenReturn(dlm);
AsyncLogWriter logWriter = mock(AsyncLogWriter.class);
when(dlm.openAsyncLogWriter()).thenReturn(FutureUtils.value(logWriter));
when(logWriter.getLastTxId()).thenReturn(-1L);
DLSN dlsn = new DLSN(0L, 0L, 0L);
when(logWriter.write(any(LogRecord.class))).thenReturn(FutureUtils.value(dlsn));
when(logWriter.asyncClose()).thenReturn(FutureUtils.Void());
AsyncLogReader logReader = mock(AsyncLogReader.class);
when(dlm.openAsyncLogReader(anyLong())).thenReturn(FutureUtils.value(logReader));
when(logReader.asyncClose()).thenReturn(FutureUtils.Void());
LogRecordWithDLSN record = new LogRecordWithDLSN(dlsn, 0L, NOP_CMD.toByteArray(), 0L);
when(logReader.readNext()).thenReturn(FutureUtils.value(record));
int numDirs = 3;
this.storeDirs = new File[numDirs];
for (int i = 0; i < numDirs; i++) {
storeDirs[i] = testDir.newFolder("test-" + i);
}
this.resources = StorageResources.create(StorageResourcesSpec.builder().numCheckpointThreads(3).numIOReadThreads(3).numIOWriteThreads(3).build());
this.factory = new MVCCStoreFactoryImpl(() -> namespace, storeDirs, resources, false);
}
use of org.apache.distributedlog.LogRecordWithDLSN in project bookkeeper by apache.
the class MVCCAsyncStoreTestBase method mockNamespace.
private static Namespace mockNamespace() throws Exception {
Namespace namespace = mock(Namespace.class);
DistributedLogManager dlm = mock(DistributedLogManager.class);
when(dlm.asyncClose()).thenReturn(FutureUtils.Void());
when(namespace.openLog(anyString())).thenReturn(dlm);
AsyncLogWriter logWriter = mock(AsyncLogWriter.class);
when(dlm.openAsyncLogWriter()).thenReturn(FutureUtils.value(logWriter));
when(logWriter.getLastTxId()).thenReturn(-1L);
DLSN dlsn = new DLSN(0L, 0L, 0L);
when(logWriter.write(any(LogRecord.class))).thenReturn(FutureUtils.value(dlsn));
when(logWriter.asyncClose()).thenReturn(FutureUtils.Void());
AsyncLogReader logReader = mock(AsyncLogReader.class);
when(dlm.openAsyncLogReader(anyLong())).thenReturn(FutureUtils.value(logReader));
when(logReader.asyncClose()).thenReturn(FutureUtils.Void());
LogRecordWithDLSN record = new LogRecordWithDLSN(dlsn, 0L, NOP_CMD.toByteArray(), 0L);
when(logReader.readNext()).thenReturn(FutureUtils.value(record));
return namespace;
}
Aggregations