Skip to content

Commit 90c9160

Browse files
committedJan 3, 2023
[cleanup][broker] Fix ClusterDataImpl#clone and add test
1 parent 9ec1d07 commit 90c9160

File tree

2 files changed

+71
-4
lines changed

2 files changed

+71
-4
lines changed
 

‎pulsar-common/src/main/java/org/apache/pulsar/common/policies/data/ClusterDataImpl.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,15 @@ public ClusterDataImplBuilder clone() {
205205
.brokerClientTlsTrustStoreType(brokerClientTlsTrustStoreType)
206206
.brokerClientTlsTrustStore(brokerClientTlsTrustStore)
207207
.brokerClientTlsTrustStorePassword(brokerClientTlsTrustStorePassword)
208-
.brokerClientTlsKeyStoreType(brokerClientTlsTrustStoreType)
209-
.brokerClientTlsKeyStore(brokerClientTlsTrustStore)
210-
.brokerClientTlsKeyStorePassword(brokerClientTlsTrustStorePassword)
208+
.brokerClientTlsKeyStoreType(brokerClientTlsKeyStoreType)
209+
.brokerClientTlsKeyStore(brokerClientTlsKeyStore)
210+
.brokerClientTlsKeyStorePassword(brokerClientTlsKeyStorePassword)
211211
.brokerClientTrustCertsFilePath(brokerClientTrustCertsFilePath)
212212
.brokerClientCertificateFilePath(brokerClientCertificateFilePath)
213213
.brokerClientKeyFilePath(brokerClientKeyFilePath)
214-
.listenerName(listenerName);
214+
.listenerName(listenerName)
215+
.migrated(migrated)
216+
.migratedClusterUrl(migratedClusterUrl);
215217
}
216218

217219
@Data
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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.common.policies.data;
20+
21+
import static org.testng.Assert.assertEquals;
22+
import static org.testng.Assert.assertNotSame;
23+
24+
import org.apache.pulsar.client.api.ProxyProtocol;
25+
import org.testng.annotations.Test;
26+
27+
import java.util.LinkedHashSet;
28+
29+
public class ClusterDataImplTest {
30+
31+
@Test
32+
public void verifyClone() {
33+
ClusterDataImpl originalData = ClusterDataImpl.builder()
34+
.serviceUrl("pulsar://test")
35+
.serviceUrlTls("pulsar+ssl://test")
36+
.brokerServiceUrl("pulsar://test:6650")
37+
.brokerServiceUrlTls("pulsar://test:6651")
38+
.proxyServiceUrl("pulsar://proxy:6650")
39+
.authenticationPlugin("test-plugin")
40+
.authenticationParameters("test-params")
41+
.proxyProtocol(ProxyProtocol.SNI)
42+
.peerClusterNames(new LinkedHashSet<>())
43+
.brokerClientTlsEnabled(true)
44+
.tlsAllowInsecureConnection(false)
45+
.brokerClientTlsEnabledWithKeyStore(true)
46+
.brokerClientTlsTrustStoreType("JKS")
47+
.brokerClientTlsTrustStore("/my/trust/store")
48+
.brokerClientTlsTrustStorePassword("some-password")
49+
.brokerClientTlsKeyStoreType("PCKS12")
50+
.brokerClientTlsKeyStore("/my/key/store")
51+
.brokerClientTlsKeyStorePassword("a-different-password")
52+
.brokerClientTrustCertsFilePath("/my/trusted/certs")
53+
.brokerClientKeyFilePath("/my/key/file")
54+
.brokerClientCertificateFilePath("/my/cert/file")
55+
.listenerName("a-listener")
56+
.migrated(true)
57+
.migratedClusterUrl(new ClusterData.ClusterUrl("pulsar://remote", "pulsar+ssl://remote"))
58+
.build();
59+
60+
ClusterDataImpl clone = originalData.clone().build();
61+
62+
assertEquals(clone, originalData, "Clones should have object equality.");
63+
assertNotSame(clone, originalData, "Clones should not be the same reference.");
64+
}
65+
}

0 commit comments

Comments
 (0)