Search in sources :

Example 1 with CACHE

use of org.apache.ignite.internal.commandline.CommandList.CACHE in project ignite by apache.

the class GridCommandHandlerIndexingCheckSizeTest method validateCheckSizes.

/**
 * Checking whether cache and index size check is correct.
 *
 * @param node Node.
 * @param cacheName Cache name.
 * @param rmvByTbl Number of deleted items per table.
 * @param cacheSizeExp Function for getting expected cache size.
 * @param idxSizeExp Function for getting expected index size.
 */
private void validateCheckSizes(IgniteEx node, String cacheName, Map<String, AtomicInteger> rmvByTbl, Function<AtomicInteger, Integer> cacheSizeExp, Function<AtomicInteger, Integer> idxSizeExp) {
    requireNonNull(node);
    requireNonNull(cacheName);
    requireNonNull(rmvByTbl);
    requireNonNull(cacheSizeExp);
    requireNonNull(idxSizeExp);
    injectTestSystemOut();
    assertEquals(EXIT_CODE_OK, execute(CACHE.text(), VALIDATE_INDEXES.text(), cacheName, CHECK_SIZES.argName()));
    String out = testOut.toString();
    assertContains(log, out, "issues found (listed above)");
    assertContains(log, out, "Size check");
    Map<String, ValidateIndexesCheckSizeResult> valIdxCheckSizeResults = ((VisorValidateIndexesTaskResult) lastOperationResult).results().get(node.localNode().id()).checkSizeResult();
    assertEquals(rmvByTbl.size(), valIdxCheckSizeResults.size());
    for (Map.Entry<String, AtomicInteger> rmvByTblEntry : rmvByTbl.entrySet()) {
        ValidateIndexesCheckSizeResult checkSizeRes = valIdxCheckSizeResults.entrySet().stream().filter(e -> e.getKey().contains(rmvByTblEntry.getKey())).map(Map.Entry::getValue).findAny().orElse(null);
        assertNotNull(checkSizeRes);
        assertEquals((int) cacheSizeExp.apply(rmvByTblEntry.getValue()), checkSizeRes.cacheSize());
        Collection<ValidateIndexesCheckSizeIssue> issues = checkSizeRes.issues();
        assertFalse(issues.isEmpty());
        issues.forEach(issue -> {
            assertEquals((int) idxSizeExp.apply(rmvByTblEntry.getValue()), issue.indexSize());
            Throwable err = issue.error();
            assertNotNull(err);
            assertEquals("Cache and index size not same.", err.getMessage());
        });
    }
}
Also used : Person(org.apache.ignite.util.GridCommandHandlerIndexingUtils.Person) CHECK_SIZES(org.apache.ignite.internal.commandline.cache.argument.ValidateIndexesCommandArg.CHECK_SIZES) GridCommandHandlerIndexingUtils.organizationEntity(org.apache.ignite.util.GridCommandHandlerIndexingUtils.organizationEntity) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) HashMap(java.util.HashMap) Random(java.util.Random) IgniteEx(org.apache.ignite.internal.IgniteEx) GridCommandHandlerIndexingUtils.createAndFillCache(org.apache.ignite.util.GridCommandHandlerIndexingUtils.createAndFillCache) Function(java.util.function.Function) EXIT_CODE_OK(org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK) ArrayList(java.util.ArrayList) CACHE_NAME(org.apache.ignite.util.GridCommandHandlerIndexingUtils.CACHE_NAME) GridCommandHandlerIndexingUtils.personEntity(org.apache.ignite.util.GridCommandHandlerIndexingUtils.personEntity) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Objects.requireNonNull(java.util.Objects.requireNonNull) Cache(javax.cache.Cache) GridCommandHandlerIndexingUtils.breakCacheDataTree(org.apache.ignite.util.GridCommandHandlerIndexingUtils.breakCacheDataTree) QueryEntity(org.apache.ignite.cache.QueryEntity) ValidateIndexesCommandArg(org.apache.ignite.internal.commandline.cache.argument.ValidateIndexesCommandArg) ValidateIndexesCheckSizeIssue(org.apache.ignite.internal.visor.verify.ValidateIndexesCheckSizeIssue) GridTestUtils.assertNotContains(org.apache.ignite.testframework.GridTestUtils.assertNotContains) VisorValidateIndexesTaskResult(org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskResult) Collections.emptyMap(java.util.Collections.emptyMap) VALIDATE_INDEXES(org.apache.ignite.internal.commandline.cache.CacheSubcommands.VALIDATE_INDEXES) GridCommandHandlerIndexingUtils.breakSqlIndex(org.apache.ignite.util.GridCommandHandlerIndexingUtils.breakSqlIndex) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Test(org.junit.Test) CacheSubcommands(org.apache.ignite.internal.commandline.cache.CacheSubcommands) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils.assertContains(org.apache.ignite.testframework.GridTestUtils.assertContains) CACHE(org.apache.ignite.internal.commandline.CommandList.CACHE) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) String.valueOf(java.lang.String.valueOf) Organization(org.apache.ignite.util.GridCommandHandlerIndexingUtils.Organization) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) GROUP_NAME(org.apache.ignite.util.GridCommandHandlerIndexingUtils.GROUP_NAME) ValidateIndexesCheckSizeResult(org.apache.ignite.internal.visor.verify.ValidateIndexesCheckSizeResult) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) ValidateIndexesCheckSizeIssue(org.apache.ignite.internal.visor.verify.ValidateIndexesCheckSizeIssue) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VisorValidateIndexesTaskResult(org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskResult) ValidateIndexesCheckSizeResult(org.apache.ignite.internal.visor.verify.ValidateIndexesCheckSizeResult) HashMap(java.util.HashMap) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap)

Aggregations

String.valueOf (java.lang.String.valueOf)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 Collections.emptyMap (java.util.Collections.emptyMap)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Random (java.util.Random)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Function (java.util.function.Function)1 Cache (javax.cache.Cache)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteDataStreamer (org.apache.ignite.IgniteDataStreamer)1 IgniteException (org.apache.ignite.IgniteException)1 QueryEntity (org.apache.ignite.cache.QueryEntity)1 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)1