use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.
the class BookieWriteLedgerTest method testWithMultipleBookieFailuresInLastEnsemble.
/**
* Verify write when few bookie failures in last ensemble and forcing
* ensemble reformation.
*/
@Test
public void testWithMultipleBookieFailuresInLastEnsemble() throws Exception {
// Create a ledger
lh = bkc.createLedger(5, 4, digestType, ledgerPassword);
LOG.info("Ledger ID: " + lh.getId());
for (int i = 0; i < numEntriesToWrite; i++) {
ByteBuffer entry = ByteBuffer.allocate(4);
entry.putInt(rng.nextInt(maxInt));
entry.position(0);
entries1.add(entry.array());
lh.addEntry(entry.array());
}
// Start three more bookies
startNewBookie();
startNewBookie();
startNewBookie();
// Shutdown three bookies in the last ensemble and continue writing
ArrayList<BookieSocketAddress> ensemble = lh.getLedgerMetadata().getEnsembles().entrySet().iterator().next().getValue();
killBookie(ensemble.get(0));
killBookie(ensemble.get(1));
killBookie(ensemble.get(2));
int i = numEntriesToWrite;
numEntriesToWrite = numEntriesToWrite + 50;
for (; i < numEntriesToWrite; i++) {
ByteBuffer entry = ByteBuffer.allocate(4);
entry.putInt(rng.nextInt(maxInt));
entry.position(0);
entries1.add(entry.array());
lh.addEntry(entry.array());
}
readEntries(lh, entries1);
lh.close();
}
use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.
the class BookieWriteLedgerTest method testAsyncWritesWithMultipleFailuresInLastEnsemble.
/**
* Verify asynchronous writing when few bookie failures in last ensemble.
*/
@Test
public void testAsyncWritesWithMultipleFailuresInLastEnsemble() throws Exception {
// Create ledgers
lh = bkc.createLedger(5, 4, digestType, ledgerPassword);
lh2 = bkc.createLedger(5, 4, digestType, ledgerPassword);
LOG.info("Ledger ID-1: " + lh.getId());
LOG.info("Ledger ID-2: " + lh2.getId());
for (int i = 0; i < numEntriesToWrite; i++) {
ByteBuffer entry = ByteBuffer.allocate(4);
entry.putInt(rng.nextInt(maxInt));
entry.position(0);
entries1.add(entry.array());
entries2.add(entry.array());
lh.addEntry(entry.array());
lh2.addEntry(entry.array());
}
// Start three more bookies
startNewBookie();
startNewBookie();
startNewBookie();
// Shutdown three bookies in the last ensemble and continue writing
ArrayList<BookieSocketAddress> ensemble = lh.getLedgerMetadata().getEnsembles().entrySet().iterator().next().getValue();
killBookie(ensemble.get(0));
killBookie(ensemble.get(1));
killBookie(ensemble.get(2));
// adding one more entry to both the ledgers async after multiple bookie
// failures. This will do asynchronously modifying the ledger metadata
// simultaneously.
numEntriesToWrite++;
ByteBuffer entry = ByteBuffer.allocate(4);
entry.putInt(rng.nextInt(maxInt));
entry.position(0);
entries1.add(entry.array());
entries2.add(entry.array());
SyncObj syncObj1 = new SyncObj();
SyncObj syncObj2 = new SyncObj();
lh.asyncAddEntry(entry.array(), this, syncObj1);
lh2.asyncAddEntry(entry.array(), this, syncObj2);
// wait for all entries to be acknowledged for the first ledger
synchronized (syncObj1) {
while (syncObj1.counter < 1) {
LOG.debug("Entries counter = " + syncObj1.counter);
syncObj1.wait();
}
assertEquals(BKException.Code.OK, syncObj1.rc);
}
// wait for all entries to be acknowledged for the second ledger
synchronized (syncObj2) {
while (syncObj2.counter < 1) {
LOG.debug("Entries counter = " + syncObj2.counter);
syncObj2.wait();
}
assertEquals(BKException.Code.OK, syncObj2.rc);
}
// reading ledger till the last entry
readEntries(lh, entries1);
readEntries(lh2, entries2);
lh.close();
lh2.close();
}
use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.
the class BookieWriteLedgerTest method testLedgerCreateAdvWithLedgerId.
/**
* Verify the functionality of Advanced Ledger which accepts ledgerId as input and returns
* LedgerHandleAdv. LedgerHandleAdv takes entryId for addEntry, and let
* user manage entryId allocation.
*
* @throws Exception
*/
@Test
public void testLedgerCreateAdvWithLedgerId() throws Exception {
// Create a ledger
long ledgerId = 0xABCDEF;
lh = bkc.createLedgerAdv(ledgerId, 5, 3, 2, digestType, ledgerPassword, null);
for (int i = 0; i < numEntriesToWrite; i++) {
ByteBuffer entry = ByteBuffer.allocate(4);
entry.putInt(rng.nextInt(maxInt));
entry.position(0);
entries1.add(entry.array());
lh.addEntry(i, entry.array());
}
// Start one more bookies
startNewBookie();
// Shutdown one bookie in the last ensemble and continue writing
ArrayList<BookieSocketAddress> ensemble = lh.getLedgerMetadata().getEnsembles().entrySet().iterator().next().getValue();
killBookie(ensemble.get(0));
int i = numEntriesToWrite;
numEntriesToWrite = numEntriesToWrite + 50;
for (; i < numEntriesToWrite; i++) {
ByteBuffer entry = ByteBuffer.allocate(4);
entry.putInt(rng.nextInt(maxInt));
entry.position(0);
entries1.add(entry.array());
lh.addEntry(i, entry.array());
}
readEntries(lh, entries1);
lh.close();
bkc.deleteLedger(ledgerId);
}
use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.
the class BookieWriteLedgerTest method testLedgerCreateAdvWithRandomAsyncWritesWithBookieFailures.
/**
* Verify Advanced asynchronous writing with entryIds in pseudo random order.
*/
@Test
public void testLedgerCreateAdvWithRandomAsyncWritesWithBookieFailures() throws Exception {
// Create ledgers
lh = bkc.createLedgerAdv(5, 3, 2, digestType, ledgerPassword);
lh2 = bkc.createLedgerAdv(5, 3, 2, digestType, ledgerPassword);
LOG.info("Ledger ID-1: " + lh.getId());
LOG.info("Ledger ID-2: " + lh2.getId());
SyncObj syncObj1 = new SyncObj();
SyncObj syncObj2 = new SyncObj();
int batchSize = 5;
int i, j;
// Fill the result buffers first
for (i = 0; i < numEntriesToWrite; i++) {
ByteBuffer entry = ByteBuffer.allocate(4);
entry.putInt(rng.nextInt(maxInt));
entry.position(0);
try {
entries1.add(0, entry.array());
entries2.add(0, entry.array());
} catch (Exception e) {
e.printStackTrace();
}
}
for (i = 0; i < batchSize; i++) {
for (j = i; j < numEntriesToWrite; j = j + batchSize) {
byte[] entry1 = entries1.get(j);
byte[] entry2 = entries2.get(j);
lh.asyncAddEntry(j, entry1, 0, entry1.length, this, syncObj1);
lh2.asyncAddEntry(j, entry2, 0, entry2.length, this, syncObj2);
}
}
// Start One more bookie and shutdown one from last ensemble before reading
startNewBookie();
ArrayList<BookieSocketAddress> ensemble = lh.getLedgerMetadata().getEnsembles().entrySet().iterator().next().getValue();
killBookie(ensemble.get(0));
// Wait for all entries to be acknowledged for the first ledger
synchronized (syncObj1) {
while (syncObj1.counter < numEntriesToWrite) {
syncObj1.wait();
}
assertEquals(BKException.Code.OK, syncObj1.rc);
}
// Wait for all entries to be acknowledged for the second ledger
synchronized (syncObj2) {
while (syncObj2.counter < numEntriesToWrite) {
syncObj2.wait();
}
assertEquals(BKException.Code.OK, syncObj2.rc);
}
// Reading ledger till the last entry
readEntries(lh, entries1);
readEntries(lh2, entries2);
lh.close();
lh2.close();
}
use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.
the class BookieWriteLedgerTest method testLedgerCreateAdvWithAsyncWritesWithBookieFailures.
/**
* Verify Advanced asynchronous writing with entryIds in reverse order.
*/
@Test
public void testLedgerCreateAdvWithAsyncWritesWithBookieFailures() throws Exception {
// Create ledgers
lh = bkc.createLedgerAdv(5, 3, 2, digestType, ledgerPassword);
lh2 = bkc.createLedgerAdv(5, 3, 2, digestType, ledgerPassword);
LOG.info("Ledger ID-1: " + lh.getId());
LOG.info("Ledger ID-2: " + lh2.getId());
SyncObj syncObj1 = new SyncObj();
SyncObj syncObj2 = new SyncObj();
for (int i = numEntriesToWrite - 1; i >= 0; i--) {
ByteBuffer entry = ByteBuffer.allocate(4);
entry.putInt(rng.nextInt(maxInt));
entry.position(0);
try {
entries1.add(0, entry.array());
entries2.add(0, entry.array());
} catch (Exception e) {
e.printStackTrace();
}
lh.asyncAddEntry(i, entry.array(), 0, entry.capacity(), this, syncObj1);
lh2.asyncAddEntry(i, entry.array(), 0, entry.capacity(), this, syncObj2);
}
// Start One more bookie and shutdown one from last ensemble before reading
startNewBookie();
ArrayList<BookieSocketAddress> ensemble = lh.getLedgerMetadata().getEnsembles().entrySet().iterator().next().getValue();
killBookie(ensemble.get(0));
// Wait for all entries to be acknowledged for the first ledger
synchronized (syncObj1) {
while (syncObj1.counter < numEntriesToWrite) {
syncObj1.wait();
}
assertEquals(BKException.Code.OK, syncObj1.rc);
}
// Wait for all entries to be acknowledged for the second ledger
synchronized (syncObj2) {
while (syncObj2.counter < numEntriesToWrite) {
syncObj2.wait();
}
assertEquals(BKException.Code.OK, syncObj2.rc);
}
// Reading ledger till the last entry
readEntries(lh, entries1);
readEntries(lh2, entries2);
lh.close();
lh2.close();
}
Aggregations