use of org.apache.bookkeeper.client.BookKeeper in project bookkeeper by apache.
the class TestAuth method connectAndWriteToBookie.
// we pass in ledgerId because the method may throw exceptions
private void connectAndWriteToBookie(ClientConfiguration conf, AtomicLong ledgerWritten) throws Exception {
LOG.info("Connecting to bookie");
BookKeeper bkc = new BookKeeper(conf, zkc);
LedgerHandle l = bkc.createLedger(1, 1, DigestType.CRC32, PASSWD);
ledgerWritten.set(l.getId());
l.addEntry(ENTRY);
l.close();
bkc.close();
}
use of org.apache.bookkeeper.client.BookKeeper in project bookkeeper by apache.
the class TestAuth method testExistantButNotValidPlugin.
/**
* Test that when the plugin class does exist, but
* doesn't implement the interface, we fail predictably.
*/
@Test
public void testExistantButNotValidPlugin() throws Exception {
ServerConfiguration bookieConf = newServerConfiguration();
bookieConf.setBookieAuthProviderFactoryClass("java.lang.String");
ClientConfiguration clientConf = newClientConfiguration();
clientConf.setClientAuthProviderFactoryClass("java.lang.String");
try {
startAndStoreBookie(bookieConf);
fail("Shouldn't get this far");
} catch (RuntimeException e) {
// received correct exception
assertTrue("Wrong exception thrown", e.getMessage().contains("not " + BookieAuthProvider.Factory.class.getName()));
}
try {
BookKeeper bkc = new BookKeeper(clientConf, zkc);
fail("Shouldn't get this far");
} catch (RuntimeException e) {
// received correct exception
assertTrue("Wrong exception thrown", e.getMessage().contains("not " + ClientAuthProvider.Factory.class.getName()));
}
}
use of org.apache.bookkeeper.client.BookKeeper in project bookkeeper by apache.
the class TestAuth method testNonExistantPlugin.
/**
* Test that when the plugin class does not exist,
* the bookie will not start and the client will
* break.
*/
@Test
public void testNonExistantPlugin() throws Exception {
ServerConfiguration bookieConf = newServerConfiguration();
bookieConf.setBookieAuthProviderFactoryClass("NonExistantClassNameForTestingAuthPlugins");
ClientConfiguration clientConf = newClientConfiguration();
clientConf.setClientAuthProviderFactoryClass("NonExistantClassNameForTestingAuthPlugins");
try {
startAndStoreBookie(bookieConf);
fail("Shouldn't get this far");
} catch (RuntimeException e) {
// received correct exception
assertEquals("Wrong exception thrown", e.getCause().getClass(), ClassNotFoundException.class);
}
try {
BookKeeper bkc = new BookKeeper(clientConf, zkc);
fail("Shouldn't get this far");
} catch (RuntimeException e) {
// received correct exception
assertEquals("Wrong exception thrown", e.getCause().getClass(), ClassNotFoundException.class);
}
}
use of org.apache.bookkeeper.client.BookKeeper in project bookkeeper by apache.
the class EnableZkSecurityBasicTest method testCreateLedgerAddEntryOnSecureZooKeepeer.
@Test
public void testCreateLedgerAddEntryOnSecureZooKeepeer() throws Exception {
startNewBookie();
ClientConfiguration conf = new ClientConfiguration();
conf.setZkServers(zkUtil.getZooKeeperConnectString());
conf.setZkTimeout(20000);
conf.setZkEnableSecurity(true);
try (BookKeeper bkc = new BookKeeper(conf)) {
try (LedgerHandle lh = bkc.createLedger(1, 1, 1, BookKeeper.DigestType.CRC32, "testPasswd".getBytes())) {
lh.addEntry("foo".getBytes(StandardCharsets.UTF_8));
}
}
checkAllAcls();
}
use of org.apache.bookkeeper.client.BookKeeper in project bookkeeper by apache.
the class LedgerStorageCheckpointTest method testIfEntryLogPerLedgerEnabledCheckpointFlushesAllLogs.
/*
* in this method it checks if entryLogPerLedger is enabled, then
* InterLeavedLedgerStorage.checkpoint flushes current activelog and flushes
* all rotatedlogs and closes them.
*
*/
@Test
public void testIfEntryLogPerLedgerEnabledCheckpointFlushesAllLogs() throws Exception {
File tmpDir = createTempDir("DiskCheck", "test");
final ServerConfiguration conf = TestBKConfiguration.newServerConfiguration().setZkServers(zkUtil.getZooKeeperConnectString()).setZkTimeout(5000).setJournalDirName(tmpDir.getPath()).setLedgerDirNames(new String[] { tmpDir.getPath() }).setAutoRecoveryDaemonEnabled(false).setFlushInterval(3000).setBookiePort(PortManager.nextFreePort()).setEntryLogPerLedgerEnabled(true).setLedgerStorageClass(InterleavedLedgerStorage.class.getName()).setFlushIntervalInBytes(10000000);
Assert.assertEquals("Number of JournalDirs", 1, conf.getJournalDirs().length);
// we know there is only one ledgerDir
File ledgerDir = Bookie.getCurrentDirectories(conf.getLedgerDirs())[0];
BookieServer server = new BookieServer(conf);
server.start();
ClientConfiguration clientConf = new ClientConfiguration();
clientConf.setZkServers(zkUtil.getZooKeeperConnectString());
BookKeeper bkClient = new BookKeeper(clientConf);
InterleavedLedgerStorage ledgerStorage = (InterleavedLedgerStorage) server.getBookie().ledgerStorage;
EntryLogger entryLogger = ledgerStorage.entryLogger;
int numOfEntries = 5;
byte[] dataBytes = "data".getBytes();
long ledgerId = 10;
LedgerHandle handle = bkClient.createLedgerAdv(ledgerId, 1, 1, 1, DigestType.CRC32, "passwd".getBytes(), null);
for (int j = 0; j < numOfEntries; j++) {
handle.addEntry(j, dataBytes);
}
handle.close();
// simulate rolling entrylog
ledgerStorage.entryLogger.rollLog();
ledgerId = 20;
handle = bkClient.createLedgerAdv(ledgerId, 1, 1, 1, DigestType.CRC32, "passwd".getBytes(), null);
for (int j = 0; j < numOfEntries; j++) {
handle.addEntry(j, dataBytes);
}
handle.close();
// simulate rolling entrylog
ledgerStorage.entryLogger.rollLog();
ledgerId = 30;
handle = bkClient.createLedgerAdv(ledgerId, 1, 1, 1, DigestType.CRC32, "passwd".getBytes(), null);
for (int j = 0; j < numOfEntries; j++) {
handle.addEntry(j, dataBytes);
}
handle.close();
Assert.assertNotEquals("bytesWrittenSinceLastFlush shouldn't be zero", 0, entryLogger.logChannel.getUnpersistedBytes());
Assert.assertNotEquals("There should be logChannelsToFlush", 0, entryLogger.logChannelsToFlush.size());
/*
* wait for atleast flushInterval period, so that checkpoint can happen.
*/
executorController.advance(Duration.ofMillis(conf.getFlushInterval()));
/*
* since checkpoint happenend, there shouldn't be any logChannelsToFlush
* and bytesWrittenSinceLastFlush should be zero.
*/
Assert.assertTrue("There shouldn't be logChannelsToFlush", ((entryLogger.logChannelsToFlush == null) || (entryLogger.logChannelsToFlush.size() == 0)));
Assert.assertEquals("bytesWrittenSinceLastFlush should be zero", 0, entryLogger.logChannel.getUnpersistedBytes());
}
Aggregations