You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2018/07/26 06:02:27 UTC

[GitHub] sijie closed pull request #2182: Issue 2110: get-retention returns retentionSizeInMB as 0 when set to -1

sijie closed pull request #2182: Issue 2110: get-retention returns retentionSizeInMB as 0 when set to -1
URL: https://github.com/apache/incubator-pulsar/pull/2182
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 0eaf81b184..4f898a576d 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
@@ -342,7 +342,7 @@ void run() throws PulsarAdminException {
         private String retentionTimeStr;
 
         @Parameter(names = { "--size", "-s" }, description = "Retention size limit (eg: 10M, 16G, 3T). "
-                + "0 means no retention and -1 means infinite size retention", required = true)
+                + "0 or less than 1MB means no retention and -1 means infinite size retention", required = true)
         private String limitStr;
 
         @Override
@@ -351,8 +351,12 @@ void run() throws PulsarAdminException {
             long sizeLimit = validateSizeString(limitStr);
             int retentionTimeInMin = validateTimeString(retentionTimeStr);
 
-            sizeLimit = sizeLimit / (1024 * 1024);
-            int retentionSizeInMB = (int) sizeLimit;
+            int retentionSizeInMB;
+            if (sizeLimit != -1) {
+                retentionSizeInMB = (int) (sizeLimit / (1024 * 1024));
+            } else {
+                retentionSizeInMB = -1;
+            }
             admin.namespaces().setRetention(namespace, new RetentionPolicies(retentionTimeInMin, retentionSizeInMB));
         }
     }
diff --git a/site/_data/cli/pulsar-admin.yaml b/site/_data/cli/pulsar-admin.yaml
index c0d483fe4e..94ec02c7d6 100644
--- a/site/_data/cli/pulsar-admin.yaml
+++ b/site/_data/cli/pulsar-admin.yaml
@@ -431,7 +431,7 @@ commands:
     argument: tenant/cluster/namespace
     options:
     - flags: -s, --size
-      description: The retention size limits (for example `10M`, `16G` or `3T`). 0 means no retention and -1 means infinite size retention
+      description: The retention size limits (for example `10M`, `16G` or `3T`). 0 or less than 1MB means no retention and -1 means infinite size retention
     - flags: -t, --time
       description: "The retention time in minutes, hours, days, or weeks. Examples: `100m`, `13h`, `2d`, `5w`. 0 means no retention and -1 means infinite time retention"
   - name: unload
diff --git a/tests/integration/src/test/java/org/apache/pulsar/tests/integration/cli/CLITest.java b/tests/integration/src/test/java/org/apache/pulsar/tests/integration/cli/CLITest.java
index e69b0dd4a5..22cc93780a 100644
--- a/tests/integration/src/test/java/org/apache/pulsar/tests/integration/cli/CLITest.java
+++ b/tests/integration/src/test/java/org/apache/pulsar/tests/integration/cli/CLITest.java
@@ -175,4 +175,42 @@ public void testSchemaCLI() throws Exception {
         assertNotEquals(0, result.getExitCode());
         assertTrue(result.getStderr().contains("Reason: HTTP 404 Not Found"));
     }
+
+    @Test
+    public void testSetInfiniteRetention() throws Exception {
+        ContainerExecResult result;
+
+        String namespace = "get-and-set-retention" + randomName(8);
+        pulsarCluster.createNamespace(namespace);
+
+        String[] setCommand = {
+            "namespaces", "set-retention", "public/" + namespace,
+            "--size", "-1",
+            "--time", "-1"
+        };
+
+        result = pulsarCluster.runAdminCommandOnAnyBroker(setCommand);
+        assertEquals(0, result.getExitCode());
+        assertTrue(
+            result.getStdout().isEmpty(),
+            result.getStdout()
+        );
+        assertTrue(
+            result.getStderr().isEmpty(),
+            result.getStdout()
+        );
+
+        String[] getCommand = {
+            "namespaces", "get-retention", "public/" + namespace
+        };
+
+        result = pulsarCluster.runAdminCommandOnAnyBroker(getCommand);
+        assertEquals(0, result.getExitCode());
+        assertTrue(
+            result.getStdout().contains("\"retentionTimeInMinutes\" : -1"),
+            result.getStdout());
+        assertTrue(
+            result.getStdout().contains("\"retentionSizeInMB\" : -1"),
+            result.getStdout());
+    }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services