}
Cache cache = cacheManager.getCache(CACHE_NAME);
// check that our settings are not ignored
SearchManager searchManager = Search.getSearchManager(cache);
assertTrue(searchManager.getSearchFactory().getStatistics().isStatisticsEnabled());
// add some test data
for(int i = 0; i < numberOfEntries; i++) {
Person person = new Person();
person.setName("key" + i);
person.setAge(i);
person.setBlurb("value " + i);
person.setNonSearchableField("i: " + i);
cache.put("key" + i, person);
}
// after adding more classes and reconfiguring the SearchFactory it might happen isStatisticsEnabled is reset, so we check again
assertTrue(searchManager.getSearchFactory().getStatistics().isStatisticsEnabled());
assertEquals(0L, server.getAttribute(name, "SearchQueryExecutionCount"));
QueryParser queryParser = createQueryParser("blurb");
Query luceneQuery = queryParser.parse("value");
CacheQuery cacheQuery = searchManager.getQuery(luceneQuery);
List<Object> found = cacheQuery.list();
assertEquals(1L, server.getAttribute(name, "SearchQueryExecutionCount"));
assertEquals(numberOfEntries, found.size());
assertEquals(numberOfEntries, server.invoke(name, "getNumberOfIndexedEntities",
new Object[]{Person.class.getCanonicalName()},
new String[]{String.class.getCanonicalName()}));
assertEquals(1, searchManager.getSearchFactory().getStatistics().indexedEntitiesCount().size());
// add more test data
AnotherGrassEater anotherGrassEater = new AnotherGrassEater("Another grass-eater", "Eats grass");
cache.put("key101", anotherGrassEater);
cacheQuery = searchManager.getQuery(luceneQuery);
found = cacheQuery.list();
assertEquals(numberOfEntries, found.size());
assertEquals(1, server.invoke(name, "getNumberOfIndexedEntities",
new Object[]{AnotherGrassEater.class.getCanonicalName()},
new String[]{String.class.getCanonicalName()}));
Set<String> classNames = (Set<String>) server.getAttribute(name, "IndexedClassNames");
assertEquals(2, classNames.size());
assertTrue("The set should contain the Person class name.", classNames.contains(Person.class.getCanonicalName()));
assertTrue("The set should contain the AnotherGrassEater class name.", classNames.contains(AnotherGrassEater.class.getCanonicalName()));
assertEquals(2, searchManager.getSearchFactory().getStatistics().indexedEntitiesCount().size());
// check the statistics and see they have reasonable values
assertTrue("The query execution total time should be > 0.", (Long) server.getAttribute(name, "SearchQueryTotalTime") > 0);
assertEquals(2L, server.getAttribute(name, "SearchQueryExecutionCount"));
assertEquals("blurb:value", server.getAttribute(name, "SearchQueryExecutionMaxTimeQueryString"));