Search in sources :

Example 71 with TabularResultData

use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.

the class LuceneIndexCommandsJUnitTest method verifyDestroyIndexCommandResult.

private void verifyDestroyIndexCommandResult(CommandResult result, List<CliFunctionResult> cliFunctionResults, String expectedStatus) {
    assertEquals(Status.OK, result.getStatus());
    TabularResultData data = (TabularResultData) result.getResultData();
    List<String> members = data.retrieveAllValues("Member");
    assertEquals(cliFunctionResults.size(), members.size());
    // Verify each member
    for (int i = 0; i < members.size(); i++) {
        assertEquals("member" + i, members.get(i));
    }
    // Verify each status
    List<String> status = data.retrieveAllValues("Status");
    for (String statu : status) {
        assertEquals(expectedStatus, statu);
    }
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) Mockito.anyString(org.mockito.Mockito.anyString)

Example 72 with TabularResultData

use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.

the class LuceneIndexCommandsDUnitTest method searchWithoutFieldNameShouldReturnCorrectResults.

@Test
public void searchWithoutFieldNameShouldReturnCorrectResults() throws Exception {
    final VM vm1 = Host.getHost(0).getVM(1);
    createIndex(vm1);
    Map<String, TestObject> entries = new HashMap<>();
    entries.put("A", new TestObject("value1 ", "value2", "value3"));
    entries.put("B", new TestObject("ABC", "EFG", "HIJ"));
    entries.put("C", new TestObject("value1", "QWE", "RTY"));
    entries.put("D", new TestObject("ABC", "EFG", "HIJ"));
    entries.put("E", new TestObject("value1", "ABC", "EFG"));
    entries.put("F", new TestObject("ABC", "EFG", "HIJ"));
    entries.put("G", new TestObject("value1", "JKR", "POW"));
    entries.put("H", new TestObject("ABC", "EFG", "H2J"));
    putEntries(vm1, entries, 8);
    CommandStringBuilder csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_SEARCH_INDEX);
    csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, INDEX_NAME);
    csb.addOption(LuceneCliStrings.LUCENE__REGION_PATH, REGION_NAME);
    csb.addOption(LuceneCliStrings.LUCENE_SEARCH_INDEX__QUERY_STRING, "QWE");
    csb.addOption(LuceneCliStrings.LUCENE_SEARCH_INDEX__DEFAULT_FIELD, "field2");
    executeCommandAndLogResult(csb);
    TabularResultData data = (TabularResultData) executeCommandAndGetResult(csb).getResultData();
    assertEquals(1, data.retrieveAllValues("key").size());
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) HashMap(java.util.HashMap) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) VM(org.apache.geode.test.dunit.VM) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 73 with TabularResultData

use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.

the class LuceneIndexCommandsDUnitTest method searchShouldReturnCorrectResults.

@Test
public void searchShouldReturnCorrectResults() throws Exception {
    final VM vm1 = Host.getHost(0).getVM(1);
    createIndex(vm1);
    Map<String, TestObject> entries = new HashMap<>();
    entries.put("A", new TestObject("value1 ", "value2", "value3"));
    entries.put("B", new TestObject("ABC", "EFG", "HIJ"));
    entries.put("C", new TestObject("value1", "QWE", "RTY"));
    entries.put("D", new TestObject("ABC", "EFG", "HIJ"));
    entries.put("E", new TestObject("value1", "ABC", "EFG"));
    entries.put("F", new TestObject("ABC", "EFG", "HIJ"));
    entries.put("G", new TestObject(" value1", "JKR", "POW"));
    entries.put("H", new TestObject("ABC", "EFG", "H2J"));
    putEntries(vm1, entries, 8);
    CommandStringBuilder csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_SEARCH_INDEX);
    csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, INDEX_NAME);
    csb.addOption(LuceneCliStrings.LUCENE__REGION_PATH, REGION_NAME);
    csb.addOption(LuceneCliStrings.LUCENE_SEARCH_INDEX__QUERY_STRING, "field1:value1");
    csb.addOption(LuceneCliStrings.LUCENE_SEARCH_INDEX__DEFAULT_FIELD, "field1");
    executeCommandAndLogResult(csb);
    TabularResultData data = (TabularResultData) executeCommandAndGetResult(csb).getResultData();
    assertEquals(4, data.retrieveAllValues("key").size());
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) HashMap(java.util.HashMap) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) VM(org.apache.geode.test.dunit.VM) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 74 with TabularResultData

use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.

the class LuceneIndexCommandsJUnitTest method testSearchIndexWhenSearchResultsHaveSameScore.

@Test
public void testSearchIndexWhenSearchResultsHaveSameScore() 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", 1));
    queryResults.add(createQueryResults("B", "Result1", 1));
    queryResults.add(createQueryResults("C", "Result1", 1));
    queryResults.add(createQueryResults("D", "Result1", 1));
    queryResults.add(createQueryResults("E", "Result1", 1));
    queryResults.add(createQueryResults("F", "Result1", 1));
    queryResults.add(createQueryResults("G", "Result1", 1));
    queryResults.add(createQueryResults("H", "Result1", 1));
    queryResults.add(createQueryResults("I", "Result1", 1));
    queryResults.add(createQueryResults("J", "Result1", 1));
    queryResults.add(createQueryResults("K", "Result1", 1));
    queryResults.add(createQueryResults("L", "Result1", 1));
    queryResults.add(createQueryResults("M", "Result1", 1));
    queryResults.add(createQueryResults("N", "Result1", 1));
    queryResults.add(createQueryResults("P", "Result1", 1));
    queryResults.add(createQueryResults("Q", "Result1", 1));
    queryResults.add(createQueryResults("R", "Result1", 1));
    queryResults.add(createQueryResults("S", "Result1", 1));
    queryResults.add(createQueryResults("T", "Result1", 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(queryResults.size(), data.retrieveAllValues("key").size());
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashSet(java.util.HashSet) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 75 with TabularResultData

use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.

the class LuceneClusterConfigurationDUnitTest method verifyMemberWithGroupStartsAfterAlterRegion.

@Test
public void verifyMemberWithGroupStartsAfterAlterRegion() throws Exception {
    // Start a member with no group
    startNodeUsingClusterConfiguration(1);
    // Start a member with group
    String group = "group1";
    Properties properties = new Properties();
    properties.setProperty(GROUPS, group);
    MemberVM vm2 = startNodeUsingClusterConfiguration(2, properties);
    // Connect Gfsh to locator
    gfshConnector.connectAndVerify(locator);
    // Create index and region in no group
    createLuceneIndexUsingGfsh();
    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
    // Alter region in group
    CommandResult alterRegionResult = alterRegionUsingGfsh(group);
    TabularResultData alterRegionResultData = (TabularResultData) alterRegionResult.getResultData();
    List<String> alterRegionResultDataStatus = alterRegionResultData.retrieveAllValues("Status");
    // Verify region is altered on only one server
    assertEquals(1, alterRegionResultDataStatus.size());
    assertEquals("Region \"/" + REGION_NAME + "\" altered on \"" + vm2.getName() + "\"", alterRegionResultDataStatus.get(0));
    // Start another member with group
    startNodeUsingClusterConfiguration(3, properties);
    // Verify all members have indexes
    CommandResult listIndexesResult = listIndexesUsingGfsh();
    TabularResultData listIndexesResultData = (TabularResultData) listIndexesResult.getResultData();
    List<String> listIndexesResultDataStatus = listIndexesResultData.retrieveAllValues("Status");
    assertEquals(3, listIndexesResultDataStatus.size());
    for (String status : listIndexesResultDataStatus) {
        assertEquals("Initialized", status);
    }
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) MemberVM(org.apache.geode.test.dunit.rules.MemberVM) Properties(java.util.Properties) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)140 Test (org.junit.Test)74 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)68 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)63 Properties (java.util.Properties)54 DistributedMember (org.apache.geode.distributed.DistributedMember)40 CliCommand (org.springframework.shell.core.annotation.CliCommand)35 Result (org.apache.geode.management.cli.Result)34 CliMetaData (org.apache.geode.management.cli.CliMetaData)33 InternalCache (org.apache.geode.internal.cache.InternalCache)32 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)31 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)30 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)29 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)29 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)28 VM (org.apache.geode.test.dunit.VM)27 ArrayList (java.util.ArrayList)26 SectionResultData (org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)23 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)18 List (java.util.List)16