use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.
the class ListBookiesCommandTest method testListEmptyBookies.
@Test
public void testListEmptyBookies() {
// overwrite regClient to return empty bookies
when(regClient.getWritableBookies()).thenReturn(value(new Versioned<>(Collections.emptySet(), new LongVersion(0L))));
when(regClient.getReadOnlyBookies()).thenReturn(value(new Versioned<>(Collections.emptySet(), new LongVersion(0L))));
CommandRunner runner = createCommandRunner(new ListBookiesCommand());
assertTrue(runner.runArgs("listbookies"));
PowerMockito.verifyStatic(CommandHelpers.class, times(0));
CommandHelpers.getBookieSocketAddrStringRepresentation(any());
}
use of org.apache.bookkeeper.versioning.LongVersion 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.bookkeeper.versioning.LongVersion 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.bookkeeper.versioning.LongVersion 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());
}
}
use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.
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 LongVersion(10));
final CompletableFuture<Version> result = new CompletableFuture<Version>();
LogMetadataForWriter metadata = mock(LogMetadataForWriter.class);
when(metadata.getMaxTxIdPath()).thenReturn(rootZkPath);
lsmStore.storeMaxTxnId(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 record transaction id if providing bad version");
} catch (ZKException zke) {
assertEquals(KeeperException.Code.BADVERSION, zke.getKeeperExceptionCode());
}
try {
Utils.ioResult(result);
fail("Should fail on storing log record transaction id 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);
}
Aggregations