This is an automated email from the ASF dual-hosted git repository.
hangc0276 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/master by this push:
new cbb336702a Fix issue where options for sanity test command are ignored
(#4691)
cbb336702a is described below
commit cbb336702aaa17608d811a52ca7b03559e29cbb0
Author: Masahiro Sakamoto <[email protected]>
AuthorDate: Wed May 27 08:25:52 2026 +0900
Fix issue where options for sanity test command are ignored (#4691)
---
.../org/apache/bookkeeper/bookie/BookieShell.java | 4 ++-
.../cli/commands/bookie/SanityTestCommand.java | 8 +++--
.../apache/bookkeeper/bookie/BookieShellTest.java | 41 ++++++++++++++++++++++
3 files changed, 50 insertions(+), 3 deletions(-)
diff --git
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
index 2722c333bd..a8c96dc0b8 100644
---
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
+++
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
@@ -1082,8 +1082,10 @@ public class BookieShell implements Tool {
@Override
int runCmd(CommandLine cmdLine) throws Exception {
- SanityTestCommand command = new SanityTestCommand();
SanityTestCommand.SanityFlags flags = new
SanityTestCommand.SanityFlags();
+ flags.entries(getOptionIntValue(cmdLine, "e", 10));
+ flags.timeout(getOptionIntValue(cmdLine, "t", 1));
+ SanityTestCommand command =
SanityTestCommand.newSanityTestCommand(flags);
boolean result = command.apply(bkConf, flags);
return (result) ? 0 : -1;
}
diff --git
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/bookie/SanityTestCommand.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/bookie/SanityTestCommand.java
index ec8137b153..690d9cfae7 100644
---
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/bookie/SanityTestCommand.java
+++
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/bookie/SanityTestCommand.java
@@ -59,12 +59,16 @@ public class SanityTestCommand extends
BookieCommand<SanityFlags> {
super(CliSpec.<SanityFlags>newBuilder().withFlags(flags).withName(NAME).withDescription(DESC).build());
}
+ public static SanityTestCommand newSanityTestCommand(SanityFlags flags) {
+ return new SanityTestCommand(flags);
+ }
+
/**
* Flags for sanity command.
*/
@Accessors(fluent = true)
@Setter
- public static class SanityFlags extends CliFlags{
+ public static class SanityFlags extends CliFlags {
@Parameter(names = {"-e", "--entries"}, description = "Total entries
to be added for the test (default 10)")
private int entries = 10;
@@ -84,7 +88,7 @@ public class SanityTestCommand extends
BookieCommand<SanityFlags> {
}
}
- private static boolean handle(ServerConfiguration conf, SanityFlags
cmdFlags) throws Exception {
+ public static boolean handle(ServerConfiguration conf, SanityFlags
cmdFlags) throws Exception {
try {
return handleAsync(conf, cmdFlags).get();
} catch (Exception e) {
diff --git
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieShellTest.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieShellTest.java
index a802fc4f6c..9df3b51c6f 100644
---
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieShellTest.java
+++
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieShellTest.java
@@ -38,6 +38,8 @@ import static org.mockito.Mockito.when;
import com.google.common.collect.Maps;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
+import java.lang.reflect.Field;
+import java.util.List;
import java.util.Set;
import java.util.SortedMap;
import java.util.function.Function;
@@ -52,6 +54,8 @@ import org.apache.bookkeeper.discover.RegistrationManager;
import org.apache.bookkeeper.meta.MetadataDrivers;
import org.apache.bookkeeper.net.BookieId;
import org.apache.bookkeeper.tools.cli.commands.bookie.LastMarkCommand;
+import org.apache.bookkeeper.tools.cli.commands.bookie.SanityTestCommand;
+import
org.apache.bookkeeper.tools.cli.commands.bookie.SanityTestCommand.SanityFlags;
import org.apache.bookkeeper.tools.cli.commands.bookies.ClusterInfoCommand;
import org.apache.bookkeeper.tools.cli.commands.bookies.ListBookiesCommand;
import org.apache.bookkeeper.tools.cli.commands.client.SimpleTestCommand;
@@ -70,6 +74,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
import org.mockito.MockedStatic;
import org.mockito.junit.MockitoJUnitRunner;
@@ -376,6 +381,42 @@ public class BookieShellTest {
.apply(same(shell.bkConf), any(CliFlags.class));
}
+ @Test
+ public void testBookieSanityTestCmd() throws Exception {
+ SanityTestCommand mockCommand = spy(new SanityTestCommand());
+
+ @Cleanup
+ MockedStatic<SanityTestCommand> commandMockedStatic =
mockStatic(SanityTestCommand.class);
+ commandMockedStatic.when(() ->
SanityTestCommand.newSanityTestCommand(any(SanityFlags.class)))
+ .thenReturn(mockCommand);
+ commandMockedStatic.when(() ->
SanityTestCommand.handle(any(ServerConfiguration.class),
any(SanityFlags.class)))
+ .thenReturn(true);
+
+ shell.run(new String[] {
+ "bookiesanity"
+ });
+
+ shell.run(new String[] {
+ "bookiesanity",
+ "-e", "20",
+ "-t", "5"
+ });
+
+ ArgumentCaptor<SanityFlags> flagsCaptor =
ArgumentCaptor.forClass(SanityFlags.class);
+ commandMockedStatic.verify(() ->
SanityTestCommand.handle(same(shell.bkConf), flagsCaptor.capture()), times(2));
+ List<SanityFlags> flagsList = flagsCaptor.getAllValues();
+
+ Field entriesField = SanityFlags.class.getDeclaredField("entries");
+ entriesField.setAccessible(true);
+ assertEquals(10, (int) entriesField.get(flagsList.get(0))); // default
value
+ assertEquals(20, (int) entriesField.get(flagsList.get(1)));
+
+ Field timeoutField = SanityFlags.class.getDeclaredField("timeout");
+ timeoutField.setAccessible(true);
+ assertEquals(1, (int) timeoutField.get(flagsList.get(0))); // default
value
+ assertEquals(5, (int) timeoutField.get(flagsList.get(1)));
+ }
+
@Test
public void testSimpleTestCmd() throws Exception {
SimpleTestCommand.Flags mockSimpleTestFlags = spy(new
SimpleTestCommand.Flags());