This is an automated email from the ASF dual-hosted git repository. jsancio pushed a commit to branch 3.4 in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/3.4 by this push: new b7996d1152f KAFKA-14963; Do not use equals with Uuid (#13668) b7996d1152f is described below commit b7996d1152f75eaaf1db468d39f49e1c551538b2 Author: José Armando García Sancio <jsan...@users.noreply.github.com> AuthorDate: Wed May 3 10:58:30 2023 -0700 KAFKA-14963; Do not use equals with Uuid (#13668) Uuid is an object so they need to be compared with the equals method and not the == operator. --- .../apache/kafka/controller/ControllerMetricsManager.java | 6 +++--- .../kafka/controller/ControllerMetricsManagerTest.java | 15 ++++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/metadata/src/main/java/org/apache/kafka/controller/ControllerMetricsManager.java b/metadata/src/main/java/org/apache/kafka/controller/ControllerMetricsManager.java index 60c48312038..f86807e76a7 100644 --- a/metadata/src/main/java/org/apache/kafka/controller/ControllerMetricsManager.java +++ b/metadata/src/main/java/org/apache/kafka/controller/ControllerMetricsManager.java @@ -202,10 +202,10 @@ final class ControllerMetricsManager { throw new IllegalArgumentException(String.format("Broker with id %s is not registered", brokerId)); } - if (fencingChange == BrokerRegistrationFencingChange.FENCE) { + if (fencingChange.equals(BrokerRegistrationFencingChange.FENCE)) { fencedBrokers.add(brokerId); updateBrokerStateMetrics(); - } else if (fencingChange == BrokerRegistrationFencingChange.UNFENCE) { + } else if (fencingChange.equals(BrokerRegistrationFencingChange.UNFENCE)) { fencedBrokers.remove(brokerId); updateBrokerStateMetrics(); } else { @@ -269,7 +269,7 @@ final class ControllerMetricsManager { private void replay(RemoveTopicRecord record) { Uuid topicId = record.topicId(); - Predicate<TopicIdPartition> matchesTopic = tp -> tp.topicId() == topicId; + Predicate<TopicIdPartition> matchesTopic = tp -> tp.topicId().equals(topicId); topicCount--; topicPartitions.keySet().removeIf(matchesTopic); diff --git a/metadata/src/test/java/org/apache/kafka/controller/ControllerMetricsManagerTest.java b/metadata/src/test/java/org/apache/kafka/controller/ControllerMetricsManagerTest.java index 8cfeea417be..c2db11a2294 100644 --- a/metadata/src/test/java/org/apache/kafka/controller/ControllerMetricsManagerTest.java +++ b/metadata/src/test/java/org/apache/kafka/controller/ControllerMetricsManagerTest.java @@ -186,11 +186,16 @@ final class ControllerMetricsManagerTest { ControllerMetrics metrics = new MockControllerMetrics(); ControllerMetricsManager manager = new ControllerMetricsManager(metrics); - Uuid id = Uuid.randomUuid(); - manager.replay(topicRecord("test", id)); - manager.replay(partitionRecord(id, 0, 0, Arrays.asList(0, 1, 2))); - manager.replay(partitionRecord(id, 1, 0, Arrays.asList(0, 1, 2))); - manager.replay(removeTopicRecord(id)); + Uuid createTopicId = Uuid.randomUuid(); + Uuid createPartitionTopicId = new Uuid( + createTopicId.getMostSignificantBits(), + createTopicId.getLeastSignificantBits() + ); + Uuid removeTopicId = new Uuid(createTopicId.getMostSignificantBits(), createTopicId.getLeastSignificantBits()); + manager.replay(topicRecord("test", createTopicId)); + manager.replay(partitionRecord(createPartitionTopicId, 0, 0, Arrays.asList(0, 1, 2))); + manager.replay(partitionRecord(createPartitionTopicId, 1, 0, Arrays.asList(0, 1, 2))); + manager.replay(removeTopicRecord(removeTopicId)); assertEquals(0, metrics.globalPartitionCount()); }