use of org.apache.geode.management.internal.cli.domain.Stock in project geode by apache.
the class IndexCommandsDUnitTest method setupSystem.
private void setupSystem() {
disconnectAllFromDS();
setUpJmxManagerOnVm0ThenConnect(null);
final String parRegName = "StocksParReg";
final VM manager = Host.getHost(0).getVM(0);
final VM vm1 = Host.getHost(0).getVM(1);
manager.invoke(new SerializableCallable() {
public Object call() {
Region parReg = createParReg(parRegName, getCache(), String.class, Stock.class);
parReg.put("VMW", new Stock("VMW", 98));
return parReg.put("APPL", new Stock("APPL", 600));
}
});
vm1.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
Properties props = new Properties();
props.setProperty(NAME, VM1Name);
props.setProperty(GROUPS, group1);
getSystem(props);
Region parReg = createParReg(parRegName, getCache(), String.class, Stock.class);
parReg.put("MSFT", new Stock("MSFT", 27));
return parReg.put("GOOG", new Stock("GOOG", 540));
}
});
}
use of org.apache.geode.management.internal.cli.domain.Stock in project geode by apache.
the class IndexCommandsDUnitTest method setupSystemPersist.
private void setupSystemPersist() {
disconnectAllFromDS();
setUpJmxManagerOnVm0ThenConnect(null);
final String parRegName = "StocksParReg";
final VM manager = Host.getHost(0).getVM(0);
final VM vm1 = Host.getHost(0).getVM(1);
manager.invoke(new SerializableCallable() {
public Object call() {
Region parReg = createParReg(parRegName, getCache(), String.class, Stock.class);
parReg.put("VMW", new Stock("VMW", 98));
Region parRegPers = createParRegWithPersistence(parRegPersName, "testCreateIndexDiskstore1", "testCreateIndexDiskDir1");
Region repRegPers = createRepRegWithPersistence(repRegPersName, "testCreateIndexDiskstore1", "testCreateIndexDiskDir1");
return parReg.put("APPL", new Stock("APPL", 600));
}
});
vm1.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
Properties props = new Properties();
props.setProperty(NAME, VM1Name);
props.setProperty(GROUPS, group1);
getSystem(props);
Region parReg = createParReg(parRegName, getCache(), String.class, Stock.class);
parReg.put("MSFT", new Stock("MSFT", 27));
Region parRegPers = createParRegWithPersistence(parRegPersName, "testCreateIndexDiskstore2", "testCreateIndexDiskDir2");
Region repRegPers = createRepRegWithPersistence(repRegPersName, "testCreateIndexDiskstore2", "testCreateIndexDiskDir2");
return parReg.put("GOOG", new Stock("GOOG", 540));
}
});
}
use of org.apache.geode.management.internal.cli.domain.Stock 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);
}
});
}
Aggregations