use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.
the class ClientCommandsDUnitTest method testDescribeClient.
@Ignore("disabled for unknown reason")
@Test
public void testDescribeClient() throws Exception {
setupSystem();
getLogWriter().info("testDescribeClient clientId=" + clientId);
assertNotNull(clientId);
String commandString = CliStrings.DESCRIBE_CLIENT + " --" + CliStrings.DESCRIBE_CLIENT__ID + "=\"" + clientId + "\"";
getLogWriter().info("testDescribeClient commandStr=" + commandString);
final VM server1 = Host.getHost(0).getVM(1);
String serverName = (String) server1.invoke("get distributed member Id", () -> getDistributedMemberId());
CommandResult commandResult = executeCommand(commandString);
getLogWriter().info("testDescribeClient commandResult=" + commandResult);
String resultAsString = commandResultToString(commandResult);
getLogWriter().info("testDescribeClient resultAsString=" + resultAsString);
assertTrue(Status.OK.equals(commandResult.getStatus()));
CompositeResultData resultData = (CompositeResultData) commandResult.getResultData();
SectionResultData section = resultData.retrieveSection("InfoSection");
assertNotNull(section);
TabularResultData tableRsultData = section.retrieveTable("Pool Stats For Pool Name = DEFAULT");
assertNotNull(tableRsultData);
List<String> minConn = tableRsultData.retrieveAllValues(CliStrings.DESCRIBE_CLIENT_MIN_CONN);
List<String> maxConn = tableRsultData.retrieveAllValues(CliStrings.DESCRIBE_CLIENT_MAX_CONN);
List<String> redudancy = tableRsultData.retrieveAllValues(CliStrings.DESCRIBE_CLIENT_REDUDANCY);
List<String> numCqs = tableRsultData.retrieveAllValues(CliStrings.DESCRIBE_CLIENT_CQs);
assertTrue(minConn.contains("1"));
assertTrue(maxConn.contains("-1"));
assertTrue(redudancy.contains("1"));
assertTrue(numCqs.contains("3"));
String puts = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_PUTS);
assertTrue(puts.equals("2"));
String queue = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_QUEUE_SIZE);
assertTrue(queue.equals("1"));
String calls = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_LISTNER_CALLS);
assertTrue(calls.equals("1"));
String primServer = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_PRIMARY_SERVERS);
assertTrue(primServer.equals(serverName));
String durable = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_DURABLE);
assertTrue(durable.equals("No"));
String threads = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_THREADS);
assertTrue(Integer.parseInt(threads) > 0);
String cpu = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_CPU);
assertTrue(Integer.parseInt(cpu) > 0);
String upTime = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_UP_TIME);
assertTrue(Integer.parseInt(upTime) >= 0);
String prcTime = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_PROCESS_CPU_TIME);
assertTrue(Long.parseLong(prcTime) > 0);
closeNonDurableClient(Host.getHost(0).getVM(2));
closeCacheServer(Host.getHost(0).getVM(1));
closeCacheServer(Host.getHost(0).getVM(3));
}
use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.
the class ClientCommandsDUnitTest method testListClientForServers.
@Test
public void testListClientForServers() throws Exception {
setupSystem3();
final VM manager = Host.getHost(0).getVM(0);
String commandString = CliStrings.LIST_CLIENTS;
System.out.println("testListClientForServers commandStr=" + commandString);
final VM server1 = Host.getHost(0).getVM(1);
final VM server2 = Host.getHost(0).getVM(3);
final DistributedMember serverMember = getMember(server1);
String[] clientIds = (String[]) manager.invoke("get client Ids", () -> {
final SystemManagementService service = (SystemManagementService) ManagementService.getManagementService(getCache());
final ObjectName cacheServerMBeanName = service.getCacheServerMBeanName(port0, serverMember);
CacheServerMXBean bean = service.getMBeanProxy(cacheServerMBeanName, CacheServerMXBean.class);
return bean.getClientIds();
});
String serverName1 = (String) server1.invoke("get distributed member Id", () -> getDistributedMemberId());
String serverName2 = (String) server2.invoke("get distributed member Id", () -> getDistributedMemberId());
CommandResult commandResult = executeCommand(commandString);
System.out.println("testListClientForServers commandResult=" + commandResult);
String resultAsString = commandResultToString(commandResult);
System.out.println("testListClientForServers resultAsString=" + resultAsString);
assertTrue(Status.OK.equals(commandResult.getStatus()));
CompositeResultData resultData = (CompositeResultData) commandResult.getResultData();
SectionResultData section = resultData.retrieveSection("section1");
assertNotNull(section);
TabularResultData tableRsultData = section.retrieveTable("TableForClientList");
assertNotNull(tableRsultData);
List<String> serverNames = tableRsultData.retrieveAllValues(CliStrings.LIST_CLIENT_COLUMN_SERVERS);
List<String> clientNames = tableRsultData.retrieveAllValues(CliStrings.LIST_CLIENT_COLUMN_Clients);
serverName1 = serverName1.replace(":", "-");
serverName2 = serverName2.replace(":", "-");
System.out.println("testListClientForServers serverNames : " + serverNames);
System.out.println("testListClientForServers serverName1 : " + serverName1);
System.out.println("testListClientForServers serverName2 : " + serverName2);
System.out.println("testListClientForServers clientNames : " + clientNames);
for (String client : clientIds) {
assertTrue(clientNames.contains(client));
}
for (String server : serverNames) {
assertTrue(server.contains(serverName1) || server.contains(serverName2));
}
closeNonDurableClient(Host.getHost(0).getVM(2));
closeCacheServer(Host.getHost(0).getVM(1));
closeCacheServer(Host.getHost(0).getVM(3));
}
use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.
the class LuceneIndexCommands method getResults.
private Result getResults(int fromIndex, int toIndex, boolean keysonly) throws Exception {
final TabularResultData data = ResultBuilder.createTabularResultData();
for (int i = fromIndex; i < toIndex; i++) {
if (!searchResults.get(i).getExeptionFlag()) {
data.accumulate("key", searchResults.get(i).getKey());
if (!keysonly) {
data.accumulate("value", searchResults.get(i).getValue());
data.accumulate("score", searchResults.get(i).getScore());
}
} else {
throw new Exception(searchResults.get(i).getExceptionMessage());
}
}
return ResultBuilder.buildResult(data);
}
use of org.apache.geode.management.internal.cli.result.TabularResultData 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"));
}
use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.
the class LuceneIndexCommandsJUnitTest method getPage.
private String getPage(final LuceneSearchResults[] expectedResults, int[] indexList) {
final TabularResultData data = ResultBuilder.createTabularResultData();
for (int i : indexList) {
data.accumulate("key", expectedResults[i].getKey());
data.accumulate("value", expectedResults[i].getValue());
data.accumulate("score", expectedResults[i].getScore());
}
CommandResult commandResult = (CommandResult) ResultBuilder.buildResult(data);
StringBuilder buffer = new StringBuilder();
while (commandResult.hasNextLine()) {
buffer.append(commandResult.nextLine());
}
return buffer.toString();
}
Aggregations