Search in sources :

Example 1 with SimpleTestCommand

use of org.apache.bookkeeper.tools.cli.commands.client.SimpleTestCommand 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

UTF_8 (com.google.common.base.Charsets.UTF_8)1 Maps (com.google.common.collect.Maps)1 Set (java.util.Set)1 SortedMap (java.util.SortedMap)1 Function (java.util.function.Function)1 MyCommand (org.apache.bookkeeper.bookie.BookieShell.MyCommand)1 RecoverCmd (org.apache.bookkeeper.bookie.BookieShell.RecoverCmd)1 BookKeeperAdmin (org.apache.bookkeeper.client.BookKeeperAdmin)1 LedgerMetadata (org.apache.bookkeeper.client.LedgerMetadata)1 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)1 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)1 RegistrationManager (org.apache.bookkeeper.discover.RegistrationManager)1 MetadataBookieDriver (org.apache.bookkeeper.meta.MetadataBookieDriver)1 MetadataDrivers (org.apache.bookkeeper.meta.MetadataDrivers)1 LastMarkCommand (org.apache.bookkeeper.tools.cli.commands.bookie.LastMarkCommand)1 SimpleTestCommand (org.apache.bookkeeper.tools.cli.commands.client.SimpleTestCommand)1 ListBookiesCommand (org.apache.bookkeeper.tools.cli.commands.cluster.ListBookiesCommand)1 EntryFormatter (org.apache.bookkeeper.util.EntryFormatter)1 LedgerIdFormatter (org.apache.bookkeeper.util.LedgerIdFormatter)1 LongVersion (org.apache.bookkeeper.versioning.LongVersion)1