|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.apache.pulsar.broker.zookeeper; |
| 20 | + |
| 21 | +import static org.testng.Assert.assertEquals; |
| 22 | +import static org.testng.Assert.assertFalse; |
| 23 | +import static org.testng.Assert.assertNotNull; |
| 24 | +import java.util.SortedMap; |
| 25 | +import org.apache.pulsar.PulsarClusterMetadataSetup; |
| 26 | +import org.apache.pulsar.PulsarClusterMetadataTeardown; |
| 27 | +import org.apache.pulsar.common.policies.data.ClusterData; |
| 28 | +import org.apache.pulsar.common.util.ObjectMapperFactory; |
| 29 | +import org.testng.annotations.AfterClass; |
| 30 | +import org.testng.annotations.AfterMethod; |
| 31 | +import org.testng.annotations.BeforeClass; |
| 32 | +import org.testng.annotations.Test; |
| 33 | + |
| 34 | +public class ClusterMetadataTeardownTest { |
| 35 | + |
| 36 | + private ClusterMetadataSetupTest.ZookeeperServerTest localZkS; |
| 37 | + |
| 38 | + @BeforeClass |
| 39 | + void setup() throws Exception { |
| 40 | + localZkS = new ClusterMetadataSetupTest.ZookeeperServerTest(0); |
| 41 | + localZkS.start(); |
| 42 | + } |
| 43 | + |
| 44 | + @AfterClass |
| 45 | + void teardown() throws Exception { |
| 46 | + localZkS.close(); |
| 47 | + } |
| 48 | + |
| 49 | + @AfterMethod(alwaysRun = true) |
| 50 | + void cleanup() { |
| 51 | + localZkS.clear(); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + public void testSetupClusterMetadataAndTeardown() throws Exception { |
| 56 | + String[] args1 = { |
| 57 | + "--cluster", "testReSetupClusterMetadata-cluster", |
| 58 | + "--zookeeper", "127.0.0.1:" + localZkS.getZookeeperPort(), |
| 59 | + "--configuration-store", "127.0.0.1:" + localZkS.getZookeeperPort(), |
| 60 | + "--configuration-metadata-store-config-path", "src/test/resources/conf/zk_client_enable_sasl.conf", |
| 61 | + "--web-service-url", "http://127.0.0.1:8080", |
| 62 | + "--web-service-url-tls", "https://127.0.0.1:8443", |
| 63 | + "--broker-service-url", "pulsar://127.0.0.1:6650", |
| 64 | + "--broker-service-url-tls", "pulsar+ssl://127.0.0.1:6651" |
| 65 | + }; |
| 66 | + PulsarClusterMetadataSetup.main(args1); |
| 67 | + SortedMap<String, String> data1 = localZkS.dumpData(); |
| 68 | + String clusterDataJson = data1.get("/admin/clusters/testReSetupClusterMetadata-cluster"); |
| 69 | + assertNotNull(clusterDataJson); |
| 70 | + ClusterData clusterData = ObjectMapperFactory |
| 71 | + .getMapper() |
| 72 | + .reader() |
| 73 | + .readValue(clusterDataJson, ClusterData.class); |
| 74 | + assertEquals(clusterData.getServiceUrl(), "http://127.0.0.1:8080"); |
| 75 | + assertEquals(clusterData.getServiceUrlTls(), "https://127.0.0.1:8443"); |
| 76 | + assertEquals(clusterData.getBrokerServiceUrl(), "pulsar://127.0.0.1:6650"); |
| 77 | + assertEquals(clusterData.getBrokerServiceUrlTls(), "pulsar+ssl://127.0.0.1:6651"); |
| 78 | + assertFalse(clusterData.isBrokerClientTlsEnabled()); |
| 79 | + |
| 80 | + String[] args2 = { |
| 81 | + "--cluster", "testReSetupClusterMetadata-cluster", |
| 82 | + "--zookeeper", "127.0.0.1:" + localZkS.getZookeeperPort(), |
| 83 | + "--configuration-store", "127.0.0.1:" + localZkS.getZookeeperPort(), |
| 84 | + "--configuration-metadata-store-config-path", "src/test/resources/conf/zk_client_enable_sasl.conf", |
| 85 | + }; |
| 86 | + PulsarClusterMetadataTeardown.main(args2); |
| 87 | + SortedMap<String, String> data2 = localZkS.dumpData(); |
| 88 | + assertFalse(data2.containsKey("/admin/clusters/testReSetupClusterMetadata-cluster")); |
| 89 | + } |
| 90 | +} |
0 commit comments