From fa50a4acae2856fe768f08d4c581ec0604d4a1bf Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Mon, 23 Nov 2020 15:42:34 -0500 Subject: [PATCH] GH-1637: Fix TopicPartitionOffset.hashCode() Resolves https://github.com/spring-projects/spring-kafka/issues/1637 **cherry-pick to 2.5.x, 2.4.x, 2.3.x** (cherry picked from commit e666153734404a4ea0638a1c60fe2fce07921e50) --- .../kafka/support/TopicPartitionOffset.java | 2 +- .../support/TopicPartitionOffsetTests.java | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 spring-kafka/src/test/java/org/springframework/kafka/support/TopicPartitionOffsetTests.java diff --git a/spring-kafka/src/main/java/org/springframework/kafka/support/TopicPartitionOffset.java b/spring-kafka/src/main/java/org/springframework/kafka/support/TopicPartitionOffset.java index d4555706..7c9d7a96 100644 --- a/spring-kafka/src/main/java/org/springframework/kafka/support/TopicPartitionOffset.java +++ b/spring-kafka/src/main/java/org/springframework/kafka/support/TopicPartitionOffset.java @@ -194,7 +194,7 @@ public class TopicPartitionOffset { @Override public int hashCode() { - return this.topicPartition.hashCode(); + return this.topicPartition.hashCode() + this.position.hashCode(); } @Override diff --git a/spring-kafka/src/test/java/org/springframework/kafka/support/TopicPartitionOffsetTests.java b/spring-kafka/src/test/java/org/springframework/kafka/support/TopicPartitionOffsetTests.java new file mode 100644 index 00000000..13f9816a --- /dev/null +++ b/spring-kafka/src/test/java/org/springframework/kafka/support/TopicPartitionOffsetTests.java @@ -0,0 +1,38 @@ +/* + * Copyright 2020 the original author or authors. + * + * Licensed 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 + * + * https://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.springframework.kafka.support; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +import org.springframework.kafka.support.TopicPartitionOffset.SeekPosition; + +/** + * @author Gary Russell + * @since 2.3.13 + * + */ +public class TopicPartitionOffsetTests { + + @Test + void hashCodeTest() { + assertThat(new TopicPartitionOffset("foo", 1, SeekPosition.BEGINNING).hashCode()) + .isNotEqualTo(new TopicPartitionOffset("foo", 1, SeekPosition.END).hashCode()); + } + +}