use of org.apache.geode.cache.lucene.internal.LuceneIndexStats in project geode by apache.
the class LuceneIndexCommandsJUnitTest method testDescribeIndex.
@Test
public void testDescribeIndex() throws Exception {
final InternalCache mockCache = mock(InternalCache.class, "InternalCache");
final String serverName = "mockServer";
final ResultCollector mockResultCollector = mock(ResultCollector.class, "ResultCollector");
final LuceneIndexCommands commands = spy(createIndexCommands(mockCache, null));
String[] searchableFields = { "field1", "field2", "field3" };
Map<String, Analyzer> fieldAnalyzers = new HashMap<>();
fieldAnalyzers.put("field1", new StandardAnalyzer());
fieldAnalyzers.put("field2", new KeywordAnalyzer());
fieldAnalyzers.put("field3", null);
final LuceneIndexStats mockIndexStats = getMockIndexStats(1, 10, 5, 1);
final List<LuceneIndexDetails> indexDetails = new ArrayList<>();
indexDetails.add(createIndexDetails("memberFive", "/Employees", searchableFields, fieldAnalyzers, mockIndexStats, true, serverName));
doReturn(mockResultCollector).when(commands).executeFunctionOnRegion(isA(LuceneDescribeIndexFunction.class), any(LuceneIndexInfo.class), eq(true));
doReturn(indexDetails).when(mockResultCollector).getResult();
CommandResult result = (CommandResult) commands.describeIndex("memberFive", "/Employees");
TabularResultData data = (TabularResultData) result.getResultData();
assertEquals(Collections.singletonList("memberFive"), data.retrieveAllValues("Index Name"));
assertEquals(Collections.singletonList("/Employees"), data.retrieveAllValues("Region Path"));
assertEquals(Collections.singletonList("[field1, field2, field3]"), data.retrieveAllValues("Indexed Fields"));
assertEquals(Collections.singletonList("{field1=StandardAnalyzer, field2=KeywordAnalyzer}"), data.retrieveAllValues("Field Analyzer"));
assertEquals(Collections.singletonList("Initialized"), data.retrieveAllValues("Status"));
assertEquals(Collections.singletonList("1"), data.retrieveAllValues("Query Executions"));
assertEquals(Collections.singletonList("10"), data.retrieveAllValues("Commits"));
assertEquals(Collections.singletonList("5"), data.retrieveAllValues("Updates"));
assertEquals(Collections.singletonList("1"), data.retrieveAllValues("Documents"));
}
use of org.apache.geode.cache.lucene.internal.LuceneIndexStats in project geode by apache.
the class LuceneIndexCommandsJUnitTest method getMockIndexStats.
private LuceneIndexStats getMockIndexStats(int queries, int commits, int updates, int docs) {
LuceneIndexStats mockIndexStats = mock(LuceneIndexStats.class);
when(mockIndexStats.getQueryExecutions()).thenReturn(queries);
when(mockIndexStats.getCommits()).thenReturn(commits);
when(mockIndexStats.getUpdates()).thenReturn(updates);
when(mockIndexStats.getDocuments()).thenReturn(docs);
return mockIndexStats;
}
use of org.apache.geode.cache.lucene.internal.LuceneIndexStats in project geode by apache.
the class LuceneIndexMaintenanceIntegrationTest method statsAreUpdatedAfterACommit.
@Test
public void statsAreUpdatedAfterACommit() throws Exception {
luceneService.createIndexFactory().setFields("title", "description").create(INDEX_NAME, REGION_NAME);
Region region = createRegion(REGION_NAME, RegionShortcut.PARTITION);
region.put("object-1", new TestObject("title 1", "hello world"));
region.put("object-2", new TestObject("title 2", "this will not match"));
region.put("object-3", new TestObject("title 3", "hello world"));
region.put("object-4", new TestObject("hello world", "hello world"));
LuceneIndexForPartitionedRegion index = (LuceneIndexForPartitionedRegion) luceneService.getIndex(INDEX_NAME, REGION_NAME);
luceneService.waitUntilFlushed(INDEX_NAME, REGION_NAME, WAIT_FOR_FLUSH_TIME, TimeUnit.MILLISECONDS);
FileSystemStats fileSystemStats = index.getFileSystemStats();
LuceneIndexStats indexStats = index.getIndexStats();
await(() -> assertEquals(4, indexStats.getDocuments()));
await(() -> assertTrue(fileSystemStats.getBytes() > 0));
}
use of org.apache.geode.cache.lucene.internal.LuceneIndexStats in project geode by apache.
the class LuceneQueryFunction method execute.
@Override
public void execute(FunctionContext context) {
RegionFunctionContext ctx = (RegionFunctionContext) context;
ResultSender<TopEntriesCollector> resultSender = ctx.getResultSender();
Region region = ctx.getDataSet();
LuceneFunctionContext<IndexResultCollector> searchContext = (LuceneFunctionContext) ctx.getArguments();
if (searchContext == null) {
throw new IllegalArgumentException("Missing search context");
}
LuceneQueryProvider queryProvider = searchContext.getQueryProvider();
if (queryProvider == null) {
throw new IllegalArgumentException("Missing query provider");
}
LuceneIndexImpl index = getLuceneIndex(region, searchContext);
if (index == null) {
throw new LuceneIndexNotFoundException(searchContext.getIndexName(), region.getFullPath());
}
RepositoryManager repoManager = index.getRepositoryManager();
LuceneIndexStats stats = index.getIndexStats();
Query query = getQuery(queryProvider, index);
if (logger.isDebugEnabled()) {
logger.debug("Executing lucene query: {}, on region {}", query, region.getFullPath());
}
int resultLimit = searchContext.getLimit();
CollectorManager manager = (searchContext == null) ? null : searchContext.getCollectorManager();
if (manager == null) {
manager = new TopEntriesCollectorManager(null, resultLimit);
}
Collection<IndexResultCollector> results = new ArrayList<>();
TopEntriesCollector mergedResult = null;
try {
long start = stats.startQuery();
Collection<IndexRepository> repositories = null;
try {
repositories = repoManager.getRepositories(ctx);
for (IndexRepository repo : repositories) {
IndexResultCollector collector = manager.newCollector(repo.toString());
if (logger.isDebugEnabled()) {
logger.debug("Executing search on repo: " + repo.toString());
}
repo.query(query, resultLimit, collector);
results.add(collector);
}
mergedResult = (TopEntriesCollector) manager.reduce(results);
} finally {
stats.endQuery(start, mergedResult == null ? 0 : mergedResult.size());
}
stats.incNumberOfQueryExecuted();
resultSender.lastResult(mergedResult);
} catch (IOException | BucketNotFoundException | CacheClosedException | PrimaryBucketException e) {
logger.debug("Exception during lucene query function", e);
throw new InternalFunctionInvocationTargetException(e);
}
}
use of org.apache.geode.cache.lucene.internal.LuceneIndexStats in project geode by apache.
the class LuceneIndexCommandsJUnitTest method testListIndexWithStats.
@Test
public void testListIndexWithStats() {
final InternalCache mockCache = mock(InternalCache.class, "InternalCache");
final String serverName = "mockServer";
final AbstractExecution mockFunctionExecutor = mock(AbstractExecution.class, "Function Executor");
final ResultCollector mockResultCollector = mock(ResultCollector.class, "ResultCollector");
final LuceneIndexStats mockIndexStats1 = getMockIndexStats(1, 10, 5, 1);
final LuceneIndexStats mockIndexStats2 = getMockIndexStats(2, 20, 10, 2);
final LuceneIndexStats mockIndexStats3 = getMockIndexStats(3, 30, 15, 3);
String[] searchableFields = { "field1", "field2", "field3" };
Map<String, Analyzer> fieldAnalyzers = new HashMap<>();
fieldAnalyzers.put("field1", new StandardAnalyzer());
fieldAnalyzers.put("field2", new KeywordAnalyzer());
fieldAnalyzers.put("field3", null);
final LuceneIndexDetails indexDetails1 = createIndexDetails("memberFive", "/Employees", searchableFields, fieldAnalyzers, mockIndexStats1, true, serverName);
final LuceneIndexDetails indexDetails2 = createIndexDetails("memberSix", "/Employees", searchableFields, fieldAnalyzers, mockIndexStats2, true, serverName);
final LuceneIndexDetails indexDetails3 = createIndexDetails("memberTen", "/Employees", searchableFields, fieldAnalyzers, mockIndexStats3, true, serverName);
final List<Set<LuceneIndexDetails>> results = new ArrayList<>();
results.add(CollectionUtils.asSet(indexDetails2, indexDetails1, indexDetails3));
when(mockFunctionExecutor.execute(isA(LuceneListIndexFunction.class))).thenReturn(mockResultCollector);
when(mockResultCollector.getResult()).thenReturn(results);
final LuceneIndexCommands commands = createIndexCommands(mockCache, mockFunctionExecutor);
CommandResult result = (CommandResult) commands.listIndex(true);
TabularResultData data = (TabularResultData) result.getResultData();
assertEquals(Arrays.asList("memberFive", "memberSix", "memberTen"), data.retrieveAllValues("Index Name"));
assertEquals(Arrays.asList("/Employees", "/Employees", "/Employees"), data.retrieveAllValues("Region Path"));
assertEquals(Arrays.asList("[field1, field2, field3]", "[field1, field2, field3]", "[field1, field2, field3]"), data.retrieveAllValues("Indexed Fields"));
assertEquals(Arrays.asList("{field1=StandardAnalyzer, field2=KeywordAnalyzer}", "{field1=StandardAnalyzer, field2=KeywordAnalyzer}", "{field1=StandardAnalyzer, field2=KeywordAnalyzer}"), data.retrieveAllValues("Field Analyzer"));
assertEquals(Arrays.asList("1", "2", "3"), data.retrieveAllValues("Query Executions"));
assertEquals(Arrays.asList("10", "20", "30"), data.retrieveAllValues("Commits"));
assertEquals(Arrays.asList("5", "10", "15"), data.retrieveAllValues("Updates"));
assertEquals(Arrays.asList("1", "2", "3"), data.retrieveAllValues("Documents"));
}
Aggregations