use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.
the class CreateAlterDestroyRegionCommandsDUnitTest method testCreateRegionWithGoodCompressor.
/**
* Asserts that the "compressor" option for the "create region" command succeeds for a recognized
* compressor.
*/
@Test
public void testCreateRegionWithGoodCompressor() {
setUpJmxManagerOnVm0ThenConnect(null);
VM vm = Host.getHost(0).getVM(1);
// Create a cache in vm 1
vm.invoke(() -> {
assertNotNull(getCache());
});
// Run create region command with compression
CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_REGION);
commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGION, "compressedRegion");
commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, "REPLICATE");
commandStringBuilder.addOption(CliStrings.CREATE_REGION__COMPRESSOR, RegionEntryContext.DEFAULT_COMPRESSION_PROVIDER);
CommandResult cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure our region exists with compression enabled
vm.invoke(() -> {
Region region = getCache().getRegion("compressedRegion");
assertNotNull(region);
assertTrue(SnappyCompressor.getDefaultInstance().equals(region.getAttributes().getCompressor()));
});
// cleanup
commandStringBuilder = new CommandStringBuilder(CliStrings.DESTROY_REGION);
commandStringBuilder.addOption(CliStrings.DESTROY_REGION__REGION, "compressedRegion");
cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
}
use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.
the class CreateAlterDestroyRegionCommandsDUnitTest method testDestroyLocalRegions.
@Test
public void testDestroyLocalRegions() {
setUpJmxManagerOnVm0ThenConnect(null);
for (int i = 1; i <= 3; i++) {
Host.getHost(0).getVM(i).invoke(() -> {
final Cache cache = getCache();
RegionFactory<Object, Object> factory = cache.createRegionFactory(RegionShortcut.REPLICATE);
factory.setScope(Scope.LOCAL);
factory.create("Customer");
});
}
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());
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"));
});
}
}
use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.
the class CreateAlterDestroyRegionCommandsDUnitTest method testDestroyRegionWithSharedConfig.
@Test
public void testDestroyRegionWithSharedConfig() {
disconnectAllFromDS();
final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
jmxPort = ports[0];
httpPort = ports[1];
try {
jmxHost = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException ignore) {
jmxHost = "localhost";
}
final String regionName = "testRegionSharedConfigRegion";
final String regionPath = "/" + regionName;
final String groupName = "testRegionSharedConfigGroup";
// Start the Locator and wait for shared configuration to be available
final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
final Properties locatorProps = new Properties();
locatorProps.setProperty(NAME, "Locator");
locatorProps.setProperty(MCAST_PORT, "0");
locatorProps.setProperty(LOG_LEVEL, "fine");
locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
locatorProps.setProperty(JMX_MANAGER, "true");
locatorProps.setProperty(JMX_MANAGER_START, "true");
locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
Host.getHost(0).getVM(0).invoke(() -> {
final File locatorLogFile = new File("locator-" + locatorPort + ".log");
try {
final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort, locatorLogFile, null, locatorProps);
waitAtMost(5, TimeUnit.SECONDS).until(() -> locator.isSharedConfigurationRunning());
} catch (IOException ioex) {
fail("Unable to create a locator with a shared configuration");
}
});
connect(jmxHost, jmxPort, httpPort, getDefaultShell());
// Create a cache in VM 1
VM vm = Host.getHost(0).getVM(1);
vm.invoke(() -> {
Properties localProps = new Properties();
localProps.setProperty(MCAST_PORT, "0");
localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
localProps.setProperty(GROUPS, groupName);
getSystem(localProps);
assertNotNull(getCache());
});
// Test creating the region
CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_REGION);
commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGION, regionName);
commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, "REPLICATE");
commandStringBuilder.addOption(CliStrings.CREATE_REGION__STATISTICSENABLED, "true");
commandStringBuilder.addOption(CliStrings.CREATE_REGION__GROUP, groupName);
CommandResult cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure that the region has been registered with the Manager MXBean
waitForRegionMBeanCreation(regionPath, 1);
// Make sure the region exists in the shared config
Host.getHost(0).getVM(0).invoke(() -> {
ClusterConfigurationService sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
try {
assertTrue(sharedConfig.getConfiguration(groupName).getCacheXmlContent().contains(regionName));
} catch (Exception e) {
fail("Error occurred in cluster configuration service");
}
});
// Test destroying the region
commandStringBuilder = new CommandStringBuilder(CliStrings.DESTROY_REGION);
commandStringBuilder.addOption(CliStrings.DESTROY_REGION__REGION, regionName);
cmdResult = executeCommand(commandStringBuilder.toString());
getLogWriter().info("#SB" + commandResultToString(cmdResult));
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure the region was removed from the shared config
Host.getHost(0).getVM(0).invoke(() -> {
ClusterConfigurationService sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
try {
assertFalse(sharedConfig.getConfiguration(groupName).getCacheXmlContent().contains(regionName));
} catch (Exception e) {
fail("Error occurred in cluster configuration service");
}
});
// Restart the data vm to make sure the region is not existing any more
vm = Host.getHost(0).getVM(1);
vm.invoke(() -> {
Cache cache = getCache();
assertNotNull(cache);
cache.close();
assertTrue(cache.isClosed());
Properties localProps = new Properties();
localProps.setProperty(MCAST_PORT, "0");
localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
localProps.setProperty(GROUPS, groupName);
localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
getSystem(localProps);
cache = getCache();
assertNotNull(cache);
Region region = cache.getRegion(regionName);
assertNull(region);
return null;
});
}
use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.
the class CliCommandTestBase method extractCommandResult.
/**
* Utility method for finding the CommandResult object in the Map of CommandOutput objects.
*
* @param commandOutput CommandOutput Map to search
* @return The CommandResult object or null if not found.
*/
protected CommandResult extractCommandResult(Map<String, Object> commandOutput) {
assert (commandOutput != null);
for (Object resultObject : commandOutput.values()) {
if (resultObject instanceof CommandResult) {
CommandResult result = (CommandResult) resultObject;
result.resetToFirstLine();
return result;
}
}
return null;
}
use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.
the class ConfigCommandsDUnitTest method testAlterRuntimeConfigOnAllMembers.
@Test
public void testAlterRuntimeConfigOnAllMembers() throws Exception {
final String member1 = "VM1";
final String controller = "controller";
String controllerDirectory = this.temporaryFolder.newFolder(controller).getAbsolutePath();
String controllerStatFilePath = new File(controllerDirectory, "stat.gfs").getAbsolutePath();
setUpJmxManagerOnVm0ThenConnect(null);
Properties localProps = new Properties();
localProps.setProperty(NAME, controller);
localProps.setProperty(LOG_LEVEL, "error");
getSystem(localProps);
final GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
final DistributionConfig config = cache.getSystem().getConfig();
Host.getHost(0).getVM(1).invoke(new SerializableRunnable() {
public void run() {
Properties localProps = new Properties();
localProps.setProperty(NAME, member1);
getSystem(localProps);
Cache cache = getCache();
}
});
CommandStringBuilder csb = new CommandStringBuilder(CliStrings.ALTER_RUNTIME_CONFIG);
csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__LEVEL, "info");
csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__FILE__SIZE__LIMIT, "50");
csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__DISK__SPACE__LIMIT, "32");
csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__FILE__SIZE__LIMIT, "49");
csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLE__RATE, "2000");
csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE, controllerStatFilePath);
csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLING__ENABLED, "true");
csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT, "10");
CommandResult cmdResult = executeCommand(csb.getCommandString());
String resultString = commandResultToString(cmdResult);
getLogWriter().info("#SB Result\n");
getLogWriter().info(resultString);
assertEquals(true, cmdResult.getStatus().equals(Status.OK));
assertEquals(LogWriterImpl.INFO_LEVEL, config.getLogLevel());
assertEquals(50, config.getLogFileSizeLimit());
assertEquals(49, config.getArchiveFileSizeLimit());
assertEquals(32, config.getArchiveDiskSpaceLimit());
assertEquals(2000, config.getStatisticSampleRate());
assertEquals("stat.gfs", config.getStatisticArchiveFile().getName());
assertEquals(true, config.getStatisticSamplingEnabled());
assertEquals(10, config.getLogDiskSpaceLimit());
// Validate the changes in the vm1
Host.getHost(0).getVM(1).invoke(new SerializableRunnable() {
public void run() {
GemFireCacheImpl cacheVM1 = (GemFireCacheImpl) getCache();
DistributionConfig configVM1 = cacheVM1.getSystem().getConfig();
assertEquals(LogWriterImpl.INFO_LEVEL, configVM1.getLogLevel());
assertEquals(50, configVM1.getLogFileSizeLimit());
assertEquals(49, configVM1.getArchiveFileSizeLimit());
assertEquals(32, configVM1.getArchiveDiskSpaceLimit());
assertEquals(2000, configVM1.getStatisticSampleRate());
assertEquals("stat.gfs", configVM1.getStatisticArchiveFile().getName());
assertEquals(true, configVM1.getStatisticSamplingEnabled());
assertEquals(10, configVM1.getLogDiskSpaceLimit());
}
});
}
Aggregations