You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by li...@apache.org on 2022/09/07 01:57:48 UTC
[pulsar] branch master updated: [improve][pulsar-client-tools] Updated set retention time description and added test cases including default time (#16130)
This is an automated email from the ASF dual-hosted git repository.
liuyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 6c0218667ca [improve][pulsar-client-tools] Updated set retention time description and added test cases including default time (#16130)
6c0218667ca is described below
commit 6c0218667cad940ac959a694fe7d7df5c664958a
Author: mans2singh <ma...@users.noreply.github.com>
AuthorDate: Tue Sep 6 21:57:41 2022 -0400
[improve][pulsar-client-tools] Updated set retention time description and added test cases including default time (#16130)
---
.../pulsar/admin/cli/PulsarAdminToolTest.java | 70 ++++++++++++++++++++++
.../org/apache/pulsar/admin/cli/CmdNamespaces.java | 11 +++-
.../apache/pulsar/admin/cli/CmdTopicPolicies.java | 11 +++-
.../org/apache/pulsar/admin/cli/CmdTopics.java | 11 +++-
4 files changed, 94 insertions(+), 9 deletions(-)
diff --git a/pulsar-client-tools-test/src/test/java/org/apache/pulsar/admin/cli/PulsarAdminToolTest.java b/pulsar-client-tools-test/src/test/java/org/apache/pulsar/admin/cli/PulsarAdminToolTest.java
index 3aac16a2309..6e59eaefd0a 100644
--- a/pulsar-client-tools-test/src/test/java/org/apache/pulsar/admin/cli/PulsarAdminToolTest.java
+++ b/pulsar-client-tools-test/src/test/java/org/apache/pulsar/admin/cli/PulsarAdminToolTest.java
@@ -23,6 +23,7 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.longThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -590,6 +591,34 @@ public class PulsarAdminToolTest {
verify(mockNamespaces).setRetention("myprop/clust/ns1",
new RetentionPolicies(60, 1));
+ // Test with default time unit (seconds)
+ namespaces = new CmdNamespaces(() -> admin);
+ reset(mockNamespaces);
+ namespaces.run(split("set-retention myprop/clust/ns1 -t 120 -s 20M"));
+ verify(mockNamespaces).setRetention("myprop/clust/ns1",
+ new RetentionPolicies(2, 20));
+
+ // Test with explicit time unit (seconds)
+ namespaces = new CmdNamespaces(() -> admin);
+ reset(mockNamespaces);
+ namespaces.run(split("set-retention myprop/clust/ns1 -t 120s -s 20M"));
+ verify(mockNamespaces).setRetention("myprop/clust/ns1",
+ new RetentionPolicies(2, 20));
+
+ // Test size with default size less than 1 mb
+ namespaces = new CmdNamespaces(() -> admin);
+ reset(mockNamespaces);
+ namespaces.run(split("set-retention myprop/clust/ns1 -t 120s -s 4096"));
+ verify(mockNamespaces).setRetention("myprop/clust/ns1",
+ new RetentionPolicies(2, 0));
+
+ // Test size with default size greater than 1mb
+ namespaces = new CmdNamespaces(() -> admin);
+ reset(mockNamespaces);
+ namespaces.run(split("set-retention myprop/clust/ns1 -t 180 -s " + (2 * 1024 * 1024)));
+ verify(mockNamespaces).setRetention("myprop/clust/ns1",
+ new RetentionPolicies(3, 2));
+
namespaces.run(split("get-retention myprop/clust/ns1"));
verify(mockNamespaces).getRetention("myprop/clust/ns1");
@@ -948,6 +977,35 @@ public class PulsarAdminToolTest {
cmdTopics.run(split("set-retention persistent://myprop/clust/ns1/ds1 -t 10m -s 20M"));
verify(mockTopicsPolicies).setRetention("persistent://myprop/clust/ns1/ds1",
new RetentionPolicies(10, 20));
+
+ // Test with default time unit (seconds)
+ cmdTopics = new CmdTopicPolicies(() -> admin);
+ reset(mockTopicsPolicies);
+ cmdTopics.run(split("set-retention persistent://myprop/clust/ns1/ds1 -t 180 -s 20M"));
+ verify(mockTopicsPolicies).setRetention("persistent://myprop/clust/ns1/ds1",
+ new RetentionPolicies(3, 20));
+
+ // Test with explicit time unit (seconds)
+ cmdTopics = new CmdTopicPolicies(() -> admin);
+ reset(mockTopicsPolicies);
+ cmdTopics.run(split("set-retention persistent://myprop/clust/ns1/ds1 -t 180s -s 20M"));
+ verify(mockTopicsPolicies).setRetention("persistent://myprop/clust/ns1/ds1",
+ new RetentionPolicies(3, 20));
+
+ // Test size with default size less than 1 mb
+ cmdTopics = new CmdTopicPolicies(() -> admin);
+ reset(mockTopicsPolicies);
+ cmdTopics.run(split("set-retention persistent://myprop/clust/ns1/ds1 -t 180 -s 4096"));
+ verify(mockTopicsPolicies).setRetention("persistent://myprop/clust/ns1/ds1",
+ new RetentionPolicies(3, 0));
+
+ // Test size with default size greater than 1mb
+ cmdTopics = new CmdTopicPolicies(() -> admin);
+ reset(mockTopicsPolicies);
+ cmdTopics.run(split("set-retention persistent://myprop/clust/ns1/ds1 -t 180 -s " + (2 * 1024 * 1024)));
+ verify(mockTopicsPolicies).setRetention("persistent://myprop/clust/ns1/ds1",
+ new RetentionPolicies(3, 2));
+
cmdTopics.run(split("remove-retention persistent://myprop/clust/ns1/ds1"));
verify(mockTopicsPolicies).removeRetention("persistent://myprop/clust/ns1/ds1");
@@ -1122,6 +1180,18 @@ public class PulsarAdminToolTest {
cmdTopics.run(split("set-retention persistent://myprop/clust/ns1/ds1 -t 10m -s 20M -g"));
verify(mockGlobalTopicsPolicies).setRetention("persistent://myprop/clust/ns1/ds1",
new RetentionPolicies(10, 20));
+
+ cmdTopics = new CmdTopicPolicies(() -> admin);
+ cmdTopics.run(split("set-retention persistent://myprop/clust/ns1/ds1 -t 1440s -s 20M -g"));
+ verify(mockGlobalTopicsPolicies).setRetention("persistent://myprop/clust/ns1/ds1",
+ new RetentionPolicies(24, 20));
+
+ cmdTopics = new CmdTopicPolicies(() -> admin);
+ reset(mockGlobalTopicsPolicies);
+ cmdTopics.run(split("set-retention persistent://myprop/clust/ns1/ds1 -t 1440 -s 20M -g"));
+ verify(mockGlobalTopicsPolicies).setRetention("persistent://myprop/clust/ns1/ds1",
+ new RetentionPolicies(24, 20));
+
cmdTopics.run(split("remove-retention persistent://myprop/clust/ns1/ds1 -g"));
verify(mockGlobalTopicsPolicies).removeRetention("persistent://myprop/clust/ns1/ds1");
diff --git a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdNamespaces.java b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdNamespaces.java
index 323b47a2359..faebdae8290 100644
--- a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdNamespaces.java
+++ b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdNamespaces.java
@@ -742,11 +742,16 @@ public class CmdNamespaces extends CmdBase {
private java.util.List<String> params;
@Parameter(names = { "--time",
- "-t" }, description = "Retention time in minutes (or minutes, hours,days,weeks eg: 100m, 3h, 2d, 5w). "
- + "0 means no retention and -1 means infinite time retention", required = true)
+ "-t" }, description = "Retention time with optional time unit suffix. "
+ + "For example, 100m, 3h, 2d, 5w. "
+ + "If the time unit is not specified, the default unit is seconds. For example, "
+ + "-t 120 sets retention to 2 minutes. "
+ + "0 means no retention and -1 means infinite time retention.", required = true)
private String retentionTimeStr;
- @Parameter(names = { "--size", "-s" }, description = "Retention size limit (eg: 10M, 16G, 3T). "
+ @Parameter(names = { "--size", "-s" }, description = "Retention size limit with optional size unit suffix. "
+ + "For example, 4096, 10M, 16G, 3T. The size unit suffix character can be k/K, m/M, g/G, or t/T. "
+ + "If the size unit suffix is not specified, the default unit is bytes. "
+ "0 or less than 1MB means no retention and -1 means infinite size retention", required = true)
private String limitStr;
diff --git a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopicPolicies.java b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopicPolicies.java
index 99bf69b10f5..4a539d519de 100644
--- a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopicPolicies.java
+++ b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopicPolicies.java
@@ -527,11 +527,16 @@ public class CmdTopicPolicies extends CmdBase {
private List<String> params;
@Parameter(names = { "--time",
- "-t" }, description = "Retention time in minutes (or minutes, hours,days,weeks eg: 100m, 3h, 2d, 5w). "
- + "0 means no retention and -1 means infinite time retention", required = true)
+ "-t" }, description = "Retention time with optional time unit suffix. "
+ + "For example, 100m, 3h, 2d, 5w. "
+ + "If the time unit is not specified, the default unit is seconds. For example, "
+ + "-t 120 sets retention to 2 minutes. "
+ + "0 means no retention and -1 means infinite time retention.", required = true)
private String retentionTimeStr;
- @Parameter(names = { "--size", "-s" }, description = "Retention size limit (eg: 10M, 16G, 3T). "
+ @Parameter(names = { "--size", "-s" }, description = "Retention size limit with optional size unit suffix. "
+ + "For example, 4096, 10M, 16G, 3T. The size unit suffix character can be k/K, m/M, g/G, or t/T. "
+ + "If the size unit suffix is not specified, the default unit is bytes. "
+ "0 or less than 1MB means no retention and -1 means infinite size retention", required = true)
private String limitStr;
diff --git a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java
index 8b12d70d057..ae37a591bae 100644
--- a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java
+++ b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java
@@ -1902,11 +1902,16 @@ public class CmdTopics extends CmdBase {
private java.util.List<String> params;
@Parameter(names = { "--time",
- "-t" }, description = "Retention time in minutes (or minutes, hours,days,weeks eg: 100m, 3h, 2d, 5w). "
- + "0 means no retention and -1 means infinite time retention", required = true)
+ "-t" }, description = "Retention time with optional time unit suffix. "
+ + "For example, 100m, 3h, 2d, 5w. "
+ + "If the time unit is not specified, the default unit is seconds. For example, "
+ + "-t 120 will set retention to 2 minutes. "
+ + "0 means no retention and -1 means infinite time retention.", required = true)
private String retentionTimeStr;
- @Parameter(names = { "--size", "-s" }, description = "Retention size limit (eg: 10M, 16G, 3T). "
+ @Parameter(names = { "--size", "-s" }, description = "Retention size limit with optional size unit suffix. "
+ + "For example, 4096, 10M, 16G, 3T. The size unit suffix character can be k/K, m/M, g/G, or t/T. "
+ + "If the size unit suffix is not specified, the default unit is bytes. "
+ "0 or less than 1MB means no retention and -1 means infinite size retention", required = true)
private String limitStr;