merlimat closed pull request #1516: Added test to ensure property name can 
contain '_' characters.
URL: https://github.com/apache/incubator-pulsar/pull/1516
 
 
   

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-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest2.java 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest2.java
index 2bc1652a78..c8c3b75804 100644
--- 
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest2.java
+++ 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest2.java
@@ -768,4 +768,41 @@ public void testPublishConsumerStats() throws Exception {
         producer.close();
         consumer.close();
     }
+
+    @Test
+    public void testTenantNameWithUnderscore() throws Exception {
+        PropertyAdmin propertyAdmin = new 
PropertyAdmin(Sets.newHashSet("role1", "role2"), Sets.newHashSet("use"));
+        admin.properties().createProperty("prop_xyz", propertyAdmin);
+
+        admin.namespaces().createNamespace("prop_xyz/use/my-namespace");
+
+        String topic = "persistent://prop_xyz/use/my-namespace/my-topic";
+
+        Producer<byte[]> producer = pulsarClient.newProducer().topic(topic)
+                .create();
+
+        PersistentTopicStats stats = admin.persistentTopics().getStats(topic);
+        assertEquals(stats.publishers.size(), 1);
+        producer.close();
+    }
+
+    @Test
+    public void testTenantNameWithInvalidCharacters() throws Exception {
+        PropertyAdmin propertyAdmin = new 
PropertyAdmin(Sets.newHashSet("role1", "role2"), Sets.newHashSet("use"));
+
+        // If we try to create property with invalid characters, it should 
fail immediately
+        try {
+            admin.properties().createProperty("prop xyz", propertyAdmin);
+            fail("Should have failed");
+        } catch (PulsarAdminException e) {
+            // Expected
+        }
+
+        try {
+            admin.properties().createProperty("prop&xyz", propertyAdmin);
+            fail("Should have failed");
+        } catch (PulsarAdminException e) {
+            // Expected
+        }
+    }
 }
diff --git 
a/pulsar-common/src/main/java/org/apache/pulsar/common/naming/NamedEntity.java 
b/pulsar-common/src/main/java/org/apache/pulsar/common/naming/NamedEntity.java
index 165fd07a9c..e5180d6935 100644
--- 
a/pulsar-common/src/main/java/org/apache/pulsar/common/naming/NamedEntity.java
+++ 
b/pulsar-common/src/main/java/org/apache/pulsar/common/naming/NamedEntity.java
@@ -18,12 +18,14 @@
  */
 package org.apache.pulsar.common.naming;
 
-import java.net.URI;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import lombok.experimental.UtilityClass;
+
 /**
  */
+@UtilityClass
 public class NamedEntity {
 
     // allowed characters for property, namespace, cluster and topic names are
@@ -37,11 +39,4 @@ public static void checkName(String name) throws 
IllegalArgumentException {
             throw new IllegalArgumentException("Invalid named entity: " + 
name);
         }
     }
-
-    public static void checkURI(URI uri, String name) {
-        if (!String.format("%s://%s%s", uri.getScheme(), uri.getHost(), 
uri.getPath()).equals(name)) {
-            throw new IllegalArgumentException("Invalid trailing chars in 
named entity: " + name);
-        }
-    }
-
 }
\ No newline at end of file
diff --git 
a/pulsar-common/src/main/java/org/apache/pulsar/common/naming/TopicDomain.java 
b/pulsar-common/src/main/java/org/apache/pulsar/common/naming/TopicDomain.java
index 744efeaf28..26b382f52b 100644
--- 
a/pulsar-common/src/main/java/org/apache/pulsar/common/naming/TopicDomain.java
+++ 
b/pulsar-common/src/main/java/org/apache/pulsar/common/naming/TopicDomain.java
@@ -30,14 +30,14 @@ private TopicDomain(String value) {
     public String value() {
         return this.value;
     }
-    
+
     public static TopicDomain getEnum(String value) {
         for (TopicDomain e : values()) {
             if (e.value.equalsIgnoreCase(value)) {
                 return e;
             }
         }
-        throw new IllegalArgumentException("Invalid enum value " + value);
+        throw new IllegalArgumentException("Invalid topic domain: '" + value + 
"'");
     }
 
     @Override
diff --git 
a/pulsar-common/src/main/java/org/apache/pulsar/common/naming/TopicName.java 
b/pulsar-common/src/main/java/org/apache/pulsar/common/naming/TopicName.java
index 6bb2693286..aa7dd4ad86 100644
--- a/pulsar-common/src/main/java/org/apache/pulsar/common/naming/TopicName.java
+++ b/pulsar-common/src/main/java/org/apache/pulsar/common/naming/TopicName.java
@@ -105,7 +105,7 @@ private TopicName(String completeTopicName) {
             // legacy: persistent://property/cluster/namespace/topic
             if (!completeTopicName.contains("://")) {
                 throw new IllegalArgumentException(
-                        "Invalid completeTopicName name: " + completeTopicName 
+ " -- Domain is missing");
+                        "Invalid topic name: " + completeTopicName + " -- 
Domain is missing");
             }
 
             List<String> parts = 
Splitter.on("://").limit(2).splitToList(completeTopicName);
@@ -139,15 +139,15 @@ private TopicName(String completeTopicName) {
                 this.partitionIndex = getPartitionIndex(completeTopicName);
                 this.namespaceName = NamespaceName.get(property, cluster, 
namespacePortion);
             } else {
-                throw new IllegalArgumentException("Invalid completeTopicName 
name: " + completeTopicName);
+                throw new IllegalArgumentException("Invalid topic name: " + 
completeTopicName);
             }
 
 
             if (localName == null || localName.isEmpty()) {
-                throw new IllegalArgumentException("Invalid completeTopicName 
name: " + completeTopicName);
+                throw new IllegalArgumentException("Invalid topic name: " + 
completeTopicName);
             }
         } catch (NullPointerException e) {
-            throw new IllegalArgumentException("Invalid completeTopicName 
name: " + completeTopicName, e);
+            throw new IllegalArgumentException("Invalid topic name: " + 
completeTopicName, e);
         }
 
     }


 

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to