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
}
}
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");
}
}
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");
}
}
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));
}
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 + "\"]"));
}
Aggregations