public static Exception bkException(String operation, int rc, long ledgerId, long entryId) {
        String message = org.apache.bookkeeper.client.api.BKException.getMessage(rc)
                + " -  ledger=" + ledgerId + " - operation=" + operation;

        if (entryId != -1) {
            message += " - entry=" + entryId;
        }
        boolean recoverable = rc != BKException.Code.NoSuchLedgerExistsException
                && rc != BKException.Code.NoSuchEntryException
                && rc != BKException.Code.NoSuchLedgerExistsOnMetadataServerException;
        return new SchemaException(recoverable, message);
    }
@Test
    public void testBkException() {
        Exception ex = bkException("test", BKException.Code.ReadException, 1, -1);
        assertEquals("Error while reading ledger -  ledger=1 - operation=test", ex.getMessage());
        ex = bkException("test", BKException.Code.ReadException, 1, 0);
        assertEquals("Error while reading ledger -  ledger=1 - operation=test - entry=0",
                ex.getMessage());
        ex = bkException("test", BKException.Code.QuorumException, 1, -1);
        assertEquals("Invalid quorum size on ensemble size -  ledger=1 - operation=test",
                ex.getMessage());
        ex = bkException("test", BKException.Code.QuorumException, 1, 0);
        assertEquals("Invalid quorum size on ensemble size -  ledger=1 - operation=test - entry=0",
                ex.getMessage());
    }