Search in sources :

Example 81 with CommandResult

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

the class ConfigCommandsDUnitTest method testDescribeConfig.

@Test
public void testDescribeConfig() throws Exception {
    setUpJmxManagerOnVm0ThenConnect(null);
    final String controllerName = "Member2";
    /*
     * Create properties for the controller VM
     */
    final Properties localProps = new Properties();
    localProps.setProperty(MCAST_PORT, "0");
    localProps.setProperty(LOG_LEVEL, "info");
    localProps.setProperty(STATISTIC_SAMPLING_ENABLED, "true");
    localProps.setProperty(ENABLE_TIME_STATISTICS, "true");
    localProps.setProperty(NAME, controllerName);
    localProps.setProperty(GROUPS, "G1");
    getSystem(localProps);
    Cache cache = getCache();
    int[] ports = getRandomAvailableTCPPorts(1);
    CacheServer cs = getCache().addCacheServer();
    cs.setPort(ports[0]);
    cs.setMaxThreads(10);
    cs.setMaxConnections(9);
    cs.start();
    try {
        RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
        List<String> jvmArgs = runtimeBean.getInputArguments();
        getLogWriter().info("#SB Actual JVM Args : ");
        for (String jvmArg : jvmArgs) {
            getLogWriter().info("#SB JVM " + jvmArg);
        }
        InternalDistributedSystem system = (InternalDistributedSystem) cache.getDistributedSystem();
        DistributionConfig config = system.getConfig();
        config.setArchiveFileSizeLimit(1000);
        String command = CliStrings.DESCRIBE_CONFIG + " --member=" + controllerName;
        CommandProcessor cmdProcessor = new CommandProcessor();
        cmdProcessor.createCommandStatement(command, Collections.EMPTY_MAP).process();
        CommandResult cmdResult = executeCommand(command);
        String resultStr = commandResultToString(cmdResult);
        getLogWriter().info("#SB Hiding the defaults\n" + resultStr);
        assertEquals(true, cmdResult.getStatus().equals(Status.OK));
        assertEquals(true, resultStr.contains("G1"));
        assertEquals(true, resultStr.contains(controllerName));
        assertEquals(true, resultStr.contains(ARCHIVE_FILE_SIZE_LIMIT));
        assertEquals(true, !resultStr.contains("copy-on-read"));
        cmdResult = executeCommand(command + " --" + CliStrings.DESCRIBE_CONFIG__HIDE__DEFAULTS + "=false");
        resultStr = commandResultToString(cmdResult);
        getLogWriter().info("#SB No hiding of defaults\n" + resultStr);
        assertEquals(true, cmdResult.getStatus().equals(Status.OK));
        assertEquals(true, resultStr.contains("is-server"));
        assertEquals(true, resultStr.contains(controllerName));
        assertEquals(true, resultStr.contains("copy-on-read"));
    } finally {
        cs.stop();
    }
}
Also used : DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) CacheServer(org.apache.geode.cache.server.CacheServer) CommandProcessor(org.apache.geode.management.internal.cli.remote.CommandProcessor) RuntimeMXBean(java.lang.management.RuntimeMXBean) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) Properties(java.util.Properties) Cache(org.apache.geode.cache.Cache) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 82 with CommandResult

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

the class FunctionCommandsDUnitTest method testExecuteFunctionWithNoRegionOnManager.

@Test
public void testExecuteFunctionWithNoRegionOnManager() throws Exception {
    setupWith2Regions();
    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
    FunctionService.registerFunction(function);
    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {

        public void run() {
            Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
            FunctionService.registerFunction(function);
        }
    });
    Thread.sleep(2500);
    String command = "execute function --id=" + function.getId() + " --region=" + "/" + "RegionOne";
    getLogWriter().info("testExecuteFunctionWithNoRegionOnManager command : " + command);
    CommandResult cmdResult = executeCommand(command);
    if (cmdResult != null) {
        String strCmdResult = commandResultToString(cmdResult);
        getLogWriter().info("testExecuteFunctionWithNoRegionOnManager stringResult : " + strCmdResult);
        assertEquals(Result.Status.OK, cmdResult.getStatus());
        assertTrue(strCmdResult.contains("Execution summary"));
    } else {
        fail("testExecuteFunctionWithNoRegionOnManager failed as did not get CommandResult");
    }
}
Also used : Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) 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 83 with CommandResult

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

the class GemfireDataCommandsDUnitTest method testSimplePutCommand.

@Test
public void testSimplePutCommand() {
    final String keyPrefix = "testKey";
    final String valuePrefix = "testValue";
    setupForGetPutRemoveLocateEntry("tesSimplePut");
    final VM vm1 = Host.getHost(0).getVM(1);
    final VM vm2 = Host.getHost(0).getVM(2);
    for (int i = 0; i < COUNT; i++) {
        String command = "put";
        String key = keyPrefix + i;
        String value = valuePrefix + i;
        command = command + " " + "--key=" + key + " --value=" + value + " --region=" + DATA_REGION_NAME_PATH;
        CommandResult cmdResult = executeCommand(command);
        printCommandOutput(cmdResult);
        validateResult(cmdResult, true);
        assertEquals(Result.Status.OK, cmdResult.getStatus());
    }
    // Bug : 51587 : GFSH command failing when ; is present in either key or value in put operation
    String command = "put";
    String key = keyPrefix + "\\;" + COUNT;
    String value = valuePrefix + "\\;" + COUNT;
    command = command + " " + "--key=" + key + " --value=" + value + " --region=" + DATA_REGION_NAME_PATH;
    CommandResult cmdResult = executeCommand(command);
    printCommandOutput(cmdResult);
    validateResult(cmdResult, true);
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    SerializableRunnable checkPutKeys = new SerializableRunnable() {

        @Override
        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion(DATA_REGION_NAME_PATH);
            assertNotNull(region);
            for (int i = 0; i < COUNT; i++) {
                String key = keyPrefix + i;
                assertEquals(true, region.containsKey(key));
            }
            // Validation for Bug 51587
            String key = keyPrefix + "\\;" + COUNT;
            assertEquals(true, region.containsKey(key));
        }
    };
    vm1.invoke(checkPutKeys);
    vm2.invoke(checkPutKeys);
}
Also used : VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Region(org.apache.geode.cache.Region) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Cache(org.apache.geode.cache.Cache) InternalCache(org.apache.geode.internal.cache.InternalCache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 84 with CommandResult

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

the class GemfireDataCommandsDUnitTest method testRebalanceForExcludeRegionFunction.

@Test
public void testRebalanceForExcludeRegionFunction() {
    setupWith2Regions();
    // check if DistributedRegionMXBean is available so that command will not fail
    final VM manager = Host.getHost(0).getVM(0);
    manager.invoke(checkRegionMBeans);
    getLogWriter().info("testRebalanceForExcludeRegionFunction verified Mbean and executing command");
    String command = "rebalance --exclude-region=" + "/" + REBALANCE_REGION2_NAME;
    getLogWriter().info("testRebalanceForExcludeRegionFunction command : " + command);
    CommandResult cmdResult = executeCommand(command);
    getLogWriter().info("testRebalanceForExcludeRegionFunction just after executing " + cmdResult);
    if (cmdResult != null) {
        String stringResult = commandResultToString(cmdResult);
        getLogWriter().info("testRebalanceForExcludeRegionFunction stringResult : " + stringResult);
        assertEquals("CommandResult=" + cmdResult, Result.Status.OK, cmdResult.getStatus());
    } else {
        fail("testRebalanceForIncludeRegionFunction failed as did not get CommandResult");
    }
}
Also used : VM(org.apache.geode.test.dunit.VM) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 85 with CommandResult

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

the class GemfireDataCommandsDUnitTest method testPutJsonKeys.

// GEODE-1430
@Category(FlakyTest.class)
@Test
public void testPutJsonKeys() {
    final String keyPrefix = "testKey";
    setupForGetPutRemoveLocateEntry("testPutJsonKeys");
    final VM vm1 = Host.getHost(0).getVM(1);
    final VM vm2 = Host.getHost(0).getVM(2);
    for (int i = 0; i < COUNT; i++) {
        String command = "put";
        String keyString = keyPrefix + i;
        String population = "" + i * 100;
        String area = "" + i * (100.4365);
        String keyJson = keyTemplate.replaceAll("\\?", keyString);
        String valueJson = valueTemplate.replaceAll("\\?1", population);
        valueJson = valueJson.replaceAll("\\?2", area);
        valueJson = valueJson.replaceAll("\\?", keyString);
        getLogWriter().info("Putting key with json key : " + keyJson);
        getLogWriter().info("Putting key with json valye : " + valueJson);
        command = command + " " + "--key=" + keyJson + " --value=" + valueJson + " --region=" + DATA_REGION_NAME_PATH;
        command = command + " --key-class=" + Key1.class.getCanonicalName() + " --value-class=" + Value2.class.getCanonicalName();
        CommandResult cmdResult = executeCommand(command);
        printCommandOutput(cmdResult);
        assertEquals(Result.Status.OK, cmdResult.getStatus());
        validateResult(cmdResult, true);
    }
    // Bug #51175
    for (int i = COUNT; i < COUNT + 5; i++) {
        String command = "put";
        String keyString = keyPrefix + i;
        String id = "" + i * 100;
        String make = "" + i * (100.4365);
        String model = "" + i * (100.4365);
        String list = "['red','white','blue']";
        String set = "['red','white','blue']";
        String map = "{'power':'90hp'}";
        String keyJson = keyTemplate.replaceAll("\\?", keyString);
        String valueJson = carTemplate.replaceAll("\\?make", make);
        valueJson = valueJson.replaceAll("\\?model", model);
        valueJson = valueJson.replaceAll("\\?list", list);
        valueJson = valueJson.replaceAll("\\?set", set);
        valueJson = valueJson.replaceAll("\\?map", map);
        getLogWriter().info("Putting key with json key : " + keyJson);
        getLogWriter().info("Putting key with json valye : " + valueJson);
        command = command + " " + "--key=" + keyJson + " --value=" + valueJson + " --region=" + DATA_REGION_NAME_PATH;
        command = command + " --key-class=" + Key1.class.getCanonicalName() + " --value-class=" + Car.class.getCanonicalName();
        CommandResult cmdResult = executeCommand(command);
        printCommandOutput(cmdResult);
        assertEquals(Result.Status.OK, cmdResult.getStatus());
        validateResult(cmdResult, true);
    }
    SerializableRunnable checkPutKeys = new SerializableRunnable() {

        @Override
        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion(DATA_REGION_NAME_PATH);
            assertNotNull(region);
            for (int i = 0; i < COUNT + 5; i++) {
                String keyString = keyPrefix + i;
                Key1 key = new Key1();
                key.setId(keyString);
                key.setName("name" + keyString);
                assertEquals(true, region.containsKey(key));
                // Bug #51175
                if (i >= COUNT) {
                    Car car = (Car) region.get(key);
                    assertNotNull(car.getAttributes());
                    assertNotNull(car.getAttributeSet());
                    assertNotNull(car.getColors());
                }
            }
        }
    };
    vm1.invoke(checkPutKeys);
    vm2.invoke(checkPutKeys);
    doBugCheck50449();
}
Also used : Key1(org.apache.geode.management.internal.cli.dto.Key1) Car(org.apache.geode.management.internal.cli.dto.Car) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Region(org.apache.geode.cache.Region) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Cache(org.apache.geode.cache.Cache) InternalCache(org.apache.geode.internal.cache.InternalCache) Category(org.junit.experimental.categories.Category) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)270 Test (org.junit.Test)222 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)208 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)131 Properties (java.util.Properties)94 VM (org.apache.geode.test.dunit.VM)80 CommandStringBuilder (org.apache.geode.management.internal.cli.util.CommandStringBuilder)71 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)67 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)45 File (java.io.File)44 Cache (org.apache.geode.cache.Cache)43 Region (org.apache.geode.cache.Region)39 Category (org.junit.experimental.categories.Category)33 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)32 InternalCache (org.apache.geode.internal.cache.InternalCache)29 DistributedMember (org.apache.geode.distributed.DistributedMember)26 ArrayList (java.util.ArrayList)16 RegionFactory (org.apache.geode.cache.RegionFactory)15 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)15 Gfsh (org.apache.geode.management.internal.cli.shell.Gfsh)14