Skip to content

Commit

Permalink
IGNITE-24286 Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
chesnokoff committed Feb 10, 2025
1 parent 1757759 commit e7fc6b1
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@

package org.apache.ignite.internal.processors.performancestatistics;

import java.io.File;
import java.lang.management.ThreadInfo;
import java.util.List;
import java.util.UUID;
import org.apache.ignite.Ignite;
import org.apache.ignite.internal.processors.cache.query.GridCacheQueryType;
import org.apache.ignite.internal.util.GridIntList;
Expand All @@ -30,6 +26,12 @@
import org.apache.ignite.mxbean.PerformanceStatisticsMBean;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;

import java.io.File;
import java.lang.management.ThreadInfo;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import static java.util.Collections.singletonList;
import static org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsWriter.PERF_STAT_DIR;
import static org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsWriter.WRITER_THREAD_NAME;
Expand Down Expand Up @@ -237,6 +239,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, long time, 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,112 @@
/*
* 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 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;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* 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 testSystemViewCaches() throws Exception {
try (IgniteEx igniteEx = startGrid(0)) {
IgniteCache<Integer, Integer> cache = igniteEx.getOrCreateCache("myCache");
cache.put(1, 1);

startCollectStatistics();

AtomicBoolean hasMyCache = new AtomicBoolean(false);
Set<String> views = new HashSet<>();
igniteEx.context().systemView().forEach(view -> views.add(view.name()));

stopCollectStatisticsAndRead(new TestHandler() {
@Override public void systemView(UUID id, String name, long time, Map<String, String> data) {
views.remove(name);
if("caches".equals(name)) {
hasMyCache.compareAndSet(false, "myCache".equals(data.get("cacheGroupName")));
}
}
});

assertTrue("System view record for myCache does not exist.", hasMyCache.get());
}
}

// @Test
// public void testSystemViewTables() throws Exception {
// try (IgniteEx igniteEx = startGrid(0)) {
// CacheConfiguration<Long, Person> personCacheCfg = new CacheConfiguration<>();
// personCacheCfg.setName("Person");
//
// QueryEntity queryEntity = new QueryEntity(Long.class, Person.class)
// .addQueryField("id", Long.class.getName(), null)
// .addQueryField("age", Integer.class.getName(), null)
// .addQueryField("salary", Float.class.getName(), null)
// .addQueryField("name", String.class.getName(), null);
//
// queryEntity.setIndexes(Arrays.asList(new QueryIndex("id"), new QueryIndex("salary", false)));
//
// personCacheCfg.setQueryEntities(List.of(queryEntity));
//
// igniteEx.createCache(personCacheCfg);
//
// startCollectStatistics();
// Set<String> viewsExpected = new HashSet<>(List.of("caches", "indexes", "table.columns", "tables"));
//
// AtomicBoolean hasMyCache = new AtomicBoolean(false);
// Set<String> views = new HashSet<>();
// igniteEx.context().systemView().forEach(view -> views.add(view.name()));
//
// stopCollectStatisticsAndRead(new TestHandler() {
// @Override public void systemView(UUID id, String name, Map<String, String> data) {
// views.remove(name);
// if("caches".equals(name)) {
// hasMyCache.compareAndSet(false, "myCache".equals(data.get("cacheGroupName")));
// }
// if("tables".equals(name)) {
// hasMyCache.compareAndSet(false, "myCache".equals(data.get("cacheGroupName")));
// }
// }
// });
//
// assertTrue("System view record for myCache does not exist.", hasMyCache.get());
// assertTrue("Not all views were found: " + views, views.isEmpty());
// }
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsPropertiesTest;
import org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsRotateFileTest;
import org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsSelfTest;
import org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsSystemViewTest;
import org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsThinClientTest;
import org.apache.ignite.internal.processors.performancestatistics.StringCacheTest;
import org.apache.ignite.internal.processors.performancestatistics.TopologyChangesTest;
Expand Down Expand Up @@ -97,6 +98,7 @@
PerformanceStatisticsSelfTest.class,
PerformanceStatisticsThinClientTest.class,
PerformanceStatisticsRotateFileTest.class,
PerformanceStatisticsSystemViewTest.class,
TopologyChangesTest.class,
IgniteClusterIdTagTest.class,
StringCacheTest.class,
Expand Down

0 comments on commit e7fc6b1

Please sign in to comment.