use of org.apache.geode.distributed.LocatorLauncher in project geode by apache.
the class LauncherLifecycleCommandsDUnitTest method test009StatusLocatorUsingMemberId.
@Test
public void test009StatusLocatorUsingMemberId() throws Exception {
final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
final int jmxManagerPort = ports[0];
final int locatorPort = ports[1];
String pathname = (getClass().getSimpleName() + "_" + getTestMethodName());
File workingDirectory = temporaryFolder.newFolder(pathname);
assertTrue(workingDirectory.isDirectory() || workingDirectory.mkdir());
try {
CommandStringBuilder command = new CommandStringBuilder(CliStrings.START_LOCATOR);
command.addOption(CliStrings.START_LOCATOR__MEMBER_NAME, pathname);
command.addOption(CliStrings.START_LOCATOR__CONNECT, Boolean.FALSE.toString());
command.addOption(CliStrings.START_LOCATOR__DIR, workingDirectory.getCanonicalPath());
command.addOption(CliStrings.START_LOCATOR__PORT, String.valueOf(locatorPort));
command.addOption(CliStrings.START_LOCATOR__ENABLE__SHARED__CONFIGURATION, Boolean.FALSE.toString());
command.addOption(CliStrings.START_LOCATOR__FORCE, Boolean.TRUE.toString());
command.addOption(CliStrings.START_LOCATOR__J, "-D" + DistributionConfig.GEMFIRE_PREFIX + "http-service-port=0");
command.addOption(CliStrings.START_LOCATOR__J, "-D" + DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-port=" + jmxManagerPort);
CommandResult result = executeCommand(command.toString());
assertNotNull(result);
assertEquals(Result.Status.OK, result.getStatus());
LocatorLauncher locatorLauncher = new LocatorLauncher.Builder().setCommand(LocatorLauncher.Command.STATUS).setBindAddress(null).setPort(locatorPort).setWorkingDirectory(workingDirectory.getPath()).build();
assertNotNull(locatorLauncher);
LocatorState expectedLocatorState = locatorLauncher.waitOnStatusResponse(60, 10, TimeUnit.SECONDS);
assertNotNull(expectedLocatorState);
assertEquals(Status.ONLINE, expectedLocatorState.getStatus());
result = executeCommand(String.format("%1$s --locator=localhost[%2$d]", CliStrings.CONNECT, locatorPort));
assertNotNull(result);
assertEquals(Result.Status.OK, result.getStatus());
result = executeCommand(String.format("%1$s --name=%2$s", CliStrings.STATUS_LOCATOR, getMemberId(jmxManagerPort, pathname)));
assertNotNull(result);
assertEquals(Result.Status.OK, result.getStatus());
assertTrue(serviceStateStatusStringNormalized(toString(result)).contains(serviceStateStatusStringNormalized(expectedLocatorState)));
} finally {
stopLocator(workingDirectory);
}
}
use of org.apache.geode.distributed.LocatorLauncher in project geode by apache.
the class LauncherLifecycleCommandsDUnitTest method test008StatusLocatorUsingMemberName.
@Test
public void test008StatusLocatorUsingMemberName() throws IOException {
final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
final int jmxManagerPort = ports[0];
final int locatorPort = ports[1];
String pathname = (getClass().getSimpleName() + "_" + getTestMethodName());
File workingDirectory = temporaryFolder.newFolder(pathname);
assertTrue(workingDirectory.isDirectory() || workingDirectory.mkdir());
try {
CommandStringBuilder command = new CommandStringBuilder(CliStrings.START_LOCATOR);
command.addOption(CliStrings.START_LOCATOR__MEMBER_NAME, pathname);
command.addOption(CliStrings.START_LOCATOR__CONNECT, Boolean.FALSE.toString());
command.addOption(CliStrings.START_LOCATOR__DIR, workingDirectory.getCanonicalPath());
command.addOption(CliStrings.START_LOCATOR__PORT, String.valueOf(locatorPort));
command.addOption(CliStrings.START_LOCATOR__ENABLE__SHARED__CONFIGURATION, Boolean.FALSE.toString());
command.addOption(CliStrings.START_LOCATOR__FORCE, Boolean.TRUE.toString());
command.addOption(CliStrings.START_LOCATOR__J, "-D" + DistributionConfig.GEMFIRE_PREFIX + "http-service-port=0");
command.addOption(CliStrings.START_LOCATOR__J, "-D" + DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-port=" + jmxManagerPort);
CommandResult result = executeCommand(command.toString());
assertNotNull(result);
assertEquals(Result.Status.OK, result.getStatus());
LocatorLauncher locatorLauncher = new LocatorLauncher.Builder().setCommand(LocatorLauncher.Command.STATUS).setBindAddress(null).setPort(locatorPort).setWorkingDirectory(workingDirectory.getPath()).build();
assertNotNull(locatorLauncher);
LocatorState expectedLocatorState = locatorLauncher.waitOnStatusResponse(60, 10, TimeUnit.SECONDS);
assertNotNull(expectedLocatorState);
assertEquals(Status.ONLINE, expectedLocatorState.getStatus());
result = executeCommand(String.format("%1$s --locator=localhost[%2$d]", CliStrings.CONNECT, locatorPort));
assertNotNull(result);
assertEquals(Result.Status.OK, result.getStatus());
result = executeCommand(String.format("%1$s --name=invalidLocatorMemberName", CliStrings.STATUS_LOCATOR));
assertNotNull(result);
assertEquals(Result.Status.ERROR, result.getStatus());
assertEquals(CliStrings.format(CliStrings.STATUS_LOCATOR__NO_LOCATOR_FOUND_FOR_MEMBER_ERROR_MESSAGE, "invalidLocatorMemberName"), StringUtils.trim(toString(result)));
result = executeCommand(String.format("%1$s --name=%2$s", CliStrings.STATUS_LOCATOR, pathname));
assertNotNull(result);
assertEquals(Result.Status.OK, result.getStatus());
assertTrue(serviceStateStatusStringNormalized(toString(result)).contains(serviceStateStatusStringNormalized(expectedLocatorState)));
} finally {
stopLocator(workingDirectory);
}
}
use of org.apache.geode.distributed.LocatorLauncher in project geode by apache.
the class LauncherLifecycleCommandsDUnitTest method test011StopLocatorUsingMemberName.
@Test
public void test011StopLocatorUsingMemberName() throws IOException {
final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
final int jmxManagerPort = ports[0];
final int locatorPort = ports[1];
String pathname = (getClass().getSimpleName() + "_" + getTestMethodName());
File workingDirectory = temporaryFolder.newFolder(pathname);
try {
assertTrue(workingDirectory.isDirectory() || workingDirectory.mkdir());
CommandStringBuilder command = new CommandStringBuilder(CliStrings.START_LOCATOR);
command.addOption(CliStrings.START_LOCATOR__MEMBER_NAME, pathname);
command.addOption(CliStrings.START_LOCATOR__CONNECT, Boolean.FALSE.toString());
command.addOption(CliStrings.START_LOCATOR__DIR, workingDirectory.getCanonicalPath());
command.addOption(CliStrings.START_LOCATOR__PORT, String.valueOf(locatorPort));
command.addOption(CliStrings.START_LOCATOR__ENABLE__SHARED__CONFIGURATION, Boolean.FALSE.toString());
command.addOption(CliStrings.START_LOCATOR__FORCE, Boolean.TRUE.toString());
command.addOption(CliStrings.START_LOCATOR__J, "-D" + DistributionConfig.GEMFIRE_PREFIX + "http-service-port=0");
command.addOption(CliStrings.START_LOCATOR__J, "-D" + DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-port=" + jmxManagerPort);
CommandResult result = executeCommand(command.toString());
assertNotNull(result);
assertEquals(Result.Status.OK, result.getStatus());
final LocatorLauncher locatorLauncher = new Builder().setCommand(Command.STOP).setBindAddress(null).setPort(locatorPort).setWorkingDirectory(workingDirectory.getPath()).build();
assertNotNull(locatorLauncher);
LocatorState locatorStatus = locatorLauncher.waitOnStatusResponse(60, 10, TimeUnit.SECONDS);
assertNotNull(locatorStatus);
assertEquals(Status.ONLINE, locatorStatus.getStatus());
result = executeCommand(String.format("%1$s --locator=localhost[%2$d]", CliStrings.CONNECT, locatorPort));
assertNotNull(result);
assertEquals(Result.Status.OK, result.getStatus());
result = executeCommand(String.format("%1$s --name=invalidLocatorMemberName", CliStrings.STOP_LOCATOR));
assertNotNull(result);
assertEquals(Result.Status.ERROR, result.getStatus());
assertEquals(CliStrings.format(CliStrings.STOP_LOCATOR__NO_LOCATOR_FOUND_FOR_MEMBER_ERROR_MESSAGE, "invalidLocatorMemberName"), StringUtils.trim(toString(result)));
locatorStatus = locatorLauncher.status();
assertNotNull(locatorStatus);
assertEquals(Status.ONLINE, locatorStatus.getStatus());
result = executeCommand(String.format("%1$s --name=%2$s", CliStrings.STOP_LOCATOR, pathname));
assertNotNull(result);
assertEquals(Result.Status.OK, result.getStatus());
// TODO figure out what output to assert and validate on now that 'stop locator' uses Gfsh's
// logger
// and standard err/out...
// assertIndexDetailsEquals(CliStrings.format(CliStrings.STOP_LOCATOR__SHUTDOWN_MEMBER_MESSAGE,
// pathname),
// StringUtils.trim(toString(result)));
WaitCriterion waitCriteria = new WaitCriterion() {
@Override
public boolean done() {
final LocatorState locatorStatus = locatorLauncher.status();
return (locatorStatus != null && Status.NOT_RESPONDING.equals(locatorStatus.getStatus()));
}
@Override
public String description() {
return "wait for the Locator to stop; the Locator will no longer respond after it stops";
}
};
waitForCriterion(waitCriteria, 15 * 1000, 5000, true);
locatorStatus = locatorLauncher.status();
assertNotNull(locatorStatus);
assertEquals(Status.NOT_RESPONDING, locatorStatus.getStatus());
} finally {
}
}
use of org.apache.geode.distributed.LocatorLauncher in project geode by apache.
the class LauncherLifecycleCommandsDUnitTest method test012StopLocatorUsingMemberId.
// @see Trac Bug # 46760
@Test
public void test012StopLocatorUsingMemberId() throws Exception {
final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
final int jmxManagerPort = ports[0];
final int locatorPort = ports[1];
String pathname = (getClass().getSimpleName() + "_" + getTestMethodName());
File workingDirectory = temporaryFolder.newFolder(pathname);
try {
assertTrue(workingDirectory.isDirectory() || workingDirectory.mkdir());
CommandStringBuilder command = new CommandStringBuilder(CliStrings.START_LOCATOR);
command.addOption(CliStrings.START_LOCATOR__MEMBER_NAME, pathname);
command.addOption(CliStrings.START_LOCATOR__CONNECT, Boolean.FALSE.toString());
command.addOption(CliStrings.START_LOCATOR__DIR, workingDirectory.getCanonicalPath());
command.addOption(CliStrings.START_LOCATOR__PORT, String.valueOf(locatorPort));
command.addOption(CliStrings.START_LOCATOR__ENABLE__SHARED__CONFIGURATION, Boolean.FALSE.toString());
command.addOption(CliStrings.START_LOCATOR__FORCE, Boolean.TRUE.toString());
command.addOption(CliStrings.START_LOCATOR__J, "-D" + DistributionConfig.GEMFIRE_PREFIX + "http-service-port=0");
command.addOption(CliStrings.START_LOCATOR__J, "-D" + DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-port=" + jmxManagerPort);
CommandResult result = executeCommand(command.toString());
assertNotNull(result);
assertEquals(Result.Status.OK, result.getStatus());
final LocatorLauncher locatorLauncher = new Builder().setCommand(Command.STOP).setBindAddress(null).setPort(locatorPort).setWorkingDirectory(workingDirectory.getPath()).build();
assertNotNull(locatorLauncher);
LocatorState locatorState = locatorLauncher.waitOnStatusResponse(60, 10, TimeUnit.SECONDS);
assertNotNull(locatorState);
assertEquals(Status.ONLINE, locatorState.getStatus());
result = executeCommand(String.format("%1$s --locator=localhost[%2$d]", CliStrings.CONNECT, locatorPort));
assertNotNull(result);
assertEquals(Result.Status.OK, result.getStatus());
String memberId = getMemberId(jmxManagerPort, pathname);
result = executeCommand(String.format("%1$s --name=%2$s", CliStrings.STOP_LOCATOR, memberId));
assertNotNull(result);
assertEquals(Result.Status.OK, result.getStatus());
// TODO figure out what output to assert and validate on now that 'stop locator' uses Gfsh's
// logger
// and standard err/out...
// assertIndexDetailsEquals(CliStrings.format(CliStrings.STOP_LOCATOR__SHUTDOWN_MEMBER_MESSAGE,
// memberId),
// StringUtils.trim(toString(result)));
WaitCriterion waitCriteria = new WaitCriterion() {
@Override
public boolean done() {
LocatorState locatorState = locatorLauncher.status();
return (locatorState != null && Status.NOT_RESPONDING.equals(locatorState.getStatus()));
}
@Override
public String description() {
return "wait for the Locator to stop; the Locator will no longer respond after it stops";
}
};
waitForCriterion(waitCriteria, 15 * 1000, 5000, true);
locatorState = locatorLauncher.status();
assertNotNull(locatorState);
assertEquals(Status.NOT_RESPONDING, locatorState.getStatus());
} finally {
}
}
use of org.apache.geode.distributed.LocatorLauncher in project geode by apache.
the class LauncherLifecycleCommandsTest method testLocatorCommandLineWithRestAPI.
/**
* Verify commandline parameters passed for starting locator
*
* @throws Exception
*/
@Test
public void testLocatorCommandLineWithRestAPI() throws Exception {
LocatorLauncher locatorLauncher = new LocatorLauncher.Builder().setCommand(LocatorLauncher.Command.START).setMemberName("testLocatorCommandLineWithRestAPI").setBindAddress("localhost").setPort(11111).build();
Properties gemfireProperties = new Properties();
gemfireProperties.setProperty(HTTP_SERVICE_PORT, "8089");
gemfireProperties.setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost");
String[] commandLineElements = launcherCommands.createStartLocatorCommandLine(locatorLauncher, null, null, gemfireProperties, null, false, new String[0], null, null);
assertNotNull(commandLineElements);
assertTrue(commandLineElements.length > 0);
Set<String> expectedCommandLineElements = new HashSet<>(6);
expectedCommandLineElements.add(locatorLauncher.getCommand().getName());
expectedCommandLineElements.add(locatorLauncher.getMemberName().toLowerCase());
expectedCommandLineElements.add(String.format("--port=%1$d", locatorLauncher.getPort()));
expectedCommandLineElements.add("-d" + DistributionConfig.GEMFIRE_PREFIX + "" + HTTP_SERVICE_PORT + "=" + "8089");
expectedCommandLineElements.add("-d" + DistributionConfig.GEMFIRE_PREFIX + "" + HTTP_SERVICE_BIND_ADDRESS + "=" + "localhost");
for (String commandLineElement : commandLineElements) {
expectedCommandLineElements.remove(commandLineElement.toLowerCase());
}
assertTrue(String.format("Expected ([]); but was (%1$s)", expectedCommandLineElements), expectedCommandLineElements.isEmpty());
}
Aggregations