mirror of
https://github.com/apache/rocketmq.git
synced 2026-08-28 20:09:14 +08:00
fix(controller): compare partial broker identities safely (#10886)
This commit is contained in:
+3
-3
@@ -17,9 +17,8 @@
|
||||
package org.apache.rocketmq.controller.impl.heartbeat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import org.apache.rocketmq.common.UtilAll;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.apache.rocketmq.common.UtilAll;
|
||||
|
||||
public class BrokerIdentityInfo implements Serializable {
|
||||
|
||||
@@ -63,7 +62,8 @@ public class BrokerIdentityInfo implements Serializable {
|
||||
|
||||
if (obj instanceof BrokerIdentityInfo) {
|
||||
BrokerIdentityInfo addr = (BrokerIdentityInfo) obj;
|
||||
return clusterName.equals(addr.clusterName) && brokerName.equals(addr.brokerName) && brokerId.equals(addr.brokerId);
|
||||
return Objects.equals(clusterName, addr.clusterName) && Objects.equals(brokerName, addr.brokerName)
|
||||
&& Objects.equals(brokerId, addr.brokerId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.rocketmq.controller.impl.heartbeat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class BrokerIdentityInfoTest {
|
||||
|
||||
@Test
|
||||
public void testEqualsCompleteIdentity() {
|
||||
BrokerIdentityInfo identity = new BrokerIdentityInfo("cluster", "broker", 1L);
|
||||
BrokerIdentityInfo sameIdentity = new BrokerIdentityInfo("cluster", "broker", 1L);
|
||||
|
||||
assertThat(identity).isEqualTo(sameIdentity);
|
||||
assertThat(identity.hashCode()).isEqualTo(sameIdentity.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsPartialIdentity() {
|
||||
assertThat(new BrokerIdentityInfo(null, "broker", null))
|
||||
.isEqualTo(new BrokerIdentityInfo(null, "broker", null));
|
||||
assertThat(new BrokerIdentityInfo("cluster", null, null))
|
||||
.isEqualTo(new BrokerIdentityInfo("cluster", null, null));
|
||||
assertThat(new BrokerIdentityInfo("cluster", "broker", null))
|
||||
.isEqualTo(new BrokerIdentityInfo("cluster", "broker", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsDifferentIdentity() {
|
||||
BrokerIdentityInfo identity = new BrokerIdentityInfo("cluster", "broker", 1L);
|
||||
|
||||
assertThat(identity).isNotEqualTo(new BrokerIdentityInfo("other-cluster", "broker", 1L));
|
||||
assertThat(identity).isNotEqualTo(new BrokerIdentityInfo("cluster", "other-broker", 1L));
|
||||
assertThat(identity).isNotEqualTo(new BrokerIdentityInfo("cluster", "broker", 2L));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user