From dd7af8f08d7d60786a2a76c88c370a674b3e5833 Mon Sep 17 00:00:00 2001 From: "Doroszlai, Attila" Date: Thu, 11 Jan 2024 20:12:07 +0100 Subject: [PATCH] HDDS-10115. Migrate MetricsAsserts to AssertJ --- .../TestReplicationManagerMetrics.java | 4 +- .../scm/pipeline/TestPipelineManagerImpl.java | 4 +- .../ozone/scm/node/TestSCMNodeMetrics.java | 6 +- hadoop-hdds/test-utils/pom.xml | 15 + .../org/apache/ozone/test/MetricsAsserts.java | 470 ++++++++++++++++++ .../TestSCMContainerManagerMetrics.java | 4 +- .../server/ratis/TestCSMMetrics.java | 6 +- .../metrics/TestContainerMetrics.java | 6 +- .../metrics/TestDatanodeQueueMetrics.java | 4 +- .../apache/hadoop/ozone/om/TestOmMetrics.java | 6 +- ...estSCMContainerPlacementPolicyMetrics.java | 4 +- .../ozone/scm/TestXceiverClientMetrics.java | 6 +- .../TestSCMPipelineBytesWrittenMetrics.java | 4 +- .../scm/pipeline/TestSCMPipelineMetrics.java | 18 +- 14 files changed, 520 insertions(+), 37 deletions(-) create mode 100644 hadoop-hdds/test-utils/src/main/java/org/apache/ozone/test/MetricsAsserts.java diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestReplicationManagerMetrics.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestReplicationManagerMetrics.java index a91d4655d664..31e2384d90df 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestReplicationManagerMetrics.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestReplicationManagerMetrics.java @@ -29,8 +29,8 @@ import static org.mockito.Mockito.when; import static org.mockito.Mockito.any; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.apache.hadoop.test.MetricsAsserts.getLongGauge; -import static org.apache.hadoop.test.MetricsAsserts.getMetrics; +import static org.apache.ozone.test.MetricsAsserts.getLongGauge; +import static org.apache.ozone.test.MetricsAsserts.getMetrics; /** * Tests for the ReplicationManagerMetrics class. diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/pipeline/TestPipelineManagerImpl.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/pipeline/TestPipelineManagerImpl.java index a5ac8af6a2fd..270ae0ef4933 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/pipeline/TestPipelineManagerImpl.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/pipeline/TestPipelineManagerImpl.java @@ -88,8 +88,8 @@ import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_PIPELINE_DESTROY_TIMEOUT; import static org.apache.hadoop.hdds.scm.pipeline.Pipeline.PipelineState.ALLOCATED; import static org.apache.hadoop.hdds.scm.pipeline.Pipeline.PipelineState.OPEN; -import static org.apache.hadoop.test.MetricsAsserts.getLongCounter; -import static org.apache.hadoop.test.MetricsAsserts.getMetrics; +import static org.apache.ozone.test.MetricsAsserts.getLongCounter; +import static org.apache.ozone.test.MetricsAsserts.getMetrics; import static org.assertj.core.api.Assertions.assertThat; import static org.apache.ratis.util.Preconditions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertInstanceOf; diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/ozone/scm/node/TestSCMNodeMetrics.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/ozone/scm/node/TestSCMNodeMetrics.java index 063427f0c5d9..79ca60131657 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/ozone/scm/node/TestSCMNodeMetrics.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/ozone/scm/node/TestSCMNodeMetrics.java @@ -47,9 +47,9 @@ import static java.lang.Thread.sleep; import static org.apache.hadoop.hdds.upgrade.HDDSLayoutVersionManager.maxLayoutVersion; -import static org.apache.hadoop.test.MetricsAsserts.assertGauge; -import static org.apache.hadoop.test.MetricsAsserts.getLongCounter; -import static org.apache.hadoop.test.MetricsAsserts.getMetrics; +import static org.apache.ozone.test.MetricsAsserts.assertGauge; +import static org.apache.ozone.test.MetricsAsserts.getLongCounter; +import static org.apache.ozone.test.MetricsAsserts.getMetrics; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-hdds/test-utils/pom.xml b/hadoop-hdds/test-utils/pom.xml index bca3b33d4464..4f78bd1f14d7 100644 --- a/hadoop-hdds/test-utils/pom.xml +++ b/hadoop-hdds/test-utils/pom.xml @@ -33,6 +33,10 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd"> + + org.assertj + assertj-core + com.google.guava guava @@ -70,6 +74,17 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd"> org.slf4j slf4j-api + + org.apache.hadoop + hadoop-common + provided + + + * + * + + + org.apache.logging.log4j log4j-api diff --git a/hadoop-hdds/test-utils/src/main/java/org/apache/ozone/test/MetricsAsserts.java b/hadoop-hdds/test-utils/src/main/java/org/apache/ozone/test/MetricsAsserts.java new file mode 100644 index 000000000000..28d3b936ecab --- /dev/null +++ b/hadoop-hdds/test-utils/src/main/java/org/apache/ozone/test/MetricsAsserts.java @@ -0,0 +1,470 @@ +/* + * 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.ozone.test; + +import static org.apache.hadoop.metrics2.lib.Interns.info; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.AdditionalMatchers.geq; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.Mockito.atLeast; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.apache.hadoop.metrics2.MetricsInfo; +import org.apache.hadoop.metrics2.MetricsCollector; +import org.apache.hadoop.metrics2.MetricsSource; +import org.apache.hadoop.metrics2.MetricsRecordBuilder; +import org.apache.hadoop.metrics2.MetricsSystem; +import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; +import org.apache.hadoop.metrics2.lib.MutableQuantiles; +import org.apache.hadoop.metrics2.util.Quantile; +import org.assertj.core.data.Offset; +import org.mockito.ArgumentCaptor; +import org.mockito.ArgumentMatcher; +import org.mockito.stubbing.Answer; +import org.mockito.invocation.InvocationOnMock; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Objects; + +/** + * Helpers for metrics source tests. + */ +public final class MetricsAsserts { + + private static final Logger LOG = LoggerFactory.getLogger(MetricsAsserts.class); + private static final Offset EPSILON = Offset.offset(0.00001); + private static final Offset EPSILON_FLOAT = Offset.offset(0.00001f); + + public static MetricsSystem mockMetricsSystem() { + MetricsSystem ms = mock(MetricsSystem.class); + DefaultMetricsSystem.setInstance(ms); + return ms; + } + + public static MetricsRecordBuilder mockMetricsRecordBuilder() { + final MetricsCollector mc = mock(MetricsCollector.class); + MetricsRecordBuilder rb = mock(MetricsRecordBuilder.class, new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + String methodName = invocation.getMethod().getName(); + if (LOG.isDebugEnabled()) { + Object[] args = invocation.getArguments(); + StringBuilder sb = new StringBuilder(); + for (Object o : args) { + if (sb.length() > 0) { + sb.append(", "); + } + sb.append(String.valueOf(o)); + } + LOG.debug("{}: {}", methodName, sb); + } + return methodName.equals("parent") || methodName.equals("endRecord") ? + mc : invocation.getMock(); + } + }); + when(mc.addRecord(anyString())).thenReturn(rb); + when(mc.addRecord(anyInfo())).thenReturn(rb); + return rb; + } + + /** + * Call getMetrics on source and get a record builder mock to verify. + * @param source the metrics source + * @param all if true, return all metrics even if not changed + * @return the record builder mock to verifyÏ + */ + public static MetricsRecordBuilder getMetrics(MetricsSource source, + boolean all) { + MetricsRecordBuilder rb = mockMetricsRecordBuilder(); + MetricsCollector mc = rb.parent(); + source.getMetrics(mc, all); + return rb; + } + + public static MetricsRecordBuilder getMetrics(String name) { + return getMetrics(DefaultMetricsSystem.instance().getSource(name)); + } + + public static MetricsRecordBuilder getMetrics(MetricsSource source) { + return getMetrics(source, true); + } + + private static class InfoWithSameName implements ArgumentMatcher { + private final String expected; + + InfoWithSameName(MetricsInfo info) { + expected = Objects.requireNonNull(info.name(), "info name"); + } + + @Override + public boolean matches(MetricsInfo info) { + return expected.equals(info.name()); + } + + @Override + public String toString() { + return "Info with name=" + expected; + } + } + + /** + * MetricInfo with the same name. + * @param info to match + * @return null + */ + public static MetricsInfo eqName(MetricsInfo info) { + return argThat(new InfoWithSameName(info)); + } + + private static class AnyInfo implements ArgumentMatcher { + @Override + public boolean matches(MetricsInfo info) { + return info != null; + } + } + + public static MetricsInfo anyInfo() { + return argThat(new AnyInfo()); + } + + /** + * Assert an int gauge metric as expected. + * @param name of the metric + * @param expected value of the metric + * @param rb the record builder mock used to getMetrics + */ + public static void assertGauge(String name, int expected, + MetricsRecordBuilder rb) { + assertThat(getIntGauge(name, rb)).as(name) + .isEqualTo(expected); + } + + public static int getIntGauge(String name, MetricsRecordBuilder rb) { + ArgumentCaptor captor = ArgumentCaptor.forClass(Integer.class); + verify(rb, atLeast(0)).addGauge(eqName(info(name, "")), captor.capture()); + checkCaptured(captor, name); + return captor.getValue(); + } + + /** + * Assert an int counter metric as expected. + * @param name of the metric + * @param expected value of the metric + * @param rb the record builder mock used to getMetrics + */ + public static void assertCounter(String name, int expected, + MetricsRecordBuilder rb) { + assertThat(getIntCounter(name, rb)).as(name) + .isEqualTo(expected); + } + + public static int getIntCounter(String name, MetricsRecordBuilder rb) { + ArgumentCaptor captor = ArgumentCaptor.forClass( + Integer.class); + verify(rb, atLeast(0)).addCounter(eqName(info(name, "")), captor.capture()); + checkCaptured(captor, name); + return captor.getValue(); + } + + /** + * Assert a long gauge metric as expected. + * @param name of the metric + * @param expected value of the metric + * @param rb the record builder mock used to getMetrics + */ + public static void assertGauge(String name, long expected, + MetricsRecordBuilder rb) { + assertThat(getLongGauge(name, rb)).as(name) + .isEqualTo(expected); + } + + public static long getLongGauge(String name, MetricsRecordBuilder rb) { + ArgumentCaptor captor = ArgumentCaptor.forClass(Long.class); + verify(rb, atLeast(0)).addGauge(eqName(info(name, "")), captor.capture()); + checkCaptured(captor, name); + return captor.getValue(); + } + + /** + * Assert a double gauge metric as expected. + * @param name of the metric + * @param expected value of the metric + * @param rb the record builder mock used to getMetrics + */ + public static void assertGauge(String name, double expected, MetricsRecordBuilder rb) { + assertThat(getDoubleGauge(name, rb)).as(name) + .isCloseTo(expected, EPSILON); + } + + public static double getDoubleGauge(String name, MetricsRecordBuilder rb) { + ArgumentCaptor captor = ArgumentCaptor.forClass(Double.class); + verify(rb, atLeast(0)).addGauge(eqName(info(name, "")), captor.capture()); + checkCaptured(captor, name); + return captor.getValue(); + } + + /** + * Assert a long counter metric as expected. + * @param name of the metric + * @param expected value of the metric + * @param rb the record builder mock used to getMetrics + */ + public static void assertCounter(String name, long expected, + MetricsRecordBuilder rb) { + assertThat(getLongCounter(name, rb)).as(name) + .isEqualTo(expected); + } + + public static long getLongCounter(String name, MetricsRecordBuilder rb) { + ArgumentCaptor captor = ArgumentCaptor.forClass(Long.class); + verify(rb, atLeast(0)).addCounter(eqName(info(name, "")), captor.capture()); + checkCaptured(captor, name); + return captor.getValue(); + } + + public static long getLongCounterWithoutCheck(String name, + MetricsRecordBuilder rb) { + ArgumentCaptor captor = ArgumentCaptor.forClass(Long.class); + verify(rb, atLeast(0)).addCounter(eqName(info(name, "")), captor.capture()); + return captor.getValue(); + } + + public static String getStringMetric(String name, MetricsRecordBuilder rb) { + ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); + verify(rb, atLeast(0)).tag(eqName(info(name, "")), captor.capture()); + checkCaptured(captor, name); + return captor.getValue(); + } + + /** + * Assert a float gauge metric as expected. + * @param name of the metric + * @param expected value of the metric + * @param rb the record builder mock used to getMetrics + */ + public static void assertGauge(String name, float expected, + MetricsRecordBuilder rb) { + assertThat(getFloatGauge(name, rb)).as(name) + .isCloseTo(expected, EPSILON_FLOAT); + } + + public static float getFloatGauge(String name, MetricsRecordBuilder rb) { + ArgumentCaptor captor = ArgumentCaptor.forClass(Float.class); + verify(rb, atLeast(0)).addGauge(eqName(info(name, "")), captor.capture()); + checkCaptured(captor, name); + return captor.getValue(); + } + + /** + * Check that this metric was captured exactly once. + */ + private static void checkCaptured(ArgumentCaptor captor, String name) { + assertThat(captor.getAllValues()).as(name) + .hasSize(1); + } + + /** + * Assert an int gauge metric as expected. + * @param name of the metric + * @param expected value of the metric + * @param source to get metrics from + */ + public static void assertGauge(String name, int expected, + MetricsSource source) { + assertGauge(name, expected, getMetrics(source)); + } + + /** + * Assert an int counter metric as expected. + * @param name of the metric + * @param expected value of the metric + * @param source to get metrics from + */ + public static void assertCounter(String name, int expected, + MetricsSource source) { + assertCounter(name, expected, getMetrics(source)); + } + + /** + * Assert a long gauge metric as expected. + * @param name of the metric + * @param expected value of the metric + * @param source to get metrics from + */ + public static void assertGauge(String name, long expected, + MetricsSource source) { + assertGauge(name, expected, getMetrics(source)); + } + + /** + * Assert a long counter metric as expected. + * @param name of the metric + * @param expected value of the metric + * @param source to get metrics from + */ + public static void assertCounter(String name, long expected, + MetricsSource source) { + assertCounter(name, expected, getMetrics(source)); + } + + /** + * Assert that a long counter metric is greater than a value. + * @param name of the metric + * @param greater value of the metric should be greater than this + * @param rb the record builder mock used to getMetrics + */ + public static void assertCounterGt(String name, long greater, + MetricsRecordBuilder rb) { + assertThat(getLongCounter(name, rb)).as(name) + .isGreaterThan(greater); + } + + /** + * Assert that a long counter metric is greater than a value. + * @param name of the metric + * @param greater value of the metric should be greater than this + * @param source the metrics source + */ + public static void assertCounterGt(String name, long greater, + MetricsSource source) { + assertCounterGt(name, greater, getMetrics(source)); + } + + /** + * Assert that a double gauge metric is greater than a value. + * @param name of the metric + * @param greater value of the metric should be greater than this + * @param rb the record builder mock used to getMetrics + */ + public static void assertGaugeGt(String name, double greater, + MetricsRecordBuilder rb) { + assertThat(getDoubleGauge(name, rb)).as(name) + .isGreaterThan(greater); + } + + /** + * Assert that a double gauge metric is greater than or equal to a value. + * @param name of the metric + * @param greater value of the metric should be greater than or equal to this + * @param rb the record builder mock used to getMetrics + */ + public static void assertGaugeGte(String name, double greater, + MetricsRecordBuilder rb) { + double curValue = getDoubleGauge(name, rb); + assertThat(curValue).as(name) + .isGreaterThanOrEqualTo(greater); + } + + /** + * Assert that a double gauge metric is greater than a value. + * @param name of the metric + * @param greater value of the metric should be greater than this + * @param source the metrics source + */ + public static void assertGaugeGt(String name, double greater, + MetricsSource source) { + assertGaugeGt(name, greater, getMetrics(source)); + } + + /** + * Asserts that the NumOps and quantiles for a metric with value name + * "Latency" have been changed at some point to a non-zero value. + * + * @param prefix of the metric + * @param rb MetricsRecordBuilder with the metric + */ + public static void assertQuantileGauges(String prefix, + MetricsRecordBuilder rb) { + assertQuantileGauges(prefix, rb, "Latency"); + } + + /** + * Asserts that the NumOps and quantiles for a metric have been changed at + * some point to a non-zero value, for the specified value name of the + * metrics (e.g., "Latency", "Count"). + * + * @param prefix of the metric + * @param rb MetricsRecordBuilder with the metric + * @param valueName the value name for the metric + */ + public static void assertQuantileGauges(String prefix, + MetricsRecordBuilder rb, String valueName) { + verify(rb).addGauge(eqName(info(prefix + "NumOps", "")), geq(0L)); + for (Quantile q : MutableQuantiles.quantiles) { + String nameTemplate = prefix + "%dthPercentile" + valueName; + int percentile = (int) (100 * q.quantile); + verify(rb).addGauge( + eqName(info(String.format(nameTemplate, percentile), "")), + geq(0L)); + } + } + + /** + * Asserts that the NumOps and inverse quantiles for a metric have been changed at + * some point to a non-zero value, for the specified value name of the + * metrics (e.g., "Rate"). + * + * @param prefix of the metric + * @param rb MetricsRecordBuilder with the metric + * @param valueName the value name for the metric + */ + public static void assertInverseQuantileGauges(String prefix, + MetricsRecordBuilder rb, String valueName) { + verify(rb).addGauge(eqName(info(prefix + "NumOps", "")), geq(0L)); + for (Quantile q : MutableQuantiles.quantiles) { + String nameTemplate = prefix + "%dthInversePercentile" + valueName; + int percentile = (int) (100 * q.quantile); + verify(rb).addGauge( + eqName(info(String.format(nameTemplate, percentile), "")), + geq(0L)); + } + } + + /** + * Assert a tag of metric as expected. + * @param name of the metric tag + * @param expected value of the metric tag + * @param rb the record builder mock used to getMetrics + */ + public static void assertTag(String name, String expected, + MetricsRecordBuilder rb) { + assertThat(getStringTag(name, rb)).as("Tag for metric " + name) + .isEqualTo(expected); + } + + /** + * get the value tag for the metric. + * @param name of the metric tag + * @param rb value of the metric tag + * @return the value tag for the metric + */ + public static String getStringTag(String name, MetricsRecordBuilder rb) { + ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); + verify(rb).tag(eqName(info(name, "")), captor.capture()); + checkCaptured(captor, name); + return captor.getValue(); + } + + private MetricsAsserts() { + // no instances + } +} diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/container/metrics/TestSCMContainerManagerMetrics.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/container/metrics/TestSCMContainerManagerMetrics.java index 0fab5fdfc552..14875781b985 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/container/metrics/TestSCMContainerManagerMetrics.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/container/metrics/TestSCMContainerManagerMetrics.java @@ -46,8 +46,8 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_CONTAINER_REPORT_INTERVAL; import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_SCM_SAFEMODE_PIPELINE_CREATION; -import static org.apache.hadoop.test.MetricsAsserts.getLongCounter; -import static org.apache.hadoop.test.MetricsAsserts.getMetrics; +import static org.apache.ozone.test.MetricsAsserts.getLongCounter; +import static org.apache.ozone.test.MetricsAsserts.getMetrics; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/TestCSMMetrics.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/TestCSMMetrics.java index fa413d194cb5..cd6dfb171c05 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/TestCSMMetrics.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/TestCSMMetrics.java @@ -18,9 +18,9 @@ package org.apache.hadoop.ozone.container.common.transport.server.ratis; -import static org.apache.hadoop.test.MetricsAsserts.assertCounter; -import static org.apache.hadoop.test.MetricsAsserts.getDoubleGauge; -import static org.apache.hadoop.test.MetricsAsserts.getMetrics; +import static org.apache.ozone.test.MetricsAsserts.assertCounter; +import static org.apache.ozone.test.MetricsAsserts.getDoubleGauge; +import static org.apache.ozone.test.MetricsAsserts.getMetrics; import java.io.File; import java.io.IOException; diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/metrics/TestContainerMetrics.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/metrics/TestContainerMetrics.java index 599f965c0514..0b83c650fe0a 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/metrics/TestContainerMetrics.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/metrics/TestContainerMetrics.java @@ -52,9 +52,9 @@ import com.google.common.collect.Maps; import static org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanodeDetails; -import static org.apache.hadoop.test.MetricsAsserts.assertCounter; -import static org.apache.hadoop.test.MetricsAsserts.assertQuantileGauges; -import static org.apache.hadoop.test.MetricsAsserts.getMetrics; +import static org.apache.ozone.test.MetricsAsserts.assertCounter; +import static org.apache.ozone.test.MetricsAsserts.assertQuantileGauges; +import static org.apache.ozone.test.MetricsAsserts.getMetrics; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/metrics/TestDatanodeQueueMetrics.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/metrics/TestDatanodeQueueMetrics.java index 17138223b6ed..06e1f933749a 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/metrics/TestDatanodeQueueMetrics.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/metrics/TestDatanodeQueueMetrics.java @@ -36,8 +36,8 @@ import static org.apache.hadoop.ozone.container.common.statemachine.DatanodeQueueMetrics.COMMAND_DISPATCHER_QUEUE_PREFIX; import static org.apache.hadoop.ozone.container.common.statemachine.DatanodeQueueMetrics.STATE_CONTEXT_COMMAND_QUEUE_PREFIX; -import static org.apache.hadoop.test.MetricsAsserts.getLongGauge; -import static org.apache.hadoop.test.MetricsAsserts.getMetrics; +import static org.apache.ozone.test.MetricsAsserts.getLongGauge; +import static org.apache.ozone.test.MetricsAsserts.getMetrics; /** * Test for queue metrics of datanodes. diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmMetrics.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmMetrics.java index d1c43b185a0f..1a87b450794f 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmMetrics.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmMetrics.java @@ -23,8 +23,8 @@ import static org.apache.hadoop.ozone.security.acl.OzoneObj.ResourceType.BUCKET; import static org.apache.hadoop.ozone.security.acl.OzoneObj.ResourceType.VOLUME; import static org.apache.hadoop.ozone.security.acl.OzoneObj.StoreType.OZONE; -import static org.apache.hadoop.test.MetricsAsserts.assertCounter; -import static org.apache.hadoop.test.MetricsAsserts.getMetrics; +import static org.apache.ozone.test.MetricsAsserts.assertCounter; +import static org.apache.ozone.test.MetricsAsserts.getMetrics; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -80,7 +80,7 @@ import org.apache.hadoop.ozone.security.acl.OzoneObj; import org.apache.hadoop.ozone.security.acl.OzoneObjInfo; import org.apache.hadoop.ozone.snapshot.SnapshotDiffResponse; -import org.apache.hadoop.test.MetricsAsserts; +import org.apache.ozone.test.MetricsAsserts; import org.apache.ozone.test.GenericTestUtils; import org.assertj.core.util.Lists; import org.junit.jupiter.api.AfterEach; diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/TestSCMContainerPlacementPolicyMetrics.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/TestSCMContainerPlacementPolicyMetrics.java index c00840c835d6..d980d761de66 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/TestSCMContainerPlacementPolicyMetrics.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/TestSCMContainerPlacementPolicyMetrics.java @@ -60,8 +60,8 @@ import static org.apache.hadoop.fs.CommonConfigurationKeysPublic .NET_TOPOLOGY_NODE_SWITCH_MAPPING_IMPL_KEY; import static org.apache.hadoop.hdds.client.ReplicationFactor.THREE; -import static org.apache.hadoop.test.MetricsAsserts.getLongCounter; -import static org.apache.hadoop.test.MetricsAsserts.getMetrics; +import static org.apache.ozone.test.MetricsAsserts.getLongCounter; +import static org.apache.ozone.test.MetricsAsserts.getMetrics; import static org.junit.jupiter.api.Assertions.assertEquals; /** diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/TestXceiverClientMetrics.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/TestXceiverClientMetrics.java index fc4dbfd391b4..42c7a58ccd36 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/TestXceiverClientMetrics.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/TestXceiverClientMetrics.java @@ -18,9 +18,9 @@ package org.apache.hadoop.ozone.scm; import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_METADATA_DIR_NAME; -import static org.apache.hadoop.test.MetricsAsserts.assertCounter; -import static org.apache.hadoop.test.MetricsAsserts.getLongCounter; -import static org.apache.hadoop.test.MetricsAsserts.getMetrics; +import static org.apache.ozone.test.MetricsAsserts.assertCounter; +import static org.apache.ozone.test.MetricsAsserts.getLongCounter; +import static org.apache.ozone.test.MetricsAsserts.getMetrics; import java.util.List; import java.util.ArrayList; diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/pipeline/TestSCMPipelineBytesWrittenMetrics.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/pipeline/TestSCMPipelineBytesWrittenMetrics.java index 017bc2331c09..29c9392a1d56 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/pipeline/TestSCMPipelineBytesWrittenMetrics.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/pipeline/TestSCMPipelineBytesWrittenMetrics.java @@ -51,8 +51,8 @@ import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_PIPELINE_REPORT_INTERVAL; import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_DATANODE_PIPELINE_LIMIT; import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_PIPELINE_AUTO_CREATE_FACTOR_ONE; -import static org.apache.hadoop.test.MetricsAsserts.getLongCounter; -import static org.apache.hadoop.test.MetricsAsserts.getMetrics; +import static org.apache.ozone.test.MetricsAsserts.getLongCounter; +import static org.apache.ozone.test.MetricsAsserts.getMetrics; import static org.junit.jupiter.api.Assertions.assertEquals; /** diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/pipeline/TestSCMPipelineMetrics.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/pipeline/TestSCMPipelineMetrics.java index 6371c1cc3899..85a61e8cb4ba 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/pipeline/TestSCMPipelineMetrics.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/scm/pipeline/TestSCMPipelineMetrics.java @@ -39,9 +39,10 @@ import java.util.Optional; import java.util.concurrent.TimeoutException; -import static org.apache.hadoop.test.MetricsAsserts.assertCounter; -import static org.apache.hadoop.test.MetricsAsserts.getLongCounter; -import static org.apache.hadoop.test.MetricsAsserts.getMetrics; +import static org.apache.ozone.test.MetricsAsserts.assertCounter; +import static org.apache.ozone.test.MetricsAsserts.getLongCounter; +import static org.apache.ozone.test.MetricsAsserts.getMetrics; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -110,8 +111,8 @@ public void testNumBlocksAllocated() throws IOException, TimeoutException { MetricsRecordBuilder metrics = getMetrics(SCMPipelineMetrics.class.getSimpleName()); Pipeline pipeline = block.getPipeline(); - long numBlocksAllocated = getLongCounter( - SCMPipelineMetrics.getBlockAllocationMetricName(pipeline), metrics); + final String metricName = SCMPipelineMetrics.getBlockAllocationMetricName(pipeline); + long numBlocksAllocated = getLongCounter(metricName, metrics); assertEquals(1, numBlocksAllocated); // destroy the pipeline @@ -122,11 +123,8 @@ public void testNumBlocksAllocated() throws IOException, TimeoutException { MetricsRecordBuilder finalMetrics = getMetrics(SCMPipelineMetrics.class.getSimpleName()); Throwable t = assertThrows(AssertionError.class, () -> - getLongCounter(SCMPipelineMetrics - .getBlockAllocationMetricName(pipeline), finalMetrics)); - assertTrue(t.getMessage().contains( - "Expected exactly one metric for name " + SCMPipelineMetrics - .getBlockAllocationMetricName(block.getPipeline()))); + getLongCounter(metricName, finalMetrics)); + assertThat(t).hasMessageContaining(metricName); } @AfterEach