Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -63,7 +62,8 @@ public boolean equals(Object obj) {

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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
Loading