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));
}
Aggregations