Skip to content

Commit 869e8be

Browse files
authored
Ensure NamespaceEphemeralData has equals() operator (apache#15092)
1 parent db73eee commit 869e8be

File tree

3 files changed

+66
-18
lines changed

3 files changed

+66
-18
lines changed

pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceEphemeralData.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,12 @@
2222
import java.util.Collections;
2323
import java.util.Map;
2424
import javax.validation.constraints.NotNull;
25-
import lombok.EqualsAndHashCode;
26-
import lombok.Getter;
25+
import lombok.Data;
2726
import lombok.NoArgsConstructor;
28-
import lombok.ToString;
2927
import org.apache.pulsar.policies.data.loadbalancer.AdvertisedListener;
3028

31-
@Getter
29+
@Data
3230
@NoArgsConstructor
33-
@EqualsAndHashCode
34-
@ToString
3531
public class NamespaceEphemeralData {
3632
private String nativeUrl;
3733
private String nativeUrlTls;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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.namespace;
20+
21+
import static org.testng.Assert.assertEquals;
22+
import java.net.URI;
23+
import java.util.HashMap;
24+
import java.util.Map;
25+
import org.apache.pulsar.policies.data.loadbalancer.AdvertisedListener;
26+
import org.testng.annotations.Test;
27+
28+
@Test(groups = "broker")
29+
public class NamespaceEphemeralDataTest {
30+
31+
private static void setFields(NamespaceEphemeralData ned) throws Exception {
32+
ned.setNativeUrl("pulsar://localhost:6650");
33+
ned.setNativeUrlTls("pulsar+ssl://localhost:6651");
34+
ned.setHttpUrl("http://localhost:8080");
35+
ned.setHttpUrlTls("https://localhost:8443");
36+
ned.setDisabled(false);
37+
38+
Map<String, AdvertisedListener> advertisedListeners = new HashMap<>();
39+
advertisedListeners.put("test-listener", AdvertisedListener.builder()
40+
.brokerServiceUrl(new URI("pulsar://adv-addr:6650"))
41+
.brokerServiceUrlTls(new URI("pulsar+ssl://adv-addr:6651"))
42+
.build());
43+
ned.setAdvertisedListeners(advertisedListeners);
44+
}
45+
46+
/**
47+
* We must ensure NamespaceEphemeralData respect the equals() properties because it's used as a resource lock,
48+
* where equality is checked in the revalidation phase.
49+
*/
50+
@Test
51+
public void testEquals() throws Exception {
52+
NamespaceEphemeralData ned1 = new NamespaceEphemeralData();
53+
setFields(ned1);
54+
55+
NamespaceEphemeralData ned2 = new NamespaceEphemeralData();
56+
setFields(ned2);
57+
58+
assertEquals(ned1.hashCode(), ned2.hashCode());
59+
assertEquals(ned1, ned2);
60+
}
61+
62+
}

pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/AdvertisedListener.java

+2-12
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,28 @@
2121
import java.net.URI;
2222
import lombok.AllArgsConstructor;
2323
import lombok.Builder;
24-
import lombok.Getter;
24+
import lombok.Data;
2525
import lombok.NoArgsConstructor;
26-
import lombok.Setter;
27-
import lombok.ToString;
2826

2927
/**
3028
* The advertisedListener for broker with brokerServiceUrl and brokerServiceUrlTls.
3129
*/
3230
@Builder
3331
@NoArgsConstructor
3432
@AllArgsConstructor
35-
@ToString
33+
@Data
3634
public class AdvertisedListener {
3735
//
38-
@Getter
39-
@Setter
4036
// the broker service uri without ssl
4137
private URI brokerServiceUrl;
4238
//
43-
@Getter
44-
@Setter
4539
// the broker service uri with ssl
4640
private URI brokerServiceUrlTls;
4741

4842
//
49-
@Getter
50-
@Setter
5143
// the broker service uri without ssl
5244
private URI brokerHttpUrl;
5345
//
54-
@Getter
55-
@Setter
5646
// the broker service uri with ssl
5747
private URI brokerHttpsUrl;
5848

0 commit comments

Comments
 (0)