Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cli] Fix: recover command doesn't accept rate limit parameter #4535

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ public RecoverCmd() {
opts.addOption("sk", "skipOpenLedgers", false, "Skip recovering open ledgers");
opts.addOption("d", "deleteCookie", false, "Delete cookie node for the bookie.");
opts.addOption("sku", "skipUnrecoverableLedgers", false, "Skip unrecoverable ledgers.");
opts.addOption("rate", "replicationRate", false, "Replication rate by bytes");
opts.addOption("rate", "replicationRate", true, "Replication rate by bytes");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
Expand All @@ -35,6 +36,8 @@
import static org.mockito.Mockito.when;

import com.google.common.collect.Maps;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Set;
import java.util.SortedMap;
import java.util.function.Function;
Expand Down Expand Up @@ -189,6 +192,14 @@ public void testRecoverCmdQuery() throws Exception {
verify(admin, times(1)).close();
}

@SuppressWarnings("unchecked")
@Test
public void testRecoverLedgerWithRateLimit() throws Exception {
testRecoverCmdRecoverLedger(
12345, false, false, false,
"-force", "-l", "12345", "-rate", "10000", "127.0.0.1:3181");
}

@Test
public void testRecoverCmdRecoverLedgerDefault() throws Exception {
// default behavior
Expand Down Expand Up @@ -235,21 +246,30 @@ void testRecoverCmdRecoverLedger(long ledgerId,
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));
bookKeeperAdminMockedStatic.verify(() -> BookKeeperAdmin.newBookKeeperAdmin(any(ClientConfiguration.class)),
times(1));
verify(admin, times(1))
.recoverBookieData(eq(ledgerId), any(Set.class), eq(dryrun), eq(skipOpenLedgers));
verify(admin, times(1)).close();
if (removeCookies) {
MetadataDrivers.runFunctionWithRegistrationManager(any(ServerConfiguration.class), any(Function.class));
verify(rm, times(1)).readCookie(any(BookieId.class));
verify(rm, times(1)).removeCookie(any(BookieId.class), eq(version));
} else {
verify(rm, times(0)).readCookie(any(BookieId.class));
verify(rm, times(0)).removeCookie(any(BookieId.class), eq(version));
final PrintStream oldPs = System.err;
try (ByteArrayOutputStream outContent = new ByteArrayOutputStream()) {
System.setErr(new PrintStream(outContent));

RecoverCmd cmd = (RecoverCmd) shell.commands.get("recover");
CommandLine cmdLine = parseCommandLine(cmd, args);
assertEquals(0, cmd.runCmd(cmdLine));
bookKeeperAdminMockedStatic.verify(() -> BookKeeperAdmin.newBookKeeperAdmin(any(ClientConfiguration.class)),
times(1));
verify(admin, times(1))
.recoverBookieData(eq(ledgerId), any(Set.class), eq(dryrun), eq(skipOpenLedgers));
verify(admin, times(1)).close();
if (removeCookies) {
MetadataDrivers.runFunctionWithRegistrationManager(any(ServerConfiguration.class), any(Function.class));
verify(rm, times(1)).readCookie(any(BookieId.class));
verify(rm, times(1)).removeCookie(any(BookieId.class), eq(version));
} else {
verify(rm, times(0)).readCookie(any(BookieId.class));
verify(rm, times(0)).removeCookie(any(BookieId.class), eq(version));
}
assertFalse("invalid value for option detected:\n" + outContent,
outContent.toString().contains("invalid value for option"));
} finally {
System.setErr(oldPs);
}
}

Expand All @@ -261,6 +281,14 @@ public void testRecoverCmdRecoverDefault() throws Exception {
"-force", "127.0.0.1:3181");
}

@Test
public void testRecoverWithRateLimit() throws Exception {
// default behavior
testRecoverCmdRecover(
false, false, false, false,
"-force", "127.0.0.1:3181");
}

@Test
public void testRecoverCmdRecoverDeleteCookie() throws Exception {
// dryrun
Expand Down Expand Up @@ -307,21 +335,30 @@ void testRecoverCmdRecover(boolean dryrun,
boolean removeCookies,
boolean skipUnrecoverableLedgers,
String... args) throws Exception {
RecoverCmd cmd = (RecoverCmd) shell.commands.get("recover");
CommandLine cmdLine = parseCommandLine(cmd, args);
assertEquals(0, cmd.runCmd(cmdLine));
bookKeeperAdminMockedStatic.verify(() -> BookKeeperAdmin.newBookKeeperAdmin(any(ClientConfiguration.class)),
times(1));
verify(admin, times(1))
.recoverBookieData(any(Set.class), eq(dryrun), eq(skipOpenLedgers), eq(skipUnrecoverableLedgers));
verify(admin, times(1)).close();
if (removeCookies) {
MetadataDrivers.runFunctionWithRegistrationManager(any(ServerConfiguration.class), any(Function.class));
verify(rm, times(1)).readCookie(any(BookieId.class));
verify(rm, times(1)).removeCookie(any(BookieId.class), eq(version));
} else {
verify(rm, times(0)).readCookie(any(BookieId.class));
verify(rm, times(0)).removeCookie(any(BookieId.class), eq(version));
final PrintStream oldPs = System.err;
try (ByteArrayOutputStream outContent = new ByteArrayOutputStream()) {
System.setErr(new PrintStream(outContent));

RecoverCmd cmd = (RecoverCmd) shell.commands.get("recover");
CommandLine cmdLine = parseCommandLine(cmd, args);
assertEquals(0, cmd.runCmd(cmdLine));
bookKeeperAdminMockedStatic.verify(() -> BookKeeperAdmin.newBookKeeperAdmin(any(ClientConfiguration.class)),
times(1));
verify(admin, times(1))
.recoverBookieData(any(Set.class), eq(dryrun), eq(skipOpenLedgers), eq(skipUnrecoverableLedgers));
verify(admin, times(1)).close();
if (removeCookies) {
MetadataDrivers.runFunctionWithRegistrationManager(any(ServerConfiguration.class), any(Function.class));
verify(rm, times(1)).readCookie(any(BookieId.class));
verify(rm, times(1)).removeCookie(any(BookieId.class), eq(version));
} else {
verify(rm, times(0)).readCookie(any(BookieId.class));
verify(rm, times(0)).removeCookie(any(BookieId.class), eq(version));
}
assertFalse("invalid value for option detected:\n" + outContent,
outContent.toString().contains("invalid value for option"));
} finally {
System.setErr(oldPs);
}
}

Expand Down
Loading