use of com.twitter.distributedlog.exceptions.ZKException in project distributedlog by twitter.
the class TestZKLogSegmentMetadataStore method testUpdateNonExistentLogSegment.
@Test(timeout = 60000)
public void testUpdateNonExistentLogSegment() throws Exception {
LogSegmentMetadata segment = createLogSegment(1L);
Transaction<Object> updateTxn = lsmStore.transaction();
lsmStore.updateLogSegment(updateTxn, segment);
try {
FutureUtils.result(updateTxn.execute());
fail("Should fail update if log segment doesn't exist");
} catch (Throwable t) {
assertTrue("Should throw NoNodeException if log segment doesn't exist", t instanceof ZKException);
ZKException zke = (ZKException) t;
assertEquals("Should throw NoNodeException if log segment doesn't exist", KeeperException.Code.NONODE, zke.getKeeperExceptionCode());
}
}
use of com.twitter.distributedlog.exceptions.ZKException in project distributedlog by twitter.
the class TestZKLogSegmentMetadataStore method testStoreMaxLogSegmentSequenceNumberBadVersion.
@Test(timeout = 60000)
public void testStoreMaxLogSegmentSequenceNumberBadVersion() throws Exception {
Transaction<Object> updateTxn = lsmStore.transaction();
Versioned<Long> value = new Versioned<Long>(999L, new ZkVersion(10));
final Promise<Version> result = new Promise<Version>();
lsmStore.storeMaxLogSegmentSequenceNumber(updateTxn, rootZkPath, value, new Transaction.OpListener<Version>() {
@Override
public void onCommit(Version r) {
result.setValue(r);
}
@Override
public void onAbort(Throwable t) {
result.setException(t);
}
});
try {
FutureUtils.result(updateTxn.execute());
fail("Should fail on storing log segment sequence number if providing bad version");
} catch (ZKException zke) {
assertEquals(KeeperException.Code.BADVERSION, zke.getKeeperExceptionCode());
}
try {
Await.result(result);
fail("Should fail on storing log segment sequence number if providing bad version");
} catch (KeeperException ke) {
assertEquals(KeeperException.Code.BADVERSION, ke.code());
}
Stat stat = new Stat();
byte[] data = zkc.get().getData(rootZkPath, false, stat);
assertEquals(0, stat.getVersion());
assertEquals(0, data.length);
}
use of com.twitter.distributedlog.exceptions.ZKException in project distributedlog by twitter.
the class TestZKLogSegmentMetadataStore method testStoreMaxTxnIdOnNonExistentPath.
@Test(timeout = 60000)
public void testStoreMaxTxnIdOnNonExistentPath() throws Exception {
Transaction<Object> updateTxn = lsmStore.transaction();
Versioned<Long> value = new Versioned<Long>(999L, new ZkVersion(10));
final Promise<Version> result = new Promise<Version>();
String nonExistentPath = rootZkPath + "/non-existent";
lsmStore.storeMaxLogSegmentSequenceNumber(updateTxn, nonExistentPath, value, new Transaction.OpListener<Version>() {
@Override
public void onCommit(Version r) {
result.setValue(r);
}
@Override
public void onAbort(Throwable t) {
result.setException(t);
}
});
try {
FutureUtils.result(updateTxn.execute());
fail("Should fail on storing log record transaction id if path doesn't exist");
} catch (ZKException zke) {
assertEquals(KeeperException.Code.NONODE, zke.getKeeperExceptionCode());
}
try {
Await.result(result);
fail("Should fail on storing log record transaction id if path doesn't exist");
} catch (KeeperException ke) {
assertEquals(KeeperException.Code.NONODE, ke.code());
}
}
use of com.twitter.distributedlog.exceptions.ZKException in project distributedlog by twitter.
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 = FutureUtils.result(allocator.tryObtain(txn, NULL_LISTENER));
txn.addOp(DefaultZKOp.of(Op.setData("/unexistedpath", "data".getBytes(UTF_8), -1)));
try {
FutureUtils.result(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 com.twitter.distributedlog.exceptions.ZKException in project distributedlog by twitter.
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 = FutureUtils.result(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)));
try {
FutureUtils.result(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 = FutureUtils.result(allocator.tryObtain(txn, NULL_LISTENER));
assertEquals(lh.getId(), newLh.getId());
FutureUtils.result(txn.execute());
data = zkc.get().getData(allocationPath, false, null);
assertEquals(0, data.length);
Utils.close(allocator);
}
Aggregations