use of org.apache.ignite.internal.processors.cache.index.AbstractSchemaSelfTest.ValueClass in project ignite by apache.
the class IndexMetricsTest method testIndexRebuildingMetric.
/**
* @throws Exception If failed.
*/
@Test
public void testIndexRebuildingMetric() throws Exception {
IgniteEx n = startGrid(0);
n.cluster().active(true);
String cacheName1 = "cache1";
String cacheName2 = "cache2";
IgniteCache<KeyClass, ValueClass> cache1 = n.getOrCreateCache(cacheConfiguration(cacheName1));
IgniteCache<KeyClass, ValueClass> cache2 = n.getOrCreateCache(cacheConfiguration(cacheName2));
int entryCnt1 = 100;
int entryCnt2 = 200;
for (int i = 0; i < entryCnt1; i++) cache1.put(new KeyClass(i), new ValueClass((long) i));
for (int i = 0; i < entryCnt2; i++) cache2.put(new KeyClass(i), new ValueClass((long) i));
List<Path> idxPaths = getIndexBinPaths(cacheName1);
idxPaths.addAll(getIndexBinPaths(cacheName2));
stopAllGrids();
idxPaths.forEach(idxPath -> assertTrue(U.delete(idxPath)));
IndexProcessor.idxRebuildCls = BlockingIndexesRebuildTask.class;
n = startGrid(0);
BooleanMetric idxRebuildInProgress1 = indexRebuildMetric(n, cacheName1, "IsIndexRebuildInProgress");
BooleanMetric idxRebuildInProgress2 = indexRebuildMetric(n, cacheName2, "IsIndexRebuildInProgress");
LongAdderMetric idxRebuildKeyProcessed1 = indexRebuildMetric(n, cacheName1, "IndexRebuildKeyProcessed");
LongAdderMetric idxRebuildKeyProcessed2 = indexRebuildMetric(n, cacheName2, "IndexRebuildKeyProcessed");
CacheMetrics cacheMetrics1 = cacheMetrics(n, cacheName1);
CacheMetrics cacheMetrics2 = cacheMetrics(n, cacheName2);
CacheMetricsMXBean cacheMetricsMXBean1 = cacheMetricsMXBean(n, cacheName1, CacheLocalMetricsMXBeanImpl.class);
CacheMetricsMXBean cacheMetricsMXBean2 = cacheMetricsMXBean(n, cacheName2, CacheLocalMetricsMXBeanImpl.class);
CacheMetricsMXBean cacheClusterMetricsMXBean1 = cacheMetricsMXBean(n, cacheName1, CacheClusterMetricsMXBeanImpl.class);
CacheMetricsMXBean cacheClusterMetricsMXBean2 = cacheMetricsMXBean(n, cacheName2, CacheClusterMetricsMXBeanImpl.class);
n.cluster().active(true);
BooleanSupplier[] idxRebuildProgressCache1 = { idxRebuildInProgress1::value, cacheMetrics1::isIndexRebuildInProgress, cacheMetricsMXBean1::isIndexRebuildInProgress };
BooleanSupplier[] idxRebuildProgressCache2 = { idxRebuildInProgress2::value, cacheMetrics2::isIndexRebuildInProgress, cacheMetricsMXBean2::isIndexRebuildInProgress };
// It must always be false, because metric is only per node.
BooleanSupplier[] idxRebuildProgressCluster = { cacheClusterMetricsMXBean1::isIndexRebuildInProgress, cacheClusterMetricsMXBean2::isIndexRebuildInProgress };
LongSupplier[] idxRebuildKeyProcessedCache1 = { idxRebuildKeyProcessed1::value, cacheMetrics1::getIndexRebuildKeysProcessed, cacheMetricsMXBean1::getIndexRebuildKeysProcessed };
LongSupplier[] idxRebuildKeyProcessedCache2 = { idxRebuildKeyProcessed2::value, cacheMetrics2::getIndexRebuildKeysProcessed, cacheMetricsMXBean2::getIndexRebuildKeysProcessed };
// It must always be 0, because metric is only per node.
LongSupplier[] idxRebuildKeyProcessedCluster = { cacheClusterMetricsMXBean1::getIndexRebuildKeysProcessed, cacheClusterMetricsMXBean2::getIndexRebuildKeysProcessed };
assertEquals(true, idxRebuildProgressCache1);
assertEquals(true, idxRebuildProgressCache2);
assertEquals(false, idxRebuildProgressCluster);
assertEquals(0, idxRebuildKeyProcessedCache1);
assertEquals(0, idxRebuildKeyProcessedCache2);
assertEquals(0, idxRebuildKeyProcessedCluster);
((BlockingIndexesRebuildTask) n.context().indexProcessor().idxRebuild()).stopBlock(cacheName1);
n.cache(cacheName1).indexReadyFuture().get(30_000);
assertEquals(false, idxRebuildProgressCache1);
assertEquals(true, idxRebuildProgressCache2);
assertEquals(false, idxRebuildProgressCluster);
assertEquals(entryCnt1, idxRebuildKeyProcessedCache1);
assertEquals(0, idxRebuildKeyProcessedCache2);
assertEquals(0, idxRebuildKeyProcessedCluster);
((BlockingIndexesRebuildTask) n.context().indexProcessor().idxRebuild()).stopBlock(cacheName2);
n.cache(cacheName2).indexReadyFuture().get(30_000);
assertEquals(false, idxRebuildProgressCache1);
assertEquals(false, idxRebuildProgressCache2);
assertEquals(false, idxRebuildProgressCluster);
assertEquals(entryCnt1, idxRebuildKeyProcessedCache1);
assertEquals(entryCnt2, idxRebuildKeyProcessedCache2);
assertEquals(0, idxRebuildKeyProcessedCluster);
}
use of org.apache.ignite.internal.processors.cache.index.AbstractSchemaSelfTest.ValueClass in project ignite by apache.
the class IndexMetricsTest method cacheConfiguration.
/**
* @return Default cache configuration.
*/
private CacheConfiguration<KeyClass, ValueClass> cacheConfiguration(String cacheName) {
CacheConfiguration<KeyClass, ValueClass> ccfg = new CacheConfiguration<>(cacheName);
QueryEntity entity = new QueryEntity();
entity.setKeyType(KeyClass.class.getName());
entity.setValueType(ValueClass.class.getName());
entity.setKeyFieldName("key");
entity.addQueryField("key", entity.getKeyType(), null);
entity.setIndexes(Collections.singletonList(new QueryIndex("key", true, cacheName + "_index")));
ccfg.setQueryEntities(Collections.singletonList(entity));
return ccfg;
}
Aggregations