This is an automated email from the ASF dual-hosted git repository.
eolivelli 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 27210ea795 Add option to clean up test ledger after simpletest. (#3474)
27210ea795 is described below
commit 27210ea795a9ec17fa4aa85e2f9c8915d3369ebf
Author: Marvin Cai <[email protected]>
AuthorDate: Mon Sep 12 03:50:21 2022 -0700
Add option to clean up test ledger after simpletest. (#3474)
* Add option to clean up test ledger after simpletest.
Ledger created by simpletest could be trouble when decommissioning if
we set small esemble size, so add option to clean it up after test.
Also adding metadata to such test ledger so we can also manually clean it
up later.
---
.../cli/commands/client/SimpleTestCommand.java | 9 ++++++
.../cli/commands/client/SimpleTestCommandTest.java | 32 +++++++++++++++++++---
2 files changed, 37 insertions(+), 4 deletions(-)
diff --git
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/client/SimpleTestCommand.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/client/SimpleTestCommand.java
index bcec5e805d..c083a515ed 100644
---
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/client/SimpleTestCommand.java
+++
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/client/SimpleTestCommand.java
@@ -21,7 +21,9 @@ package org.apache.bookkeeper.tools.cli.commands.client;
import static org.apache.bookkeeper.common.concurrent.FutureUtils.result;
import com.beust.jcommander.Parameter;
+import com.google.common.collect.ImmutableMap;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
import lombok.Setter;
import lombok.experimental.Accessors;
@@ -59,6 +61,8 @@ public class SimpleTestCommand extends ClientCommand<Flags> {
private int ackQuorumSize = 2;
@Parameter(names = { "-n", "--num-entries" }, description = "Entries
to write (default 100)")
private int numEntries = 100;
+ @Parameter(names = { "-c", "--clean-up" }, description = "Clean up
ledger created after simple test")
+ private boolean cleanup = false;
}
public SimpleTestCommand() {
@@ -83,6 +87,7 @@ public class SimpleTestCommand extends ClientCommand<Flags> {
.withWriteQuorumSize(flags.writeQuorumSize)
.withAckQuorumSize(flags.ackQuorumSize)
.withDigestType(DigestType.CRC32C)
+ .withCustomMetadata(ImmutableMap.of("Bookie",
NAME.getBytes(StandardCharsets.UTF_8)))
.withPassword(new byte[0])
.execute())) {
@@ -97,6 +102,10 @@ public class SimpleTestCommand extends ClientCommand<Flags>
{
}
}
LOG.info("{} entries written to ledger {}", flags.numEntries,
wh.getId());
+ if (flags.cleanup) {
+ LOG.info("Cleaning up the ledger {}", wh.getId());
+
result(bk.newDeleteLedgerOp().withLedgerId(wh.getId()).execute());
+ }
}
}
}
diff --git
a/tools/ledger/src/test/java/org/apache/bookkeeper/tools/cli/commands/client/SimpleTestCommandTest.java
b/tools/ledger/src/test/java/org/apache/bookkeeper/tools/cli/commands/client/SimpleTestCommandTest.java
index a63e108062..d7c80279ee 100644
---
a/tools/ledger/src/test/java/org/apache/bookkeeper/tools/cli/commands/client/SimpleTestCommandTest.java
+++
b/tools/ledger/src/test/java/org/apache/bookkeeper/tools/cli/commands/client/SimpleTestCommandTest.java
@@ -18,21 +18,29 @@
*/
package org.apache.bookkeeper.tools.cli.commands.client;
+import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.bookkeeper.client.api.CreateBuilder;
+import org.apache.bookkeeper.client.api.DeleteBuilder;
import org.apache.bookkeeper.client.api.DigestType;
import org.apache.bookkeeper.client.api.WriteHandle;
import org.apache.bookkeeper.common.concurrent.FutureUtils;
import org.apache.bookkeeper.tools.cli.helpers.ClientCommandTestBase;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
/**
* Unit test of {@link SimpleTestCommand}.
@@ -45,7 +53,8 @@ public class SimpleTestCommandTest extends
ClientCommandTestBase {
"-e", "5",
"-w", "3",
"-a", "3",
- "-n", "10");
+ "-n", "10",
+ "-c");
}
@Test
@@ -54,34 +63,49 @@ public class SimpleTestCommandTest extends
ClientCommandTestBase {
"--ensemble-size", "5",
"--write-quorum-size", "3",
"--ack-quorum-size", "3",
- "--num-entries", "10");
+ "--num-entries", "10",
+ "-c");
}
+ @SuppressWarnings("unchecked")
public void testCommand(String... args) throws Exception {
WriteHandle wh = mock(WriteHandle.class);
AtomicLong counter = new AtomicLong(0L);
when(wh.append(any(byte[].class))).thenReturn(counter.get());
CreateBuilder createBuilder = mock(CreateBuilder.class);
- when(createBuilder.execute())
- .thenReturn(FutureUtils.value(wh));
+ when(createBuilder.execute()).thenReturn(FutureUtils.value(wh));
when(createBuilder.withEnsembleSize(anyInt())).thenReturn(createBuilder);
+
when(createBuilder.withCustomMetadata(any())).thenReturn(createBuilder);
when(createBuilder.withWriteQuorumSize(anyInt())).thenReturn(createBuilder);
when(createBuilder.withAckQuorumSize(anyInt())).thenReturn(createBuilder);
when(createBuilder.withDigestType(any(DigestType.class))).thenReturn(createBuilder);
when(createBuilder.withPassword(any(byte[].class))).thenReturn(createBuilder);
+
when(createBuilder.execute()).thenReturn(CompletableFuture.completedFuture(wh));
when(mockBk.newCreateLedgerOp()).thenReturn(createBuilder);
+ DeleteBuilder deleteBuilder = mock(DeleteBuilder.class);
+ when(deleteBuilder.withLedgerId(anyLong())).thenReturn(deleteBuilder);
+
when(deleteBuilder.execute()).thenReturn(CompletableFuture.completedFuture(null));
+ when(mockBk.newDeleteLedgerOp()).thenReturn(deleteBuilder);
+
SimpleTestCommand cmd = new SimpleTestCommand();
cmd.apply(bkFlags, args);
// verify create builder
+ ArgumentCaptor<Map> mapArgumentCaptor =
ArgumentCaptor.forClass(Map.class);
verify(createBuilder, times(1)).withEnsembleSize(eq(5));
verify(createBuilder, times(1)).withWriteQuorumSize(eq(3));
verify(createBuilder, times(1)).withAckQuorumSize(eq(3));
+ verify(createBuilder,
times(1)).withCustomMetadata(mapArgumentCaptor.capture());
+ assertTrue(Arrays.equals((byte[])
mapArgumentCaptor.getValue().get("Bookie"),
+ "simpletest".getBytes(StandardCharsets.UTF_8)));
verify(createBuilder, times(1)).withDigestType(eq(DigestType.CRC32C));
verify(createBuilder, times(1)).withPassword(eq(new byte[0]));
verify(createBuilder, times(1)).execute();
+ verify(deleteBuilder, times(1)).withLedgerId(eq(0L));
+ verify(deleteBuilder, times(1)).execute();
+
// verify appends
verify(wh, times(10)).append(eq(new byte[100]));
}