You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by zi...@apache.org on 2022/10/08 03:19:15 UTC
[pulsar] branch master updated: [fix][broker] Fix create ns (#17864)
This is an automated email from the ASF dual-hosted git repository.
zixuan 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 e1b537f76b2 [fix][broker] Fix create ns (#17864)
e1b537f76b2 is described below
commit e1b537f76b2c525f91c08621364daf1aefcdb0dd
Author: Zixuan Liu <no...@gmail.com>
AuthorDate: Sat Oct 8 11:19:06 2022 +0800
[fix][broker] Fix create ns (#17864)
Signed-off-by: Zixuan Liu <no...@gmail.com>
---
.../src/main/java/org/apache/pulsar/PulsarStandalone.java | 6 +-----
.../src/test/java/org/apache/pulsar/PulsarStandaloneTest.java | 11 ++++++++++-
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java
index 4fd22eba785..ce46d460d52 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java
@@ -25,7 +25,6 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Sets;
import java.io.File;
import java.nio.file.Paths;
-import java.util.Collections;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.apache.bookkeeper.conf.ServerConfiguration;
@@ -39,7 +38,6 @@ import org.apache.pulsar.common.naming.NamespaceName;
import org.apache.pulsar.common.naming.TopicName;
import org.apache.pulsar.common.partition.PartitionedTopicMetadata;
import org.apache.pulsar.common.policies.data.ClusterData;
-import org.apache.pulsar.common.policies.data.Policies;
import org.apache.pulsar.common.policies.data.TenantInfo;
import org.apache.pulsar.common.util.ShutdownUtil;
import org.apache.pulsar.functions.instance.state.PulsarMetadataStateStoreProviderImpl;
@@ -394,9 +392,7 @@ public class PulsarStandalone implements AutoCloseable {
}
if (!nsr.namespaceExists(ns)) {
- Policies nsp = new Policies();
- nsp.replication_clusters = Collections.singleton(config.getClusterName());
- nsr.createPolicies(ns, nsp);
+ broker.getAdminClient().namespaces().createNamespace(ns.toString());
}
}
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/PulsarStandaloneTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/PulsarStandaloneTest.java
index b7b62eccb51..7061cb28b0f 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/PulsarStandaloneTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/PulsarStandaloneTest.java
@@ -26,6 +26,8 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import org.apache.pulsar.client.admin.Namespaces;
+import org.apache.pulsar.client.admin.PulsarAdmin;
import org.apache.pulsar.common.naming.NamespaceName;
import org.apache.pulsar.broker.PulsarService;
import org.apache.pulsar.broker.ServiceConfiguration;
@@ -61,12 +63,18 @@ public class PulsarStandaloneTest {
when(resources.getTenantResources()).thenReturn(tr);
when(resources.getNamespaceResources()).thenReturn(nsr);
+ Namespaces namespaces = mock(Namespaces.class);
+ doNothing().when(namespaces).createNamespace(any());
+ PulsarAdmin admin = mock(PulsarAdmin.class);
+ when(admin.namespaces()).thenReturn(namespaces);
+
PulsarService broker = mock(PulsarService.class);
when(broker.getPulsarResources()).thenReturn(resources);
when(broker.getWebServiceAddress()).thenReturn("pulsar://localhost:8080");
when(broker.getWebServiceAddressTls()).thenReturn(null);
when(broker.getBrokerServiceUrl()).thenReturn("pulsar://localhost:6650");
when(broker.getBrokerServiceUrlTls()).thenReturn(null);
+ when(broker.getAdminClient()).thenReturn(admin);
ServiceConfiguration config = new ServiceConfiguration();
config.setClusterName(cluster);
@@ -79,7 +87,8 @@ public class PulsarStandaloneTest {
standalone.createNameSpace(cluster, tenant, ns);
verify(cr, times(1)).createCluster(eq(cluster), any());
verify(tr, times(1)).createTenant(eq(tenant), any());
- verify(nsr, times(1)).createPolicies(eq(ns), any());
+ verify(admin, times(1)).namespaces();
+ verify(admin.namespaces(), times(1)).createNamespace(eq(ns.toString()));
}
}