use of org.apache.geode.management.internal.cli.HeadlessGfsh in project geode by apache.
the class ClusterConfigurationDUnitTest method setup.
private Object[] setup() throws IOException {
final int locator1Port = getRandomAvailableTCPPort();
final String locator1Name = "locator1-" + locator1Port;
final String locatorLogPath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + "locator-" + locator1Port + ".log";
VM locatorAndMgr = getHost(0).getVM(3);
Object[] result = (Object[]) locatorAndMgr.invoke(() -> {
int httpPort;
int jmxPort;
String jmxHost;
try {
jmxHost = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException ignore) {
jmxHost = "localhost";
}
final int[] ports = getRandomAvailableTCPPorts(2);
jmxPort = ports[0];
httpPort = ports[1];
final File locatorLogFile = new File(locatorLogPath);
final Properties locatorProps = new Properties();
locatorProps.setProperty(NAME, locator1Name);
locatorProps.setProperty(MCAST_PORT, "0");
locatorProps.setProperty(LOG_LEVEL, "config");
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));
final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator1Port, 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";
}
};
waitForCriterion(wc, TIMEOUT, INTERVAL, true);
final Object[] results = new Object[4];
results[0] = locator1Port;
results[1] = jmxHost;
results[2] = jmxPort;
results[3] = httpPort;
return results;
});
HeadlessGfsh gfsh = getDefaultShell();
String jmxHost = (String) result[1];
int jmxPort = (Integer) result[2];
int httpPort = (Integer) result[3];
connect(jmxHost, jmxPort, httpPort, gfsh);
final String dataMemberWorkingDir = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + dataMember;
// Create a cache in VM 1
VM dataMember = getHost(0).getVM(1);
dataMember.invoke(() -> {
Properties localProps = new Properties();
File workingDir = new File(dataMemberWorkingDir);
workingDir.mkdirs();
localProps.setProperty(MCAST_PORT, "0");
localProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
localProps.setProperty(NAME, ClusterConfigurationDUnitTest.dataMember);
localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
localProps.setProperty(DEPLOY_WORKING_DIR, workingDir.getCanonicalPath());
getSystem(localProps);
InternalCache cache = getCache();
assertNotNull(cache);
return getAllNormalMembers(cache);
});
return result;
}
Aggregations