Search in sources :

Example 31 with BookKeeper

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();
}
Also used : LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) BookKeeper(org.apache.bookkeeper.client.BookKeeper)

Example 32 with BookKeeper

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()));
    }
}
Also used : ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) BookKeeper(org.apache.bookkeeper.client.BookKeeper) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) Test(org.junit.Test)

Example 33 with BookKeeper

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);
    }
}
Also used : ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) BookKeeper(org.apache.bookkeeper.client.BookKeeper) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) Test(org.junit.Test)

Example 34 with BookKeeper

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();
}
Also used : LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) BookKeeper(org.apache.bookkeeper.client.BookKeeper) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) Test(org.junit.Test)

Example 35 with BookKeeper

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());
}
Also used : LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) BookieServer(org.apache.bookkeeper.proto.BookieServer) BookKeeper(org.apache.bookkeeper.client.BookKeeper) File(java.io.File) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

BookKeeper (org.apache.bookkeeper.client.BookKeeper)76 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)48 Test (org.junit.Test)25 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)24 BKException (org.apache.bookkeeper.client.BKException)18 IOException (java.io.IOException)17 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)12 List (java.util.List)11 CompletableFuture (java.util.concurrent.CompletableFuture)10 CountDownLatch (java.util.concurrent.CountDownLatch)10 LedgerEntry (org.apache.bookkeeper.client.LedgerEntry)10 ArrayList (java.util.ArrayList)9 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)8 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)7 AsyncCallback (org.apache.bookkeeper.client.AsyncCallback)7 HttpServiceResponse (org.apache.bookkeeper.http.service.HttpServiceResponse)7 BookkeeperCommitLog (herddb.cluster.BookkeeperCommitLog)6 TableSpaceManager (herddb.core.TableSpaceManager)6 DataScanner (herddb.model.DataScanner)6 StatementExecutionException (herddb.model.StatementExecutionException)6