This repository has been archived by the owner on Apr 30, 2019. It is now read-only.
forked from apache/bookkeeper
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support DbLedgerStorage in LedgerCmd to get list of logger files for …
…a given ledgerId (#6)
- Loading branch information
Showing
3 changed files
with
162 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
bookkeeper-server/src/test/java/org/apache/bookkeeper/client/LedgerCmdTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/** | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
package org.apache.bookkeeper.client; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import org.apache.bookkeeper.bookie.BookieShell; | ||
import org.apache.bookkeeper.bookie.storage.ldb.DbLedgerStorage; | ||
import org.apache.bookkeeper.client.AsyncCallback.AddCallback; | ||
import org.apache.bookkeeper.client.BookKeeper.DigestType; | ||
import org.apache.bookkeeper.conf.ServerConfiguration; | ||
import org.apache.bookkeeper.test.BookKeeperClusterTestCase; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import junit.framework.Assert; | ||
|
||
public class LedgerCmdTest extends BookKeeperClusterTestCase { | ||
|
||
private final static Logger LOG = LoggerFactory.getLogger(LedgerCmdTest.class); | ||
private DigestType digestType = DigestType.CRC32; | ||
private static final String PASSWORD = "testPasswd"; | ||
|
||
public LedgerCmdTest() { | ||
super(1); | ||
baseConf.setLedgerStorageClass(DbLedgerStorage.class.getName()); | ||
baseConf.setGcWaitTime(60000); | ||
baseConf.setFlushInterval(1); | ||
} | ||
|
||
|
||
/** | ||
* list of entry logger files that contains given ledgerId | ||
*/ | ||
@Test | ||
public void testLedgerDbStorageCmd() throws Exception { | ||
|
||
BookKeeper bk = new BookKeeper(baseClientConf, zkc); | ||
LOG.info("Create ledger and add entries to it"); | ||
LedgerHandle lh1 = createLedgerWithEntries(bk, 10); | ||
|
||
String[] argv = new String[] { "ledger", Long.toString(lh1.getId()) }; | ||
final ServerConfiguration conf = bsConfs.get(0); | ||
conf.setUseHostNameAsBookieID(true); | ||
|
||
BookieShell bkShell = new BookieShell(); | ||
bkShell.setConf(conf); | ||
|
||
Assert.assertEquals("Failed to return exit code!", 0, bkShell.run(argv)); | ||
|
||
} | ||
|
||
private LedgerHandle createLedgerWithEntries(BookKeeper bk, int numOfEntries) throws Exception { | ||
LedgerHandle lh = bk.createLedger(1, 1, digestType, PASSWORD.getBytes()); | ||
final AtomicInteger rc = new AtomicInteger(BKException.Code.OK); | ||
final CountDownLatch latch = new CountDownLatch(numOfEntries); | ||
|
||
final AddCallback cb = new AddCallback() { | ||
public void addComplete(int rccb, LedgerHandle lh, long entryId, Object ctx) { | ||
rc.compareAndSet(BKException.Code.OK, rccb); | ||
latch.countDown(); | ||
} | ||
}; | ||
for (int i = 0; i < numOfEntries; i++) { | ||
lh.asyncAddEntry(("foobar" + i).getBytes(), cb, null); | ||
} | ||
if (!latch.await(30, TimeUnit.SECONDS)) { | ||
throw new Exception("Entries took too long to add"); | ||
} | ||
if (rc.get() != BKException.Code.OK) { | ||
throw BKException.create(rc.get()); | ||
} | ||
return lh; | ||
} | ||
} |