Skip to content

Commit

Permalink
ISPN-12976 Use statistics to calculate how many entries are in the in…
Browse files Browse the repository at this point in the history
…dex instead of getResultSize/hitCount
  • Loading branch information
Gustavo committed May 11, 2021
1 parent 1765fb5 commit 484ee2b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected void verifyFindsCar(Cache cache, int expectedCount, String carMake) {
String q = String.format("FROM %s WHERE make:'%s'", Car.class.getName(), carMake);
Query cacheQuery = Search.getQueryFactory(cache).create(q);

assertEquals(expectedCount, cacheQuery.execute().hitCount().orElse(-1));
assertEquals(expectedCount, cacheQuery.execute().list().size());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected void verifyFindsCar(Cache cache, int count, String carMake) {
String q = String.format("FROM %s where make:'%s'", Car.class.getName(), carMake);
Query cacheQuery = Search.getQueryFactory(cache).create(q);

assertEquals(count, cacheQuery.execute().hitCount().orElse(-1));
assertEquals(count, cacheQuery.execute().list().size());

StaticTestingErrorHandler.assertAllGood(cache);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package org.infinispan.query.distributed;

import static org.testng.AssertJUnit.assertEquals;
import static org.infinispan.functional.FunctionalTestUtils.await;
import static org.testng.Assert.assertEquals;

import org.infinispan.Cache;
import org.infinispan.configuration.cache.ClusteringConfiguration;
import org.infinispan.context.Flag;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.query.Search;
import org.infinispan.query.core.stats.IndexInfo;
import org.infinispan.query.core.stats.IndexStatisticsSnapshot;
import org.infinispan.query.dsl.Query;
import org.infinispan.query.helper.StaticTestingErrorHandler;
import org.infinispan.query.queries.faceting.Car;
Expand Down Expand Up @@ -58,11 +62,12 @@ public void testReindexing() throws Exception {
//re-sync datacontainer with indexes:
rebuildIndexes();
verifyFindsCar(3, "megane");
//verify we cleanup old stale index values:
//verify we cleanup old stale index values by deleting an entry without deleting the corresponding index value
cache(2).getAdvancedCache().withFlags(Flag.SKIP_INDEXING).remove(key("F2NUM"));
verifyFindsCar(3, "megane");
assertIndexedEntities(3, Car.class, cache(2));
//re-sync
rebuildIndexes();
assertIndexedEntities(2, Car.class, cache(2));
verifyFindsCar(2, "megane");
}

Expand Down Expand Up @@ -93,8 +98,22 @@ protected void verifyFindsCar(int expectedCount, String carMake) {

protected void verifyFindsCar(Cache<?, Car> cache, int expectedCount, String carMake) {
String q = String.format("FROM %s where make:'%s'", Car.class.getName(), carMake);
Query cacheQuery = Search.getQueryFactory(cache).create(q);
assertEquals(expectedCount, cacheQuery.getResultSize());
assertEquals(expectedCount, cacheQuery.list().size());
Query<Car> cacheQuery = Search.getQueryFactory(cache).create(q);
assertEquals(cacheQuery.list().size(), expectedCount);
}

private void assertIndexedEntities(int expected, Class<?> entityClass, Cache<?, Car> cache) {
IndexStatisticsSnapshot indexStatistics = await(Search.getClusteredSearchStatistics(cache)).getIndexStatistics();
IndexInfo indexInfo = indexStatistics.indexInfos().get(entityClass.getName());
int count = (int) indexInfo.count();
// each entry is indexed in all owners for redundancy
final ClusteringConfiguration clusteringConfiguration = cache.getCacheConfiguration().clustering();
long indexedCount;
if (clusteringConfiguration.cacheMode().isReplicated()) {
indexedCount = count / caches().size();
} else {
indexedCount = count / clusteringConfiguration.hash().numOwners();
}
assertEquals(indexedCount, expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ protected void verifyFindsCar(Cache cache, int expectedCount, String carMake) {
QueryFactory queryFactory = Search.getQueryFactory(cache);
String q = String.format("FROM %s WHERE make:'%s'", Car.class.getName(), carMake);
Query cacheQuery = queryFactory.create(q);
assertEquals(expectedCount, cacheQuery.execute().hitCount().orElse(-1));
assertEquals(expectedCount, cacheQuery.execute().list().size());
}
}

0 comments on commit 484ee2b

Please sign in to comment.