zymap commented on code in PR #3675:
URL: https://github.com/apache/bookkeeper/pull/3675#discussion_r1034232650
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/client/SimpleTestCommand.java:
##########
@@ -81,6 +83,7 @@ public SimpleTestCommand(Flags flags) {
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")
protected void run(BookKeeper bk, Flags flags) throws Exception {
byte[] data = new byte[100]; // test data
+ Arrays.fill(data, (byte) '1');
Review Comment:
Fill them randomly?
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/client/SimpleTestCommand.java:
##########
@@ -61,8 +65,6 @@ public static class Flags extends CliFlags {
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")
Review Comment:
It is an easily way to generate a ledger. I am not sure if it should be
deleted automatically. If we delete it automatically, the only way to get a
ledger is writing a program, it looks very inconvenient.
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/client/SimpleTestCommand.java:
##########
@@ -102,10 +105,15 @@ protected void run(BookKeeper bk, Flags flags) throws
Exception {
}
}
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());
+
+ try (ReadHandle rh =
result(bk.newOpenLedgerOp().withLedgerId(wh.getId()).withDigestType(DigestType.CRC32C)
+ .withPassword(new byte[0]).execute())) {
+ LedgerEntries ledgerEntries = rh.read(0, flags.numEntries);
+ for (LedgerEntry ledgerEntry : ledgerEntries) {
+ assert Arrays.equals(ledgerEntry.getEntryBytes(), data);
Review Comment:
The `assert` is always used to check whether the argument is null or not. We
need to enable it with `-ea` when executing the program. Does it make more
sense to log errors or throw exceptions?
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/client/SimpleTestCommand.java:
##########
@@ -102,10 +105,15 @@ protected void run(BookKeeper bk, Flags flags) throws
Exception {
}
}
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());
+
+ try (ReadHandle rh =
result(bk.newOpenLedgerOp().withLedgerId(wh.getId()).withDigestType(DigestType.CRC32C)
+ .withPassword(new byte[0]).execute())) {
+ LedgerEntries ledgerEntries = rh.read(0, flags.numEntries);
+ for (LedgerEntry ledgerEntry : ledgerEntries) {
+ assert Arrays.equals(ledgerEntry.getEntryBytes(), data);
+ }
}
+ result(bk.newDeleteLedgerOp().withLedgerId(wh.getId()).execute());
Review Comment:
In Finally?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]