From 375228541cde0e1744027c7e45f7f70ffe6cc70d Mon Sep 17 00:00:00 2001 From: Suneet Saldanha <44787917+suneet-s@users.noreply.github.com> Date: Mon, 16 Dec 2019 14:33:00 -0800 Subject: [PATCH] Fix equalsAndHashCode in ClientCompactQueryTuningConfig (#9035) * Fix equalsAndHashCode in ClientCompactQueryTuningConfig This change introduces a dependency to EqualsVerifier for the test scope. The dependency is licensed under Apache 2. The library makes it trivial to add equals and hashCode checks to prevent bugs like this from happening in the future * fix checkstyle * fix test name --- pom.xml | 6 ++++ server/pom.xml | 5 +++ .../ClientCompactQueryTuningConfig.java | 3 ++ .../ClientCompactQueryTuningConfigTest.java | 34 +++++++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 server/src/test/java/org/apache/druid/indexing/ClientCompactQueryTuningConfigTest.java diff --git a/pom.xml b/pom.xml index ff56a8e68c9a..73303857bd66 100644 --- a/pom.xml +++ b/pom.xml @@ -1198,6 +1198,12 @@ ${guava.version} test + + nl.jqno.equalsverifier + equalsverifier + 3.1.10 + test + com.github.stefanbirkner system-rules diff --git a/server/pom.xml b/server/pom.xml index 4be28f7c3c80..2810c40320a1 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -421,6 +421,11 @@ assertj-core test + + nl.jqno.equalsverifier + equalsverifier + test + diff --git a/server/src/main/java/org/apache/druid/client/indexing/ClientCompactQueryTuningConfig.java b/server/src/main/java/org/apache/druid/client/indexing/ClientCompactQueryTuningConfig.java index c99a7cb0bf49..026c6a746afc 100644 --- a/server/src/main/java/org/apache/druid/client/indexing/ClientCompactQueryTuningConfig.java +++ b/server/src/main/java/org/apache/druid/client/indexing/ClientCompactQueryTuningConfig.java @@ -193,6 +193,7 @@ public boolean equals(Object o) Objects.equals(maxBytesInMemory, that.maxBytesInMemory) && Objects.equals(maxRowsInMemory, that.maxRowsInMemory) && Objects.equals(maxTotalRows, that.maxTotalRows) && + Objects.equals(splitHintSpec, that.splitHintSpec) && Objects.equals(indexSpec, that.indexSpec) && Objects.equals(maxPendingPersists, that.maxPendingPersists) && Objects.equals(pushTimeout, that.pushTimeout) && @@ -207,6 +208,7 @@ public int hashCode() maxBytesInMemory, maxRowsInMemory, maxTotalRows, + splitHintSpec, indexSpec, maxPendingPersists, pushTimeout, @@ -222,6 +224,7 @@ public String toString() ", maxBytesInMemory=" + maxBytesInMemory + ", maxRowsInMemory=" + maxRowsInMemory + ", maxTotalRows=" + maxTotalRows + + ", splitHintSpec=" + splitHintSpec + ", indexSpec=" + indexSpec + ", maxPendingPersists=" + maxPendingPersists + ", pushTimeout=" + pushTimeout + diff --git a/server/src/test/java/org/apache/druid/indexing/ClientCompactQueryTuningConfigTest.java b/server/src/test/java/org/apache/druid/indexing/ClientCompactQueryTuningConfigTest.java new file mode 100644 index 000000000000..eb7f42c7eb90 --- /dev/null +++ b/server/src/test/java/org/apache/druid/indexing/ClientCompactQueryTuningConfigTest.java @@ -0,0 +1,34 @@ +/* + * 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.druid.indexing; + +import nl.jqno.equalsverifier.EqualsVerifier; +import org.apache.druid.client.indexing.ClientCompactQueryTuningConfig; +import org.junit.Test; + +public class ClientCompactQueryTuningConfigTest +{ + @Test + public void testEqualsContract() + { + // If this test failed, make sure to validate that toString was also updated correctly! + EqualsVerifier.forClass(ClientCompactQueryTuningConfig.class).usingGetClass().verify(); + } +}