use of org.apache.geode.distributed.ServerLauncher.Builder in project geode by apache.
the class ServerLauncherLocalIntegrationTest method testStartUsingDisableDefaultServerSkipsPortCheck.
/**
* Confirms fix for #47778.
*/
@Test
public void testStartUsingDisableDefaultServerSkipsPortCheck() throws Throwable {
String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
// generate one free port and then use TEST_OVERRIDE_DEFAULT_PORT_PROPERTY
this.socket = SocketCreatorFactory.createNonDefaultInstance(false, false, null, null, System.getProperties()).createServerSocket(this.serverPort, 50, null, -1);
assertFalse(AvailablePort.isPortAvailable(this.serverPort, AvailablePort.SOCKET));
// build and start the server
final Builder builder = new Builder().setDisableDefaultServer(true).setMemberName(getUniqueName()).setRedirectOutput(true).setWorkingDirectory(rootFolder).set(LOG_LEVEL, "config").set(MCAST_PORT, "0");
this.launcher = builder.build();
// wait for server to start
try {
// if start succeeds without throwing exception then #47778 is fixed
this.launcher.start();
waitForServerToStart(this.launcher);
// validate the pid file and its contents
this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
assertTrue(this.pidFile.exists());
int pid = readPid(this.pidFile);
assertTrue(pid > 0);
assertTrue(ProcessUtils.isProcessAlive(pid));
assertEquals(getPid(), pid);
final ServerState status = this.launcher.status();
final String portString = status.getPort();
assertEquals("Port should be \"\" instead of " + portString, "", portString);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
// stop the server
try {
assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
waitForFileToDelete(this.pidFile);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
// verify port is still in use
this.errorCollector.checkThat(AvailablePort.isPortAvailable(this.serverPort, AvailablePort.SOCKET), is(equalTo(false)));
}
use of org.apache.geode.distributed.ServerLauncher.Builder in project geode by apache.
the class ServerLauncherLocalIntegrationTest method testStatusUsingPid.
@Test
public void testStatusUsingPid() throws Throwable {
String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
// build and start the server
final Builder builder = new Builder().setDisableDefaultServer(true).setMemberName(getUniqueName()).setRedirectOutput(true).setWorkingDirectory(rootFolder).set(LOG_LEVEL, "config").set(MCAST_PORT, "0");
assertFalse(builder.getForce());
this.launcher = builder.build();
assertFalse(this.launcher.isForcing());
ServerLauncher pidLauncher = null;
try {
this.launcher.start();
waitForServerToStart(this.launcher);
this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
assertTrue(this.pidFile.exists());
final int pid = readPid(this.pidFile);
assertTrue(pid > 0);
assertEquals(ProcessUtils.identifyPid(), pid);
pidLauncher = new Builder().setPid(pid).build();
assertNotNull(pidLauncher);
assertFalse(pidLauncher.isRunning());
final ServerState actualStatus = pidLauncher.status();
assertNotNull(actualStatus);
assertEquals(Status.ONLINE, actualStatus.getStatus());
assertEquals(pid, actualStatus.getPid().intValue());
assertTrue(actualStatus.getUptime() > 0);
// getWorkingDirectory returns user.dir instead of rootFolder because test is starting Server
// in this process (to move logFile and pidFile into temp dir)
assertEquals(ManagementFactory.getRuntimeMXBean().getClassPath(), actualStatus.getClasspath());
assertEquals(GemFireVersion.getGemFireVersion(), actualStatus.getGemFireVersion());
assertEquals(System.getProperty("java.version"), actualStatus.getJavaVersion());
assertEquals(InetAddress.getLocalHost().getCanonicalHostName(), actualStatus.getHost());
assertEquals(getUniqueName(), actualStatus.getMemberName());
} catch (Throwable e) {
this.errorCollector.addError(e);
}
if (pidLauncher == null) {
try {
assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
waitForFileToDelete(this.pidFile);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
} else {
try {
assertEquals(Status.STOPPED, pidLauncher.stop().getStatus());
waitForFileToDelete(this.pidFile);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
}
}
use of org.apache.geode.distributed.ServerLauncher.Builder in project geode by apache.
the class ServerLauncherLocalIntegrationTest method testStatusUsingWorkingDirectory.
@Test
public void testStatusUsingWorkingDirectory() throws Throwable {
String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
// build and start the server
final Builder builder = new Builder().setDisableDefaultServer(true).setMemberName(getUniqueName()).setRedirectOutput(true).setWorkingDirectory(rootFolder).set(LOG_LEVEL, "config").set(MCAST_PORT, "0");
assertFalse(builder.getForce());
this.launcher = builder.build();
assertFalse(this.launcher.isForcing());
ServerLauncher dirLauncher = null;
try {
this.launcher.start();
waitForServerToStart(this.launcher);
this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
assertTrue(this.pidFile.exists());
final int pid = readPid(this.pidFile);
assertTrue(pid > 0);
assertEquals(ProcessUtils.identifyPid(), pid);
dirLauncher = new Builder().setWorkingDirectory(rootFolder).build();
assertNotNull(dirLauncher);
assertFalse(dirLauncher.isRunning());
final ServerState actualStatus = dirLauncher.status();
assertNotNull(actualStatus);
assertEquals(Status.ONLINE, actualStatus.getStatus());
assertEquals(pid, actualStatus.getPid().intValue());
assertTrue(actualStatus.getUptime() > 0);
// getWorkingDirectory returns user.dir instead of rootFolder because test is starting Server
// in this process (to move logFile and pidFile into temp dir)
assertEquals(ManagementFactory.getRuntimeMXBean().getClassPath(), actualStatus.getClasspath());
assertEquals(GemFireVersion.getGemFireVersion(), actualStatus.getGemFireVersion());
assertEquals(System.getProperty("java.version"), actualStatus.getJavaVersion());
assertEquals(InetAddress.getLocalHost().getCanonicalHostName(), actualStatus.getHost());
assertEquals(getUniqueName(), actualStatus.getMemberName());
} catch (Throwable e) {
this.errorCollector.addError(e);
}
if (dirLauncher == null) {
try {
assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
waitForFileToDelete(this.pidFile);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
} else {
try {
assertEquals(Status.STOPPED, dirLauncher.stop().getStatus());
waitForFileToDelete(this.pidFile);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
}
}
use of org.apache.geode.distributed.ServerLauncher.Builder in project geode by apache.
the class ServerLauncherLocalIntegrationTest method testStartCreatesPidFile.
@Test
public void testStartCreatesPidFile() throws Throwable {
String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
// build and start the Server locally
final Builder builder = new Builder().setDisableDefaultServer(true).setMemberName(getUniqueName()).setRedirectOutput(true).setWorkingDirectory(rootFolder).set(LOG_LEVEL, "config").set(MCAST_PORT, "0");
this.launcher = builder.build();
assertNotNull(this.launcher);
try {
this.launcher.start();
waitForServerToStart(this.launcher);
assertEquals(Status.ONLINE, this.launcher.status().getStatus());
// validate the pid file and its contents
this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
assertTrue(this.pidFile.exists());
final int pid = readPid(this.pidFile);
assertTrue(pid > 0);
assertTrue(ProcessUtils.isProcessAlive(pid));
assertEquals(getPid(), pid);
assertEquals(Status.ONLINE, this.launcher.status().getStatus());
} catch (Throwable e) {
this.errorCollector.addError(e);
}
try {
assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
waitForFileToDelete(this.pidFile);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
}
use of org.apache.geode.distributed.ServerLauncher.Builder in project geode by apache.
the class ServerLauncherLocalIntegrationTest method testStopUsingWorkingDirectory.
@Test
public void testStopUsingWorkingDirectory() throws Throwable {
String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
// build and start the server
final Builder builder = new Builder().setDisableDefaultServer(true).setMemberName(getUniqueName()).setRedirectOutput(true).setWorkingDirectory(rootFolder).set(LOG_LEVEL, "config").set(MCAST_PORT, "0");
assertFalse(builder.getForce());
this.launcher = builder.build();
assertFalse(this.launcher.isForcing());
ServerLauncher dirLauncher = null;
try {
this.launcher.start();
waitForServerToStart(this.launcher);
// validate the pid file and its contents
this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
assertTrue(this.pidFile.exists());
final int pid = readPid(this.pidFile);
assertTrue(pid > 0);
assertEquals(ProcessUtils.identifyPid(), pid);
dirLauncher = new Builder().setWorkingDirectory(rootFolder).build();
assertNotNull(dirLauncher);
assertFalse(dirLauncher.isRunning());
// stop the server
final ServerState serverState = dirLauncher.stop();
assertNotNull(serverState);
assertEquals(Status.STOPPED, serverState.getStatus());
} catch (Throwable e) {
this.errorCollector.addError(e);
}
try {
this.launcher.stop();
} catch (Throwable e) {
// ignore
}
try {
// verify the PID file was deleted
waitForFileToDelete(this.pidFile);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
}
Aggregations