use of org.apache.distributedlog.metadata.LogMetadata in project bookkeeper by apache.
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 LongVersion(10));
final CompletableFuture<Version> result = new CompletableFuture<Version>();
LogMetadata metadata = mock(LogMetadata.class);
when(metadata.getLogSegmentsPath()).thenReturn(rootZkPath);
lsmStore.storeMaxLogSegmentSequenceNumber(updateTxn, metadata, value, new Transaction.OpListener<Version>() {
@Override
public void onCommit(Version r) {
result.complete(r);
}
@Override
public void onAbort(Throwable t) {
result.completeExceptionally(t);
}
});
try {
Utils.ioResult(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 {
Utils.ioResult(result);
fail("Should fail on storing log segment sequence number if providing bad version");
} catch (ZKException ze) {
assertEquals(KeeperException.Code.BADVERSION, ze.getKeeperExceptionCode());
}
Stat stat = new Stat();
byte[] data = zkc.get().getData(rootZkPath, false, stat);
assertEquals(0, stat.getVersion());
assertEquals(0, data.length);
}
use of org.apache.distributedlog.metadata.LogMetadata in project bookkeeper by apache.
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 LongVersion(0));
final CompletableFuture<Version> result = new CompletableFuture<Version>();
LogMetadata metadata = mock(LogMetadata.class);
when(metadata.getLogSegmentsPath()).thenReturn(rootZkPath);
lsmStore.storeMaxLogSegmentSequenceNumber(updateTxn, metadata, value, new Transaction.OpListener<Version>() {
@Override
public void onCommit(Version r) {
result.complete(r);
}
@Override
public void onAbort(Throwable t) {
result.completeExceptionally(t);
}
});
Utils.ioResult(updateTxn.execute());
assertEquals(1L, ((LongVersion) Utils.ioResult(result)).getLongVersion());
Stat stat = new Stat();
byte[] data = zkc.get().getData(rootZkPath, false, stat);
assertEquals(999L, DLUtils.deserializeLogSegmentSequenceNumber(data));
assertEquals(1, stat.getVersion());
}
use of org.apache.distributedlog.metadata.LogMetadata in project bookkeeper by apache.
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 LongVersion(10));
final CompletableFuture<Version> result = new CompletableFuture<Version>();
String nonExistentPath = rootZkPath + "/non-existent";
LogMetadata metadata = mock(LogMetadata.class);
when(metadata.getLogSegmentsPath()).thenReturn(nonExistentPath);
lsmStore.storeMaxLogSegmentSequenceNumber(updateTxn, metadata, value, new Transaction.OpListener<Version>() {
@Override
public void onCommit(Version r) {
result.complete(r);
}
@Override
public void onAbort(Throwable t) {
result.completeExceptionally(t);
}
});
try {
Utils.ioResult(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 {
Utils.ioResult(result);
fail("Should fail on storing log segment sequence number if path doesn't exist");
} catch (ZKException ke) {
assertEquals(KeeperException.Code.NONODE, ke.getKeeperExceptionCode());
}
}
Aggregations