Search in sources :

Example 86 with CommandResult

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

the class GemfireDataCommandsDUnitTest method testGetLocateEntryFromRegionOnDifferentVM.

@Test
public void testGetLocateEntryFromRegionOnDifferentVM() {
    final String keyPrefix = "testKey";
    final String valuePrefix = "testValue";
    setupForGetPutRemoveLocateEntry("testGetLocateEntryFromRegionOnDifferentVM");
    final VM vm1 = Host.getHost(0).getVM(1);
    final VM vm2 = Host.getHost(0).getVM(2);
    SerializableRunnable putKeys1 = new SerializableRunnable() {

        @Override
        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion(DATA_REGION_NAME_VM1_PATH);
            Region parRegion = cache.getRegion(DATA_PAR_REGION_NAME_VM1_PATH);
            assertNotNull(region);
            region.clear();
            for (int i = 0; i < COUNT; i++) {
                if (i % 2 == 0) {
                    String key = keyPrefix + i;
                    String value = valuePrefix + i;
                    region.put(key, value);
                    parRegion.put(key, value);
                }
            }
        }
    };
    SerializableRunnable putKeys2 = new SerializableRunnable() {

        @Override
        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion(DATA_REGION_NAME_VM2_PATH);
            Region parRegion = cache.getRegion(DATA_PAR_REGION_NAME_VM2_PATH);
            assertNotNull(region);
            region.clear();
            for (int i = 0; i < COUNT; i++) {
                if (i % 2 != 0) {
                    String key = keyPrefix + i;
                    String value = valuePrefix + i;
                    region.put(key, value);
                    parRegion.put(key, value);
                }
            }
        }
    };
    vm1.invoke(putKeys1);
    vm2.invoke(putKeys2);
    for (int i = 0; i < COUNT; i++) {
        String command = "get";
        String key = keyPrefix + i;
        String value = valuePrefix + i;
        if (i % 2 == 0)
            command = command + " " + "--key=" + key + " --region=" + DATA_REGION_NAME_VM1_PATH;
        else if (i % 2 == 1)
            command = command + " " + "--key=" + key + " --region=" + DATA_REGION_NAME_VM2_PATH;
        CommandResult cmdResult = executeCommand(command);
        printCommandOutput(cmdResult);
        assertEquals(Result.Status.OK, cmdResult.getStatus());
        validateResult(cmdResult, true);
        command = "locate entry";
        if (i % 2 == 0)
            command = command + " " + "--key=" + key + " --region=" + DATA_REGION_NAME_VM1_PATH;
        else if (i % 2 == 1)
            command = command + " " + "--key=" + key + " --region=" + DATA_REGION_NAME_VM2_PATH;
        cmdResult = executeCommand(command);
        printCommandOutput(cmdResult);
        assertEquals(Result.Status.OK, cmdResult.getStatus());
        validateResult(cmdResult, true);
        command = "locate entry";
        if (i % 2 == 0)
            command = command + " " + "--key=" + key + " --region=" + DATA_PAR_REGION_NAME_VM1_PATH;
        else if (i % 2 == 1)
            command = command + " " + "--key=" + key + " --region=" + DATA_PAR_REGION_NAME_VM2_PATH;
        cmdResult = executeCommand(command);
        printCommandOutput(cmdResult);
        assertEquals(Result.Status.OK, cmdResult.getStatus());
        validateResult(cmdResult, true);
        // 1 Regions X (2-1) 2 Copies but redundancy not
        validateLocationsResult(cmdResult, 1);
    // satisfied = 1
    }
}
Also used : VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) InternalCache(org.apache.geode.internal.cache.InternalCache) 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 87 with CommandResult

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

the class FunctionCommandsDUnitTest method testDestroyOnMember.

@Test
public void testDestroyOnMember() {
    setUpJmxManagerOnVm0ThenConnect(null);
    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
    FunctionService.registerFunction(function);
    final VM vm1 = Host.getHost(0).getVM(1);
    final String vm1MemberId = (String) vm1.invoke(() -> getMemberId());
    String command = "destroy function --id=" + function.getId() + " --member=" + vm1MemberId;
    getLogWriter().info("testDestroyOnMember command=" + command);
    CommandResult cmdResult = executeCommand(command);
    if (cmdResult != null) {
        String strCmdResult = commandResultToString(cmdResult);
        assertEquals(Result.Status.OK, cmdResult.getStatus());
        getLogWriter().info("testDestroyOnMember strCmdResult=" + strCmdResult);
        assertTrue(strCmdResult.contains("Destroyed TestFunction1 Successfully"));
    } else {
        fail("testDestroyOnMember 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 88 with CommandResult

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

the class FunctionCommandsDUnitTest method testExecuteFunctionOnRegionBug51480.

@Test
public void testExecuteFunctionOnRegionBug51480() {
    setupForBug51480();
    // check if DistributedRegionMXBean is available so that command will not fail
    final VM manager = Host.getHost(0).getVM(0);
    manager.invoke(checkRegionMBeans);
    final Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {

        public void run() {
            FunctionService.registerFunction(function);
        }
    });
    String command = "execute function --id=" + function.getId() + " --region=" + REGION_ONE;
    getLogWriter().info("testExecuteFunctionOnRegionBug51480 command=" + command);
    CommandResult cmdResult = executeCommand(command);
    if (cmdResult != null) {
        getLogWriter().info("testExecuteFunctionOnRegionBug51480 cmdResult=" + cmdResult);
        assertEquals(Result.Status.OK, cmdResult.getStatus());
        String stringResult = commandResultToString(cmdResult);
        getLogWriter().info("testExecuteFunctionOnRegionBug51480 stringResult=" + stringResult);
        assertTrue(stringResult.contains("Execution summary"));
    } else {
        fail("testExecuteFunctionOnRegionBug51480 did not return 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 89 with CommandResult

use of org.apache.geode.management.internal.cli.result.CommandResult 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 90 with CommandResult

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

the class FunctionCommandsDUnitTest method testDestroyOnGroups.

@Test
public void testDestroyOnGroups() {
    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() {
            Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
            FunctionService.registerFunction(function);
        }
    });
    String command = "destroy function --id=" + TestFunction.TEST_FUNCTION1 + " --groups=Group1,Group2";
    getLogWriter().info("testDestroyOnGroups command=" + command);
    CommandResult cmdResult = executeCommand(command);
    getLogWriter().info("testDestroyOnGroups cmdResult=" + cmdResult);
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    String content = null;
    try {
        content = cmdResult.getContent().get("message").toString();
        getLogWriter().info("testDestroyOnGroups content = " + content);
    } catch (GfJsonException e) {
        fail("testDestroyOnGroups exception=" + e);
    }
    assertNotNull(content);
    assertTrue(content.equals("[\"Destroyed " + TestFunction.TEST_FUNCTION1 + " Successfully on " + vm1id + "," + vm2id + "\"]") || content.equals("[\"Destroyed " + TestFunction.TEST_FUNCTION1 + " Successfully on " + vm2id + "," + vm1id + "\"]"));
}
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) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Cache(org.apache.geode.cache.Cache) 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)

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