nizhikov commented on a change in pull request #8284: URL: https://github.com/apache/ignite/pull/8284#discussion_r498671398
########## File path: modules/control-utility/src/test/java/org/apache/ignite/util/MetricCommandTest.java ########## @@ -0,0 +1,644 @@ +/* + * 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.ignite.util; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ThreadPoolExecutor.AbortPolicy; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.configuration.DataRegionConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.commandline.CommandList; +import org.apache.ignite.internal.commandline.metric.MetricCommandArg; +import org.apache.ignite.internal.processors.metric.MetricRegistry; +import org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.thread.IgniteThreadFactory; +import org.junit.Test; + +import static java.lang.Long.parseLong; +import static java.lang.System.currentTimeMillis; +import static java.util.regex.Pattern.quote; +import static org.apache.ignite.cluster.ClusterState.ACTIVE; +import static org.apache.ignite.configuration.IgniteConfiguration.DFLT_THREAD_KEEP_ALIVE_TIME; +import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_INVALID_ARGUMENTS; +import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK; +import static org.apache.ignite.internal.commandline.CommandList.METRIC; +import static org.apache.ignite.internal.commandline.TablePrinter.COLUMN_SEPARATOR; +import static org.apache.ignite.internal.commandline.metric.MetricCommandArg.NODE_ID; +import static org.apache.ignite.internal.managers.communication.GridIoManager.COMM_METRICS; +import static org.apache.ignite.internal.processors.cache.persistence.DataStorageMetricsImpl.DATASTORAGE_METRIC_PREFIX; +import static org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.SNAPSHOT_METRICS; +import static org.apache.ignite.internal.processors.job.GridJobProcessor.JOBS_METRICS; +import static org.apache.ignite.internal.processors.metric.GridMetricManager.CLUSTER_METRICS; +import static org.apache.ignite.internal.processors.metric.GridMetricManager.IGNITE_METRICS; +import static org.apache.ignite.internal.processors.metric.GridMetricManager.PME_METRICS; +import static org.apache.ignite.internal.processors.metric.GridMetricManager.SYS_METRICS; +import static org.apache.ignite.internal.processors.metric.GridMetricManager.THREAD_POOLS; +import static org.apache.ignite.internal.processors.metric.GridMetricManager.TX_METRICS; +import static org.apache.ignite.internal.processors.metric.impl.MetricUtils.SEPARATOR; +import static org.apache.ignite.internal.processors.metric.impl.MetricUtils.cacheMetricsRegistryName; +import static org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName; +import static org.apache.ignite.testframework.GridTestUtils.assertContains; +import static org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause; + +/** Tests output of {@link CommandList#METRIC} command. */ +public class MetricCommandTest extends GridCommandHandlerClusterByClassAbstractTest { + /** Command line argument for printing metric values. */ + private static final String CMD_METRIC = METRIC.text(); + + /** Test node with 0 index. */ + private IgniteEx ignite0; + + /** Test node with 1 index. */ + private IgniteEx ignite1; + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + awaitPartitionMapExchange(); + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + injectTestSystemOut(); + + autoConfirmation = false; + + ignite0 = ignite(0); + ignite1 = ignite(1); + } + + /** Tests command error output in case of mandatory metric name is omitted. */ + @Test + public void testMetricNameMissedFailure() { + assertContains(log, executeCommand(EXIT_CODE_INVALID_ARGUMENTS, CMD_METRIC), + "The name of a metric(metric registry) is expected."); + } + + /** Tests command error output in case value of {@link MetricCommandArg#NODE_ID} argument is omitted. */ + @Test + public void testNodeIdMissedFailure() { + assertContains(log, executeCommand(EXIT_CODE_INVALID_ARGUMENTS, CMD_METRIC, SYS_METRICS, NODE_ID.argName()), + "ID of the node from which metric values should be obtained is expected."); + } + + /** Tests command error output in case value of {@link MetricCommandArg#NODE_ID} argument is invalid.*/ + @Test + public void testInvalidNodeIdFailure() { + assertContains(log, + executeCommand(EXIT_CODE_INVALID_ARGUMENTS, CMD_METRIC, SYS_METRICS, NODE_ID.argName(), "invalid_node_id"), + "Failed to parse " + NODE_ID.argName() + + " command argument. String representation of \"java.util.UUID\" is exepected." + + " For example: 123e4567-e89b-42d3-a456-556642440000" + ); + } + + /** Tests command error output in case multiple metric names are specified. */ + @Test + public void testMultipleMetricNamesFailure() { + assertContains(log, + executeCommand(EXIT_CODE_INVALID_ARGUMENTS, CMD_METRIC, IGNITE_METRICS, SYS_METRICS), + "Multiple metric(metric registry) names are not supported."); + } + + /** Tests command error output in case {@link MetricCommandArg#NODE_ID} argument value refers to nonexistent node. */ + @Test + public void testNonExistentNodeIdFailure() { + String incorrectNodeId = UUID.randomUUID().toString(); + + assertContains(log, + executeCommand(EXIT_CODE_INVALID_ARGUMENTS, CMD_METRIC, "--node-id", incorrectNodeId, IGNITE_METRICS), + "Failed to perform operation.\nNode with id=" + incorrectNodeId + " not found"); + } + + /** Tests command output in case nonexistent metric name is specified. */ + @Test + public void testNonExistentMetric() { + assertContains(log, executeCommand(EXIT_CODE_OK, CMD_METRIC, IGNITE_METRICS + SEPARATOR), + "No metric with specified name was found [name=" + IGNITE_METRICS + SEPARATOR + ']'); + + assertContains(log, executeCommand(EXIT_CODE_OK, CMD_METRIC, "nonexistent.metric"), + "No metric with specified name was found [name=nonexistent.metric]"); + } + + /** */ + @Test + public void testCommunicationMetrics() { + Map<String, String> metrics = metrics(ignite0, COMM_METRICS); + + assertTrue(Integer.parseInt(metrics.get(metricName(COMM_METRICS, "SentBytesCount"))) > 0); + assertTrue(Integer.parseInt(metrics.get(metricName(COMM_METRICS, "ReceivedBytesCount"))) > 0); + assertEquals("0", metrics.get(metricName(COMM_METRICS, "OutboundMessagesQueueSize"))); + assertTrue(Integer.parseInt(metrics.get(metricName(COMM_METRICS, "ReceivedMessagesCount"))) > 0); + assertTrue(Integer.parseInt(metrics.get(metricName(COMM_METRICS, "SentMessagesCount"))) > 0); + } + + /** */ + @Test + public void testJobsMetrics() { Review comment: Le'ts keep one test for each type of metric and remove all other tests. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
