use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.
the class TestZKLogSegmentMetadataStore method testStoreMaxTxnId.
@Test(timeout = 60000)
public void testStoreMaxTxnId() throws Exception {
Transaction<Object> updateTxn = lsmStore.transaction();
Versioned<Long> value = new Versioned<Long>(999L, new LongVersion(0));
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);
}
});
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.deserializeTransactionId(data));
assertEquals(1, stat.getVersion());
}
use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.
the class TestZKLogStreamMetadataStoreUtils method testProcessLogMetadatasMissingLockPath.
@SuppressWarnings("unchecked")
@Test(timeout = 60000, expected = UnexpectedException.class)
public void testProcessLogMetadatasMissingLockPath() throws Exception {
String rootPath = "/test-missing-version";
URI uri = DLMTestUtil.createDLMURI(2181, rootPath);
String logName = "test-log";
String logIdentifier = "<default>";
List<Versioned<byte[]>> metadatas = Lists.newArrayList(new Versioned<byte[]>(null, null), new Versioned<byte[]>(null, null), new Versioned<byte[]>(DLUtils.serializeTransactionId(1L), new LongVersion(1)), new Versioned<byte[]>(intToBytes(LogMetadata.LAYOUT_VERSION), null), new Versioned<byte[]>(null, null));
processLogMetadatas(uri, logName, logIdentifier, metadatas, false);
}
use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.
the class TestZKLogStreamMetadataStoreUtils method testProcessLogMetadatasWrongVersion.
@SuppressWarnings("unchecked")
@Test(timeout = 60000, expected = UnexpectedException.class)
public void testProcessLogMetadatasWrongVersion() throws Exception {
String rootPath = "/test-missing-version";
URI uri = DLMTestUtil.createDLMURI(2181, rootPath);
String logName = "test-log";
String logIdentifier = "<default>";
List<Versioned<byte[]>> metadatas = Lists.newArrayList(new Versioned<byte[]>(null, null), new Versioned<byte[]>(null, null), new Versioned<byte[]>(DLUtils.serializeTransactionId(1L), new LongVersion(1)), new Versioned<byte[]>(intToBytes(9999), null));
processLogMetadatas(uri, logName, logIdentifier, metadatas, false);
}
use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.
the class TestZKLogStreamMetadataStoreUtils method testProcessLogMetadatasMissingAllocatorPath.
@SuppressWarnings("unchecked")
@Test(timeout = 60000, expected = UnexpectedException.class)
public void testProcessLogMetadatasMissingAllocatorPath() throws Exception {
String rootPath = "/test-missing-version";
URI uri = DLMTestUtil.createDLMURI(2181, rootPath);
String logName = "test-log";
String logIdentifier = "<default>";
List<Versioned<byte[]>> metadatas = Lists.newArrayList(new Versioned<byte[]>(null, null), new Versioned<byte[]>(null, null), new Versioned<byte[]>(DLUtils.serializeTransactionId(1L), new LongVersion(1)), new Versioned<byte[]>(intToBytes(LogMetadata.LAYOUT_VERSION), null), new Versioned<byte[]>(new byte[0], new LongVersion(1)), new Versioned<byte[]>(new byte[0], new LongVersion(1)), new Versioned<byte[]>(DLUtils.serializeLogSegmentSequenceNumber(1L), new LongVersion(1)), new Versioned<byte[]>(null, null));
processLogMetadatas(uri, logName, logIdentifier, metadatas, true);
}
use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.
the class BookieShellTest method setup.
@Before
public void setup() throws Exception {
// setup the required mocks before constructing bookie shell.
this.mockLastMarkCommand = mock(LastMarkCommand.class);
whenNew(LastMarkCommand.class).withNoArguments().thenReturn(mockLastMarkCommand);
this.mockSimpleTestCommand = spy(new SimpleTestCommand());
doNothing().when(mockSimpleTestCommand).run(any(ServerConfiguration.class));
whenNew(SimpleTestCommand.class).withNoArguments().thenReturn(mockSimpleTestCommand);
this.mockListBookiesCommand = spy(new ListBookiesCommand());
doNothing().when(mockListBookiesCommand).run(any(ServerConfiguration.class));
whenNew(ListBookiesCommand.class).withNoArguments().thenReturn(mockListBookiesCommand);
// construct the bookie shell.
this.shell = new BookieShell(LedgerIdFormatter.LONG_LEDGERID_FORMATTER, EntryFormatter.STRING_FORMATTER);
this.admin = PowerMockito.mock(BookKeeperAdmin.class);
whenNew(BookKeeperAdmin.class).withParameterTypes(ClientConfiguration.class).withArguments(any(ClientConfiguration.class)).thenReturn(admin);
this.clientConf = new ClientConfiguration();
this.clientConf.setMetadataServiceUri("zk://127.0.0.1/path/to/ledgers");
when(admin.getConf()).thenReturn(this.clientConf);
this.rm = PowerMockito.mock(RegistrationManager.class);
this.cookie = Cookie.newBuilder().setBookieHost("127.0.0.1:3181").setInstanceId("xyz").setJournalDirs("/path/to/journal/dir").setLedgerDirs("/path/to/journal/dir").setLayoutVersion(Cookie.CURRENT_COOKIE_LAYOUT_VERSION).build();
this.version = new LongVersion(1L);
when(rm.readCookie(anyString())).thenReturn(new Versioned<>(cookie.toString().getBytes(UTF_8), version));
this.driver = mock(MetadataBookieDriver.class);
when(driver.getRegistrationManager()).thenReturn(rm);
PowerMockito.mockStatic(MetadataDrivers.class);
PowerMockito.doAnswer(invocationOnMock -> {
Function<RegistrationManager, Object> function = invocationOnMock.getArgument(1);
function.apply(rm);
return null;
}).when(MetadataDrivers.class, "runFunctionWithRegistrationManager", any(ServerConfiguration.class), any(Function.class));
}
Aggregations