use of org.apache.bookkeeper.client.BKException.BKClientClosedException in project bookkeeper by apache.
the class BookKeeperCloseTest method testCloseLedger.
/**
* Test that closing a ledger using bookkeeper client which is closed should
* throw ClientClosedException.
*/
@Test
public void testCloseLedger() throws Exception {
BookKeeper bk = new BookKeeper(baseClientConf, zkc);
LOG.info("Create ledger and add entries to it");
LedgerHandle lh = createLedgerWithEntries(bk, 100);
LedgerHandle lh2 = createLedgerWithEntries(bk, 100);
LOG.info("Closing bookkeeper client");
bk.close();
try {
lh.close();
fail("should have failed, client is closed");
} catch (BKClientClosedException e) {
// correct
}
final CountDownLatch completeLatch = new CountDownLatch(1);
final AtomicInteger rc = new AtomicInteger(BKException.Code.OK);
lh2.asyncClose(new CloseCallback() {
public void closeComplete(int rccb, LedgerHandle lh, Object ctx) {
rc.set(rccb);
completeLatch.countDown();
}
}, null);
LOG.info("Waiting to finish adding another entry asynchronously");
assertTrue("Close ledger call should have completed", completeLatch.await(20, TimeUnit.SECONDS));
assertEquals("Close ledger should have succeeded through closed bkclient!", BKException.Code.ClientClosedException, rc.get());
}
use of org.apache.bookkeeper.client.BKException.BKClientClosedException in project bookkeeper by apache.
the class BookKeeperCloseTest method testReadLedgerEntry.
/**
* Test that reading entry from a ledger using bookkeeper client which is
* closed should throw ClientClosedException.
*/
@Test
public void testReadLedgerEntry() throws Exception {
BookKeeper bk = new BookKeeper(baseClientConf, zkc);
LOG.info("Create ledger and add entries to it");
int numOfEntries = 100;
LedgerHandle lh = createLedgerWithEntries(bk, numOfEntries);
LOG.info("Closing bookkeeper client");
restartBookieSlow();
bk.close();
try {
lh.readEntries(0, numOfEntries - 1);
fail("should have failed, client is closed");
} catch (BKClientClosedException e) {
// correct
}
final CountDownLatch readLatch = new CountDownLatch(1);
final AtomicInteger rc = new AtomicInteger(BKException.Code.OK);
ReadCallback cb = new ReadCallback() {
@Override
public void readComplete(int rccb, LedgerHandle lh, Enumeration<LedgerEntry> seq, Object ctx) {
rc.set(rccb);
readLatch.countDown();
}
};
lh.asyncReadEntries(0, numOfEntries - 1, cb, readLatch);
LOG.info("Waiting to finish reading the entries asynchronously");
assertTrue("Read entry ledger call should have completed", readLatch.await(20, TimeUnit.SECONDS));
assertEquals("Read entry ledger should have succeeded through closed bkclient!", BKException.Code.ClientClosedException, rc.get());
}
use of org.apache.bookkeeper.client.BKException.BKClientClosedException in project bookkeeper by apache.
the class BookKeeperCloseTest method testDeleteLedger.
/**
* Test that deleting a ledger using bookkeeper client which is closed
* should throw ClientClosedException.
*/
@Test
public void testDeleteLedger() throws Exception {
BookKeeper bk = new BookKeeper(baseClientConf, zkc);
LOG.info("Create ledger and add entries to it");
LedgerHandle lh = createLedgerWithEntries(bk, 100);
LOG.info("Closing bookkeeper client");
bk.close();
try {
bk.deleteLedger(lh.getId());
fail("should have failed, client is closed");
} catch (BKClientClosedException e) {
// correct
}
// using async, because this could trigger an assertion
final AtomicInteger returnCode = new AtomicInteger(0);
final CountDownLatch openLatch = new CountDownLatch(1);
AsyncCallback.DeleteCallback cb = new AsyncCallback.DeleteCallback() {
public void deleteComplete(int rc, Object ctx) {
returnCode.set(rc);
openLatch.countDown();
}
};
bk.asyncDeleteLedger(lh.getId(), cb, openLatch);
LOG.info("Waiting to delete the ledger asynchronously");
assertTrue("Delete call should have completed", openLatch.await(20, TimeUnit.SECONDS));
assertEquals("Delete should not have succeeded through closed bkclient!", BKException.Code.ClientClosedException, returnCode.get());
}
use of org.apache.bookkeeper.client.BKException.BKClientClosedException in project bookkeeper by apache.
the class BookKeeperCloseTest method testAddLedgerEntry.
/**
* Test that adding entry to a ledger using bookkeeper client which is
* closed should throw ClientClosedException.
*/
@Test
public void testAddLedgerEntry() throws Exception {
BookKeeper bk = new BookKeeper(baseClientConf, zkc);
LOG.info("Create ledger and add entries to it");
LedgerHandle lh = createLedgerWithEntries(bk, 1);
LOG.info("Closing bookkeeper client");
restartBookieSlow();
bk.close();
try {
lh.addEntry("foobar".getBytes());
fail("should have failed, client is closed");
} catch (BKClientClosedException e) {
// correct
}
final CountDownLatch completeLatch = new CountDownLatch(1);
final AtomicInteger rc = new AtomicInteger(BKException.Code.OK);
lh.asyncAddEntry("foobar".getBytes(), new AddCallback() {
public void addComplete(int rccb, LedgerHandle lh, long entryId, Object ctx) {
rc.set(rccb);
completeLatch.countDown();
}
}, null);
LOG.info("Waiting to finish adding another entry asynchronously");
assertTrue("Add entry to ledger call should have completed", completeLatch.await(20, TimeUnit.SECONDS));
assertEquals("Add entry to ledger should not have succeeded through closed bkclient!", BKException.Code.ClientClosedException, rc.get());
}
use of org.apache.bookkeeper.client.BKException.BKClientClosedException in project bookkeeper by apache.
the class BookKeeperCloseTest method testReadLastConfirmed.
/**
* Test that readlastconfirmed entry from a ledger using bookkeeper client
* which is closed should throw ClientClosedException.
*/
@Test
public void testReadLastConfirmed() throws Exception {
BookKeeper bk = new BookKeeper(baseClientConf, zkc);
LOG.info("Create ledger and add entries to it");
LedgerHandle lh = createLedgerWithEntries(bk, 100);
LOG.info("Closing bookkeeper client");
// make all bookies slow
restartBookieSlow();
restartBookieSlow();
restartBookieSlow();
bk.close();
final CountDownLatch readLatch = new CountDownLatch(1);
final AtomicInteger rc = new AtomicInteger(BKException.Code.OK);
AsyncCallback.ReadLastConfirmedCallback cb = new AsyncCallback.ReadLastConfirmedCallback() {
@Override
public void readLastConfirmedComplete(int rccb, long lastConfirmed, Object ctx) {
rc.set(rccb);
readLatch.countDown();
}
};
lh.asyncReadLastConfirmed(cb, readLatch);
LOG.info("Waiting to finish reading last confirmed entry asynchronously");
assertTrue("ReadLastConfirmed call should have completed", readLatch.await(20, TimeUnit.SECONDS));
assertEquals("ReadLastConfirmed should have succeeded through closed bkclient!", BKException.Code.ClientClosedException, rc.get());
try {
lh.readLastConfirmed();
fail("should have failed, client is closed");
} catch (BKClientClosedException e) {
// correct
}
}
Aggregations