From notifications-return-3947-archive-asf-public=cust-asf.ponee.io@ignite.apache.org Tue Jun 25 16:39:31 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 4730F18075F for ; Tue, 25 Jun 2019 18:39:31 +0200 (CEST) Received: (qmail 77830 invoked by uid 500); 25 Jun 2019 16:38:11 -0000 Mailing-List: contact notifications-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list notifications@ignite.apache.org Received: (qmail 75868 invoked by uid 99); 25 Jun 2019 16:32:40 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Jun 2019 16:32:40 +0000 From: GitBox To: notifications@ignite.apache.org Subject: [GitHub] [ignite] alex-plekhanov commented on a change in pull request #6622: IGNITE-11926: GridJobProcessor metrics migration. Message-ID: <156148036048.8585.6787554744434802045.gitbox@gitbox.apache.org> Date: Tue, 25 Jun 2019 16:32:40 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit alex-plekhanov commented on a change in pull request #6622: IGNITE-11926: GridJobProcessor metrics migration. URL: https://github.com/apache/ignite/pull/6622#discussion_r297277152 ########## File path: modules/core/src/test/java/org/apache/ignite/internal/processors/jobmetrics/GridJobMetricsSelfTest.java ########## @@ -0,0 +1,358 @@ +/* + * 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.internal.processors.jobmetrics; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CountDownLatch; +import org.apache.ignite.IgniteException; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.compute.ComputeJob; +import org.apache.ignite.compute.ComputeJobResult; +import org.apache.ignite.compute.ComputeTaskAdapter; +import org.apache.ignite.compute.ComputeTaskFuture; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.job.GridJobProcessor; +import org.apache.ignite.spi.IgniteSpiAdapter; +import org.apache.ignite.spi.IgniteSpiException; +import org.apache.ignite.spi.IgniteSpiMultipleInstancesSupport; +import org.apache.ignite.spi.collision.CollisionContext; +import org.apache.ignite.spi.collision.CollisionExternalListener; +import org.apache.ignite.spi.collision.CollisionJobContext; +import org.apache.ignite.spi.collision.CollisionSpi; +import org.apache.ignite.spi.metric.LongMetric; +import org.apache.ignite.spi.metric.ReadOnlyMetricRegistry; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.jetbrains.annotations.Nullable; +import org.junit.Test; + +import static org.apache.ignite.internal.processors.job.GridJobProcessor.ACTIVE; +import static org.apache.ignite.internal.processors.job.GridJobProcessor.CANCELED; +import static org.apache.ignite.internal.processors.job.GridJobProcessor.EXECUTION_TIME; +import static org.apache.ignite.internal.processors.job.GridJobProcessor.FINISHED; +import static org.apache.ignite.internal.processors.job.GridJobProcessor.JOBS; +import static org.apache.ignite.internal.processors.job.GridJobProcessor.REJECTED; +import static org.apache.ignite.internal.processors.job.GridJobProcessor.STARTED; +import static org.apache.ignite.internal.processors.job.GridJobProcessor.WAITING; +import static org.apache.ignite.internal.processors.job.GridJobProcessor.WAITING_TIME; +import static org.apache.ignite.testframework.GridTestUtils.waitForCondition; + +/** + * Grid job metrics processor load test. + */ +public class GridJobMetricsSelfTest extends GridCommonAbstractTest { + /** */ + public static final long TIMEOUT = 10_000; + + /** */ + private static CountDownLatch latch; + + /** Test correct calculation of rejected and waiting metrics of the {@link GridJobProcessor}. */ + @Test + public void testGridJobWaitingRejectedMetrics() throws Exception { + latch = new CountDownLatch(1); + + GridTestCollision collisioinSpi = new GridTestCollision(); + + IgniteConfiguration cfg = new IgniteConfiguration() + .setCollisionSpi(collisioinSpi); + + try (IgniteEx g = startGrid(cfg)) { + ReadOnlyMetricRegistry mreg = g.context().metric().registry().withPrefix(JOBS); + + LongMetric started = (LongMetric)mreg.findMetric(STARTED); + LongMetric active = (LongMetric)mreg.findMetric(ACTIVE); + LongMetric waiting = (LongMetric)mreg.findMetric(WAITING); + LongMetric canceled = (LongMetric)mreg.findMetric(CANCELED); + LongMetric rejected = (LongMetric)mreg.findMetric(REJECTED); + LongMetric finished = (LongMetric)mreg.findMetric(FINISHED); + LongMetric totalExecutionTime = (LongMetric)mreg.findMetric(EXECUTION_TIME); + LongMetric totalWaitingTime = (LongMetric)mreg.findMetric(WAITING_TIME); + + assertNotNull(started); + assertNotNull(active); + assertNotNull(waiting); + assertNotNull(canceled); + assertNotNull(rejected); + assertNotNull(finished); + assertNotNull(totalExecutionTime); + assertNotNull(totalWaitingTime); + + assertEquals(0, started.value()); + assertEquals(0, active.value()); + assertEquals(0, waiting.value()); + assertEquals(0, canceled.value()); + assertEquals(0, rejected.value()); + assertEquals(0, finished.value()); + assertEquals(0, totalExecutionTime.value()); + assertEquals(0, totalWaitingTime.value()); + + SimplestTask task1 = new SimplestTask(); + SimplestTask task2 = new SimplestTask(); + SimplestTask task3 = new SimplestTask(); + + task1.block = true; + task2.block = true; + task3.block = true; + + //Task will become "waiting", because of CollisionSpi implementation. + ComputeTaskFuture fut1 = g.compute().executeAsync(task1, 1); + ComputeTaskFuture fut2 = g.compute().executeAsync(task2, 1); + ComputeTaskFuture fut3 = g.compute().executeAsync(task3, 1); + + assertEquals(0, started.value()); + assertEquals(0, active.value()); + assertEquals(3, waiting.value()); + assertEquals(0, canceled.value()); + assertEquals(0, rejected.value()); + assertEquals(0, finished.value()); + + //Activating 2 of 3 jobs. Rejecting 1 of them. + Iterator iter = collisioinSpi.jobs.values().iterator(); + + iter.next().cancel(); + + assertEquals(1, rejected.value()); + + Thread.sleep(100); //Sleeping to make sure totalWaitingTime will become more the zero. + + iter.next().activate(); + iter.next().activate(); + + boolean res = waitForCondition(() -> active.value() > 0, TIMEOUT); + + assertTrue(res); + + Thread.sleep(100); //Sleeping to make sure totalExecutionTime will become more the zero. + + latch.countDown(); + + res = waitForCondition(() -> fut1.isDone() && fut2.isDone() && fut3.isDone(), TIMEOUT); + + assertTrue(res); + + res = waitForCondition(() -> finished.value() == 3, TIMEOUT); + + assertTrue(res); + + assertTrue("Execution time should be greater then zero.", totalExecutionTime.value() > 0); + assertTrue("Waiting time should be greater then zero.", totalWaitingTime.value() > 0); + } + } + + /** Test correct calculation of finished, started, active, canceled metrics of the {@link GridJobProcessor}. */ + @Test + public void testGridJobMetrics() throws Exception { + latch = new CountDownLatch(1); + + try(IgniteEx g = startGrid(0)) { + ReadOnlyMetricRegistry mreg = g.context().metric().registry().withPrefix(JOBS); + + LongMetric started = (LongMetric)mreg.findMetric(STARTED); + LongMetric active = (LongMetric)mreg.findMetric(ACTIVE); + LongMetric waiting = (LongMetric)mreg.findMetric(WAITING); + LongMetric canceled = (LongMetric)mreg.findMetric(CANCELED); + LongMetric rejected = (LongMetric)mreg.findMetric(REJECTED); + LongMetric finished = (LongMetric)mreg.findMetric(FINISHED); + LongMetric totalExecutionTime = (LongMetric)mreg.findMetric(EXECUTION_TIME); + LongMetric totalWaitingTime = (LongMetric)mreg.findMetric(WAITING_TIME); + + assertNotNull(started); + assertNotNull(active); + assertNotNull(waiting); + assertNotNull(canceled); + assertNotNull(rejected); + assertNotNull(finished); + assertNotNull(totalExecutionTime); + assertNotNull(totalWaitingTime); + + assertEquals(0, started.value()); + assertEquals(0, active.value()); + assertEquals(0, waiting.value()); + assertEquals(0, canceled.value()); + assertEquals(0, rejected.value()); + assertEquals(0, finished.value()); + assertEquals(0, totalExecutionTime.value()); + assertEquals(0, totalWaitingTime.value()); + + SimplestTask task = new SimplestTask(); + + g.compute().execute(task, 1); + + //Waiting task to finish. + boolean res = waitForCondition(() -> active.value() == 0, TIMEOUT); + + assertTrue("Active = " + active.value(), res); + + assertEquals(1, started.value()); + assertEquals(0, waiting.value()); + assertEquals(0, canceled.value()); + assertEquals(0, rejected.value()); + assertEquals(1, finished.value()); + + //Task should block until latch is down. + task.block = true; + + ComputeTaskFuture fut = g.compute().executeAsync(task, 1); + + //Waiting task to start execution. + res = waitForCondition(() -> active.value() == 1, TIMEOUT); + + assertTrue("Active = " + active.value(), res); + + assertEquals(2, started.value()); + assertEquals(0, waiting.value()); + assertEquals(0, canceled.value()); + assertEquals(0, rejected.value()); + assertEquals(1, finished.value()); + + res = waitForCondition(() -> active.value() > 0, TIMEOUT); Review comment: There nothing happened between wait for `active.value() == 1` and wait for `active.value() > 0`. Why should we wait twice? ---------------------------------------------------------------- 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: users@infra.apache.org With regards, Apache Git Services