Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
import org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses.TestObjectEnum;
import org.apache.ignite.internal.management.SystemViewCommand;
import org.apache.ignite.internal.management.SystemViewTask;
import org.apache.ignite.internal.metric.SystemViewSelfTest.TestPredicate;
import org.apache.ignite.internal.metric.SystemViewSelfTest.TestRunnable;
import org.apache.ignite.internal.metric.SystemViewSelfTest.TestTransformer;
import org.apache.ignite.internal.metric.SystemViewExecutorsTest.TestRunnable;
import org.apache.ignite.internal.metric.SystemViewQueriesTest.TestPredicate;
import org.apache.ignite.internal.metric.SystemViewQueriesTest.TestTransformer;
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
import org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState;
import org.apache.ignite.internal.processors.cache.metric.SqlViewExporterSpiTest.TestAffinityFunction;
Expand Down Expand Up @@ -93,8 +93,8 @@
import static org.apache.ignite.internal.management.SystemViewCommand.COLUMN_SEPARATOR;
import static org.apache.ignite.internal.managers.discovery.GridDiscoveryManager.NODES_SYS_VIEW;
import static org.apache.ignite.internal.managers.systemview.ScanQuerySystemView.SCAN_QRY_SYS_VIEW;
import static org.apache.ignite.internal.metric.SystemViewSelfTest.TEST_PREDICATE;
import static org.apache.ignite.internal.metric.SystemViewSelfTest.TEST_TRANSFORMER;
import static org.apache.ignite.internal.metric.SystemViewQueriesTest.TEST_PREDICATE;
import static org.apache.ignite.internal.metric.SystemViewQueriesTest.TEST_TRANSFORMER;
import static org.apache.ignite.internal.processors.cache.ClusterCachesInfo.CACHES_VIEW;
import static org.apache.ignite.internal.processors.cache.ClusterCachesInfo.CACHE_GRPS_VIEW;
import static org.apache.ignite.internal.processors.cache.GridCacheProcessor.CACHE_GRP_PAGE_LIST_VIEW;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
import org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses.TestObjectAllTypes;
import org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses.TestObjectEnum;
import org.apache.ignite.internal.client.thin.ProtocolVersion;
import org.apache.ignite.internal.metric.SystemViewSelfTest.TestPredicate;
import org.apache.ignite.internal.metric.SystemViewSelfTest.TestTransformer;
import org.apache.ignite.internal.metric.SystemViewQueriesTest.TestPredicate;
import org.apache.ignite.internal.metric.SystemViewQueriesTest.TestTransformer;
import org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager;
import org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage;
import org.apache.ignite.internal.processors.metric.GridMetricManager;
Expand All @@ -91,8 +91,8 @@
import static org.apache.ignite.internal.managers.systemview.ScanQuerySystemView.SCAN_QRY_SYS_VIEW;
import static org.apache.ignite.internal.managers.systemview.SystemViewMBean.FILTER_OPERATION;
import static org.apache.ignite.internal.managers.systemview.SystemViewMBean.VIEWS;
import static org.apache.ignite.internal.metric.SystemViewSelfTest.TEST_PREDICATE;
import static org.apache.ignite.internal.metric.SystemViewSelfTest.TEST_TRANSFORMER;
import static org.apache.ignite.internal.metric.SystemViewQueriesTest.TEST_PREDICATE;
import static org.apache.ignite.internal.metric.SystemViewQueriesTest.TEST_TRANSFORMER;
import static org.apache.ignite.internal.processors.cache.CacheMetricsImpl.CACHE_METRICS;
import static org.apache.ignite.internal.processors.cache.ClusterCachesInfo.CACHES_VIEW;
import static org.apache.ignite.internal.processors.cache.ClusterCachesInfo.CACHE_GRPS_VIEW;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.metric;

import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;

/** Abstract base class for system view tests. */
public abstract class SystemViewAbstractTest extends GridCommonAbstractTest {
/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
super.beforeTestsStarted();

cleanPersistenceDir();
}

/** {@inheritDoc} */
@Override protected void afterTestsStopped() throws Exception {
super.afterTestsStopped();

cleanPersistenceDir();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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.metric;

import java.lang.reflect.Field;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses.TestObjectAllTypes;
import org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses.TestObjectEnum;
import org.apache.ignite.spi.systemview.view.BinaryMetadataView;
import org.apache.ignite.spi.systemview.view.SystemView;
import org.junit.Test;

import static org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl.BINARY_METADATA_VIEW;

/** Tests for {@link SystemView} for binary meta. */
public class SystemViewBinaryMetaTest extends SystemViewAbstractTest {
/** */
@Test
public void testBinaryMeta() throws Exception {
try (IgniteEx g = startGrid(0)) {
IgniteCache<Integer, TestObjectAllTypes> c1 = g.createCache("test-cache");
IgniteCache<Integer, TestObjectEnum> c2 = g.createCache("test-enum-cache");

c1.put(1, new TestObjectAllTypes());
c2.put(1, TestObjectEnum.A);

SystemView<BinaryMetadataView> view = g.context().systemView().view(BINARY_METADATA_VIEW);

assertNotNull(view);
assertEquals(2, view.size());

for (BinaryMetadataView meta : view) {
if (TestObjectEnum.class.getName().contains(meta.typeName())) {
assertTrue(meta.isEnum());

assertEquals(0, meta.fieldsCount());
}
else {
assertFalse(meta.isEnum());

Field[] fields = TestObjectAllTypes.class.getDeclaredFields();

assertEquals(fields.length, meta.fieldsCount());

for (Field field : fields)
assertTrue(meta.fields().contains(field.getName()));
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
/*
* 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.metric;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import javax.cache.expiry.CreatedExpiryPolicy;
import javax.cache.expiry.Duration;
import javax.cache.expiry.EternalExpiryPolicy;
import javax.cache.expiry.ModifiedExpiryPolicy;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.cluster.ClusterState;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.DataRegionConfiguration;
import org.apache.ignite.configuration.DataStorageConfiguration;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.lang.IgnitePredicate;
import org.apache.ignite.spi.systemview.view.CacheGroupIoView;
import org.apache.ignite.spi.systemview.view.CacheGroupView;
import org.apache.ignite.spi.systemview.view.CacheView;
import org.apache.ignite.spi.systemview.view.SystemView;
import org.junit.Test;

import static org.apache.ignite.internal.processors.cache.ClusterCachesInfo.CACHES_VIEW;
import static org.apache.ignite.internal.processors.cache.ClusterCachesInfo.CACHE_GRPS_VIEW;
import static org.apache.ignite.internal.processors.cache.GridCacheProcessor.CACHE_GRP_IO_VIEW;
import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;

/** Tests for {@link SystemView} for caches. */
public class SystemViewCacheTest extends SystemViewAbstractTest {
/** Tests work of {@link SystemView} for caches. */
@Test
public void testCachesView() throws Exception {
try (IgniteEx g = startGrid()) {
Set<String> cacheNames = new HashSet<>(Arrays.asList("cache-1", "cache-2"));

for (String name : cacheNames)
g.createCache(name);

SystemView<CacheView> caches = g.context().systemView().view(CACHES_VIEW);

assertEquals(g.context().cache().cacheDescriptors().size(), F.size(caches.iterator()));

for (CacheView row : caches)
cacheNames.remove(row.cacheName());

assertTrue(cacheNames.toString(), cacheNames.isEmpty());
}
}

/** Tests work of {@link SystemView} for cache groups. */
@Test
public void testCacheGroupsView() throws Exception {
try (IgniteEx g = startGrid()) {
Set<String> grpNames = new HashSet<>(Arrays.asList("grp-1", "grp-2"));

for (String grpName : grpNames)
g.createCache(new CacheConfiguration<>("cache-" + grpName).setGroupName(grpName));

SystemView<CacheGroupView> grps = g.context().systemView().view(CACHE_GRPS_VIEW);

assertEquals(g.context().cache().cacheGroupDescriptors().size(), F.size(grps.iterator()));

for (CacheGroupView row : grps)
grpNames.remove(row.cacheGroupName());

assertTrue(grpNames.toString(), grpNames.isEmpty());
}
}

/** Tests work of {@link SystemView} for cache expiry policy info with in-memory configuration. */
@Test
public void testCacheViewExpiryPolicyWithInMemory() throws Exception {
testCacheViewExpiryPolicy(false);
}

/** Tests work of {@link SystemView} for cache expiry policy info with persist configuration. */
@Test
public void testCacheViewExpiryPolicyWithPersist() throws Exception {
testCacheViewExpiryPolicy(true);
}

/** Tests work of {@link SystemView} for cache groups expiry policy info. */
private void testCacheViewExpiryPolicy(boolean withPersistence) throws Exception {
try (IgniteEx g = !withPersistence ? startGrid() : startGrid(getConfiguration().setDataStorageConfiguration(
new DataStorageConfiguration().setDefaultDataRegionConfiguration(
new DataRegionConfiguration().setPersistenceEnabled(true)
)))) {

if (withPersistence)
g.cluster().state(ClusterState.ACTIVE);

String eternalCacheName = "eternalCache";
String createdCacheName = "createdCache";
String eagerTtlCacheName = "eagerTtlCache";
String withoutGrpCacheName = "withoutGrpCache";
String dfltCacheName = "defaultCache";

CacheConfiguration<Long, Long> eternalCache = new CacheConfiguration<Long, Long>(eternalCacheName)
.setGroupName("group1")
.setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf());

CacheConfiguration<Long, Long> createdCache = new CacheConfiguration<Long, Long>(createdCacheName)
.setGroupName("group2")
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));

CacheConfiguration<Long, Long> eagerTtlCache = new CacheConfiguration<Long, Long>(eagerTtlCacheName)
.setGroupName("group2")
.setEagerTtl(false)
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));

CacheConfiguration<Long, Long> withoutGrpCache = new CacheConfiguration<Long, Long>(withoutGrpCacheName)
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));

CacheConfiguration<Long, Long> dfltCache = new CacheConfiguration<Long, Long>(dfltCacheName)
.setGroupName("group3");

g.createCache(eternalCache);
g.createCache(createdCache);
g.createCache(eagerTtlCache);
g.createCache(withoutGrpCache);
g.createCache(dfltCache);

SystemView<CacheView> caches = g.context().systemView().view(CACHES_VIEW);

for (CacheView row : caches) {
switch (row.cacheName()) {
case "defaultCache":
case "eternalCache":
assertEquals("No", row.hasExpiringEntries());

g.cache(row.cacheName()).put(0, 0);

assertEquals("No", row.hasExpiringEntries());

g.cache(row.cacheName())
.withExpiryPolicy(new CreatedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, 200L)))
.put(1, 1);

assertEquals("Yes", row.hasExpiringEntries());
assertTrue(waitForCondition(() -> "No".equals(row.hasExpiringEntries()), getTestTimeout()));

break;

case "withoutGrpCache":
case "createdCache":
assertEquals("No", row.hasExpiringEntries());

g.cache(row.cacheName()).put(0, 0);

assertEquals("Yes", row.hasExpiringEntries());
assertTrue(waitForCondition(() -> "No".equals(row.hasExpiringEntries()), getTestTimeout()));

g.cache(row.cacheName())
.withExpiryPolicy(new ModifiedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, 200L)))
.put(1, 1);

assertEquals("Yes", row.hasExpiringEntries());
assertTrue(waitForCondition(() -> "No".equals(row.hasExpiringEntries()), getTestTimeout()));

if (row.cacheName().equals(createdCacheName)) {
g.cache(eagerTtlCacheName).put(2, 2);
assertEquals("No", row.hasExpiringEntries());
}

break;

case "eagerTtlCache":
assertEquals("Unknown", row.hasExpiringEntries());

break;
}
}
}
}

/** Tests work of {@link SystemView} for cache group I/O operations. */
@Test
public void testCacheGroupIo() throws Exception {
cleanPersistenceDir();

try (IgniteEx ignite = startGrid(getConfiguration().setDataStorageConfiguration(
new DataStorageConfiguration().setDefaultDataRegionConfiguration(
new DataRegionConfiguration().setPersistenceEnabled(true))))
) {
ignite.cluster().state(ClusterState.ACTIVE);

IgniteCache<Object, Object> cache = ignite.createCache("cache");

cache.put(0, 0);
cache.get(0);

SystemView<CacheGroupIoView> view = ignite.context().systemView().view(CACHE_GRP_IO_VIEW);

CacheGroupIoView row = F.find(view, null,
(IgnitePredicate<CacheGroupIoView>)r -> "cache".equals(r.cacheGroupName()));

assertNotNull(row);
assertTrue(row.logicalReads() > 0);
assertTrue(row.insertedBytes() > 0);
}
}
}
Loading
Loading