Browse Source
1. It should not require a TopicPartition during construction and normal usage. 2. Simplify `equals` since `topicId` and `topicPartition` are never null. 3. Inline `Objects.hash` to avoid array allocation. 4. Make `toString` more concise using a similar approach as `TopicPartition` since this `TopicIdPartition` will replace `TopicPartition` in many places in the future. 5. Add unit tests for `TopicIdPartition`, it seems like we had none. 6. Minor clean-up in calling/called classes. Reviewers: David Jacot <djacot@confluent.io>, Satish Duggana <satishd@apache.org>pull/11384/head
Ismael Juma
3 years ago
committed by
GitHub
7 changed files with 99 additions and 16 deletions
@ -0,0 +1,63 @@ |
|||||||
|
/* |
||||||
|
* 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.kafka.common; |
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals; |
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotEquals; |
||||||
|
|
||||||
|
import java.util.Objects; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
|
||||||
|
class TopicIdPartitionTest { |
||||||
|
|
||||||
|
private final Uuid topicId0 = new Uuid(-4883993789924556279L, -5960309683534398572L); |
||||||
|
private final String topicName0 = "a_topic_name"; |
||||||
|
private final int partition1 = 1; |
||||||
|
private final TopicPartition topicPartition0 = new TopicPartition(topicName0, partition1); |
||||||
|
private final TopicIdPartition topicIdPartition0 = new TopicIdPartition(topicId0, topicPartition0); |
||||||
|
private final TopicIdPartition topicIdPartition1 = new TopicIdPartition(topicName0, topicId0, |
||||||
|
partition1); |
||||||
|
|
||||||
|
private final Uuid topicId1 = new Uuid(7759286116672424028L, -5081215629859775948L); |
||||||
|
private final String topicName1 = "another_topic_name"; |
||||||
|
private final TopicIdPartition topicIdPartition2 = new TopicIdPartition(topicName1, topicId1, |
||||||
|
partition1); |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testEquals() { |
||||||
|
assertEquals(topicIdPartition0, topicIdPartition1); |
||||||
|
assertEquals(topicIdPartition1, topicIdPartition0); |
||||||
|
|
||||||
|
assertNotEquals(topicIdPartition0, topicIdPartition2); |
||||||
|
assertNotEquals(topicIdPartition2, topicIdPartition0); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testHashCode() { |
||||||
|
assertEquals(Objects.hash(topicIdPartition0.topicId(), topicIdPartition0.topicPartition()), |
||||||
|
topicIdPartition0.hashCode()); |
||||||
|
assertEquals(topicIdPartition0.hashCode(), topicIdPartition1.hashCode()); |
||||||
|
assertNotEquals(topicIdPartition0.hashCode(), topicIdPartition2.hashCode()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testToString() { |
||||||
|
assertEquals("vDiRhkpVQgmtSLnsAZx7lA:a_topic_name-1", topicIdPartition0.toString()); |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue