2121import static org .testng .Assert .assertEquals ;
2222import static org .testng .Assert .assertFalse ;
2323import static org .testng .Assert .assertNotNull ;
24+ import static org .testng .Assert .assertTrue ;
2425import java .util .SortedMap ;
2526import org .apache .pulsar .PulsarClusterMetadataSetup ;
2627import org .apache .pulsar .PulsarClusterMetadataTeardown ;
@@ -54,7 +55,7 @@ void cleanup() {
5455 @ Test
5556 public void testSetupClusterMetadataAndTeardown () throws Exception {
5657 String [] args1 = {
57- "--cluster" , "testReSetupClusterMetadata-cluster " ,
58+ "--cluster" , "cluster1 " ,
5859 "--zookeeper" , "127.0.0.1:" + localZkS .getZookeeperPort (),
5960 "--configuration-store" , "127.0.0.1:" + localZkS .getZookeeperPort (),
6061 "--configuration-metadata-store-config-path" , "src/test/resources/conf/zk_client_enable_sasl.conf" ,
@@ -65,7 +66,7 @@ public void testSetupClusterMetadataAndTeardown() throws Exception {
6566 };
6667 PulsarClusterMetadataSetup .main (args1 );
6768 SortedMap <String , String > data1 = localZkS .dumpData ();
68- String clusterDataJson = data1 .get ("/admin/clusters/testReSetupClusterMetadata-cluster " );
69+ String clusterDataJson = data1 .get ("/admin/clusters/cluster1 " );
6970 assertNotNull (clusterDataJson );
7071 ClusterData clusterData = ObjectMapperFactory
7172 .getMapper ()
@@ -78,13 +79,78 @@ public void testSetupClusterMetadataAndTeardown() throws Exception {
7879 assertFalse (clusterData .isBrokerClientTlsEnabled ());
7980
8081 String [] args2 = {
81- "--cluster" , "testReSetupClusterMetadata-cluster " ,
82+ "--cluster" , "cluster1 " ,
8283 "--zookeeper" , "127.0.0.1:" + localZkS .getZookeeperPort (),
8384 "--configuration-store" , "127.0.0.1:" + localZkS .getZookeeperPort (),
8485 "--configuration-metadata-store-config-path" , "src/test/resources/conf/zk_client_enable_sasl.conf" ,
8586 };
8687 PulsarClusterMetadataTeardown .main (args2 );
8788 SortedMap <String , String > data2 = localZkS .dumpData ();
88- assertFalse (data2 .containsKey ("/admin/clusters/testReSetupClusterMetadata-cluster" ));
89+ assertFalse (data2 .containsKey ("/admin/clusters/cluster1" ));
90+ }
91+
92+ @ Test
93+ public void testSetupMultipleClusterMetadataAndTeardown () throws Exception {
94+ String [] cluster1Args = {
95+ "--cluster" , "cluster1" ,
96+ "--zookeeper" , "127.0.0.1:" + localZkS .getZookeeperPort (),
97+ "--configuration-store" , "127.0.0.1:" + localZkS .getZookeeperPort (),
98+ "--configuration-metadata-store-config-path" , "src/test/resources/conf/zk_client_enable_sasl.conf" ,
99+ "--web-service-url" , "http://127.0.0.1:8080" ,
100+ "--web-service-url-tls" , "https://127.0.0.1:8443" ,
101+ "--broker-service-url" , "pulsar://127.0.0.1:6650" ,
102+ "--broker-service-url-tls" , "pulsar+ssl://127.0.0.1:6651"
103+ };
104+ PulsarClusterMetadataSetup .main (cluster1Args );
105+ String [] cluster2Args = {
106+ "--cluster" , "cluster2" ,
107+ "--zookeeper" , "127.0.0.1:" + localZkS .getZookeeperPort (),
108+ "--configuration-store" , "127.0.0.1:" + localZkS .getZookeeperPort (),
109+ "--configuration-metadata-store-config-path" , "src/test/resources/conf/zk_client_enable_sasl.conf" ,
110+ "--web-service-url" , "http://127.0.0.1:8081" ,
111+ "--web-service-url-tls" , "https://127.0.0.1:8445" ,
112+ "--broker-service-url" , "pulsar://127.0.0.1:6651" ,
113+ "--broker-service-url-tls" , "pulsar+ssl://127.0.0.1:6652"
114+ };
115+ PulsarClusterMetadataSetup .main (cluster2Args );
116+ SortedMap <String , String > data1 = localZkS .dumpData ();
117+ String clusterDataJson = data1 .get ("/admin/clusters/cluster1" );
118+ assertNotNull (clusterDataJson );
119+ ClusterData clusterData = ObjectMapperFactory
120+ .getMapper ()
121+ .reader ()
122+ .readValue (clusterDataJson , ClusterData .class );
123+ assertEquals (clusterData .getServiceUrl (), "http://127.0.0.1:8080" );
124+ assertEquals (clusterData .getServiceUrlTls (), "https://127.0.0.1:8443" );
125+ assertEquals (clusterData .getBrokerServiceUrl (), "pulsar://127.0.0.1:6650" );
126+ assertEquals (clusterData .getBrokerServiceUrlTls (), "pulsar+ssl://127.0.0.1:6651" );
127+ assertFalse (clusterData .isBrokerClientTlsEnabled ());
128+
129+ String [] args2 = {
130+ "--cluster" , "cluster1" ,
131+ "--zookeeper" , "127.0.0.1:" + localZkS .getZookeeperPort (),
132+ "--configuration-store" , "127.0.0.1:" + localZkS .getZookeeperPort (),
133+ "--configuration-metadata-store-config-path" , "src/test/resources/conf/zk_client_enable_sasl.conf" ,
134+ };
135+ PulsarClusterMetadataTeardown .main (args2 );
136+ SortedMap <String , String > data2 = localZkS .dumpData ();
137+ assertFalse (data2 .containsKey ("/admin/clusters/cluster1" ));
138+ assertTrue (data2 .containsKey ("/admin/clusters/cluster2" ));
139+
140+ assertTrue (data2 .containsKey ("/admin/policies/public" ));
141+ assertFalse (data2 .get ("/admin/policies/public" ).contains ("cluster1" ));
142+ assertTrue (data2 .get ("/admin/policies/public" ).contains ("cluster2" ));
143+
144+ assertTrue (data2 .containsKey ("/admin/policies/pulsar" ));
145+ assertFalse (data2 .get ("/admin/policies/pulsar" ).contains ("cluster1" ));
146+ assertTrue (data2 .get ("/admin/policies/pulsar" ).contains ("cluster2" ));
147+
148+ assertTrue (data2 .containsKey ("/admin/policies/public/default" ));
149+ assertFalse (data2 .get ("/admin/policies/public/default" ).contains ("cluster1" ));
150+ assertTrue (data2 .get ("/admin/policies/public/default" ).contains ("cluster2" ));
151+
152+ assertTrue (data2 .containsKey ("/admin/policies/pulsar/system" ));
153+ assertFalse (data2 .get ("/admin/policies/pulsar/system" ).contains ("cluster1" ));
154+ assertTrue (data2 .get ("/admin/policies/pulsar/system" ).contains ("cluster2" ));
89155 }
90156}
0 commit comments