Search in sources :

Example 1 with RecoverCmd

use of org.apache.bookkeeper.bookie.BookieShell.RecoverCmd in project bookkeeper by apache.

the class BookieShellTest method testRecoverCmdRecoverLedger.

@SuppressWarnings("unchecked")
void testRecoverCmdRecoverLedger(long ledgerId, boolean dryrun, boolean skipOpenLedgers, boolean removeCookies, String... args) throws Exception {
    RecoverCmd cmd = (RecoverCmd) shell.commands.get("recover");
    CommandLine cmdLine = parseCommandLine(cmd, args);
    assertEquals(0, cmd.runCmd(cmdLine));
    PowerMockito.verifyNew(BookKeeperAdmin.class, times(1)).withArguments(any(ClientConfiguration.class));
    verify(admin, times(1)).recoverBookieData(eq(ledgerId), any(Set.class), eq(dryrun), eq(skipOpenLedgers));
    verify(admin, times(1)).close();
    if (removeCookies) {
        PowerMockito.verifyStatic(MetadataDrivers.class);
        MetadataDrivers.runFunctionWithRegistrationManager(any(ServerConfiguration.class), any(Function.class));
        verify(rm, times(1)).readCookie(anyString());
        verify(rm, times(1)).removeCookie(anyString(), eq(version));
    } else {
        verify(rm, times(0)).readCookie(anyString());
        verify(rm, times(0)).removeCookie(anyString(), eq(version));
    }
}
Also used : Function(java.util.function.Function) CommandLine(org.apache.commons.cli.CommandLine) Set(java.util.Set) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) RecoverCmd(org.apache.bookkeeper.bookie.BookieShell.RecoverCmd) BookKeeperAdmin(org.apache.bookkeeper.client.BookKeeperAdmin) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration)

Example 2 with RecoverCmd

use of org.apache.bookkeeper.bookie.BookieShell.RecoverCmd in project bookkeeper by apache.

the class BookieShellTest method testRecoverCmdQuery.

@SuppressWarnings("unchecked")
@Test
public void testRecoverCmdQuery() throws Exception {
    SortedMap<Long, LedgerMetadata> ledgersContainBookies = Maps.newTreeMap();
    when(admin.getLedgersContainBookies(any(Set.class))).thenReturn(ledgersContainBookies);
    RecoverCmd cmd = (RecoverCmd) shell.commands.get("recover");
    CommandLine cmdLine = parseCommandLine(cmd, "-force", "-q", "127.0.0.1:3181");
    assertEquals(0, cmd.runCmd(cmdLine));
    PowerMockito.verifyNew(BookKeeperAdmin.class, times(1)).withArguments(any(ClientConfiguration.class));
    verify(admin, times(1)).getLedgersContainBookies(any(Set.class));
    verify(admin, times(1)).close();
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) Set(java.util.Set) LedgerMetadata(org.apache.bookkeeper.client.LedgerMetadata) RecoverCmd(org.apache.bookkeeper.bookie.BookieShell.RecoverCmd) BookKeeperAdmin(org.apache.bookkeeper.client.BookKeeperAdmin) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with RecoverCmd

use of org.apache.bookkeeper.bookie.BookieShell.RecoverCmd in project bookkeeper by apache.

the class BookieShellTest method testRecoverCmdMissingArgument.

@Test
public void testRecoverCmdMissingArgument() throws Exception {
    RecoverCmd cmd = (RecoverCmd) shell.commands.get("recover");
    CommandLine cmdLine = parseCommandLine(cmd);
    try {
        cmd.runCmd(cmdLine);
        fail("should fail running command when the arguments are missing");
    } catch (MissingArgumentException e) {
    // expected
    }
    PowerMockito.verifyNew(BookKeeperAdmin.class, never()).withArguments(any(ClientConfiguration.class));
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) MissingArgumentException(org.apache.commons.cli.MissingArgumentException) RecoverCmd(org.apache.bookkeeper.bookie.BookieShell.RecoverCmd) BookKeeperAdmin(org.apache.bookkeeper.client.BookKeeperAdmin) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with RecoverCmd

use of org.apache.bookkeeper.bookie.BookieShell.RecoverCmd in project bookkeeper by apache.

the class BookieShellTest method testRecoverCmdRecover.

@SuppressWarnings("unchecked")
void testRecoverCmdRecover(boolean dryrun, boolean skipOpenLedgers, boolean removeCookies, String... args) throws Exception {
    RecoverCmd cmd = (RecoverCmd) shell.commands.get("recover");
    CommandLine cmdLine = parseCommandLine(cmd, args);
    assertEquals(0, cmd.runCmd(cmdLine));
    PowerMockito.verifyNew(BookKeeperAdmin.class, times(1)).withArguments(any(ClientConfiguration.class));
    verify(admin, times(1)).recoverBookieData(any(Set.class), eq(dryrun), eq(skipOpenLedgers));
    verify(admin, times(1)).close();
    if (removeCookies) {
        PowerMockito.verifyStatic(MetadataDrivers.class);
        MetadataDrivers.runFunctionWithRegistrationManager(any(ServerConfiguration.class), any(Function.class));
        verify(rm, times(1)).readCookie(anyString());
        verify(rm, times(1)).removeCookie(anyString(), eq(version));
    } else {
        verify(rm, times(0)).readCookie(anyString());
        verify(rm, times(0)).removeCookie(anyString(), eq(version));
    }
}
Also used : Function(java.util.function.Function) CommandLine(org.apache.commons.cli.CommandLine) Set(java.util.Set) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) RecoverCmd(org.apache.bookkeeper.bookie.BookieShell.RecoverCmd) BookKeeperAdmin(org.apache.bookkeeper.client.BookKeeperAdmin) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration)

Example 5 with RecoverCmd

use of org.apache.bookkeeper.bookie.BookieShell.RecoverCmd in project bookkeeper by apache.

the class BookieShellTest method testRecoverCmdInvalidBookieAddress.

@Test
public void testRecoverCmdInvalidBookieAddress() throws Exception {
    RecoverCmd cmd = (RecoverCmd) shell.commands.get("recover");
    CommandLine cmdLine = parseCommandLine(cmd, "127.0.0.1");
    assertEquals(-1, cmd.runCmd(cmdLine));
    PowerMockito.verifyNew(BookKeeperAdmin.class, never()).withArguments(any(ClientConfiguration.class));
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) RecoverCmd(org.apache.bookkeeper.bookie.BookieShell.RecoverCmd) BookKeeperAdmin(org.apache.bookkeeper.client.BookKeeperAdmin) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

RecoverCmd (org.apache.bookkeeper.bookie.BookieShell.RecoverCmd)5 BookKeeperAdmin (org.apache.bookkeeper.client.BookKeeperAdmin)5 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)5 CommandLine (org.apache.commons.cli.CommandLine)5 Set (java.util.Set)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Function (java.util.function.Function)2 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)2 LedgerMetadata (org.apache.bookkeeper.client.LedgerMetadata)1 MissingArgumentException (org.apache.commons.cli.MissingArgumentException)1