use of org.apache.bookkeeper.client.LedgerEntry in project bookkeeper by apache.
the class CompactionTest method verifyLedger.
private void verifyLedger(long lid, long startEntryId, long endEntryId) throws Exception {
LedgerHandle lh = bkc.openLedger(lid, digestType, "".getBytes());
Enumeration<LedgerEntry> entries = lh.readEntries(startEntryId, endEntryId);
while (entries.hasMoreElements()) {
LedgerEntry entry = entries.nextElement();
assertEquals(msg, new String(entry.getEntry()));
}
}
use of org.apache.bookkeeper.client.LedgerEntry in project bookkeeper by apache.
the class BookieMultipleJournalsTest method testMultipleWritesAndBookieRestart.
@Test
public void testMultipleWritesAndBookieRestart() throws Exception {
// Creates few ledgers so that writes are spread across all journals
final int numLedgers = 16;
final int numEntriesPerLedger = 30;
List<LedgerHandle> writeHandles = new ArrayList<>();
for (int i = 0; i < numLedgers; i++) {
writeHandles.add(bkc.createLedger(1, 1, DigestType.CRC32, new byte[0]));
}
for (int i = 0; i < numEntriesPerLedger; i++) {
for (int j = 0; j < numLedgers; j++) {
writeHandles.get(j).addEntry(("entry-" + i).getBytes());
}
}
restartBookies();
// Write another set of entries
for (int i = numEntriesPerLedger; i < 2 * numEntriesPerLedger; i++) {
for (int j = 0; j < numLedgers; j++) {
writeHandles.get(j).addEntry(("entry-" + i).getBytes());
}
}
restartBookies();
List<LedgerHandle> readHandles = new ArrayList<>();
for (int i = 0; i < numLedgers; i++) {
readHandles.add(bkc.openLedger(writeHandles.get(i).getId(), DigestType.CRC32, new byte[0]));
}
for (int i = 0; i < numLedgers; i++) {
Enumeration<LedgerEntry> entries = readHandles.get(i).readEntries(0, numEntriesPerLedger - 1);
for (int j = 0; j < numEntriesPerLedger; j++) {
LedgerEntry entry = entries.nextElement();
assertEquals("entry-" + j, new String(entry.getEntry()));
}
}
}
use of org.apache.bookkeeper.client.LedgerEntry in project bookkeeper by apache.
the class IndexCorruptionTest method testNoSuchLedger.
@Test
public void testNoSuchLedger() throws Exception {
LOG.debug("Testing NoSuchLedger");
SyncThread syncThread = bs.get(0).getBookie().syncThread;
syncThread.suspendSync();
// Create a ledger
LedgerHandle lh = bkc.createLedger(1, 1, digestType, "".getBytes());
// Close the ledger which cause a readEntry(0) call
LedgerHandle newLh = bkc.openLedger(lh.getId(), digestType, "".getBytes());
// Create a new ledger to write entries
String dummyMsg = "NoSuchLedger";
int numMsgs = 3;
LedgerHandle wlh = bkc.createLedger(1, 1, digestType, "".getBytes());
for (int i = 0; i < numMsgs; i++) {
wlh.addEntry(dummyMsg.getBytes());
}
syncThread.resumeSync();
// trigger sync
Thread.sleep(2 * baseConf.getFlushInterval());
// restart bookies
restartBookies();
Enumeration<LedgerEntry> seq = wlh.readEntries(0, numMsgs - 1);
assertTrue("Enumeration of ledger entries has no element", seq.hasMoreElements());
int entryId = 0;
while (seq.hasMoreElements()) {
LedgerEntry e = seq.nextElement();
assertEquals(entryId, e.getEntryId());
assertArrayEquals(dummyMsg.getBytes(), e.getEntry());
++entryId;
}
assertEquals(entryId, numMsgs);
}
use of org.apache.bookkeeper.client.LedgerEntry in project bookkeeper by apache.
the class IndexCorruptionTest method testEmptyIndexPage.
@Test
public void testEmptyIndexPage() throws Exception {
LOG.debug("Testing EmptyIndexPage");
SyncThread syncThread = bs.get(0).getBookie().syncThread;
assertNotNull("Not found SyncThread.", syncThread);
syncThread.suspendSync();
// Create a ledger
LedgerHandle lh1 = bkc.createLedger(1, 1, digestType, "".getBytes());
String dummyMsg = "NoSuchLedger";
// write two page entries to ledger 2
int numMsgs = 2 * pageSize / 8;
LedgerHandle lh2 = bkc.createLedger(1, 1, digestType, "".getBytes());
for (int i = 0; i < numMsgs; i++) {
lh2.addEntry(dummyMsg.getBytes());
}
syncThread.resumeSync();
// trigger sync
Thread.sleep(2 * baseConf.getFlushInterval());
syncThread.suspendSync();
// Close ledger 1 which cause a readEntry(0) call
LedgerHandle newLh1 = bkc.openLedger(lh1.getId(), digestType, "".getBytes());
// write another 3 entries to ledger 2
for (int i = 0; i < 3; i++) {
lh2.addEntry(dummyMsg.getBytes());
}
syncThread.resumeSync();
// wait for sync again
Thread.sleep(2 * baseConf.getFlushInterval());
// restart bookies
restartBookies();
numMsgs += 3;
Enumeration<LedgerEntry> seq = lh2.readEntries(0, numMsgs - 1);
assertTrue("Enumeration of ledger entries has no element", seq.hasMoreElements());
int entryId = 0;
while (seq.hasMoreElements()) {
LedgerEntry e = seq.nextElement();
assertEquals(entryId, e.getEntryId());
assertArrayEquals(dummyMsg.getBytes(), e.getEntry());
++entryId;
}
assertEquals(entryId, numMsgs);
}
use of org.apache.bookkeeper.client.LedgerEntry in project bookkeeper by apache.
the class GSSAPIBookKeeperTest method entryCount.
/**
* check if the entry exists. Restart the bookie to allow access
*/
private int entryCount(long ledgerId, ClientConfiguration clientConf) throws Exception {
LOG.info("Counting entries in {}", ledgerId);
for (ServerConfiguration conf : bsConfs) {
conf.setUseHostNameAsBookieID(true);
conf.setBookieAuthProviderFactoryClass(SASLBookieAuthProviderFactory.class.getName());
}
clientConf.setClientAuthProviderFactoryClass(SASLClientProviderFactory.class.getName());
restartBookies();
try (BookKeeper bkc = new BookKeeper(clientConf, zkc);
LedgerHandle lh = bkc.openLedger(ledgerId, DigestType.CRC32, PASSWD)) {
if (lh.getLastAddConfirmed() < 0) {
return 0;
}
Enumeration<LedgerEntry> e = lh.readEntries(0, lh.getLastAddConfirmed());
int count = 0;
while (e.hasMoreElements()) {
count++;
assertTrue("Should match what we wrote", Arrays.equals(e.nextElement().getEntry(), ENTRY));
}
return count;
}
}
Aggregations