You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by jl...@apache.org on 2021/02/28 07:37:05 UTC
[incubator-pinot] 01/01: Override equals and hashCode methods for
PinotMetricName
This is an automated email from the ASF dual-hosted git repository.
jlli pushed a commit to branch override-equals-and-hashcode-for-pinot-metric-name
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git
commit d26675b791cb127b806e50a0e04a43c0d4cbce54
Author: Jack Li(Analytics Engineering) <jl...@jlli-mn1.linkedin.biz>
AuthorDate: Sat Feb 27 23:36:27 2021 -0800
Override equals and hashCode methods for PinotMetricName
---
.../common/metrics/yammer/YammerMetricName.java | 25 +++++++++++++++++++++-
.../pinot/common/metrics/MetricsHelperTest.java | 12 +++++++++++
.../apache/pinot/spi/metrics/PinotMetricName.java | 13 +++++++++++
3 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/pinot-common/src/main/java/org/apache/pinot/common/metrics/yammer/YammerMetricName.java b/pinot-common/src/main/java/org/apache/pinot/common/metrics/yammer/YammerMetricName.java
index 70726c0..fc21012 100644
--- a/pinot-common/src/main/java/org/apache/pinot/common/metrics/yammer/YammerMetricName.java
+++ b/pinot-common/src/main/java/org/apache/pinot/common/metrics/yammer/YammerMetricName.java
@@ -23,7 +23,7 @@ import org.apache.pinot.spi.metrics.PinotMetricName;
public class YammerMetricName implements PinotMetricName {
- private MetricName _metricName;
+ private final MetricName _metricName;
public YammerMetricName(Class<?> klass, String name) {
_metricName = new MetricName(klass, name);
@@ -37,4 +37,27 @@ public class YammerMetricName implements PinotMetricName {
public MetricName getMetricName() {
return _metricName;
}
+
+ /**
+ * Overrides equals method by calling the equals from the actual metric name.
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ YammerMetricName that = (YammerMetricName) obj;
+ return _metricName.equals(that._metricName);
+ }
+
+ /**
+ * Overrides hashCode method by calling the hashCode method from the actual metric name.
+ */
+ @Override
+ public int hashCode() {
+ return _metricName.hashCode();
+ }
}
diff --git a/pinot-common/src/test/java/org/apache/pinot/common/metrics/MetricsHelperTest.java b/pinot-common/src/test/java/org/apache/pinot/common/metrics/MetricsHelperTest.java
index 24507c9..ea70bd6 100644
--- a/pinot-common/src/test/java/org/apache/pinot/common/metrics/MetricsHelperTest.java
+++ b/pinot-common/src/test/java/org/apache/pinot/common/metrics/MetricsHelperTest.java
@@ -23,6 +23,7 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.pinot.common.exception.InvalidConfigException;
import org.apache.pinot.spi.metrics.PinotMeter;
+import org.apache.pinot.spi.metrics.PinotMetricName;
import org.apache.pinot.spi.metrics.PinotMetricsRegistry;
import org.apache.pinot.spi.env.PinotConfiguration;
import org.testng.Assert;
@@ -88,4 +89,15 @@ public class MetricsHelperTest {
pinotMeter.mark(2L);
Assert.assertEquals(pinotMeter.count(), 3L);
}
+
+ @Test
+ public void testPinotMetricName() {
+ PinotMetricName testMetricName1 =
+ PinotMetricUtils.generatePinotMetricName(MetricsHelperTest.class, "testMetricName");
+ PinotMetricName testMetricName2 =
+ PinotMetricUtils.generatePinotMetricName(MetricsHelperTest.class, "testMetricName");
+ Assert.assertNotNull(testMetricName1);
+ Assert.assertNotNull(testMetricName2);
+ Assert.assertEquals(testMetricName1, testMetricName2);
+ }
}
diff --git a/pinot-spi/src/main/java/org/apache/pinot/spi/metrics/PinotMetricName.java b/pinot-spi/src/main/java/org/apache/pinot/spi/metrics/PinotMetricName.java
index 95c52b2..eb949ac 100644
--- a/pinot-spi/src/main/java/org/apache/pinot/spi/metrics/PinotMetricName.java
+++ b/pinot-spi/src/main/java/org/apache/pinot/spi/metrics/PinotMetricName.java
@@ -23,5 +23,18 @@ package org.apache.pinot.spi.metrics;
*/
public interface PinotMetricName {
+ /**
+ * Returns the actual metric name.
+ */
Object getMetricName();
+
+ /**
+ * Overrides the equals method.
+ */
+ boolean equals(Object obj);
+
+ /**
+ * Overrides the hashCode method.
+ */
+ int hashCode();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org