Skip to content

Commit

Permalink
IGNITE-24286 Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chesnokoff committed Jan 22, 2025
1 parent a7647d4 commit 05cb868
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import org.apache.ignite.internal.util.typedef.G;
import org.junit.Test;

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.CommandHandler.EXIT_CODE_UNEXPECTED_ERROR;
import static org.apache.ignite.internal.management.performancestatistics.PerformanceStatisticsTask.STATUS_DISABLED;
import static org.apache.ignite.internal.management.performancestatistics.PerformanceStatisticsTask.STATUS_ENABLED;
import static org.apache.ignite.internal.processors.cache.ClusterCachesInfo.CACHES_VIEW;
import static org.apache.ignite.internal.processors.performancestatistics.AbstractPerformanceStatisticsTest.TIMEOUT;
import static org.apache.ignite.internal.processors.performancestatistics.AbstractPerformanceStatisticsTest.cleanPerformanceStatisticsDir;
import static org.apache.ignite.internal.processors.performancestatistics.AbstractPerformanceStatisticsTest.statisticsFiles;
Expand All @@ -45,6 +47,12 @@ public class PerformanceStatisticsCommandTest extends GridCommandHandlerClusterB
/** */
public static final String STATUS = "status";

/** */
public static final String ALL_VIEWS = "--all-system-views";

/** */
public static final String VIEWS = "--system-views";

/** */
public static final String PERFORMANCE_STATISTICS = "--performance-statistics";

Expand Down Expand Up @@ -150,4 +158,21 @@ public void testStopAlreadyStopped() {

assertEquals(EXIT_CODE_OK, res);
}

/** */
@Test
public void testSystemViews() {
int res = execute(PERFORMANCE_STATISTICS, START, VIEWS);

assertEquals(EXIT_CODE_INVALID_ARGUMENTS, res);

res = execute(PERFORMANCE_STATISTICS, START, ALL_VIEWS);
assertEquals(EXIT_CODE_OK, res);

res = execute(PERFORMANCE_STATISTICS, STOP);
assertEquals(EXIT_CODE_OK, res);

res = execute(PERFORMANCE_STATISTICS, START, VIEWS, CACHES_VIEW);
assertEquals(EXIT_CODE_OK, res);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.File;
import java.lang.management.ThreadInfo;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.ignite.Ignite;
import org.apache.ignite.internal.processors.cache.query.GridCacheQueryType;
Expand Down Expand Up @@ -81,6 +82,17 @@ public static void startCollectStatistics() throws Exception {
waitForStatisticsEnabled(true);
}

/** Start collecting performance statistics and specified system views. */
public static void startCollectStatisticsWithSystemViews(List<String> views) throws Exception {
List<Ignite> grids = G.allGrids();

assertFalse(grids.isEmpty());

statisticsMBean(grids.get(0).name()).startWithViews(views);

waitForStatisticsEnabled(true);
}

/** Rotate file collecting performance statistics. */
public static void rotateCollectStatistics() throws Exception {
List<Ignite> grids = G.allGrids();
Expand Down Expand Up @@ -236,6 +248,11 @@ public static class TestHandler implements PerformanceStatisticsHandler {
@Override public void pagesWriteThrottle(UUID nodeId, long endTime, long duration) {
// No-op.
}

/** {@inheritDoc} */
@Override public void systemView(UUID id, String name, Map<String, String> data) {
// No-op.
}
}

/** Client type to run load from. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.cache.CacheAtomicityMode;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.IgniteEx;
import org.junit.Test;

/**
* Tests performance start with system views.
*/
public class PerformanceStatisticsSystemViewTest extends AbstractPerformanceStatisticsTest {
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

cfg.setCacheConfiguration(defaultCacheConfiguration().setAtomicityMode(CacheAtomicityMode.ATOMIC));

return cfg;
}

/** @throws Exception If failed. */
@Test
public void testSystemView() throws Exception {
try (
IgniteEx igniteEx = startGrid(0)
) {
IgniteCache<Integer, Integer> cache = igniteEx.getOrCreateCache("myCache");
cache.put(1, 1);
startCollectStatisticsWithSystemViews(List.of("CACHES"));

AtomicInteger cachesOps = new AtomicInteger();
AtomicInteger extraOps = new AtomicInteger();
AtomicBoolean hasMyCache = new AtomicBoolean(false);

stopCollectStatisticsAndRead(new TestHandler() {
@Override public void systemView(UUID id, String name, Map<String, String> data) {
if ("caches".equals(name)) {
cachesOps.incrementAndGet();
if ("myCache".equals(data.get("cacheGroupName")))
hasMyCache.compareAndSet(false, true);
}
else
extraOps.incrementAndGet();
}
});

assertTrue("System view record for myCache does not exist.", hasMyCache.get());
assertEquals("\"caches\" view required only.", 0, extraOps.get());
assertEquals(3, cachesOps.get());
}
}
}

0 comments on commit 05cb868

Please sign in to comment.