Search in sources :

Example 6 with LocatorLauncher

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);
    }
}
Also used : LocatorLauncher(org.apache.geode.distributed.LocatorLauncher) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) Builder(org.apache.geode.distributed.LocatorLauncher.Builder) LocatorState(org.apache.geode.distributed.LocatorLauncher.LocatorState) File(java.io.File) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 7 with LocatorLauncher

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);
    }
}
Also used : LocatorLauncher(org.apache.geode.distributed.LocatorLauncher) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) Builder(org.apache.geode.distributed.LocatorLauncher.Builder) LocatorState(org.apache.geode.distributed.LocatorLauncher.LocatorState) File(java.io.File) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 8 with LocatorLauncher

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 {
    }
}
Also used : LocatorLauncher(org.apache.geode.distributed.LocatorLauncher) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) Builder(org.apache.geode.distributed.LocatorLauncher.Builder) LocatorState(org.apache.geode.distributed.LocatorLauncher.LocatorState) File(java.io.File) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 9 with LocatorLauncher

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 {
    }
}
Also used : LocatorLauncher(org.apache.geode.distributed.LocatorLauncher) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) Builder(org.apache.geode.distributed.LocatorLauncher.Builder) LocatorState(org.apache.geode.distributed.LocatorLauncher.LocatorState) File(java.io.File) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 10 with LocatorLauncher

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());
}
Also used : LocatorLauncher(org.apache.geode.distributed.LocatorLauncher) Properties(java.util.Properties) HashSet(java.util.HashSet) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

LocatorLauncher (org.apache.geode.distributed.LocatorLauncher)11 File (java.io.File)7 LocatorState (org.apache.geode.distributed.LocatorLauncher.LocatorState)7 CommandStringBuilder (org.apache.geode.management.internal.cli.util.CommandStringBuilder)6 Test (org.junit.Test)6 Builder (org.apache.geode.distributed.LocatorLauncher.Builder)5 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)5 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 CliMetaData (org.apache.geode.management.cli.CliMetaData)3 CliCommand (org.springframework.shell.core.annotation.CliCommand)3 Properties (java.util.Properties)2 MemberMXBean (org.apache.geode.management.MemberMXBean)2 MXBeanProvider.getMemberMXBean (org.apache.geode.management.internal.cli.shell.MXBeanProvider.getMemberMXBean)2 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)2 InetAddress (java.net.InetAddress)1 HashSet (java.util.HashSet)1 Status (org.apache.geode.distributed.AbstractLauncher.Status)1 OSProcess (org.apache.geode.internal.OSProcess)1 ProcessStreamReader (org.apache.geode.internal.process.ProcessStreamReader)1 InputListener (org.apache.geode.internal.process.ProcessStreamReader.InputListener)1