gemmellr commented on code in PR #4742:
URL: https://github.com/apache/activemq-artemis/pull/4742#discussion_r1457558346
##########
artemis-server/src/main/java/org/apache/activemq/artemis/core/config/amqpBrokerConnectivity/AMQPBrokerConnectionElement.java:
##########
@@ -95,4 +98,31 @@ public void setName(String name) {
this.name = name;
}
+ @Override
+ public int hashCode() {
+ // Don't pass the parent into hash or you will get a loop of hash code
computations.
+ return Objects.hash(matchAddress, name, queueName, type) +
System.identityHashCode(parent);
Review Comment:
Might having parent here allow for two objects that are equals() (which
doesnt consider the parent) to then have a different hashCode, which isnt
allowed?
##########
artemis-server/src/test/java/org/apache/activemq/artemis/core/config/amqpBrokerConnectivity/AMQPBrokerConnectionElementTest.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.activemq.artemis.core.config.amqpBrokerConnectivity;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+import org.junit.Test;
+
+/**
+ * Test basic API functionality of the AMQPBrokerConnectionElement type
+ */
+public class AMQPBrokerConnectionElementTest {
+
+ @Test
+ public void testEquals() {
+ AMQPBrokerConnectionElement element1 = new AMQPBrokerConnectionElement();
+ AMQPBrokerConnectionElement element2 = new AMQPBrokerConnectionElement();
+
+ assertEquals(element1, element2);
+
+ // Name
+ element1.setName("test");
+ assertNotEquals(element1, element2);
+ element2.setName("test");
+ assertEquals(element1, element2);
+
+ // Match Address
+ element1.setMatchAddress("test");
+ assertNotEquals(element1, element2);
+ element2.setMatchAddress("test");
+ assertEquals(element1, element2);
+
+ // Queue Name
+ element1.setQueueName("test");
+ assertNotEquals(element1, element2);
+ element2.setQueueName("test");
+ assertEquals(element1, element2);
+
+ // Type
+ element1.setType(AMQPBrokerConnectionAddressType.MIRROR);
+ assertNotEquals(element1, element2);
+ element2.setType(AMQPBrokerConnectionAddressType.MIRROR);
+ assertEquals(element1, element2);
+ }
+
+ @Test
+ public void testHashCode() {
+ AMQPBrokerConnectionElement element1 = new AMQPBrokerConnectionElement();
+ AMQPBrokerConnectionElement element2 = new AMQPBrokerConnectionElement();
+
+ assertEquals(element1.hashCode(), element2.hashCode());
+
+ // Name
+ element1.setName("test");
+ assertNotEquals(element1.hashCode(), element2.hashCode());
+ element2.setName("test");
+ assertEquals(element1.hashCode(), element2.hashCode());
+
+ // Match Address
+ element1.setMatchAddress("test");
+ assertNotEquals(element1.hashCode(), element2.hashCode());
+ element2.setMatchAddress("test");
+ assertEquals(element1.hashCode(), element2.hashCode());
+
+ // Queue Name
+ element1.setQueueName("test");
+ assertNotEquals(element1.hashCode(), element2.hashCode());
+ element2.setQueueName("test");
+ assertEquals(element1.hashCode(), element2.hashCode());
+
+ // Type
+ element1.setType(AMQPBrokerConnectionAddressType.MIRROR);
+ assertNotEquals(element1.hashCode(), element2.hashCode());
+ element2.setType(AMQPBrokerConnectionAddressType.MIRROR);
+ assertEquals(element1.hashCode(), element2.hashCode());
+
+ // Parent
+ final AMQPBrokerConnectConfiguration parent = new
AMQPBrokerConnectConfiguration();
+
+ element1.setParent(parent);
+ assertNotEquals(element1.hashCode(), element2.hashCode());
+ element2.setParent(parent);
+ assertEquals(element1.hashCode(), element2.hashCode());
Review Comment:
Specifically, also checking equals() here would presumably show it violating
the joint contract (the 2 beeing equal throughput but having different, and
changing, hashCodes).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]