use of org.apache.geode.distributed.LocatorLauncher.Builder in project geode by apache.
the class LocatorLauncherTest method testSetBindAddressToLocalHost.
@Test
public void testSetBindAddressToLocalHost() throws Exception {
String host = InetAddress.getLocalHost().getHostName();
new Builder().setBindAddress(host);
}
use of org.apache.geode.distributed.LocatorLauncher.Builder in project geode by apache.
the class LocatorLauncherTest method testSetAndGetCommand.
@Test
public void testSetAndGetCommand() {
final Builder builder = new Builder();
assertEquals(Builder.DEFAULT_COMMAND, builder.getCommand());
assertSame(builder, builder.setCommand(Command.START));
assertEquals(Command.START, builder.getCommand());
assertSame(builder, builder.setCommand(Command.STATUS));
assertEquals(Command.STATUS, builder.getCommand());
assertSame(builder, builder.setCommand(Command.STOP));
assertEquals(Command.STOP, builder.getCommand());
assertSame(builder, builder.setCommand(null));
assertEquals(Builder.DEFAULT_COMMAND, builder.getCommand());
}
use of org.apache.geode.distributed.LocatorLauncher.Builder in project geode by apache.
the class LocatorLauncherRemoteFileIntegrationTest method testStopUsingPid.
/**
* Override because FileProcessController cannot request stop with PID
*/
@Override
@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;
File pidFile = null;
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
pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.LOCATOR.getPidFileName());
assertTrue(pidFile.exists());
pid = readPid(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());
// stop with pid only should throw AttachAPINotFoundException
try {
pidLauncher.stop();
fail("FileProcessController should have thrown AttachAPINotFoundException");
} catch (AttachAPINotFoundException e) {
// passed
}
} catch (Throwable e) {
this.errorCollector.addError(e);
}
try {
// stop the locator
assertEquals(Status.STOPPED, dirLauncher.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 LocatorLauncherIntegrationTest method testBuilderSetWorkingDirectoryToFile.
@Test
public void testBuilderSetWorkingDirectoryToFile() throws IOException {
// given: a file instead of a directory
File tmpFile = this.temporaryFolder.newFile();
// when: setting WorkingDirectory to that file
when(new Builder()).setWorkingDirectory(tmpFile.getCanonicalPath());
// then: throw IllegalArgumentException
then(caughtException()).isExactlyInstanceOf(IllegalArgumentException.class).hasMessage(LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_NOT_FOUND_ERROR_MESSAGE.toLocalizedString("Locator")).hasCause(new FileNotFoundException(tmpFile.getCanonicalPath()));
}
use of org.apache.geode.distributed.LocatorLauncher.Builder in project geode by apache.
the class LocatorLauncherLocalIntegrationTest method testStartUsingPort.
/*
* // create existing pid file 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());
*
* this.pidFile = new File(ProcessType.LOCATOR.getPidFileName());
* writePid(this.pidFile, realPid);
*
* // build and start the locator final Builder builder = new Builder()
* .setMemberName(getUniqueName()) .setPort(this.locatorPort)
* .setRedirectOutput(true) .set(logLevel, "config");
*
* assertFalse(builder.getForce()); this.launcher = builder.build();
* assertFalse(this.launcher.isForcing());
*
* // collect and throw the FIRST failure Throwable failure = null;
* RuntimeException expected = null;
*
* try { this.launcher.start();
* fail("LocatorLauncher start should have thrown RuntimeException caused by FileAlreadyExistsException"
* ); } catch (RuntimeException e) { expected = e;
* assertNotNull(expected.getMessage()); assertTrue(expected.getMessage(),
* expected.getMessage().
* contains("A PID file already exists and a Locator may be running in"));
* assertIndexDetailsEquals(RuntimeException.class, expected.getClass()); }
* catch (Throwable e) { logger.error(e); if (failure == null) { failure =
* e; } }
*
* // just in case the launcher started... LocatorState status = null; try
* { status = this.launcher.stop(); } catch (Throwable t) { // ignore }
*
* try { assertNotNull(expected); final Throwable cause =
* expected.getCause(); assertNotNull(cause); assertTrue(cause instanceof
* FileAlreadyExistsException);
* assertTrue(cause.getMessage().contains("Pid file already exists: "));
* assertTrue(cause.getMessage().contains("vf.gf.locator.pid for process "
* + realPid)); } catch (Throwable e) { logger.error(e); if (failure ==
* null) { failure = e; } }
*
* try { delete(this.pidFile); 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
*/
@Test
public void testStartUsingPort() throws Throwable {
// generate one free port and then use it instead of default
final int freeTCPPort = AvailablePortHelper.getRandomAvailableTCPPort();
assertTrue(AvailablePort.isPortAvailable(freeTCPPort, AvailablePort.SOCKET));
this.launcher = new Builder().setMemberName(getUniqueName()).setPort(freeTCPPort).setRedirectOutput(true).setWorkingDirectory(this.workingDirectory).set(CLUSTER_CONFIGURATION_DIR, this.clusterConfigDirectory).set(LOG_LEVEL, "config").build();
int pid = 0;
try {
// if start succeeds without throwing exception then #47778 is fixed
this.launcher.start();
waitForLocatorToStart(this.launcher);
// validate the pid file and its contents
this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.LOCATOR.getPidFileName());
assertTrue(pidFile.exists());
pid = readPid(pidFile);
assertTrue(pid > 0);
assertTrue(ProcessUtils.isProcessAlive(pid));
assertEquals(getPid(), pid);
// verify locator did not use default port
assertTrue(AvailablePort.isPortAvailable(this.locatorPort, AvailablePort.SOCKET));
final LocatorState status = this.launcher.status();
final String portString = status.getPort();
assertEquals("Port should be \"" + freeTCPPort + "\" instead of " + portString, String.valueOf(freeTCPPort), portString);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
// stop the locator
try {
assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
waitForFileToDelete(this.pidFile);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
}
Aggregations