use of org.apache.geode.distributed.ServerLauncher.ServerState in project geode by apache.
the class ServerLauncherRemoteIntegrationTest method testRunningServerOutlivesForkingProcess.
@Test
@Ignore("TRAC bug #52304: test is broken and needs to be reworked")
public void testRunningServerOutlivesForkingProcess() throws Throwable {
// launch ServerLauncherForkingProcess which then launches server
// final List<String> command = new ArrayList<String>();
// command.add(new File(new File(System.getProperty("java.home"), "bin"),
// "java").getCanonicalPath());
// command.add("-cp");
// command.add(System.getProperty("java.class.path"));
// command.add(ServerLauncherDUnitTest.class.getName().concat("$").concat(ServerLauncherForkingProcess.class.getSimpleName()));
//
// process = new ProcessBuilder(command).directory(temporaryFolder.getRoot()).start();
// assertNotNull(process);
// processOutReader = new ProcessStreamReader(process.getInputStream(), createListener("sysout",
// getUniqueName() + "#sysout")).start();
// processErrReader = new ProcessStreamReader(process.getErrorStream(), createListener("syserr",
// getUniqueName() + "#syserr")).start();
@SuppressWarnings("unused") File file = new File(this.temporaryFolder.getRoot(), ServerLauncherForkingProcess.class.getSimpleName().concat(".log"));
// -logger.info("log file is " + file);
final ProcessWrapper pw = new ProcessWrapper.Builder().mainClass(ServerLauncherForkingProcess.class).build();
pw.execute(null, this.temporaryFolder.getRoot()).waitFor(true);
// logger.info("[testRunningServerOutlivesForkingProcess] ServerLauncherForkingProcess output
// is:\n\n"+pw.getOutput());
// // create waiting thread since waitFor does not have a timeout
// Thread waiting = new Thread(new Runnable() {
// @Override
// public void run() {
// try {
// assertIndexDetailsEquals(0, process.waitFor());
// } catch (InterruptedException e) {
// logger.error("Interrupted while waiting for process", e);
// }
// }
// });
// // start waiting thread and join to it for timeout
// try {
// waiting.start();
// waiting.join(TIMEOUT_MILLISECONDS);
// assertFalse("ServerLauncherForkingProcess took too long and caused timeout",
// waiting.isAlive());
//
// } catch (Throwable e) {
// logger.error(e);
// if (failure == null) {
// failure = e;
// }
// } finally {
// if (waiting.isAlive()) {
// waiting.interrupt();
// }
// }
// wait for server to start
int pid = 0;
final String serverName = ServerLauncherForkingProcess.class.getSimpleName() + "_server";
final ServerLauncher dirLauncher = new ServerLauncher.Builder().setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath()).build();
try {
waitForServerToStart(dirLauncher);
// validate the pid file and its contents
this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
assertTrue(this.pidFile.exists());
pid = readPid(this.pidFile);
assertTrue(pid > 0);
assertTrue(ProcessUtils.isProcessAlive(pid));
// validate log file was created
final String logFileName = serverName + ".log";
assertTrue("Log file should exist: " + logFileName, new File(this.temporaryFolder.getRoot(), logFileName).exists());
// validate the status
final ServerState actualStatus = dirLauncher.status();
assertNotNull(actualStatus);
assertEquals(Status.ONLINE, actualStatus.getStatus());
assertEquals(pid, actualStatus.getPid().intValue());
assertTrue(actualStatus.getUptime() > 0);
assertEquals(this.temporaryFolder.getRoot().getCanonicalPath(), actualStatus.getWorkingDirectory());
assertEquals(getJvmArguments(), actualStatus.getJvmArguments());
assertEquals(ManagementFactory.getRuntimeMXBean().getClassPath(), actualStatus.getClasspath());
assertEquals(GemFireVersion.getGemFireVersion(), actualStatus.getGemFireVersion());
assertEquals(System.getProperty("java.version"), actualStatus.getJavaVersion());
assertEquals(this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + serverName + ".log", actualStatus.getLogFile());
assertEquals(InetAddress.getLocalHost().getCanonicalHostName(), actualStatus.getHost());
assertEquals(serverName, actualStatus.getMemberName());
} catch (Throwable e) {
this.errorCollector.addError(e);
}
// stop the server
try {
assertEquals(Status.STOPPED, dirLauncher.stop().getStatus());
waitForPidToStop(pid);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
}
use of org.apache.geode.distributed.ServerLauncher.ServerState in project geode by apache.
the class ServerLauncherRemoteIntegrationTest method testStatusUsingPid.
/*
* this.temporaryFolder.getRoot() = new File(getUniqueName());
* this.temporaryFolder.getRoot().mkdir();
* assertTrue(this.temporaryFolder.getRoot().isDirectory() &&
* this.temporaryFolder.getRoot().canWrite());
*
* // create existing pid file this.pidFile = new
* File(this.temporaryFolder.getRoot(),
* ProcessType.SERVER.getPidFileName()); final int realPid =
* Host.getHost(0).getVM(3).invoke(() -> ProcessUtils.identifyPid());
* assertFalse("Remote pid shouldn't be the same as local pid " + realPid,
* realPid == ProcessUtils.identifyPid()); writePid(this.pidFile, realPid);
*
* // build and start the server 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(ServerLauncher.class.getName());
* command.add(ServerLauncher.Command.START.getName());
* command.add(getUniqueName()); command.add("--disable-default-server");
* 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();
*
* // collect and throw the FIRST failure Throwable failure = null;
*
* final ServerLauncher dirLauncher = new ServerLauncher.Builder()
* .setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath())
* .build(); try { waitForServerToStart(dirLauncher, 10*1000, false); }
* catch (Throwable e) { logger.error(e); if (failure == null) { failure =
* e; } }
*
* try { // check the status final ServerState serverState =
* dirLauncher.status(); assertNotNull(serverState);
* assertIndexDetailsEquals(Status.NOT_RESPONDING,
* serverState.getStatus());
*
* final String logFileName = getUniqueName()+".log";
* assertFalse("Log file should not exist: " + logFileName, new
* File(this.temporaryFolder.getRoot(), logFileName).exists());
*
* } catch (Throwable e) { logger.error(e); if (failure == null) { failure
* = e; } }
*
* // just in case the launcher started... ServerState status = null; try {
* status = dirLauncher.stop(); } catch (Throwable t) { // ignore }
*
* try { final Status theStatus = status.getStatus(); assertFalse(theStatus
* == Status.STARTING); assertFalse(theStatus == Status.ONLINE); } catch
* (Throwable e) { logger.error(e); if (failure == null) { failure = e; } }
*
* if (failure != null) { throw failure; } } //
* testStartWithExistingPidFileFails
*/
// GEODE-957: random ports, BindException, fork JVM
@Category(FlakyTest.class)
@Test
public void testStatusUsingPid() 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(ServerLauncher.class.getName());
command.add(ServerLauncher.Command.START.getName());
command.add(getUniqueName());
command.add("--disable-default-server");
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();
// wait for server to start
int pid = 0;
ServerLauncher pidLauncher = null;
this.launcher = new ServerLauncher.Builder().setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath()).build();
try {
waitForServerToStart();
// validate the pid file and its contents
this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.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 ServerState actualStatus = pidLauncher.status();
assertNotNull(actualStatus);
assertEquals(Status.ONLINE, actualStatus.getStatus());
assertEquals(pid, actualStatus.getPid().intValue());
assertTrue(actualStatus.getUptime() > 0);
assertEquals(this.temporaryFolder.getRoot().getCanonicalPath(), actualStatus.getWorkingDirectory());
assertEquals(jvmArguments, actualStatus.getJvmArguments());
assertEquals(ManagementFactory.getRuntimeMXBean().getClassPath(), actualStatus.getClasspath());
assertEquals(GemFireVersion.getGemFireVersion(), actualStatus.getGemFireVersion());
assertEquals(System.getProperty("java.version"), actualStatus.getJavaVersion());
assertEquals(this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + getUniqueName() + ".log", actualStatus.getLogFile());
assertEquals(InetAddress.getLocalHost().getCanonicalHostName(), actualStatus.getHost());
assertEquals(getUniqueName(), actualStatus.getMemberName());
} catch (Throwable e) {
this.errorCollector.addError(e);
}
// stop the server
try {
if (pidLauncher == null) {
assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
} else {
assertEquals(Status.STOPPED, pidLauncher.stop().getStatus());
}
waitForPidToStop(pid);
waitForFileToDelete(this.pidFile);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
}
use of org.apache.geode.distributed.ServerLauncher.ServerState in project geode by apache.
the class ServerLauncherRemoteIntegrationTest method testStartUsingServerPortOverridesCacheXml.
/**
* Confirms part of fix for #47664
*/
@Test
public void testStartUsingServerPortOverridesCacheXml() throws Throwable {
// generate two free ports
final int[] freeTCPPorts = AvailablePortHelper.getRandomAvailableTCPPorts(2);
// write out cache.xml with one port
final CacheCreation creation = new CacheCreation();
final RegionAttributesCreation attrs = new RegionAttributesCreation(creation);
attrs.setScope(Scope.DISTRIBUTED_ACK);
attrs.setDataPolicy(DataPolicy.REPLICATE);
creation.createRegion(getUniqueName(), attrs);
creation.addCacheServer().setPort(freeTCPPorts[0]);
File cacheXmlFile = new File(this.temporaryFolder.getRoot(), getUniqueName() + ".xml");
final PrintWriter pw = new PrintWriter(new FileWriter(cacheXmlFile), true);
CacheXmlGenerator.generate(creation, pw);
pw.close();
// launch server and specify a different port
final List<String> jvmArguments = getJvmArguments();
jvmArguments.add("-D" + DistributionConfig.GEMFIRE_PREFIX + "" + CACHE_XML_FILE + "=" + cacheXmlFile.getCanonicalPath());
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(ServerLauncher.class.getName());
command.add(ServerLauncher.Command.START.getName());
command.add(getUniqueName());
command.add("--redirect-output");
command.add("--server-port=" + freeTCPPorts[1]);
String expectedString = "java.net.BindException";
AtomicBoolean outputContainedExpectedString = new AtomicBoolean();
this.process = new ProcessBuilder(command).directory(this.temporaryFolder.getRoot()).start();
this.processOutReader = new ProcessStreamReader.Builder(this.process).inputStream(this.process.getInputStream()).inputListener(createExpectedListener("sysout", getUniqueName() + "#sysout", expectedString, outputContainedExpectedString)).build().start();
this.processErrReader = new ProcessStreamReader.Builder(this.process).inputStream(this.process.getErrorStream()).inputListener(createExpectedListener("syserr", getUniqueName() + "#syserr", expectedString, outputContainedExpectedString)).build().start();
// wait for server to start up
int pid = 0;
this.launcher = new ServerLauncher.Builder().setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath()).build();
try {
waitForServerToStart();
// validate the pid file and its contents
this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.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());
// verify server used --server-port instead of default or port in cache.xml
assertTrue(AvailablePort.isPortAvailable(freeTCPPorts[0], AvailablePort.SOCKET));
assertFalse(AvailablePort.isPortAvailable(freeTCPPorts[1], AvailablePort.SOCKET));
ServerState status = this.launcher.status();
String portString = status.getPort();
int port = Integer.valueOf(portString);
assertEquals("Port should be " + freeTCPPorts[1] + " instead of " + port, freeTCPPorts[1], port);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
// stop the server
try {
assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
waitForPidToStop(pid);
waitForFileToDelete(this.pidFile);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
}
use of org.apache.geode.distributed.ServerLauncher.ServerState in project geode by apache.
the class ServerLauncherRemoteIntegrationTest method testStatusUsingWorkingDirectory.
@Test
public void testStatusUsingWorkingDirectory() 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(ServerLauncher.class.getName());
command.add(ServerLauncher.Command.START.getName());
command.add(getUniqueName());
command.add("--disable-default-server");
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();
// wait for server to start
int pid = 0;
this.launcher = new ServerLauncher.Builder().setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath()).build();
try {
waitForServerToStart();
// validate the pid file and its contents
this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.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());
assertNotNull(this.launcher);
assertFalse(this.launcher.isRunning());
// validate the status
final ServerState actualStatus = this.launcher.status();
assertNotNull(actualStatus);
assertEquals(Status.ONLINE, actualStatus.getStatus());
assertEquals(pid, actualStatus.getPid().intValue());
assertTrue(actualStatus.getUptime() > 0);
assertEquals(this.temporaryFolder.getRoot().getCanonicalPath(), actualStatus.getWorkingDirectory());
assertEquals(jvmArguments, actualStatus.getJvmArguments());
assertEquals(ManagementFactory.getRuntimeMXBean().getClassPath(), actualStatus.getClasspath());
assertEquals(GemFireVersion.getGemFireVersion(), actualStatus.getGemFireVersion());
assertEquals(System.getProperty("java.version"), actualStatus.getJavaVersion());
assertEquals(this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + getUniqueName() + ".log", actualStatus.getLogFile());
assertEquals(InetAddress.getLocalHost().getCanonicalHostName(), actualStatus.getHost());
assertEquals(getUniqueName(), actualStatus.getMemberName());
} catch (Throwable e) {
this.errorCollector.addError(e);
}
// stop the server
try {
assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
waitForPidToStop(pid);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
}
use of org.apache.geode.distributed.ServerLauncher.ServerState in project geode by apache.
the class ServerLauncherRemoteIntegrationTest 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(ServerLauncher.class.getName());
command.add(ServerLauncher.Command.START.getName());
command.add(getUniqueName());
command.add("--disable-default-server");
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 server to start
int pid = 0;
ServerLauncher pidLauncher = null;
this.launcher = new ServerLauncher.Builder().setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath()).build();
try {
waitForServerToStart();
// validate the pid file and its contents
this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.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 ServerState status = pidLauncher.status();
assertNotNull(status);
assertEquals(Status.ONLINE, status.getStatus());
assertEquals(pid, status.getPid().intValue());
} catch (Throwable e) {
this.errorCollector.addError(e);
}
// stop the server
try {
if (pidLauncher == null) {
assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
} else {
assertEquals(Status.STOPPED, pidLauncher.stop().getStatus());
}
waitForPidToStop(pid);
waitForFileToDelete(this.pidFile);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
}
Aggregations