Search in sources :

Example 21 with LocatorState

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

the class LocatorLauncherRemoteIntegrationTest method testStatusWithNoPidFile.

@Test
public void testStatusWithNoPidFile() throws Exception {
    final LocatorLauncher dirLauncher = new LocatorLauncher.Builder().setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath()).build();
    LocatorState locatorState = dirLauncher.status();
    assertEquals(Status.NOT_RESPONDING, locatorState.getStatus());
}
Also used : Builder(org.apache.geode.distributed.LocatorLauncher.Builder) LocatorState(org.apache.geode.distributed.LocatorLauncher.LocatorState) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 22 with LocatorState

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

the class LocatorLauncherRemoteIntegrationTest method testStatusUsingWorkingDirectory.

// GEODE-569: BindException, random ports
@Category(FlakyTest.class)
@Test
public void testStatusUsingWorkingDirectory() 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;
    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());
        assertNotNull(dirLauncher);
        assertFalse(dirLauncher.isRunning());
        // validate the status
        final LocatorState actualStatus = dirLauncher.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 {
        assertEquals(Status.STOPPED, dirLauncher.stop().getStatus());
        waitForPidToStop(pid);
    } 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) Category(org.junit.experimental.categories.Category) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 23 with LocatorState

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

the class LocatorLauncherLocalIntegrationTest method testStatusUsingWorkingDirectory.

@Test
public void testStatusUsingWorkingDirectory() throws Throwable {
    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 dirLauncher = 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);
        dirLauncher = new Builder().setWorkingDirectory(this.workingDirectory).build();
        assertNotNull(dirLauncher);
        assertFalse(dirLauncher.isRunning());
        final LocatorState actualStatus = dirLauncher.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 (dirLauncher == null) {
        try {
            assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
            waitForFileToDelete(this.pidFile);
        } catch (Throwable e) {
            this.errorCollector.addError(e);
        }
    } else {
        try {
            assertEquals(Status.STOPPED, dirLauncher.stop().getStatus());
            waitForFileToDelete(this.pidFile);
        } catch (Throwable e) {
            this.errorCollector.addError(e);
        }
    }
}
Also used : Builder(org.apache.geode.distributed.LocatorLauncher.Builder) LocatorState(org.apache.geode.distributed.LocatorLauncher.LocatorState) File(java.io.File) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 24 with LocatorState

use of org.apache.geode.distributed.LocatorLauncher.LocatorState 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);
        }
    }
}
Also used : Builder(org.apache.geode.distributed.LocatorLauncher.Builder) LocatorState(org.apache.geode.distributed.LocatorLauncher.LocatorState) File(java.io.File) 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