use of org.apache.geode.distributed.LocatorLauncher.Builder in project geode by apache.
the class LocatorLauncherLocalIntegrationTest method testStartOverwritesStalePidFile.
@Test
public void testStartOverwritesStalePidFile() throws Throwable {
// create existing pid file
this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.LOCATOR.getPidFileName());
assertFalse("Integer.MAX_VALUE shouldn't be the same as local pid " + Integer.MAX_VALUE, Integer.MAX_VALUE == ProcessUtils.identifyPid());
writePid(this.pidFile, Integer.MAX_VALUE);
// build and start the locator
final Builder builder = new Builder().setMemberName(getUniqueName()).setPort(this.locatorPort).setRedirectOutput(true).setWorkingDirectory(this.workingDirectory).set(CLUSTER_CONFIGURATION_DIR, this.clusterConfigDirectory).set(LOG_LEVEL, "config");
assertFalse(builder.getForce());
this.launcher = builder.build();
assertFalse(this.launcher.isForcing());
this.launcher.start();
try {
waitForLocatorToStart(this.launcher);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
try {
// validate the pid file and its contents
assertTrue(this.pidFile.exists());
final int pid = readPid(this.pidFile);
assertTrue(pid > 0);
assertTrue(ProcessUtils.isProcessAlive(pid));
assertEquals(getPid(), pid);
} 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.LocatorLauncher.Builder in project geode by apache.
the class LocatorLauncherLocalIntegrationTest method testStatusUsingPid.
@Test
public void testStatusUsingPid() throws Throwable {
// build and start the locator
final Builder builder = new Builder().setMemberName(getUniqueName()).setPort(this.locatorPort).setRedirectOutput(true).setWorkingDirectory(this.workingDirectory).set(CLUSTER_CONFIGURATION_DIR, this.clusterConfigDirectory).set(LOG_LEVEL, "config");
assertFalse(builder.getForce());
this.launcher = builder.build();
assertFalse(this.launcher.isForcing());
LocatorLauncher pidLauncher = null;
try {
this.launcher.start();
waitForLocatorToStart(this.launcher);
this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.LOCATOR.getPidFileName());
assertTrue("Pid file " + this.pidFile.getCanonicalPath().toString() + " should exist", 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 LocatorState 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 Locator
// 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(this.workingDirectory + File.separator + getUniqueName() + ".log", actualStatus.getLogFile());
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.LocatorLauncher.Builder in project geode by apache.
the class LocatorLauncherIntegrationTest method testBuildWithMemberNameSetInGemFirePropertiesOnStart.
@Test
public void testBuildWithMemberNameSetInGemFirePropertiesOnStart() throws Exception {
// given: gemfire.properties with a name
Properties gemfireProperties = new Properties();
gemfireProperties.setProperty(NAME, "locator123");
useGemFirePropertiesFileInTemporaryFolder(DistributionConfig.GEMFIRE_PREFIX + "properties", gemfireProperties);
// when: starting with null MemberName
LocatorLauncher launcher = new Builder().setCommand(Command.START).build();
// then: name in gemfire.properties file should be used for MemberName
assertThat(launcher).isNotNull();
assertThat(launcher.getCommand()).isEqualTo(Command.START);
assertThat(launcher.getMemberName()).isNull();
}
use of org.apache.geode.distributed.LocatorLauncher.Builder in project geode by apache.
the class LocatorLauncherIntegrationTest method testBuildWithNoMemberNameOnStart.
@Test
public void testBuildWithNoMemberNameOnStart() throws Exception {
// given: gemfire.properties with no name
useGemFirePropertiesFileInTemporaryFolder(DistributionConfig.GEMFIRE_PREFIX + "properties", new Properties());
// when: no MemberName is specified
when(new Builder().setCommand(Command.START)).build();
// then: throw IllegalStateException
then(caughtException()).isExactlyInstanceOf(IllegalStateException.class).hasMessage(LocalizedStrings.Launcher_Builder_MEMBER_NAME_VALIDATION_ERROR_MESSAGE.toLocalizedString("Locator"));
}
use of org.apache.geode.distributed.LocatorLauncher.Builder in project geode by apache.
the class LocatorLauncherIntegrationTest method testBuilderSetWorkingDirectoryToNonExistingDirectory.
@Test
public void testBuilderSetWorkingDirectoryToNonExistingDirectory() {
// when: setting WorkingDirectory to non-existing directory
when(new Builder()).setWorkingDirectory("/path/to/non_existing/directory");
// then: throw IllegalArgumentException
then(caughtException()).isExactlyInstanceOf(IllegalArgumentException.class).hasMessage(LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_NOT_FOUND_ERROR_MESSAGE.toLocalizedString("Locator")).hasCause(new FileNotFoundException("/path/to/non_existing/directory"));
}
Aggregations