use of org.apache.geode.cache.execute.Function 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.cache.execute.Function 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.cache.execute.Function in project geode by apache.
the class FunctionCommandsDUnitTest method setupWith2Regions.
void setupWith2Regions() {
final VM vm1 = Host.getHost(0).getVM(1);
final VM vm2 = Host.getHost(0).getVM(2);
setUpJmxManagerOnVm0ThenConnect(null);
vm1.invoke(new SerializableRunnable() {
public void run() {
final Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
FunctionService.registerFunction(function);
// no need to close cache as it will be closed as part of teardown2
Cache cache = getCache();
RegionFactory<Integer, Integer> dataRegionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
Region region = dataRegionFactory.create("RegionOne");
for (int i = 0; i < 10; i++) {
region.put("key" + (i + 200), "value" + (i + 200));
}
region = dataRegionFactory.create("RegionTwo");
for (int i = 0; i < 1000; i++) {
region.put("key" + (i + 200), "value" + (i + 200));
}
}
});
vm2.invoke(new SerializableRunnable() {
public void run() {
final Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
FunctionService.registerFunction(function);
// no need to close cache as it will be closed as part of teardown2
Cache cache = getCache();
RegionFactory<Integer, Integer> dataRegionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
Region region = dataRegionFactory.create("RegionOne");
for (int i = 0; i < 10000; i++) {
region.put("key" + (i + 400), "value" + (i + 400));
}
region = dataRegionFactory.create("Regiontwo");
for (int i = 0; i < 10; i++) {
region.put("key" + (i + 200), "value" + (i + 200));
}
}
});
}
use of org.apache.geode.cache.execute.Function 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.cache.execute.Function 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