nizhikov commented on a change in pull request #7693:
URL: https://github.com/apache/ignite/pull/7693#discussion_r487701521



##########
File path: 
modules/core/src/test/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsSelfTest.java
##########
@@ -0,0 +1,305 @@
+/*
+ * 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.performancestatistics;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.locks.Lock;
+import java.util.function.Consumer;
+import javax.cache.processor.EntryProcessor;
+import javax.cache.processor.EntryProcessorException;
+import javax.cache.processor.MutableEntry;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheEntryProcessor;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.GridIntList;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.lang.IgniteRunnable;
+import org.apache.ignite.lang.IgniteUuid;
+import org.apache.ignite.transactions.Transaction;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static 
org.apache.ignite.internal.processors.performancestatistics.AbstractPerformanceStatisticsTest.LoadNode.CLIENT;
+import static 
org.apache.ignite.internal.processors.performancestatistics.AbstractPerformanceStatisticsTest.LoadNode.SERVER;
+import static 
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_GET;
+import static 
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_GET_ALL;
+import static 
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_GET_AND_PUT;
+import static 
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_GET_AND_REMOVE;
+import static 
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_INVOKE;
+import static 
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_INVOKE_ALL;
+import static 
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_LOCK;
+import static 
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_PUT;
+import static 
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_PUT_ALL;
+import static 
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_REMOVE;
+import static 
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_REMOVE_ALL;
+
+/**
+ * Tests performance statistics.
+ */
+@RunWith(Parameterized.class)
+@SuppressWarnings({"LockAcquiredButNotSafelyReleased"})
+public class PerformanceStatisticsSelfTest extends 
AbstractPerformanceStatisticsTest {
+    /** Test entry processor. */
+    private static final EntryProcessor<Object, Object, Object> ENTRY_PROC =
+        new EntryProcessor<Object, Object, Object>() {
+        @Override public Object process(MutableEntry<Object, Object> entry, 
Object... arguments)
+            throws EntryProcessorException {
+            return null;
+        }
+    };
+
+    /** Test cache entry processor. */
+    private static final CacheEntryProcessor<Object, Object, Object> 
CACHE_ENTRY_PROC =
+        new CacheEntryProcessor<Object, Object, Object>() {
+        @Override public Object process(MutableEntry<Object, Object> entry, 
Object... arguments)
+            throws EntryProcessorException {
+            return null;
+        }
+    };
+
+    /** Cache entry count. */
+    private static final int ENTRY_COUNT = 100;
+
+    /** Load node to run operations from. */
+    @Parameterized.Parameter
+    public LoadNode loadNode;
+
+    /** @return Test parameters. */
+    @Parameterized.Parameters(name = "loadNode={0}")
+    public static Collection<?> parameters() {
+        return Arrays.asList(new Object[][] {{SERVER}, {CLIENT}});
+    }
+
+    /** Ignite. */
+    private static IgniteEx srv;
+
+    /** Ignite node to run load from. */
+    private static IgniteEx node;
+
+    /** Test cache. */
+    private static IgniteCache<Object, Object> cache;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        cfg.setCacheConfiguration(defaultCacheConfiguration());
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        srv = startGrid(0);
+
+        IgniteEx client = startClientGrid(1);
+
+        node = loadNode == SERVER ? srv : client;
+
+        cache = node.cache(DEFAULT_CACHE_NAME);
+
+        for (int i = 0; i < ENTRY_COUNT; i++)
+            cache.put(i, i);
+    }
+
+    /** @throws Exception If failed. */
+    @Test
+    public void testCompute() throws Exception {
+        String testTaskName = "testTask";
+        int executions = 5;
+
+        startCollectStatistics();
+
+        IgniteRunnable task = new IgniteRunnable() {
+            @Override public void run() {
+                // No-op.
+            }
+        };
+
+        for (int i = 0; i < executions; i++)
+            node.compute().withName(testTaskName).run(task);
+
+        HashMap<IgniteUuid, Integer> sessions = new HashMap<>();
+        AtomicInteger tasks = new AtomicInteger();
+        AtomicInteger jobs = new AtomicInteger();
+
+        stopCollectStatisticsAndRead(new TestHandler() {
+            @Override public void task(UUID nodeId, IgniteUuid sesId, String 
taskName, long startTime, long duration,
+                int affPartId) {
+                sessions.compute(sesId, (uuid, cnt) -> cnt == null ? 1 : 
++cnt);
+
+                tasks.incrementAndGet();
+
+                assertEquals(node.context().localNodeId(), nodeId);
+                assertEquals(testTaskName, taskName);
+                assertTrue(startTime > 0);

Review comment:
       Let's store `System.currentTimeMillis` before running jobs and here 
check.
   `assertTrue(startTime >= jobsStartTime);`




----------------------------------------------------------------
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]


Reply via email to