From 301c0649a718205aff4b9e5aea64fa61721dbcc8 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 c4f47c6c899..ae22bdcddaa 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 e4850fb5527..d3f902dd481 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 c99a7cb0bf4..026c6a746af 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 class ClientCompactQueryTuningConfig 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 class ClientCompactQueryTuningConfig maxBytesInMemory, maxRowsInMemory, maxTotalRows, + splitHintSpec, indexSpec, maxPendingPersists, pushTimeout, @@ -222,6 +224,7 @@ public class ClientCompactQueryTuningConfig ", 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 00000000000..eb7f42c7eb9 --- /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(); + } +}