Search in sources :

Example 31 with LongVersion

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());
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) CompletableFuture(java.util.concurrent.CompletableFuture) Stat(org.apache.zookeeper.data.Stat) Transaction(org.apache.distributedlog.util.Transaction) LongVersion(org.apache.bookkeeper.versioning.LongVersion) Version(org.apache.bookkeeper.versioning.Version) LongVersion(org.apache.bookkeeper.versioning.LongVersion) LogMetadataForWriter(org.apache.distributedlog.metadata.LogMetadataForWriter) Test(org.junit.Test)

Example 32 with LongVersion

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);
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) LongVersion(org.apache.bookkeeper.versioning.LongVersion) URI(java.net.URI) Test(org.junit.Test)

Example 33 with LongVersion

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);
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) LongVersion(org.apache.bookkeeper.versioning.LongVersion) URI(java.net.URI) Test(org.junit.Test)

Example 34 with LongVersion

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);
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) LongVersion(org.apache.bookkeeper.versioning.LongVersion) URI(java.net.URI) Test(org.junit.Test)

Example 35 with LongVersion

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));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) LongVersion(org.apache.bookkeeper.versioning.LongVersion) EntryFormatter(org.apache.bookkeeper.util.EntryFormatter) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RunWith(org.junit.runner.RunWith) LedgerMetadata(org.apache.bookkeeper.client.LedgerMetadata) UTF_8(com.google.common.base.Charsets.UTF_8) PowerMockito.verifyNew(org.powermock.api.mockito.PowerMockito.verifyNew) RecoverCmd(org.apache.bookkeeper.bookie.BookieShell.RecoverCmd) MetadataDrivers(org.apache.bookkeeper.meta.MetadataDrivers) Function(java.util.function.Function) RegistrationManager(org.apache.bookkeeper.discover.RegistrationManager) ListBookiesCommand(org.apache.bookkeeper.tools.cli.commands.cluster.ListBookiesCommand) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) BasicParser(org.apache.commons.cli.BasicParser) Versioned(org.apache.bookkeeper.versioning.Versioned) CommandLine(org.apache.commons.cli.CommandLine) Assert.fail(org.junit.Assert.fail) PowerMockito.whenNew(org.powermock.api.mockito.PowerMockito.whenNew) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) PowerMockito(org.powermock.api.mockito.PowerMockito) Before(org.junit.Before) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) Maps(com.google.common.collect.Maps) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) LastMarkCommand(org.apache.bookkeeper.tools.cli.commands.bookie.LastMarkCommand) SimpleTestCommand(org.apache.bookkeeper.tools.cli.commands.client.SimpleTestCommand) PowerMockito.spy(org.powermock.api.mockito.PowerMockito.spy) MyCommand(org.apache.bookkeeper.bookie.BookieShell.MyCommand) ParseException(org.apache.commons.cli.ParseException) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) BookKeeperAdmin(org.apache.bookkeeper.client.BookKeeperAdmin) LedgerIdFormatter(org.apache.bookkeeper.util.LedgerIdFormatter) Assert.assertEquals(org.junit.Assert.assertEquals) SortedMap(java.util.SortedMap) MetadataBookieDriver(org.apache.bookkeeper.meta.MetadataBookieDriver) Version(org.apache.bookkeeper.versioning.Version) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ArgumentMatchers.same(org.mockito.ArgumentMatchers.same) Mockito.mock(org.mockito.Mockito.mock) MissingArgumentException(org.apache.commons.cli.MissingArgumentException) RegistrationManager(org.apache.bookkeeper.discover.RegistrationManager) SimpleTestCommand(org.apache.bookkeeper.tools.cli.commands.client.SimpleTestCommand) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) MetadataBookieDriver(org.apache.bookkeeper.meta.MetadataBookieDriver) Function(java.util.function.Function) LastMarkCommand(org.apache.bookkeeper.tools.cli.commands.bookie.LastMarkCommand) ListBookiesCommand(org.apache.bookkeeper.tools.cli.commands.cluster.ListBookiesCommand) LongVersion(org.apache.bookkeeper.versioning.LongVersion) BookKeeperAdmin(org.apache.bookkeeper.client.BookKeeperAdmin) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) Before(org.junit.Before)

Aggregations

LongVersion (org.apache.bookkeeper.versioning.LongVersion)56 Test (org.junit.Test)37 Versioned (org.apache.bookkeeper.versioning.Versioned)29 Stat (org.apache.zookeeper.data.Stat)25 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)21 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)20 Version (org.apache.bookkeeper.versioning.Version)18 GenericCallbackFuture (org.apache.bookkeeper.test.TestCallbacks.GenericCallbackFuture)16 BKException (org.apache.bookkeeper.client.BKException)12 VoidCallback (org.apache.zookeeper.AsyncCallback.VoidCallback)12 Set (java.util.Set)11 LedgerMetadata (org.apache.bookkeeper.client.LedgerMetadata)10 StatCallback (org.apache.zookeeper.AsyncCallback.StatCallback)10 DataCallback (org.apache.zookeeper.AsyncCallback.DataCallback)9 Before (org.junit.Before)9 URI (java.net.URI)8 ZKException (org.apache.distributedlog.exceptions.ZKException)8 KeeperException (org.apache.zookeeper.KeeperException)8 Assert.assertEquals (org.junit.Assert.assertEquals)8 Assert.fail (org.junit.Assert.fail)8