Search in sources :

Example 16 with LocatorState

use of org.apache.geode.distributed.LocatorLauncher.LocatorState in project geode by apache.

the class FileProcessControllerIntegrationJUnitTest method generateStatusJson.

private static String generateStatusJson() {
    Builder builder = new Builder();
    LocatorLauncher defaultLauncher = builder.build();
    Status status = Status.ONLINE;
    LocatorState locatorState = new LocatorState(defaultLauncher, status);
    return locatorState.toJson();
}
Also used : Status(org.apache.geode.distributed.AbstractLauncher.Status) LocatorLauncher(org.apache.geode.distributed.LocatorLauncher) Builder(org.apache.geode.distributed.LocatorLauncher.Builder) LocatorState(org.apache.geode.distributed.LocatorLauncher.LocatorState)

Example 17 with LocatorState

use of org.apache.geode.distributed.LocatorLauncher.LocatorState 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 18 with LocatorState

use of org.apache.geode.distributed.LocatorLauncher.LocatorState 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 19 with LocatorState

use of org.apache.geode.distributed.LocatorLauncher.LocatorState in project geode by apache.

the class LocatorLauncherRemoteIntegrationTest method testStartWithDefaultPortInUseFails.

@Test
public void testStartWithDefaultPortInUseFails() throws Throwable {
    String expectedString = "java.net.BindException";
    AtomicBoolean outputContainedExpectedString = new AtomicBoolean();
    this.socket = SocketCreatorFactory.createNonDefaultInstance(false, false, null, null, System.getProperties()).createServerSocket(this.locatorPort, 50, null, -1);
    this.locatorPort = this.socket.getLocalPort();
    assertFalse(AvailablePort.isPortAvailable(this.locatorPort, AvailablePort.SOCKET));
    assertTrue(this.socket.isBound());
    assertFalse(this.socket.isClosed());
    // launch locator
    final List<String> jvmArguments = getJvmArguments();
    jvmArguments.add("-D" + DistributionLocator.TEST_OVERRIDE_DEFAULT_PORT_PROPERTY + "=" + this.locatorPort);
    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("--redirect-output");
    this.process = new ProcessBuilder(command).directory(this.temporaryFolder.getRoot()).start();
    this.processOutReader = new ProcessStreamReader.Builder(this.process).inputStream(this.process.getInputStream()).inputListener(createExpectedListener("sysout", getUniqueName() + "#sysout", expectedString, outputContainedExpectedString)).build().start();
    this.processErrReader = new ProcessStreamReader.Builder(this.process).inputStream(this.process.getErrorStream()).inputListener(createExpectedListener("syserr", getUniqueName() + "#syserr", expectedString, outputContainedExpectedString)).build().start();
    // wait for locator to start up
    final LocatorLauncher dirLauncher = new LocatorLauncher.Builder().setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath()).build();
    try {
        // TODO: create flavor with timeout in ProcessUtils
        int code = process.waitFor();
        assertEquals("Expected exit code 1 but was " + code, 1, code);
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    try {
        // check the status
        final LocatorState locatorState = dirLauncher.status();
        assertNotNull(locatorState);
        assertEquals(Status.NOT_RESPONDING, locatorState.getStatus());
        // creation of log file seems to be random -- look into why sometime
        final String logFileName = getUniqueName() + ".log";
        assertFalse("Log file should exist: " + logFileName, new File(this.temporaryFolder.getRoot(), logFileName).exists());
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    // if the following fails, then the SHORTER_TIMEOUT might be too short for slow machines
    // or this test needs to use MainLauncher in ProcessWrapper
    // validate that output contained BindException
    this.errorCollector.checkThat(outputContainedExpectedString.get(), is(equalTo(true)));
    // just in case the launcher started...
    LocatorState status = null;
    try {
        status = dirLauncher.stop();
    } catch (Throwable t) {
    // ignore
    }
    this.errorCollector.checkThat(status.getStatus(), is(equalTo(getExpectedStopStatusForNotRunning())));
}
Also used : Builder(org.apache.geode.distributed.LocatorLauncher.Builder) ArrayList(java.util.ArrayList) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProcessStreamReader(org.apache.geode.internal.process.ProcessStreamReader) LocatorState(org.apache.geode.distributed.LocatorLauncher.LocatorState) File(java.io.File) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 20 with LocatorState

use of org.apache.geode.distributed.LocatorLauncher.LocatorState in project geode by apache.

the class LocatorLauncherRemoteIntegrationTest method testStatusUsingPid.

/*
                          * this.temporaryFolder.getRoot() = new File(getUniqueName());
                          * this.temporaryFolder.getRoot().mkdir();
                          * assertTrue(this.temporaryFolder.getRoot().isDirectory() &&
                          * this.temporaryFolder.getRoot().canWrite());
                          * 
                          * // create existing pid file this.pidFile = new
                          * File(this.temporaryFolder.getRoot(),
                          * ProcessType.LOCATOR.getPidFileName()); 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()); writePid(this.pidFile, realPid);
                          * 
                          * // build and start the locator 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()).build().start(); this.processErrReader = new
                          * ProcessStreamReader.Builder(this.process).inputStream(this.process.
                          * getErrorStream()).build().start();
                          * 
                          * // collect and throw the FIRST failure Throwable failure = null;
                          * 
                          * final LocatorLauncher dirLauncher = new LocatorLauncher.Builder()
                          * .setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath())
                          * .build(); try { waitForLocatorToStart(dirLauncher, 10*1000, false); }
                          * catch (Throwable e) { logger.error(e); if (failure == null) { failure =
                          * e; } }
                          * 
                          * try { // check the status final LocatorState locatorState =
                          * dirLauncher.status(); assertNotNull(locatorState);
                          * assertIndexDetailsEquals(Status.NOT_RESPONDING,
                          * locatorState.getStatus());
                          * 
                          * final String logFileName = getUniqueName()+".log";
                          * assertFalse("Log file should not exist: " + logFileName, new
                          * File(this.temporaryFolder.getRoot(), logFileName).exists());
                          * 
                          * } catch (Throwable e) { logger.error(e); if (failure == null) { failure
                          * = e; } }
                          * 
                          * // just in case the launcher started... try { final LocatorState status
                          * = dirLauncher.stop(); 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 testStatusUsingPid() 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()).build().start();
    this.processErrReader = new ProcessStreamReader.Builder(this.process).inputStream(this.process.getErrorStream()).build().start();
    // wait for locator to start
    int pid = 0;
    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
        this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.LOCATOR.getPidFileName());
        assertTrue(this.pidFile.exists());
        pid = readPid(this.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());
        // validate the status
        final LocatorState actualStatus = pidLauncher.status();
        assertNotNull(actualStatus);
        assertEquals(Status.ONLINE, actualStatus.getStatus());
        assertEquals(pid, actualStatus.getPid().intValue());
        assertTrue(actualStatus.getUptime() > 0);
        assertEquals(this.temporaryFolder.getRoot().getCanonicalPath(), actualStatus.getWorkingDirectory());
        assertEquals(jvmArguments, actualStatus.getJvmArguments());
        assertEquals(ManagementFactory.getRuntimeMXBean().getClassPath(), actualStatus.getClasspath());
        assertEquals(GemFireVersion.getGemFireVersion(), actualStatus.getGemFireVersion());
        assertEquals(System.getProperty("java.version"), actualStatus.getJavaVersion());
        assertEquals(this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + getUniqueName() + ".log", actualStatus.getLogFile());
        assertEquals(InetAddress.getLocalHost().getCanonicalHostName(), actualStatus.getHost());
        assertEquals(getUniqueName(), actualStatus.getMemberName());
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    // stop the locator
    try {
        if (pidLauncher == null) {
            assertEquals(Status.STOPPED, dirLauncher.stop().getStatus());
        } else {
            assertEquals(Status.STOPPED, pidLauncher.stop().getStatus());
        }
        waitForPidToStop(pid);
        waitForFileToDelete(this.pidFile);
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
}
Also used : Builder(org.apache.geode.distributed.LocatorLauncher.Builder) ArrayList(java.util.ArrayList) LocatorState(org.apache.geode.distributed.LocatorLauncher.LocatorState) File(java.io.File) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

LocatorState (org.apache.geode.distributed.LocatorLauncher.LocatorState)24 Test (org.junit.Test)22 File (java.io.File)21 Builder (org.apache.geode.distributed.LocatorLauncher.Builder)21 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)16 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)10 LocatorLauncher (org.apache.geode.distributed.LocatorLauncher)7 ArrayList (java.util.ArrayList)6 CommandStringBuilder (org.apache.geode.management.internal.cli.util.CommandStringBuilder)6 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)5 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 ProcessStreamReader (org.apache.geode.internal.process.ProcessStreamReader)4 Category (org.junit.experimental.categories.Category)3 BindException (java.net.BindException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)2 InetAddress (java.net.InetAddress)1 Properties (java.util.Properties)1 Status (org.apache.geode.distributed.AbstractLauncher.Status)1 OSProcess (org.apache.geode.internal.OSProcess)1