Search in sources :

Example 1 with ProcessWrapper

use of org.apache.geode.test.process.ProcessWrapper in project geode by apache.

the class ServerLauncherRemoteIntegrationTest method testRunningServerOutlivesForkingProcess.

@Test
@Ignore("TRAC bug #52304: test is broken and needs to be reworked")
public void testRunningServerOutlivesForkingProcess() throws Throwable {
    // launch ServerLauncherForkingProcess which then launches server
    // final List<String> command = new ArrayList<String>();
    // command.add(new File(new File(System.getProperty("java.home"), "bin"),
    // "java").getCanonicalPath());
    // command.add("-cp");
    // command.add(System.getProperty("java.class.path"));
    // command.add(ServerLauncherDUnitTest.class.getName().concat("$").concat(ServerLauncherForkingProcess.class.getSimpleName()));
    //
    // process = new ProcessBuilder(command).directory(temporaryFolder.getRoot()).start();
    // assertNotNull(process);
    // processOutReader = new ProcessStreamReader(process.getInputStream(), createListener("sysout",
    // getUniqueName() + "#sysout")).start();
    // processErrReader = new ProcessStreamReader(process.getErrorStream(), createListener("syserr",
    // getUniqueName() + "#syserr")).start();
    @SuppressWarnings("unused") File file = new File(this.temporaryFolder.getRoot(), ServerLauncherForkingProcess.class.getSimpleName().concat(".log"));
    // -logger.info("log file is " + file);
    final ProcessWrapper pw = new ProcessWrapper.Builder().mainClass(ServerLauncherForkingProcess.class).build();
    pw.execute(null, this.temporaryFolder.getRoot()).waitFor(true);
    // logger.info("[testRunningServerOutlivesForkingProcess] ServerLauncherForkingProcess output
    // is:\n\n"+pw.getOutput());
    // // create waiting thread since waitFor does not have a timeout
    // Thread waiting = new Thread(new Runnable() {
    // @Override
    // public void run() {
    // try {
    // assertIndexDetailsEquals(0, process.waitFor());
    // } catch (InterruptedException e) {
    // logger.error("Interrupted while waiting for process", e);
    // }
    // }
    // });
    // // start waiting thread and join to it for timeout
    // try {
    // waiting.start();
    // waiting.join(TIMEOUT_MILLISECONDS);
    // assertFalse("ServerLauncherForkingProcess took too long and caused timeout",
    // waiting.isAlive());
    //
    // } catch (Throwable e) {
    // logger.error(e);
    // if (failure == null) {
    // failure = e;
    // }
    // } finally {
    // if (waiting.isAlive()) {
    // waiting.interrupt();
    // }
    // }
    // wait for server to start
    int pid = 0;
    final String serverName = ServerLauncherForkingProcess.class.getSimpleName() + "_server";
    final ServerLauncher dirLauncher = new ServerLauncher.Builder().setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath()).build();
    try {
        waitForServerToStart(dirLauncher);
        // validate the pid file and its contents
        this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
        assertTrue(this.pidFile.exists());
        pid = readPid(this.pidFile);
        assertTrue(pid > 0);
        assertTrue(ProcessUtils.isProcessAlive(pid));
        // validate log file was created
        final String logFileName = serverName + ".log";
        assertTrue("Log file should exist: " + logFileName, new File(this.temporaryFolder.getRoot(), logFileName).exists());
        // validate the status
        final ServerState 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(getJvmArguments(), 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 + serverName + ".log", actualStatus.getLogFile());
        assertEquals(InetAddress.getLocalHost().getCanonicalHostName(), actualStatus.getHost());
        assertEquals(serverName, actualStatus.getMemberName());
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    // stop the server
    try {
        assertEquals(Status.STOPPED, dirLauncher.stop().getStatus());
        waitForPidToStop(pid);
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
}
Also used : ProcessWrapper(org.apache.geode.test.process.ProcessWrapper) Builder(org.apache.geode.distributed.ServerLauncher.Builder) ServerState(org.apache.geode.distributed.ServerLauncher.ServerState) File(java.io.File) Ignore(org.junit.Ignore) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with ProcessWrapper

use of org.apache.geode.test.process.ProcessWrapper in project geode by apache.

the class PassWithExpectedProblemTestCase method testPassWithExpectedProblem.

/**
   * Process output has an expected warning/error/severe message and should pass
   */
@Test
public void testPassWithExpectedProblem() throws Exception {
    final String goldenString = "Begin " + name() + ".main" + "\n" + "Press Enter to continue." + "\n" + "\n" + expectedProblemLines()[this.problemLine] + "\n" + "End " + name() + ".main" + "\n";
    debug(goldenString, "GOLDEN");
    final ProcessWrapper process = createProcessWrapper(new ProcessWrapper.Builder(), getClass());
    process.execute(createProperties());
    process.waitForOutputToMatch("Begin " + name() + "\\.main");
    process.waitForOutputToMatch("Press Enter to continue\\.");
    process.sendInput();
    process.waitForOutputToMatch("End " + name() + "\\.main");
    process.waitFor();
    assertOutputMatchesGoldenFile(process.getOutput(), goldenString);
}
Also used : ProcessWrapper(org.apache.geode.test.process.ProcessWrapper) Test(org.junit.Test)

Example 3 with ProcessWrapper

use of org.apache.geode.test.process.ProcessWrapper in project geode by apache.

the class FailWithLineMissingFromEndOfOutputJUnitTest method testFailWithLineMissingFromEndOfOutput.

@Test
public void testFailWithLineMissingFromEndOfOutput() throws Exception {
    final String goldenString = "Begin " + name() + ".main" + "\n" + "Press Enter to continue." + "\n" + "End " + name() + ".main" + "\n" + problem() + "\n";
    debug(goldenString, "GOLDEN");
    final ProcessWrapper process = createProcessWrapper(new ProcessWrapper.Builder(), getClass());
    process.execute(createProperties());
    process.waitForOutputToMatch("Begin " + name() + "\\.main");
    process.waitForOutputToMatch("Press Enter to continue\\.");
    process.sendInput();
    process.waitForOutputToMatch("End " + name() + "\\.main");
    process.waitFor();
    try {
        assertOutputMatchesGoldenFile(process.getOutput(), goldenString);
        fail("assertOutputMatchesGoldenFile should have failed due to " + problem());
    } catch (AssertionError expected) {
        assertTrue("AssertionError message should contain \"" + problem() + "\"", expected.getMessage().contains(problem()));
    }
}
Also used : ProcessWrapper(org.apache.geode.test.process.ProcessWrapper) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with ProcessWrapper

use of org.apache.geode.test.process.ProcessWrapper in project geode by apache.

the class FailWithLineMissingFromMiddleOfOutputJUnitTest method testFailWithLineMissingFromEndOfOutput.

@Test
public void testFailWithLineMissingFromEndOfOutput() throws Exception {
    final String goldenString = "Begin " + name() + ".main" + "\n" + "Press Enter to continue." + "\n" + problem() + "\n" + "End " + name() + ".main" + "\n";
    debug(goldenString, "GOLDEN");
    final ProcessWrapper process = createProcessWrapper(new ProcessWrapper.Builder(), getClass());
    process.execute(createProperties());
    process.waitForOutputToMatch("Begin " + name() + "\\.main");
    process.waitForOutputToMatch("Press Enter to continue\\.");
    process.sendInput();
    process.waitFor();
    try {
        assertOutputMatchesGoldenFile(process.getOutput(), goldenString);
        fail("assertOutputMatchesGoldenFile should have failed due to " + problem());
    } catch (AssertionError expected) {
        assertTrue("AssertionError message should contain \"" + problem() + "\"", expected.getMessage().contains(problem()));
    }
}
Also used : ProcessWrapper(org.apache.geode.test.process.ProcessWrapper) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 5 with ProcessWrapper

use of org.apache.geode.test.process.ProcessWrapper in project geode by apache.

the class FailWithProblemInOutputTestCase method testFailWithProblemLogMessageInOutput.

@Test
public void testFailWithProblemLogMessageInOutput() throws Exception {
    final String goldenString = "Begin " + name() + ".main" + "\n" + "Press Enter to continue." + "\n" + "End " + name() + ".main" + "\n";
    debug(goldenString, "GOLDEN");
    final ProcessWrapper process = createProcessWrapper(new ProcessWrapper.Builder(), getClass());
    process.execute(createProperties());
    process.waitForOutputToMatch("Begin " + name() + "\\.main");
    process.waitForOutputToMatch("Press Enter to continue\\.");
    process.sendInput();
    process.waitForOutputToMatch("End " + name() + "\\.main");
    process.waitFor();
    try {
        assertOutputMatchesGoldenFile(process.getOutput(), goldenString);
        fail("assertOutputMatchesGoldenFile should have failed due to " + problem());
    } catch (AssertionError expected) {
        assertTrue(expected.getMessage().contains(problem()));
    }
}
Also used : ProcessWrapper(org.apache.geode.test.process.ProcessWrapper) Test(org.junit.Test)

Aggregations

ProcessWrapper (org.apache.geode.test.process.ProcessWrapper)9 Test (org.junit.Test)7 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)5 File (java.io.File)1 Builder (org.apache.geode.distributed.ServerLauncher.Builder)1 ServerState (org.apache.geode.distributed.ServerLauncher.ServerState)1 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)1 After (org.junit.After)1 Ignore (org.junit.Ignore)1