Skip to content

Commit 472687a

Browse files
committed
[fix][broker] Fix create cluster with empty url
Signed-off-by: Zixuan Liu <nodeces@gmail.com>
1 parent da30b2e commit 472687a

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiClusterTest.java

+34
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import static org.testng.Assert.assertNotNull;
2323
import static org.testng.Assert.assertThrows;
2424
import static org.testng.Assert.fail;
25+
import java.util.ArrayList;
26+
import java.util.List;
2527
import java.util.Set;
2628
import java.util.UUID;
2729
import lombok.extern.slf4j.Slf4j;
@@ -107,4 +109,36 @@ public void testDeleteExistFailureDomain() throws PulsarAdminException {
107109

108110
admin.clusters().deleteFailureDomain(CLUSTER, domainName);
109111
}
112+
113+
@Test
114+
public void testCreateCluster() throws PulsarAdminException {
115+
List<ClusterData> clusterDataList = new ArrayList<>();
116+
clusterDataList.add(ClusterData.builder()
117+
.serviceUrl("http://pulsar.app:8080")
118+
.serviceUrlTls("")
119+
.brokerServiceUrl("pulsar://pulsar.app:6650")
120+
.brokerServiceUrlTls("")
121+
.build());
122+
clusterDataList.add(ClusterData.builder()
123+
.serviceUrl("")
124+
.serviceUrlTls("https://pulsar.app:8443")
125+
.brokerServiceUrl("")
126+
.brokerServiceUrlTls("pulsar+ssl://pulsar.app:6651")
127+
.build());
128+
clusterDataList.add(ClusterData.builder()
129+
.serviceUrl("")
130+
.serviceUrlTls("")
131+
.brokerServiceUrl("")
132+
.brokerServiceUrlTls("")
133+
.build());
134+
clusterDataList.add(ClusterData.builder()
135+
.serviceUrl(null)
136+
.serviceUrlTls(null)
137+
.brokerServiceUrl(null)
138+
.brokerServiceUrlTls(null)
139+
.build());
140+
for (int i = 0; i < clusterDataList.size(); i++) {
141+
admin.clusters().createCluster("cluster-test-" + i, clusterDataList.get(i));
142+
}
143+
}
110144
}

pulsar-common/src/main/java/org/apache/pulsar/common/util/URIPreconditions.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static void checkURIIfPresent(@Nullable String uri,
6767
public static void checkURIIfPresent(@Nullable String uri,
6868
@Nonnull Predicate<URI> predicate,
6969
@Nullable String errorMessage) throws IllegalArgumentException {
70-
if (uri == null) {
70+
if (uri == null || uri.length() == 0) {
7171
return;
7272
}
7373
checkURI(uri, predicate, errorMessage);

pulsar-common/src/test/java/org/apache/pulsar/common/util/URIPreconditionsTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public void testCheckURI() {
3030
// normal
3131
checkURI("http://pulsar.apache.org", uri -> true);
3232
checkURI("http://pulsar.apache.org", uri -> Objects.equals(uri.getScheme(), "http"));
33+
checkURI("", uri -> true);
3334
// illegal
3435
try {
3536
checkURI("pulsar.apache.org", uri -> Objects.equals(uri.getScheme(), "http"));
@@ -48,6 +49,7 @@ public void testCheckURI() {
4849
@Test
4950
public void testCheckURIIfPresent() {
5051
checkURIIfPresent(null, uri -> false);
52+
checkURIIfPresent("", uri -> false);
5153
checkURIIfPresent("http://pulsar.apache.org", uri -> true);
5254
try {
5355
checkURIIfPresent("http/pulsar.apache.org", uri -> uri.getScheme() != null, "Error");

0 commit comments

Comments
 (0)