Search in sources :

Example 96 with TabularResultData

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

the class DataCommandFunctionWithPDXJUnitTest method testVerifyDataDoesNotShift.

@Test
public void testVerifyDataDoesNotShift() throws Exception {
    TabularResultData rawTable = getTableFromQuery("select * from /" + PARTITIONED_REGION + " order by id");
    // Verify any table built
    assertThat(rawTable.getGfJsonObject()).isNotNull();
    assertThat(rawTable.getGfJsonObject().getJSONObject("content")).isNotNull();
    GfJsonObject tableJson = rawTable.getGfJsonObject().getJSONObject("content");
    // Table only contains correct keys
    assertThat(tableJson.getJSONArray("missingKey")).isNull();
    // Table contains correct data
    assertThatRowIsBuiltCorrectly(tableJson, 0, alice);
    assertThatRowIsBuiltCorrectly(tableJson, 1, bob);
    assertThatRowIsBuiltCorrectly(tableJson, 2, charlie);
    assertThatRowIsBuiltCorrectly(tableJson, 3, 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 97 with TabularResultData

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

the class DataCommandFunctionWithPDXJUnitTest method testFilteredQueryWithoutPhone.

@Test
public void testFilteredQueryWithoutPhone() throws Exception {
    TabularResultData rawTable = getTableFromQuery("select * from /" + PARTITIONED_REGION + " c where IS_UNDEFINED ( 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", "firstName", "lastName" }) {
        assertThat(tableJson.getJSONArray(k).size()).isEqualTo(2);
    }
    assertThatRowIsBuiltCorrectly(tableJson, 0, alice);
    assertThatRowIsBuiltCorrectly(tableJson, 1, bob);
}
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 98 with TabularResultData

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

the class GemfireDataCommandsDUnitTest method validateJSONGetResult.

private void validateJSONGetResult(CommandResult cmdResult, String[] expectedCols) {
    CompositeResultData rd = (CompositeResultData) cmdResult.getResultData();
    SectionResultData section = rd.retrieveSectionByIndex(0);
    TabularResultData table = section.retrieveTableByIndex(0);
    GfJsonArray array = table.getHeaders();
    assertEquals(expectedCols.length, array.size());
    try {
        for (String col : expectedCols) {
            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);
    }
}
Also used : 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 99 with TabularResultData

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

the class GemfireDataCommandsDUnitTest method validateJSONGetResultValues.

private void validateJSONGetResultValues(CommandResult cmdResult, String[] expectedCols) {
    CompositeResultData rd = (CompositeResultData) cmdResult.getResultData();
    SectionResultData section = rd.retrieveSectionByIndex(0);
    TabularResultData table = section.retrieveTableByIndex(0);
    GfJsonArray array = table.getHeaders();
    assertEquals(expectedCols.length, array.size());
    try {
        for (String col : expectedCols) {
            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);
            List<String> values = table.retrieveAllValues(col);
            for (String value : values) {
                assertNotSame("null", value);
            }
        }
    } catch (GfJsonException e) {
        fail("Error accessing table data", e);
    }
}
Also used : 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 100 with TabularResultData

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

the class WanCommandStatusDUnitTest method testGatewaySenderStatus_OnGroups.

@Test
public void testGatewaySenderStatus_OnGroups() {
    Integer lnPort = (Integer) vm1.invoke(() -> createFirstLocatorWithDSId(1));
    Properties props = getDistributedSystemProperties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "localhost[" + lnPort + "]");
    setUpJmxManagerOnVm0ThenConnect(props);
    Integer nyPort = (Integer) vm2.invoke(() -> createFirstRemoteLocator(2, lnPort));
    vm7.invoke(() -> createAndStartReceiver(nyPort));
    vm3.invoke(() -> createCacheWithGroups(lnPort, "Serial_Sender, Parallel_Sender"));
    vm3.invoke(() -> createSender("ln_Serial", 2, false, 100, 400, false, false, null, true));
    vm3.invoke(() -> createSender("ln_Parallel", 2, true, 100, 400, false, false, null, true));
    vm4.invoke(() -> createCacheWithGroups(lnPort, "Serial_Sender, Parallel_Sender"));
    vm4.invoke(() -> createSender("ln_Serial", 2, false, 100, 400, false, false, null, true));
    vm4.invoke(() -> createSender("ln_Parallel", 2, true, 100, 400, false, false, null, true));
    vm5.invoke(() -> createCacheWithGroups(lnPort, "Parallel_Sender"));
    vm5.invoke(() -> createSender("ln_Serial", 2, false, 100, 400, false, false, null, true));
    vm5.invoke(() -> createSender("ln_Parallel", 2, true, 100, 400, false, false, null, true));
    vm6.invoke(() -> createCacheWithGroups(lnPort, "Serial_Sender"));
    final DistributedMember vm1Member = (DistributedMember) vm3.invoke(() -> getMember());
    pause(10000);
    String command = CliStrings.STATUS_GATEWAYSENDER + " --" + CliStrings.STATUS_GATEWAYSENDER__ID + "=ln_Serial --" + CliStrings.STATUS_GATEWAYSENDER__GROUP + "=Serial_Sender";
    CommandResult cmdResult = executeCommand(command);
    if (cmdResult != null) {
        TabularResultData tableResultData = ((CompositeResultData) cmdResult.getResultData()).retrieveSection(CliStrings.SECTION_GATEWAY_SENDER_AVAILABLE).retrieveTable(CliStrings.TABLE_GATEWAY_SENDER);
        List<String> result_Status = tableResultData.retrieveAllValues(CliStrings.RESULT_STATUS);
        assertEquals(2, result_Status.size());
        assertFalse(result_Status.contains(CliStrings.GATEWAY_RUNNING));
        tableResultData = ((CompositeResultData) cmdResult.getResultData()).retrieveSection(CliStrings.SECTION_GATEWAY_SENDER_NOT_AVAILABLE).retrieveTable(CliStrings.TABLE_GATEWAY_SENDER);
        List<String> result_hosts = tableResultData.retrieveAllValues(CliStrings.RESULT_HOST_MEMBER);
        assertEquals(1, result_hosts.size());
        String strCmdResult = commandResultToString(cmdResult);
        getLogWriter().info("testGatewaySenderStatus_OnGroups : " + strCmdResult + ">>>>> ");
        assertEquals(Result.Status.OK, cmdResult.getStatus());
    } else {
        fail("testListGatewaySender failed as did not get CommandResult");
    }
    vm3.invoke(() -> startSender("ln_Serial"));
    vm3.invoke(() -> startSender("ln_Parallel"));
    vm4.invoke(() -> startSender("ln_Serial"));
    vm4.invoke(() -> startSender("ln_Parallel"));
    pause(10000);
    command = CliStrings.STATUS_GATEWAYSENDER + " --" + CliStrings.STATUS_GATEWAYSENDER__ID + "=ln_Serial --" + CliStrings.STATUS_GATEWAYSENDER__GROUP + "=Serial_Sender";
    cmdResult = executeCommand(command);
    if (cmdResult != null) {
        TabularResultData tableResultData = ((CompositeResultData) cmdResult.getResultData()).retrieveSection(CliStrings.SECTION_GATEWAY_SENDER_AVAILABLE).retrieveTable(CliStrings.TABLE_GATEWAY_SENDER);
        List<String> result_Status = tableResultData.retrieveAllValues(CliStrings.RESULT_STATUS);
        assertEquals(2, result_Status.size());
        assertFalse(result_Status.contains(CliStrings.GATEWAY_NOT_RUNNING));
        tableResultData = ((CompositeResultData) cmdResult.getResultData()).retrieveSection(CliStrings.SECTION_GATEWAY_SENDER_NOT_AVAILABLE).retrieveTable(CliStrings.TABLE_GATEWAY_SENDER);
        List<String> result_hosts = tableResultData.retrieveAllValues(CliStrings.RESULT_HOST_MEMBER);
        assertEquals(1, result_hosts.size());
        String strCmdResult = commandResultToString(cmdResult);
        getLogWriter().info("testGatewaySenderStatus_OnGroups : " + strCmdResult + ">>>>> ");
        assertEquals(Result.Status.OK, cmdResult.getStatus());
    } else {
        fail("testListGatewaySender failed as did not get CommandResult");
    }
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) DistributedMember(org.apache.geode.distributed.DistributedMember) 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) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

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