use of org.apache.bookkeeper.client.LedgerHandle in project bookkeeper by apache.
the class TestAsyncReaderWriter method testCreateLogStreamWithDifferentReplicationFactor.
@Test(timeout = 60000)
public void testCreateLogStreamWithDifferentReplicationFactor() throws Exception {
String name = runtime.getMethodName();
DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.addConfiguration(testConf);
confLocal.setOutputBufferSize(0);
confLocal.setImmediateFlushEnabled(false);
confLocal.setPeriodicFlushFrequencyMilliSeconds(0);
ConcurrentBaseConfiguration baseConf = new ConcurrentConstConfiguration(confLocal);
DynamicDistributedLogConfiguration dynConf = new DynamicDistributedLogConfiguration(baseConf);
dynConf.setProperty(DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE, DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE_DEFAULT - 1);
URI uri = createDLMURI("/" + name);
ensureURICreated(uri);
Namespace namespace = NamespaceBuilder.newBuilder().conf(confLocal).uri(uri).build();
// use the pool
DistributedLogManager dlm = namespace.openLog(name + "-pool");
AsyncLogWriter writer = dlm.startAsyncLogSegmentNonPartitioned();
Utils.ioResult(writer.write(DLMTestUtil.getLogRecordInstance(1L)));
List<LogSegmentMetadata> segments = dlm.getLogSegments();
assertEquals(1, segments.size());
long ledgerId = segments.get(0).getLogSegmentId();
LedgerHandle lh = ((BKNamespaceDriver) namespace.getNamespaceDriver()).getReaderBKC().get().openLedgerNoRecovery(ledgerId, BookKeeper.DigestType.CRC32, confLocal.getBKDigestPW().getBytes(UTF_8));
LedgerMetadata metadata = BookKeeperAccessor.getLedgerMetadata(lh);
assertEquals(DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE_DEFAULT, metadata.getEnsembleSize());
lh.close();
Utils.close(writer);
dlm.close();
// use customized configuration
dlm = namespace.openLog(name + "-custom", java.util.Optional.empty(), java.util.Optional.of(dynConf), java.util.Optional.empty());
writer = dlm.startAsyncLogSegmentNonPartitioned();
Utils.ioResult(writer.write(DLMTestUtil.getLogRecordInstance(1L)));
segments = dlm.getLogSegments();
assertEquals(1, segments.size());
ledgerId = segments.get(0).getLogSegmentId();
lh = ((BKNamespaceDriver) namespace.getNamespaceDriver()).getReaderBKC().get().openLedgerNoRecovery(ledgerId, BookKeeper.DigestType.CRC32, confLocal.getBKDigestPW().getBytes(UTF_8));
metadata = BookKeeperAccessor.getLedgerMetadata(lh);
assertEquals(DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE_DEFAULT - 1, metadata.getEnsembleSize());
lh.close();
Utils.close(writer);
dlm.close();
namespace.close();
}
use of org.apache.bookkeeper.client.LedgerHandle in project bookkeeper by apache.
the class TestLedgerAllocator method testAllocation.
/**
* {@link https://issues.apache.org/jira/browse/DL-43}.
*/
@DistributedLogAnnotations.FlakyTest
@Ignore
@Test(timeout = 60000)
public void testAllocation() throws Exception {
String allocationPath = "/allocation1";
SimpleLedgerAllocator allocator = createAllocator(allocationPath);
allocator.allocate();
ZKTransaction txn = newTxn();
LedgerHandle lh = Utils.ioResult(allocator.tryObtain(txn, NULL_LISTENER));
logger.info("Try obtaining ledger handle {}", lh.getId());
byte[] data = zkc.get().getData(allocationPath, false, null);
assertEquals((Long) lh.getId(), Long.valueOf(new String(data, UTF_8)));
txn.addOp(DefaultZKOp.of(Op.setData("/unexistedpath", "data".getBytes(UTF_8), -1), null));
try {
Utils.ioResult(txn.execute());
fail("Should fail the transaction when setting unexisted path");
} catch (ZKException ke) {
// expected
logger.info("Should fail on executing transaction when setting unexisted path", ke);
}
data = zkc.get().getData(allocationPath, false, null);
assertEquals((Long) lh.getId(), Long.valueOf(new String(data, UTF_8)));
// Create new transaction to obtain the ledger again.
txn = newTxn();
// we could obtain the ledger if it was obtained
LedgerHandle newLh = Utils.ioResult(allocator.tryObtain(txn, NULL_LISTENER));
assertEquals(lh.getId(), newLh.getId());
Utils.ioResult(txn.execute());
data = zkc.get().getData(allocationPath, false, null);
assertEquals(0, data.length);
Utils.close(allocator);
}
use of org.apache.bookkeeper.client.LedgerHandle in project bookkeeper by apache.
the class TestLedgerAllocator method testCloseAllocatorAfterConfirm.
/**
* {@link https://issues.apache.org/jira/browse/DL-26}.
*/
@DistributedLogAnnotations.FlakyTest
@Ignore
@Test(timeout = 60000)
public void testCloseAllocatorAfterConfirm() throws Exception {
String allocationPath = "/allocation2";
SimpleLedgerAllocator allocator = createAllocator(allocationPath);
allocator.allocate();
ZKTransaction txn = newTxn();
// close during obtaining ledger.
LedgerHandle lh = Utils.ioResult(allocator.tryObtain(txn, NULL_LISTENER));
Utils.ioResult(txn.execute());
Utils.close(allocator);
byte[] data = zkc.get().getData(allocationPath, false, null);
assertEquals(0, data.length);
// the ledger is not deleted.
bkc.get().openLedger(lh.getId(), BookKeeper.DigestType.CRC32, dlConf.getBKDigestPW().getBytes(UTF_8));
}
use of org.apache.bookkeeper.client.LedgerHandle in project bookkeeper by apache.
the class TestLedgerAllocator method testCloseAllocatorAfterAbort.
@Test(timeout = 60000)
public void testCloseAllocatorAfterAbort() throws Exception {
String allocationPath = "/allocation3";
SimpleLedgerAllocator allocator = createAllocator(allocationPath);
allocator.allocate();
ZKTransaction txn = newTxn();
// close during obtaining ledger.
LedgerHandle lh = Utils.ioResult(allocator.tryObtain(txn, NULL_LISTENER));
txn.addOp(DefaultZKOp.of(Op.setData("/unexistedpath", "data".getBytes(UTF_8), -1), null));
try {
Utils.ioResult(txn.execute());
fail("Should fail the transaction when setting unexisted path");
} catch (ZKException ke) {
// expected
}
Utils.close(allocator);
byte[] data = zkc.get().getData(allocationPath, false, null);
assertEquals((Long) lh.getId(), Long.valueOf(new String(data, UTF_8)));
// the ledger is not deleted.
bkc.get().openLedger(lh.getId(), BookKeeper.DigestType.CRC32, dlConf.getBKDigestPW().getBytes(UTF_8));
}
use of org.apache.bookkeeper.client.LedgerHandle in project bookkeeper by apache.
the class TestLedgerAllocator method testObtainMultipleLedgers.
@Test(timeout = 60000)
public void testObtainMultipleLedgers() throws Exception {
String allocationPath = "/" + runtime.getMethodName();
SimpleLedgerAllocator allocator = createAllocator(allocationPath);
int numLedgers = 10;
Set<LedgerHandle> allocatedLedgers = new HashSet<LedgerHandle>();
for (int i = 0; i < numLedgers; i++) {
allocator.allocate();
ZKTransaction txn = newTxn();
LedgerHandle lh = Utils.ioResult(allocator.tryObtain(txn, NULL_LISTENER));
Utils.ioResult(txn.execute());
allocatedLedgers.add(lh);
}
assertEquals(numLedgers, allocatedLedgers.size());
}
Aggregations