use of org.apache.geode.distributed.LocatorLauncher.Builder in project geode by apache.
the class HostedLocatorsDUnitTest method testGetAllHostedLocatorsUsingPortZero.
@Test
public void testGetAllHostedLocatorsUsingPortZero() throws Exception {
final InternalDistributedSystem system = getSystem();
final String dunitLocator = system.getConfig().getLocators();
assertNotNull(dunitLocator);
assertFalse(dunitLocator.isEmpty());
// This will eventually contain the ports used by locators
final int[] ports = new int[] { 0, 0, 0, 0 };
final String uniqueName = getUniqueName();
for (int i = 0; i < 4; i++) {
final int whichvm = i;
Integer port = (Integer) Host.getHost(0).getVM(whichvm).invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
try {
System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "locators", dunitLocator);
System.setProperty(DistributionConfig.GEMFIRE_PREFIX + MCAST_PORT, "0");
final String name = uniqueName + "-" + whichvm;
final File subdir = new File(name);
subdir.mkdir();
assertTrue(subdir.exists() && subdir.isDirectory());
final Builder builder = new Builder().setMemberName(name).setPort(ports[whichvm]).setRedirectOutput(true).setWorkingDirectory(name);
launcher = builder.build();
assertEquals(Status.ONLINE, launcher.start().getStatus());
waitForLocatorToStart(launcher, TIMEOUT_MILLISECONDS, 10, true);
return launcher.getPort();
} finally {
System.clearProperty(DistributionConfig.GEMFIRE_PREFIX + "locators");
System.clearProperty(DistributionConfig.GEMFIRE_PREFIX + MCAST_PORT);
}
}
});
ports[i] = port;
}
final String host = SocketCreator.getLocalHost().getHostAddress();
final Set<String> locators = new HashSet<String>();
locators.add(host + "[" + dunitLocator.substring(dunitLocator.indexOf("[") + 1, dunitLocator.indexOf("]")) + "]");
for (int port : ports) {
locators.add(host + "[" + port + "]");
}
// validation within non-locator
final DistributionManager dm = (DistributionManager) system.getDistributionManager();
final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
assertEquals(5, locatorIds.size());
final Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
assertTrue(!hostedLocators.isEmpty());
assertEquals(5, hostedLocators.size());
for (InternalDistributedMember member : hostedLocators.keySet()) {
assertEquals(1, hostedLocators.get(member).size());
final String hostedLocator = hostedLocators.get(member).iterator().next();
assertTrue(locators + " does not contain " + hostedLocator, locators.contains(hostedLocator));
}
// validate fix for #46324
for (int whichvm = 0; whichvm < 4; whichvm++) {
Host.getHost(0).getVM(whichvm).invoke(new SerializableRunnable() {
@Override
public void run() {
final DistributionManager dm = (DistributionManager) InternalDistributedSystem.getAnyInstance().getDistributionManager();
final InternalDistributedMember self = dm.getDistributionManagerId();
final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
assertTrue(locatorIds.contains(self));
final Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
assertTrue("hit bug #46324: " + hostedLocators + " is missing " + InternalLocator.getLocatorStrings() + " for " + self, hostedLocators.containsKey(self));
}
});
}
// validation with locators
for (int whichvm = 0; whichvm < 4; whichvm++) {
Host.getHost(0).getVM(whichvm).invoke(new SerializableRunnable() {
@Override
public void run() {
final DistributionManager dm = (DistributionManager) InternalDistributedSystem.getAnyInstance().getDistributionManager();
final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
assertEquals(5, locatorIds.size());
final Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
assertTrue(!hostedLocators.isEmpty());
assertEquals(5, hostedLocators.size());
for (InternalDistributedMember member : hostedLocators.keySet()) {
assertEquals(1, hostedLocators.get(member).size());
final String hostedLocator = hostedLocators.get(member).iterator().next();
assertTrue(locators + " does not contain " + hostedLocator, locators.contains(hostedLocator));
}
}
});
}
}
use of org.apache.geode.distributed.LocatorLauncher.Builder in project geode by apache.
the class LocatorLauncherRemoteIntegrationTest method testStopUsingPid.
@Test
public void testStopUsingPid() throws Throwable {
final List<String> jvmArguments = getJvmArguments();
final List<String> command = new ArrayList<String>();
command.add(new File(new File(System.getProperty("java.home"), "bin"), "java").getCanonicalPath());
for (String jvmArgument : jvmArguments) {
command.add(jvmArgument);
}
command.add("-cp");
command.add(System.getProperty("java.class.path"));
command.add(LocatorLauncher.class.getName());
command.add(LocatorLauncher.Command.START.getName());
command.add(getUniqueName());
command.add("--port=" + this.locatorPort);
command.add("--redirect-output");
this.process = new ProcessBuilder(command).directory(this.temporaryFolder.getRoot()).start();
this.processOutReader = new ProcessStreamReader.Builder(this.process).inputStream(this.process.getInputStream()).inputListener(createLoggingListener("sysout", getUniqueName() + "#sysout")).build().start();
this.processErrReader = new ProcessStreamReader.Builder(this.process).inputStream(this.process.getErrorStream()).inputListener(createLoggingListener("syserr", getUniqueName() + "#syserr")).build().start();
// wait for locator to start
int pid = 0;
LocatorLauncher pidLauncher = null;
final LocatorLauncher dirLauncher = new LocatorLauncher.Builder().setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath()).build();
try {
waitForLocatorToStart(dirLauncher);
// validate the pid file and its contents
this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.LOCATOR.getPidFileName());
assertTrue(this.pidFile.exists());
pid = readPid(this.pidFile);
assertTrue(pid > 0);
assertTrue(ProcessUtils.isProcessAlive(pid));
// validate log file was created
final String logFileName = getUniqueName() + ".log";
assertTrue("Log file should exist: " + logFileName, new File(this.temporaryFolder.getRoot(), logFileName).exists());
// use launcher with pid
pidLauncher = new Builder().setPid(pid).build();
assertNotNull(pidLauncher);
assertFalse(pidLauncher.isRunning());
// validate the status
final LocatorState status = pidLauncher.status();
assertNotNull(status);
assertEquals(Status.ONLINE, status.getStatus());
assertEquals(pid, status.getPid().intValue());
} catch (Throwable e) {
this.errorCollector.addError(e);
}
// stop the locator
try {
if (pidLauncher == null) {
assertEquals(Status.STOPPED, dirLauncher.stop().getStatus());
} else {
assertEquals(Status.STOPPED, pidLauncher.stop().getStatus());
}
waitForPidToStop(pid);
waitForFileToDelete(pidFile);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
}
use of org.apache.geode.distributed.LocatorLauncher.Builder in project geode by apache.
the class LocatorLauncherRemoteIntegrationTest method testStartCreatesPidFile.
/*
* // TODO: fix up this test
*
* this.temporaryFolder.getRoot() = new File(getUniqueName());
* this.temporaryFolder.getRoot().mkdir();
* assertTrue(this.temporaryFolder.getRoot().isDirectory() &&
* this.temporaryFolder.getRoot().canWrite());
*
* // launch LocatorLauncherForkingProcess which then launches the GemFire
* Locator final List<String> jvmArguments = getJvmArguments();
*
* final List<String> command = new ArrayList<String>(); command.add(new
* File(new File(System.getProperty("java.home"), "bin"),
* "java").getCanonicalPath()); for (String jvmArgument : jvmArguments) {
* command.add(jvmArgument); } command.add("-cp");
* command.add(System.getProperty("java.class.path"));
* command.add(LocatorLauncherRemoteDUnitTest.class.getName().concat("$").
* concat(LocatorLauncherForkingProcess.class.getSimpleName()));
* command.add(String.valueOf(this.locatorPort));
*
* this.process = new
* ProcessBuilder(command).directory(this.temporaryFolder.getRoot()).start(
* ); this.processOutReader = new
* ProcessStreamReader.Builder(this.process).inputStream(this.process.
* getInputStream()).build().start(); this.processErrReader = new
* ProcessStreamReader.Builder(this.process).inputStream(this.process.
* getErrorStream()).build().start();
*
* Thread waiting = new Thread(new Runnable() { public void run() { try {
* assertIndexDetailsEquals(0, process.waitFor()); } catch
* (InterruptedException ignore) {
* logger.error("Interrupted while waiting for process!", ignore); } } });
*
* try { waiting.start(); waiting.join(TIMEOUT_MILLISECONDS);
* assertFalse("Process took too long and timed out!", waiting.isAlive());
* } finally { if (waiting.isAlive()) { waiting.interrupt(); } }
*
* LocatorLauncher locatorLauncher = new
* Builder().setWorkingDirectory(this.temporaryFolder.getRoot().
* getCanonicalPath()).build();
*
* assertIndexDetailsEquals(Status.ONLINE,
* locatorLauncher.status().getStatus());
* assertIndexDetailsEquals(Status.STOPPED,
* locatorLauncher.stop().getStatus()); }
*/
// GEODE-473: random ports, BindException, forks JVM, uses
@Category(FlakyTest.class)
// ErrorCollector
@Test
public void testStartCreatesPidFile() throws Throwable {
// build and start the locator
final List<String> jvmArguments = getJvmArguments();
final List<String> command = new ArrayList<String>();
command.add(new File(new File(System.getProperty("java.home"), "bin"), "java").getCanonicalPath());
for (String jvmArgument : jvmArguments) {
command.add(jvmArgument);
}
command.add("-cp");
command.add(System.getProperty("java.class.path"));
command.add(LocatorLauncher.class.getName());
command.add(LocatorLauncher.Command.START.getName());
command.add(getUniqueName());
command.add("--port=" + this.locatorPort);
command.add("--redirect-output");
this.process = new ProcessBuilder(command).directory(this.temporaryFolder.getRoot()).start();
this.processOutReader = new ProcessStreamReader.Builder(this.process).inputStream(this.process.getInputStream()).build().start();
this.processErrReader = new ProcessStreamReader.Builder(this.process).inputStream(this.process.getErrorStream()).build().start();
int pid = 0;
this.launcher = new LocatorLauncher.Builder().setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath()).build();
try {
waitForLocatorToStart(this.launcher);
// validate the pid file and its contents
this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.LOCATOR.getPidFileName());
assertTrue(this.pidFile.exists());
pid = readPid(this.pidFile);
assertTrue(pid > 0);
assertTrue(ProcessUtils.isProcessAlive(pid));
final String logFileName = getUniqueName() + ".log";
assertTrue("Log file should exist: " + logFileName, new File(this.temporaryFolder.getRoot(), logFileName).exists());
// check the status
final LocatorState locatorState = this.launcher.status();
assertNotNull(locatorState);
assertEquals(Status.ONLINE, locatorState.getStatus());
} catch (Throwable e) {
this.errorCollector.addError(e);
}
// stop the locator
try {
assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
waitForPidToStop(pid);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
}
use of org.apache.geode.distributed.LocatorLauncher.Builder in project geode by apache.
the class LocatorLauncherTest method testBuild.
@Test
public void testBuild() throws Exception {
Builder builder = new Builder();
LocatorLauncher launcher = builder.setCommand(Command.START).setDebug(true).setHostnameForClients("beanstock.vmware.com").setMemberName("Beanstock").setPort(8192).build();
assertThat(launcher).isNotNull();
assertEquals(builder.getCommand(), launcher.getCommand());
assertTrue(launcher.isDebugging());
assertEquals(builder.getHostnameForClients(), launcher.getHostnameForClients());
assertEquals(builder.getMemberName(), launcher.getMemberName());
assertEquals(builder.getPort(), launcher.getPort());
assertEquals(builder.getWorkingDirectory(), launcher.getWorkingDirectory());
assertFalse(launcher.isHelping());
assertFalse(launcher.isRunning());
}
use of org.apache.geode.distributed.LocatorLauncher.Builder in project geode by apache.
the class LocatorLauncherTest method testForceSetToTrue.
@Test
public void testForceSetToTrue() {
Builder builder = new Builder();
builder.parseArguments("start", "--force");
assertTrue(Boolean.TRUE.equals(builder.getForce()));
}
Aggregations