use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.
the class LuceneIndexCommandsJUnitTest method testListIndexWithoutStats.
@Test
public void testListIndexWithoutStats() {
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");
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, true, serverName);
final LuceneIndexDetails indexDetails2 = createIndexDetails("memberSix", "/Employees", searchableFields, fieldAnalyzers, false, serverName);
final LuceneIndexDetails indexDetails3 = createIndexDetails("memberTen", "/Employees", searchableFields, fieldAnalyzers, 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(false);
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("Initialized", "Defined", "Initialized"), data.retrieveAllValues("Status"));
}
use of org.apache.geode.management.internal.cli.result.TabularResultData 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.management.internal.cli.result.TabularResultData in project geode by apache.
the class LuceneIndexCommandsDUnitTest method listIndexShouldReturnCorrectStatus.
@Test
public void listIndexShouldReturnCorrectStatus() throws Exception {
final VM vm1 = Host.getHost(0).getVM(1);
createIndexWithoutRegion(vm1);
CommandStringBuilder csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_LIST_INDEX);
csb.addOption(LuceneCliStrings.LUCENE_LIST_INDEX__STATS, "true");
TabularResultData data = (TabularResultData) executeCommandAndGetResult(csb).getResultData();
assertEquals(Collections.singletonList(INDEX_NAME), data.retrieveAllValues("Index Name"));
assertEquals(Collections.singletonList("Defined"), data.retrieveAllValues("Status"));
}
use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.
the class LuceneIndexCommandsJUnitTest method testSearchIndexWithKeysOnly.
@Test
public void testSearchIndexWithKeysOnly() throws Exception {
final InternalCache mockCache = mock(InternalCache.class, "InternalCache");
final ResultCollector mockResultCollector = mock(ResultCollector.class, "ResultCollector");
final LuceneIndexCommands commands = spy(createIndexCommands(mockCache, null));
final List<Set<LuceneSearchResults>> queryResultsList = new ArrayList<>();
HashSet<LuceneSearchResults> queryResults = new HashSet<>();
queryResults.add(createQueryResults("A", "Result1", Float.valueOf("1.3")));
queryResults.add(createQueryResults("B", "Result1", Float.valueOf("1.2")));
queryResults.add(createQueryResults("C", "Result1", Float.valueOf("1.1")));
queryResultsList.add(queryResults);
doReturn(mockResultCollector).when(commands).executeSearch(isA(LuceneQueryInfo.class));
doReturn(queryResultsList).when(mockResultCollector).getResult();
CommandResult result = (CommandResult) commands.searchIndex("index", "region", "Result1", "field1", -1, true);
TabularResultData data = (TabularResultData) result.getResultData();
assertEquals(Arrays.asList("C", "B", "A"), data.retrieveAllValues("key"));
}
use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.
the class LuceneIndexCommandsJUnitTest method testCreateIndex.
@Test
public void testCreateIndex() throws Exception {
final InternalCache mockCache = mock(InternalCache.class);
final ResultCollector mockResultCollector = mock(ResultCollector.class);
final LuceneIndexCommands commands = spy(createIndexCommands(mockCache, null));
final List<CliFunctionResult> cliFunctionResults = new ArrayList<>();
cliFunctionResults.add(new CliFunctionResult("member1", true, "Index Created"));
cliFunctionResults.add(new CliFunctionResult("member2", false, "Index creation failed"));
cliFunctionResults.add(new CliFunctionResult("member3", true, "Index Created"));
doReturn(mockResultCollector).when(commands).executeFunctionOnAllMembers(isA(LuceneCreateIndexFunction.class), any(LuceneIndexInfo.class));
doReturn(cliFunctionResults).when(mockResultCollector).getResult();
String indexName = "index";
String regionPath = "regionPath";
String[] searchableFields = { "field1", "field2", "field3" };
String[] fieldAnalyzers = { StandardAnalyzer.class.getCanonicalName(), KeywordAnalyzer.class.getCanonicalName(), StandardAnalyzer.class.getCanonicalName() };
CommandResult result = (CommandResult) commands.createIndex(indexName, regionPath, searchableFields, fieldAnalyzers);
assertEquals(Status.OK, result.getStatus());
TabularResultData data = (TabularResultData) result.getResultData();
assertEquals(Arrays.asList("member1", "member2", "member3"), data.retrieveAllValues("Member"));
assertEquals(Arrays.asList("Successfully created lucene index", "Failed: Index creation failed", "Successfully created lucene index"), data.retrieveAllValues("Status"));
}
Aggregations