use of org.apache.geode.management.internal.cli.util.CommandStringBuilder in project geode by apache.
the class IndexCommandsDUnitTest method testCreateIndexMultipleIterators.
public void testCreateIndexMultipleIterators() {
setupSystem();
CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_INDEX);
csb.addOption(CliStrings.CREATE_INDEX__NAME, indexName);
csb.addOption(CliStrings.CREATE_INDEX__EXPRESSION, "\"h.low\"");
csb.addOption(CliStrings.CREATE_INDEX__REGION, "\"/StocksParReg s, s.history h\"");
String commandString = csb.toString();
writeToLog("Command String :\n ", commandString);
CommandResult commandResult = executeCommand(commandString);
String resultAsString = commandResultToString(commandResult);
writeToLog("testCreateIndexMultipleIterators", resultAsString);
assertEquals(Status.OK, commandResult.getStatus());
csb = new CommandStringBuilder(CliStrings.LIST_INDEX);
commandString = csb.toString();
commandResult = executeCommand(commandString);
resultAsString = commandResultToString(commandResult);
writeToLog("testCreateIndexMultipleIterators", resultAsString);
assertEquals(Status.OK, commandResult.getStatus());
assertTrue(resultAsString.contains(indexName));
}
use of org.apache.geode.management.internal.cli.util.CommandStringBuilder in project geode by apache.
the class IndexCommandsDUnitTest method testCreateAndDestroyIndexWithIncorrectInput.
@Test
public void testCreateAndDestroyIndexWithIncorrectInput() {
setupSystem();
CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_INDEX);
csb.addOption(CliStrings.CREATE_INDEX__NAME, indexName);
csb.addOption(CliStrings.CREATE_INDEX__EXPRESSION, "key");
csb.addOption(CliStrings.CREATE_INDEX__REGION, "/StocksParReg");
csb.addOption(CliStrings.CREATE_INDEX__TYPE, "hash");
String commandString = csb.toString();
CommandResult commandResult = executeCommand(commandString);
String resultAsString = commandResultToString(commandResult);
assertEquals(commandResult.getStatus(), Status.OK);
// CREATE the same index
csb = new CommandStringBuilder(CliStrings.CREATE_INDEX);
csb.addOption(CliStrings.CREATE_INDEX__NAME, indexName);
csb.addOption(CliStrings.CREATE_INDEX__EXPRESSION, "key");
csb.addOption(CliStrings.CREATE_INDEX__REGION, "/StocksParReg");
csb.addOption(CliStrings.CREATE_INDEX__TYPE, "hash");
commandString = csb.toString();
commandResult = executeCommand(commandString);
resultAsString = commandResultToString(commandResult);
assertTrue(commandResult.getStatus().equals(Status.ERROR));
// assertTrue(resultAsString.contains(CliStrings.format(CliStrings.CREATE_INDEX__NAME__CONFLICT,
// indexName)));
writeToLog("Command String :\n ", commandString);
writeToLog("testCreateAndDestroyIndexWithIncorrectInput", resultAsString);
// Create index on a wrong regionPath
csb = new CommandStringBuilder(CliStrings.CREATE_INDEX);
csb.addOption(CliStrings.CREATE_INDEX__NAME, indexName);
csb.addOption(CliStrings.CREATE_INDEX__EXPRESSION, "key");
csb.addOption(CliStrings.CREATE_INDEX__REGION, "/StocsParReg");
csb.addOption(CliStrings.CREATE_INDEX__TYPE, "hash");
commandString = csb.toString();
commandResult = executeCommand(commandString);
resultAsString = commandResultToString(commandResult);
writeToLog("Command String :\n ", commandString);
writeToLog("testCreateAndDestroyIndexWithIncorrectInput", resultAsString);
assertTrue(commandResult.getStatus().equals(Status.ERROR));
// assertTrue(resultAsString.contains(CliStrings.format(CliStrings.CREATE_INDEX__INVALID__REGIONPATH,
// "/StocsParReg")));
// Create index with wrong expression
csb = new CommandStringBuilder(CliStrings.CREATE_INDEX);
csb.addOption(CliStrings.CREATE_INDEX__NAME, "Id2");
csb.addOption(CliStrings.CREATE_INDEX__EXPRESSION, "rey");
csb.addOption(CliStrings.CREATE_INDEX__REGION, "/StocksParReg");
csb.addOption(CliStrings.CREATE_INDEX__TYPE, "hash");
commandString = csb.toString();
commandResult = executeCommand(commandString);
resultAsString = commandResultToString(commandResult);
writeToLog("Command String :\n ", commandString);
writeToLog("testCreateAndDestroyIndexWithIncorrectInput", resultAsString);
assertTrue(commandResult.getStatus().equals(Status.ERROR));
// Create index with wrong type
csb = new CommandStringBuilder(CliStrings.CREATE_INDEX);
csb.addOption(CliStrings.CREATE_INDEX__NAME, indexName);
csb.addOption(CliStrings.CREATE_INDEX__EXPRESSION, "key");
csb.addOption(CliStrings.CREATE_INDEX__REGION, "/StocksParReg");
csb.addOption(CliStrings.CREATE_INDEX__TYPE, "bash");
commandString = csb.toString();
commandResult = executeCommand(commandString);
resultAsString = commandResultToString(commandResult);
writeToLog("Command String :\n ", commandString);
writeToLog("testCreateAndDestroyIndexWithIncorrectInput", resultAsString);
assertTrue(resultAsString.contains(CliStrings.CREATE_INDEX__INVALID__INDEX__TYPE__MESSAGE));
assertTrue(commandResult.getStatus().equals(Status.ERROR));
// Destroy index with incorrect indexName
csb = new CommandStringBuilder(CliStrings.DESTROY_INDEX);
csb.addOption(CliStrings.DESTROY_INDEX__NAME, "Id2");
commandString = csb.toString();
commandResult = executeCommand(commandString);
resultAsString = commandResultToString(commandResult);
writeToLog("Command String :\n ", commandString);
writeToLog("testCreateAndDestroyIndexWithIncorrectInput", resultAsString);
assertTrue(commandResult.getStatus().equals(Status.ERROR));
assertTrue(resultAsString.contains(CliStrings.format(CliStrings.DESTROY_INDEX__INDEX__NOT__FOUND, "Id2")));
// Destroy index with incorrect region
csb = new CommandStringBuilder(CliStrings.DESTROY_INDEX);
csb.addOption(CliStrings.DESTROY_INDEX__NAME, indexName);
csb.addOption(CliStrings.DESTROY_INDEX__REGION, "Region");
commandString = csb.toString();
commandResult = executeCommand(commandString);
resultAsString = commandResultToString(commandResult);
writeToLog("Command String :\n ", commandString);
writeToLog("testCreateAndDestroyIndexWithIncorrectInput", resultAsString);
assertTrue(commandResult.getStatus().equals(Status.ERROR));
assertTrue(resultAsString.contains(CliStrings.format(CliStrings.DESTROY_INDEX__REGION__NOT__FOUND, "Region")));
// Destroy index with incorrect memberName
csb = new CommandStringBuilder(CliStrings.DESTROY_INDEX);
csb.addOption(CliStrings.DESTROY_INDEX__NAME, indexName);
csb.addOption(CliStrings.DESTROY_INDEX__REGION, "Region");
csb.addOption(CliStrings.DESTROY_INDEX__MEMBER, "wrongOne");
commandString = csb.toString();
commandResult = executeCommand(commandString);
resultAsString = commandResultToString(commandResult);
writeToLog("Command String :\n ", commandString);
writeToLog("testCreateAndDestroyIndexWithIncorrectInput", resultAsString);
assertTrue(commandResult.getStatus().equals(Status.ERROR));
// Destroy index with no option
csb = new CommandStringBuilder(CliStrings.DESTROY_INDEX);
commandString = csb.toString();
commandResult = executeCommand(commandString);
resultAsString = commandResultToString(commandResult);
writeToLog("Command String :\n ", commandString);
writeToLog("testCreateAndDestroyIndexWithIncorrectInput", resultAsString);
assertTrue(commandResult.getStatus().equals(Status.ERROR));
}
use of org.apache.geode.management.internal.cli.util.CommandStringBuilder in project geode by apache.
the class IndexCommandsDUnitTest method testCreateAndDestroyIndexOnMember.
@Test
public void testCreateAndDestroyIndexOnMember() {
setupSystem();
/***
* Basic Create and Destroy
*/
CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_INDEX);
csb.addOption(CliStrings.CREATE_INDEX__NAME, indexName);
csb.addOption(CliStrings.CREATE_INDEX__EXPRESSION, "key");
csb.addOption(CliStrings.CREATE_INDEX__REGION, "/StocksParReg");
csb.addOption(CliStrings.CREATE_INDEX__MEMBER, VM1Name);
csb.addOption(CliStrings.CREATE_INDEX__TYPE, "key");
String commandString = csb.toString();
CommandResult commandResult = executeCommand(commandString);
String resultAsString = commandResultToString(commandResult);
writeToLog("Command String :\n ", commandString);
writeToLog("testCreateAndDestroyIndexOnMember", resultAsString);
assertEquals(Status.OK, commandResult.getStatus());
csb = new CommandStringBuilder(CliStrings.LIST_INDEX);
commandString = csb.toString();
commandResult = executeCommand(commandString);
resultAsString = commandResultToString(commandResult);
writeToLog("Command String :\n ", commandString);
writeToLog("testCreateAndDestroyIndexOnMember", resultAsString);
assertEquals(Status.OK, commandResult.getStatus());
assertTrue(resultAsString.contains(indexName));
assertTrue(resultAsString.contains(VM1Name));
csb = new CommandStringBuilder(CliStrings.DESTROY_INDEX);
csb.addOption(CliStrings.DESTROY_INDEX__NAME, indexName);
csb.addOption(CliStrings.DESTROY_INDEX__REGION, "/StocksParReg");
csb.addOption(CliStrings.DESTROY_INDEX__MEMBER, VM1Name);
commandString = csb.toString();
commandResult = executeCommand(commandString);
resultAsString = commandResultToString(commandResult);
writeToLog("Command String :\n ", commandString);
writeToLog("testCreateAndDestroyIndexOnMember", resultAsString);
assertEquals(commandResult.getStatus(), Status.OK);
commandResult = executeCommand(CliStrings.LIST_INDEX);
resultAsString = commandResultToString(commandResult);
writeToLog("Command String :\n ", commandString);
writeToLog("testCreateAndDestroyIndexOnMember", resultAsString);
assertEquals(commandResult.getStatus(), Status.OK);
assertFalse(resultAsString.contains(VM1Name));
}
use of org.apache.geode.management.internal.cli.util.CommandStringBuilder in project geode by apache.
the class IndexCommandsDUnitTest method testCreateDestroyUpdatesSharedConfig.
/**
* Asserts that creating and destroying indexes correctly updates the shared configuration.
*/
// GEODE-1954
@Category(FlakyTest.class)
@Test
public void testCreateDestroyUpdatesSharedConfig() {
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 = "testIndexSharedConfigRegion";
final String groupName = "testIndexSharedConfigGroup";
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));
// Start the Locator and wait for shared configuration to be available
final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
final File locatorLogFile = new File("locator-" + locatorPort + ".log");
try {
final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort, locatorLogFile, null, locatorProps);
WaitCriterion wc = new WaitCriterion() {
@Override
public boolean done() {
return locator.isSharedConfigurationRunning();
}
@Override
public String description() {
return "Waiting for shared configuration to be started";
}
};
Wait.waitForCriterion(wc, 5000, 500, true);
} catch (IOException ioex) {
fail("Unable to create a locator with a shared configuration");
}
}
});
// Start the default manager
connect(jmxHost, jmxPort, httpPort, getDefaultShell());
// Create a cache in VM 1
VM vm = Host.getHost(0).getVM(1);
vm.invoke(new SerializableRunnable() {
@Override
public void run() {
Properties localProps = new Properties();
localProps.setProperty(MCAST_PORT, "0");
localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
localProps.setProperty(GROUPS, groupName);
getSystem(localProps);
assertNotNull(getCache());
Region parReg = createParReg(regionName, getCache(), String.class, Stock.class);
parReg.put("VMW", new Stock("VMW", 98));
}
});
// Test creating the index
CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_INDEX);
commandStringBuilder.addOption(CliStrings.CREATE_INDEX__EXPRESSION, "key");
commandStringBuilder.addOption(CliStrings.CREATE_INDEX__NAME, indexName);
commandStringBuilder.addOption(CliStrings.CREATE_INDEX__GROUP, groupName);
commandStringBuilder.addOption(CliStrings.CREATE_INDEX__REGION, "\"/" + regionName + " p\"");
CommandResult cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure the index exists in the shared config
Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
ClusterConfigurationService sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
String xmlFromConfig;
try {
xmlFromConfig = sharedConfig.getConfiguration(groupName).getCacheXmlContent();
assertTrue(xmlFromConfig.contains(indexName));
} catch (Exception e) {
Assert.fail("Error occurred in cluster configuration service", e);
}
}
});
// Restart a member and make sure he gets the shared configuration
vm = Host.getHost(0).getVM(1);
vm.invoke(new SerializableRunnable() {
@Override
public void run() {
getCache().close();
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 cache = getCache();
assertNotNull(cache);
Region region = cache.getRegion(regionName);
assertNotNull(region);
Index index = cache.getQueryService().getIndex(region, indexName);
assertNotNull(index);
}
});
// Test destroying the index
commandStringBuilder = new CommandStringBuilder(CliStrings.DESTROY_INDEX);
commandStringBuilder.addOption(CliStrings.DESTROY_INDEX__NAME, indexName);
commandStringBuilder.addOption(CliStrings.DESTROY_INDEX__GROUP, groupName);
commandStringBuilder.addOption(CliStrings.DESTROY_INDEX__REGION, "/" + regionName);
cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure the index was removed from the shared config
Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
ClusterConfigurationService sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
String xmlFromConfig;
try {
xmlFromConfig = sharedConfig.getConfiguration(groupName).getCacheXmlContent();
assertFalse(xmlFromConfig.contains(indexName));
} catch (Exception e) {
Assert.fail("Error occurred in cluster configuration service", e);
}
}
});
// Restart the data member cache to make sure that the index is destroyed.
vm = Host.getHost(0).getVM(1);
vm.invoke(new SerializableRunnable() {
@Override
public void run() {
getCache().close();
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 cache = getCache();
assertNotNull(cache);
Region region = cache.getRegion(regionName);
assertNotNull(region);
Index index = cache.getQueryService().getIndex(region, indexName);
assertNull(index);
}
});
}
use of org.apache.geode.management.internal.cli.util.CommandStringBuilder in project geode by apache.
the class IndexCommandsDUnitTest method testCreateMultipleIndexes.
// GEODE-1048: HeadlessGFSH, random ports
@Category(FlakyTest.class)
@Test
public void testCreateMultipleIndexes() {
setupSystem();
CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DEFINE_INDEX);
csb.addOption(CliStrings.CREATE_INDEX__NAME, indexName);
csb.addOption(CliStrings.CREATE_INDEX__EXPRESSION, "key");
csb.addOption(CliStrings.CREATE_INDEX__REGION, "/StocksParReg");
String commandString = csb.toString();
writeToLog("Command String :\n ", commandString);
CommandResult commandResult = executeCommand(commandString);
String resultAsString = commandResultToString(commandResult);
writeToLog("testCreateMultipleIndexes", resultAsString);
assertEquals(Status.OK, commandResult.getStatus());
csb = new CommandStringBuilder(CliStrings.DEFINE_INDEX);
csb.addOption(CliStrings.CREATE_INDEX__NAME, indexName + "2");
csb.addOption(CliStrings.CREATE_INDEX__EXPRESSION, "key");
csb.addOption(CliStrings.CREATE_INDEX__REGION, "/StocksParReg");
csb = new CommandStringBuilder(CliStrings.CREATE_DEFINED_INDEXES);
commandString = csb.toString();
commandResult = executeCommand(commandString);
resultAsString = commandResultToString(commandResult);
assertEquals(Status.OK, commandResult.getStatus());
csb = new CommandStringBuilder(CliStrings.LIST_INDEX);
commandString = csb.toString();
commandResult = executeCommand(commandString);
resultAsString = commandResultToString(commandResult);
assertEquals(Status.OK, commandResult.getStatus());
assertTrue(resultAsString.contains(indexName));
}
Aggregations