|
27 | 27 | import com.google.common.collect.Lists;
|
28 | 28 |
|
29 | 29 | import java.time.Duration;
|
| 30 | +import java.util.ArrayList; |
| 31 | +import java.util.Collections; |
30 | 32 | import java.util.List;
|
31 | 33 | import java.util.Optional;
|
32 | 34 | import java.util.concurrent.CompletableFuture;
|
|
48 | 50 | import org.apache.pulsar.client.api.Schema;
|
49 | 51 | import org.apache.pulsar.client.api.SubscriptionType;
|
50 | 52 | import org.apache.pulsar.common.api.proto.BaseCommand;
|
| 53 | +import org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace; |
51 | 54 | import org.apache.pulsar.common.api.proto.CommandWatchTopicListSuccess;
|
52 | 55 | import org.apache.pulsar.common.naming.NamespaceName;
|
53 | 56 | import org.apache.pulsar.common.naming.TopicName;
|
@@ -1113,4 +1116,57 @@ public void testTopicDeletion() throws Exception {
|
1113 | 1116 | assertEquals(pulsar.getBrokerService().getTopicIfExists(baseTopicName + "-1").join(), Optional.empty());
|
1114 | 1117 | assertTrue(pulsar.getBrokerService().getTopicIfExists(baseTopicName + "-2").join().isPresent());
|
1115 | 1118 | }
|
| 1119 | + |
| 1120 | + @Test(dataProvider = "partitioned") |
| 1121 | + public void testPatternQuote(boolean partitioned) throws Exception { |
| 1122 | + final NamespaceName namespace = NamespaceName.get("public/default"); |
| 1123 | + final String topicName = BrokerTestUtil.newUniqueName("persistent://public/default/tp"); |
| 1124 | + final PulsarClientImpl client = (PulsarClientImpl) pulsarClient; |
| 1125 | + final LookupService lookup = client.getLookup(); |
| 1126 | + List<String> expectedRes = new ArrayList<>(); |
| 1127 | + if (partitioned) { |
| 1128 | + admin.topics().createPartitionedTopic(topicName, 2); |
| 1129 | + expectedRes.add(TopicName.get(topicName).getPartition(0).toString()); |
| 1130 | + expectedRes.add(TopicName.get(topicName).getPartition(1).toString()); |
| 1131 | + Collections.sort(expectedRes); |
| 1132 | + } else { |
| 1133 | + admin.topics().createNonPartitionedTopic(topicName); |
| 1134 | + expectedRes.add(topicName); |
| 1135 | + } |
| 1136 | + |
| 1137 | + // Verify 1: "java.util.regex.Pattern.quote". |
| 1138 | + String pattern1 = java.util.regex.Pattern.quote(topicName); |
| 1139 | + List<String> res1 = lookup.getTopicsUnderNamespace(namespace, CommandGetTopicsOfNamespace.Mode.PERSISTENT, |
| 1140 | + pattern1, null).join().getNonPartitionedOrPartitionTopics(); |
| 1141 | + Collections.sort(res1); |
| 1142 | + assertEquals(res1, expectedRes); |
| 1143 | + |
| 1144 | + // Verify 2: "com.google.re2j.Pattern.quote" |
| 1145 | + String pattern2 = com.google.re2j.Pattern.quote(topicName); |
| 1146 | + List<String> res2 = lookup.getTopicsUnderNamespace(namespace, CommandGetTopicsOfNamespace.Mode.PERSISTENT, |
| 1147 | + pattern2, null).join().getNonPartitionedOrPartitionTopics(); |
| 1148 | + Collections.sort(res2); |
| 1149 | + assertEquals(res2, expectedRes); |
| 1150 | + |
| 1151 | + // Verify 3: "java.util.regex.Pattern.quote" & "^$" |
| 1152 | + String pattern3 = "^" + java.util.regex.Pattern.quote(topicName) + "$"; |
| 1153 | + List<String> res3 = lookup.getTopicsUnderNamespace(namespace, CommandGetTopicsOfNamespace.Mode.PERSISTENT, |
| 1154 | + pattern3, null).join().getNonPartitionedOrPartitionTopics(); |
| 1155 | + Collections.sort(res3); |
| 1156 | + assertEquals(res3, expectedRes); |
| 1157 | + |
| 1158 | + // Verify 4: "com.google.re2j.Pattern.quote" & "^$" |
| 1159 | + String pattern4 = "^" + com.google.re2j.Pattern.quote(topicName) + "$"; |
| 1160 | + List<String> res4 = lookup.getTopicsUnderNamespace(namespace, CommandGetTopicsOfNamespace.Mode.PERSISTENT, |
| 1161 | + pattern4, null).join().getNonPartitionedOrPartitionTopics(); |
| 1162 | + Collections.sort(res4); |
| 1163 | + assertEquals(res4, expectedRes); |
| 1164 | + |
| 1165 | + // cleanup. |
| 1166 | + if (partitioned) { |
| 1167 | + admin.topics().deletePartitionedTopic(topicName, false); |
| 1168 | + } else { |
| 1169 | + admin.topics().delete(topicName, false); |
| 1170 | + } |
| 1171 | + } |
1116 | 1172 | }
|
0 commit comments