Search in sources :

Example 26 with TabularResultData

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

the class DataCommandFunctionWithPDXJUnitTest method testFilteredQueryWithPhone.

@Test
public void testFilteredQueryWithPhone() throws Exception {
    TabularResultData rawTable = getTableFromQuery("select * from /" + PARTITIONED_REGION + " c where IS_DEFINED ( c.phone ) order by id");
    assertThat(rawTable.getGfJsonObject()).isNotNull();
    assertThat(rawTable.getGfJsonObject().getJSONObject("content")).isNotNull();
    GfJsonObject tableJson = rawTable.getGfJsonObject().getJSONObject("content");
    for (String k : new String[] { "id", "phone", "firstName", "lastName" }) {
        assertThat(tableJson.getJSONArray(k).size()).isEqualTo(2);
    }
    assertThatRowIsBuiltCorrectly(tableJson, 0, charlie);
    assertThatRowIsBuiltCorrectly(tableJson, 1, dan);
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 27 with TabularResultData

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

the class FunctionCommandsDUnitTest method testExecuteFunctionOnGroups.

// GEODE-1563: JMX RMI (java.rmi.NoSuchObjectException: no such object
@Category(FlakyTest.class)
// in table)
@Test
public void testExecuteFunctionOnGroups() {
    Properties localProps = new Properties();
    localProps.setProperty(NAME, "Manager");
    localProps.setProperty(GROUPS, "Group0");
    setUpJmxManagerOnVm0ThenConnect(localProps);
    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
    FunctionService.registerFunction(function);
    VM vm1 = Host.getHost(0).getVM(1);
    VM vm2 = Host.getHost(0).getVM(2);
    String vm1id = (String) vm1.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            Properties localProps = new Properties();
            localProps.setProperty(GROUPS, "Group1");
            getSystem(localProps);
            Cache cache = getCache();
            Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
            FunctionService.registerFunction(function);
            return cache.getDistributedSystem().getDistributedMember().getId();
        }
    });
    String vm2id = (String) vm2.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            Properties localProps = new Properties();
            localProps.setProperty(GROUPS, "Group2");
            getSystem(localProps);
            Cache cache = getCache();
            Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
            FunctionService.registerFunction(function);
            return cache.getDistributedSystem().getDistributedMember().getId();
        }
    });
    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {

        public void run() {
            RegionFactory<Integer, Integer> dataRegionFactory = getCache().createRegionFactory(RegionShortcut.REPLICATE);
            Region region = dataRegionFactory.create(REGION_NAME);
            Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
            assertNotNull(region);
            FunctionService.registerFunction(function);
        }
    });
    String command = "execute function --id=" + TestFunction.TEST_FUNCTION1 + " --groups=Group1,Group2";
    getLogWriter().info("testExecuteFunctionOnGroups command=" + command);
    CommandResult cmdResult = executeCommand(command);
    getLogWriter().info("testExecuteFunctionOnGroups cmdResult=" + cmdResult);
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    TabularResultData resultData = (TabularResultData) cmdResult.getResultData();
    List<String> members = resultData.retrieveAllValues("Member ID/Name");
    getLogWriter().info("testExecuteFunctionOnGroups members=" + members);
    assertTrue(members.size() == 2 && members.contains(vm1id) && members.contains(vm2id));
}
Also used : TestFunction(org.apache.geode.internal.cache.functions.TestFunction) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) RegionFactory(org.apache.geode.cache.RegionFactory) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) Category(org.junit.experimental.categories.Category) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 28 with TabularResultData

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

the class GemfireDataCommandsDUnitTest method validateSelectResult.

private void validateSelectResult(CommandResult cmdResult, boolean expectedFlag, int expectedRows, String[] cols) {
    if (ResultData.TYPE_COMPOSITE.equals(cmdResult.getType())) {
        CompositeResultData rd = (CompositeResultData) cmdResult.getResultData();
        SectionResultData section = rd.retrieveSectionByIndex(0);
        boolean result = (Boolean) section.retrieveObject("Result");
        assertEquals(expectedFlag, result);
        if (expectedFlag && expectedRows != -1) {
            int rowsReturned = (Integer) section.retrieveObject("Rows");
            assertEquals(expectedRows, rowsReturned);
            if (rowsReturned > 0 && cols != null) {
                try {
                    TabularResultData table = section.retrieveTableByIndex(0);
                    GfJsonArray array = table.getHeaders();
                    assertEquals(cols.length, array.size());
                    for (String col : cols) {
                        boolean found = false;
                        getLogWriter().info("Validating column " + col);
                        for (int i = 0; i < array.size(); i++) {
                            String header = (String) array.get(i);
                            if (col.equals(header))
                                found = true;
                        }
                        assertEquals(true, found);
                    }
                } catch (GfJsonException e) {
                    fail("Error accessing table data", e);
                }
            }
        }
    } else
        fail("Expected CompositeResult Returned Result Type " + cmdResult.getType());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GfJsonArray(org.apache.geode.management.internal.cli.json.GfJsonArray) CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)

Example 29 with TabularResultData

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

the class ClientCommandsDUnitTest method testDescribeClientWithServers.

@Test
public void testDescribeClientWithServers() throws Exception {
    setupSystem2();
    String commandString = CliStrings.DESCRIBE_CLIENT + " --" + CliStrings.DESCRIBE_CLIENT__ID + "=\"" + clientId + "\"";
    getLogWriter().info("testDescribeClientWithServers 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("testDescribeClientWithServers commandResult=" + commandResult);
    String resultAsString = commandResultToString(commandResult);
    getLogWriter().info("testDescribeClientWithServers 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));
    closeNonDurableClient(Host.getHost(0).getVM(3));
    closeCacheServer(Host.getHost(0).getVM(1));
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) VM(org.apache.geode.test.dunit.VM) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 30 with TabularResultData

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

the class ClientCommandsDUnitTest method testListClient.

// GEODE-908: random ports, BindException, time sensitive, HeadlessGfsh
@Category(FlakyTest.class)
@Test
public void testListClient() throws Exception {
    setupSystemForListClient();
    final VM manager = Host.getHost(0).getVM(0);
    String commandString = CliStrings.LIST_CLIENTS;
    getLogWriter().info("testListClient commandStr=" + commandString);
    waitForListClientMbean();
    final VM server1 = Host.getHost(0).getVM(1);
    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 serverName = (String) server1.invoke("get distributed member Id", () -> getDistributedMemberId());
    CommandResult commandResult = executeCommand(commandString);
    getLogWriter().info("testListClient commandResult=" + commandResult);
    String resultAsString = commandResultToString(commandResult);
    getLogWriter().info("testListClient 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);
    getLogWriter().info("testListClients serverNames : " + serverNames);
    getLogWriter().info("testListClients clientNames : " + clientNames);
    assertEquals(2, serverNames.size());
    assertEquals(2, clientNames.size());
    assertTrue(clientNames.contains(clientIds[0]));
    assertTrue(clientNames.contains(clientIds[1]));
    serverName = serverName.replace(":", "-");
    getLogWriter().info("testListClients serverName : " + serverName);
    for (String str : serverNames) {
        assertTrue(str.contains(serverName));
    }
    closeNonDurableClient(Host.getHost(0).getVM(2));
    closeCacheServer(Host.getHost(0).getVM(1));
    closeCacheServer(Host.getHost(0).getVM(3));
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) VM(org.apache.geode.test.dunit.VM) DistributedMember(org.apache.geode.distributed.DistributedMember) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) CacheServerMXBean(org.apache.geode.management.CacheServerMXBean) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) ObjectName(javax.management.ObjectName) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Category(org.junit.experimental.categories.Category) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) 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