use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.
the class FunctionCommandsDUnitTest method testListFunction.
@Test
public void testListFunction() {
// Create the default setup, putting the Manager VM into Group1
Properties localProps = new Properties();
localProps.setProperty(GROUPS, "Group1");
setUpJmxManagerOnVm0ThenConnect(localProps);
// Find no functions
CommandResult cmdResult = executeCommand(CliStrings.LIST_FUNCTION);
assertEquals(Result.Status.OK, cmdResult.getStatus());
assertTrue(commandResultToString(cmdResult).contains("No Functions Found"));
// Add a function in the manager VM (VM 0)
final Function function1 = new TestFunction(true, TestFunction.TEST_FUNCTION1);
final VM managerVm = Host.getHost(0).getVM(0);
managerVm.invoke(new SerializableRunnable() {
public void run() {
FunctionService.registerFunction(function1);
}
});
// Add functions in another VM (VM 1)
final Function function2 = new TestFunction(true, TestFunction.TEST_FUNCTION2);
final Function function3 = new TestFunction(true, TestFunction.TEST_FUNCTION3);
final VM vm1 = Host.getHost(0).getVM(1);
final String vm1Name = "VM" + vm1.getPid();
vm1.invoke(new SerializableRunnable() {
public void run() {
Properties localProps = new Properties();
localProps.setProperty(NAME, vm1Name);
localProps.setProperty(GROUPS, "Group2");
getSystem(localProps);
getCache();
FunctionService.registerFunction(function2);
FunctionService.registerFunction(function3);
}
});
// Add functions in a third VM (VM 2)
final Function function4 = new TestFunction(true, TestFunction.TEST_FUNCTION4);
final Function function5 = new TestFunction(true, TestFunction.TEST_FUNCTION5);
final Function function6 = new TestFunction(true, TestFunction.TEST_FUNCTION6);
final VM vm2 = Host.getHost(0).getVM(2);
final String vm2Name = "VM" + vm2.getPid();
vm2.invoke(new SerializableRunnable() {
public void run() {
Properties localProps = new Properties();
localProps.setProperty(NAME, vm2Name);
localProps.setProperty(GROUPS, "Group3");
getSystem(localProps);
getCache();
FunctionService.registerFunction(function4);
FunctionService.registerFunction(function5);
FunctionService.registerFunction(function6);
}
});
// Find all functions
cmdResult = executeCommand(CliStrings.LIST_FUNCTION);
assertEquals(Result.Status.OK, cmdResult.getStatus());
String stringResult = commandResultToString(cmdResult);
assertEquals(8, countLinesInString(stringResult, false));
assertTrue(stringContainsLine(stringResult, "Member.*Function"));
assertTrue(stringContainsLine(stringResult, "Manager.*" + function1.getId()));
assertTrue(stringContainsLine(stringResult, vm1Name + ".*" + function2.getId()));
assertTrue(stringContainsLine(stringResult, vm1Name + ".*" + function3.getId()));
assertTrue(stringContainsLine(stringResult, vm2Name + ".*" + function4.getId()));
assertTrue(stringContainsLine(stringResult, vm2Name + ".*" + function5.getId()));
assertTrue(stringContainsLine(stringResult, vm2Name + ".*" + function6.getId()));
// Find functions in group Group3
cmdResult = executeCommand(CliStrings.LIST_FUNCTION + " --group=Group1,Group3");
assertEquals(Result.Status.OK, cmdResult.getStatus());
stringResult = commandResultToString(cmdResult);
assertEquals(6, countLinesInString(stringResult, false));
assertTrue(stringContainsLine(stringResult, "Member.*Function"));
assertTrue(stringContainsLine(stringResult, "Manager.*" + function1.getId()));
assertFalse(stringContainsLine(stringResult, vm1Name + ".*"));
assertTrue(stringContainsLine(stringResult, vm2Name + ".*" + function4.getId()));
assertTrue(stringContainsLine(stringResult, vm2Name + ".*" + function5.getId()));
assertTrue(stringContainsLine(stringResult, vm2Name + ".*" + function6.getId()));
// Find functions for Manager member
cmdResult = executeCommand(CliStrings.LIST_FUNCTION + " --member=Manager," + vm1Name);
assertEquals(Result.Status.OK, cmdResult.getStatus());
stringResult = commandResultToString(cmdResult);
assertEquals(5, countLinesInString(stringResult, false));
assertTrue(stringContainsLine(stringResult, "Member.*Function"));
assertTrue(stringContainsLine(stringResult, "Manager.*" + function1.getId()));
assertTrue(stringContainsLine(stringResult, vm1Name + ".*" + function2.getId()));
assertTrue(stringContainsLine(stringResult, vm1Name + ".*" + function3.getId()));
assertFalse(stringContainsLine(stringResult, vm2Name + ".*"));
// Find functions that match a pattern
cmdResult = executeCommand(CliStrings.LIST_FUNCTION + " --matches=.*[135]$");
assertEquals(Result.Status.OK, cmdResult.getStatus());
stringResult = commandResultToString(cmdResult);
assertEquals(5, countLinesInString(stringResult, false));
assertTrue(stringContainsLine(stringResult, "Member.*Function"));
assertTrue(stringContainsLine(stringResult, "Manager.*" + function1.getId()));
assertFalse(stringContainsLine(stringResult, vm2Name + ".*" + function2.getId()));
assertTrue(stringContainsLine(stringResult, vm1Name + ".*" + function3.getId()));
assertFalse(stringContainsLine(stringResult, vm2Name + ".*" + function4.getId()));
assertTrue(stringContainsLine(stringResult, vm2Name + ".*" + function5.getId()));
assertFalse(stringContainsLine(stringResult, vm2Name + ".*" + function6.getId()));
}
use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.
the class FunctionCommandsDUnitTest method testExecuteFunctionOnMember.
@Test
public void testExecuteFunctionOnMember() {
Properties localProps = new Properties();
localProps.setProperty(NAME, "Manager");
localProps.setProperty(GROUPS, "Group1");
setUpJmxManagerOnVm0ThenConnect(localProps);
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());
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=" + function.getId() + " --member=" + vm1MemberId;
getLogWriter().info("testExecuteFunctionOnMember command=" + command);
CommandResult cmdResult = executeCommand(command);
assertEquals(Result.Status.OK, cmdResult.getStatus());
String stringResult = commandResultToString(cmdResult);
getLogWriter().info("testExecuteFunctionOnMember stringResult:" + stringResult);
assertTrue(stringResult.contains("Execution summary"));
}
use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.
the class FunctionCommandsDUnitTest method testExecuteFunctionOnRegion.
@Test
public void testExecuteFunctionOnRegion() {
setUpJmxManagerOnVm0ThenConnect(null);
final Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
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);
assertNotNull(region);
FunctionService.registerFunction(function);
}
});
String command = "execute function --id=" + function.getId() + " --region=" + REGION_NAME;
getLogWriter().info("testExecuteFunctionOnRegion command=" + command);
CommandResult cmdResult = executeCommand(command);
if (cmdResult != null) {
assertEquals(Result.Status.OK, cmdResult.getStatus());
getLogWriter().info("testExecuteFunctionOnRegion cmdResult=" + cmdResult);
String stringResult = commandResultToString(cmdResult);
getLogWriter().info("testExecuteFunctionOnRegion stringResult=" + stringResult);
assertTrue(stringResult.contains("Execution summary"));
} else {
fail("testExecuteFunctionOnRegion did not return CommandResult");
}
}
use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.
the class CreateAlterDestroyRegionCommandsDUnitTest method testDestroyLocalAndDistributedRegions.
@Test
public void testDestroyLocalAndDistributedRegions() {
setUpJmxManagerOnVm0ThenConnect(null);
for (int i = 1; i <= 2; i++) {
Host.getHost(0).getVM(i).invoke(() -> {
final Cache cache = getCache();
RegionFactory<Object, Object> factory = cache.createRegionFactory(RegionShortcut.PARTITION);
factory.create("Customer");
factory.create("Customer-2");
factory.create("Customer_3");
});
}
Host.getHost(0).getVM(3).invoke(() -> {
final Cache cache = getCache();
RegionFactory<Object, Object> factory = cache.createRegionFactory(RegionShortcut.REPLICATE);
factory.setScope(Scope.LOCAL);
factory.create("Customer");
factory.create("Customer-2");
factory.create("Customer_3");
});
waitForRegionMBeanCreation("/Customer", 3);
// Test failure when region not found
String command = "destroy region --name=DOESNOTEXIST";
getLogWriter().info("testDestroyRegion command=" + command);
CommandResult cmdResult = executeCommand(command);
String strr = commandResultToString(cmdResult);
getLogWriter().info("testDestroyRegion strr=" + strr);
assertTrue(stringContainsLine(strr, "Could not find.*\"DOESNOTEXIST\".*"));
assertEquals(Result.Status.ERROR, cmdResult.getStatus());
command = "destroy region --name=/Customer";
getLogWriter().info("testDestroyRegion command=" + command);
cmdResult = executeCommand(command);
strr = commandResultToString(cmdResult);
assertTrue(stringContainsLine(strr, ".*Customer.*destroyed successfully.*"));
getLogWriter().info("testDestroyRegion strr=" + strr);
assertEquals(Result.Status.OK, cmdResult.getStatus());
command = "destroy region --name=/Customer_3";
getLogWriter().info("testDestroyRegion command=" + command);
cmdResult = executeCommand(command);
strr = commandResultToString(cmdResult);
assertTrue(stringContainsLine(strr, ".*Customer_3.*destroyed successfully.*"));
getLogWriter().info("testDestroyRegion strr=" + strr);
assertEquals(Result.Status.OK, cmdResult.getStatus());
command = "destroy region --name=/Customer-2";
getLogWriter().info("testDestroyRegion command=" + command);
cmdResult = executeCommand(command);
strr = commandResultToString(cmdResult);
assertTrue(stringContainsLine(strr, ".*Customer-2.*destroyed successfully.*"));
getLogWriter().info("testDestroyRegion strr=" + strr);
assertEquals(Result.Status.OK, cmdResult.getStatus());
for (int i = 1; i <= 3; i++) {
final int x = i;
Host.getHost(0).getVM(i).invoke(() -> {
assertNull("Region still exists in VM " + x, getCache().getRegion("Customer"));
assertNull("Region still exists in VM " + x, getCache().getRegion("Customer-2"));
assertNull("Region still exists in VM " + x, getCache().getRegion("Customer_3"));
});
}
}
use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.
the class CreateAlterDestroyRegionCommandsDUnitTest method regionAlterGroupTest.
private void regionAlterGroupTest() {
CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.ALTER_REGION);
commandStringBuilder.addOption(CliStrings.ALTER_REGION__REGION, this.alterRegionName);
commandStringBuilder.addOption(CliStrings.ALTER_REGION__GROUP, "Group1");
commandStringBuilder.addOption(CliStrings.ALTER_REGION__EVICTIONMAX, "5764");
CommandResult cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
String stringResult = commandResultToString(cmdResult);
assertEquals(4, countLinesInString(stringResult, false));
assertEquals(false, stringResult.contains("ERROR"));
assertTrue(stringContainsLine(stringResult, this.alterVm1Name + ".*Region \"/" + this.alterRegionName + "\" altered.*"));
assertTrue(stringContainsLine(stringResult, this.alterVm2Name + ".*Region \"/" + this.alterRegionName + "\" altered.*"));
this.alterVm1.invoke(() -> {
RegionAttributes attributes = getCache().getRegion(alterRegionName).getAttributes();
assertEquals(5764, attributes.getEvictionAttributes().getMaximum());
});
this.alterVm2.invoke(() -> {
RegionAttributes attributes = getCache().getRegion(alterRegionName).getAttributes();
assertEquals(5764, attributes.getEvictionAttributes().getMaximum());
});
commandStringBuilder = new CommandStringBuilder(CliStrings.ALTER_REGION);
commandStringBuilder.addOption(CliStrings.ALTER_REGION__REGION, "/" + this.alterRegionName);
commandStringBuilder.addOption(CliStrings.ALTER_REGION__GROUP, "Group2");
commandStringBuilder.addOption(CliStrings.ALTER_REGION__EVICTIONMAX, "6963");
cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
stringResult = commandResultToString(cmdResult);
assertEquals(3, countLinesInString(stringResult, false));
assertEquals(false, stringResult.contains("ERROR"));
assertFalse(stringContainsLine(stringResult, this.alterVm1Name + ".*Region \"/" + this.alterRegionName + "\" altered.*"));
assertTrue(stringContainsLine(stringResult, this.alterVm2Name + ".*Region \"/" + this.alterRegionName + "\" altered.*"));
this.alterVm1.invoke(() -> {
RegionAttributes attributes = getCache().getRegion(alterRegionName).getAttributes();
assertEquals(5764, attributes.getEvictionAttributes().getMaximum());
});
this.alterVm2.invoke(() -> {
RegionAttributes attributes = getCache().getRegion(alterRegionName).getAttributes();
assertEquals(6963, attributes.getEvictionAttributes().getMaximum());
});
}
Aggregations