|
| 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 | +} |
0 commit comments