use of com.twitter.distributedlog.util.Transaction in project distributedlog by twitter.
the class TestZKLogSegmentMetadataStore method testStoreMaxLogSegmentSequenceNumber.
@Test(timeout = 60000)
public void testStoreMaxLogSegmentSequenceNumber() throws Exception {
Transaction<Object> updateTxn = lsmStore.transaction();
Versioned<Long> value = new Versioned<Long>(999L, new ZkVersion(0));
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);
}
});
FutureUtils.result(updateTxn.execute());
assertEquals(1, ((ZkVersion) FutureUtils.result(result)).getZnodeVersion());
Stat stat = new Stat();
byte[] data = zkc.get().getData(rootZkPath, false, stat);
assertEquals(999L, DLUtils.deserializeLogSegmentSequenceNumber(data));
assertEquals(1, stat.getVersion());
}
use of com.twitter.distributedlog.util.Transaction in project distributedlog by twitter.
the class TestZKLogSegmentMetadataStore method testStoreMaxTxnIdBadVersion.
@Test(timeout = 60000)
public void testStoreMaxTxnIdBadVersion() 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.storeMaxTxnId(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 record transaction id if providing bad version");
} catch (ZKException zke) {
assertEquals(KeeperException.Code.BADVERSION, zke.getKeeperExceptionCode());
}
try {
Await.result(result);
fail("Should fail on storing log record transaction id 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.util.Transaction in project distributedlog by twitter.
the class TestZKLogSegmentMetadataStore method testStoreMaxLogSegmentSequenceNumberOnNonExistentPath.
@Test(timeout = 60000)
public void testStoreMaxLogSegmentSequenceNumberOnNonExistentPath() 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 segment sequence number if path doesn't exist");
} catch (ZKException zke) {
assertEquals(KeeperException.Code.NONODE, zke.getKeeperExceptionCode());
}
try {
Await.result(result);
fail("Should fail on storing log segment sequence number if path doesn't exist");
} catch (KeeperException ke) {
assertEquals(KeeperException.Code.NONODE, ke.code());
}
}
use of com.twitter.distributedlog.util.Transaction 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.util.Transaction 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());
}
}
Aggregations