Search in sources :

Example 1 with AttachAPINotFoundException

use of org.apache.geode.lang.AttachAPINotFoundException in project geode by apache.

the class ServerLauncherRemoteFileIntegrationTest method testStopUsingPid.

@Override
@Test
public /**
   * Override because FileProcessController cannot request stop with PID
   */
void testStopUsingPid() 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(ServerLauncher.class.getName());
    command.add(ServerLauncher.Command.START.getName());
    command.add(getUniqueName());
    command.add("--disable-default-server");
    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(createLoggingListener("sysout", getUniqueName() + "#sysout")).build().start();
    this.processErrReader = new ProcessStreamReader.Builder(this.process).inputStream(this.process.getErrorStream()).inputListener(createLoggingListener("syserr", getUniqueName() + "#syserr")).build().start();
    // wait for server to start
    int pid = 0;
    ServerLauncher pidLauncher = null;
    this.launcher = new ServerLauncher.Builder().setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath()).build();
    try {
        waitForServerToStart();
        // 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 = 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());
        // stop with pid only should throw AttachAPINotFoundException
        try {
            pidLauncher.stop();
            fail("FileProcessController should have thrown AttachAPINotFoundException");
        } catch (AttachAPINotFoundException e) {
        // passed
        }
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    try {
        // stop the server
        assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
        waitForPidToStop(pid);
        waitForFileToDelete(this.pidFile);
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    } finally {
        // TODO: delete
        new File(ProcessType.SERVER.getStopRequestFileName()).delete();
    }
}
Also used : Builder(org.apache.geode.distributed.ServerLauncher.Builder) ArrayList(java.util.ArrayList) Builder(org.apache.geode.distributed.ServerLauncher.Builder) AttachAPINotFoundException(org.apache.geode.lang.AttachAPINotFoundException) ProcessStreamReader(org.apache.geode.internal.process.ProcessStreamReader) File(java.io.File) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with AttachAPINotFoundException

use of org.apache.geode.lang.AttachAPINotFoundException in project geode by apache.

the class ServerLauncherRemoteFileIntegrationTest method testStatusUsingPid.

@Override
@Test
public /**
   * Override because FileProcessController cannot request status with PID
   */
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(ServerLauncher.class.getName());
    command.add(ServerLauncher.Command.START.getName());
    command.add(getUniqueName());
    command.add("--disable-default-server");
    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 server to start
    int pid = 0;
    ServerLauncher pidLauncher = null;
    this.launcher = new ServerLauncher.Builder().setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath()).build();
    try {
        waitForServerToStart();
        // 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 = 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());
        // status with pid only should throw AttachAPINotFoundException
        try {
            pidLauncher.status();
            fail("FileProcessController should have thrown AttachAPINotFoundException");
        } catch (AttachAPINotFoundException e) {
        // passed
        }
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    // stop the server
    try {
        assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
        waitForPidToStop(pid, true);
        waitForFileToDelete(this.pidFile);
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    } finally {
        // TODO: delete
        new File(ProcessType.SERVER.getStatusRequestFileName()).delete();
    }
}
Also used : Builder(org.apache.geode.distributed.ServerLauncher.Builder) ArrayList(java.util.ArrayList) File(java.io.File) Builder(org.apache.geode.distributed.ServerLauncher.Builder) AttachAPINotFoundException(org.apache.geode.lang.AttachAPINotFoundException) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with AttachAPINotFoundException

use of org.apache.geode.lang.AttachAPINotFoundException in project geode by apache.

the class LocatorLauncherRemoteFileIntegrationTest method testStopUsingPid.

/**
   * Override because FileProcessController cannot request stop with PID
   */
@Override
@Test
public void testStopUsingPid() 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()).inputListener(createLoggingListener("sysout", getUniqueName() + "#sysout")).build().start();
    this.processErrReader = new ProcessStreamReader.Builder(this.process).inputStream(this.process.getErrorStream()).inputListener(createLoggingListener("syserr", getUniqueName() + "#syserr")).build().start();
    // wait for locator to start
    int pid = 0;
    File pidFile = null;
    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
        pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.LOCATOR.getPidFileName());
        assertTrue(pidFile.exists());
        pid = readPid(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());
        // stop with pid only should throw AttachAPINotFoundException
        try {
            pidLauncher.stop();
            fail("FileProcessController should have thrown AttachAPINotFoundException");
        } catch (AttachAPINotFoundException e) {
        // passed
        }
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    try {
        // stop the locator
        assertEquals(Status.STOPPED, dirLauncher.stop().getStatus());
        waitForPidToStop(pid);
        waitForFileToDelete(pidFile);
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
}
Also used : ProcessStreamReader(org.apache.geode.internal.process.ProcessStreamReader) Builder(org.apache.geode.distributed.LocatorLauncher.Builder) ArrayList(java.util.ArrayList) File(java.io.File) AttachAPINotFoundException(org.apache.geode.lang.AttachAPINotFoundException) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with AttachAPINotFoundException

use of org.apache.geode.lang.AttachAPINotFoundException in project geode by apache.

the class LocatorLauncherRemoteFileIntegrationTest method testStatusUsingPid.

/**
   * Override because FileProcessController cannot request status with PID
   */
@Override
@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
        final File pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.LOCATOR.getPidFileName());
        assertTrue(pidFile.exists());
        pid = readPid(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());
        // status with pid only should throw AttachAPINotFoundException
        try {
            pidLauncher.status();
            fail("FileProcessController should have thrown AttachAPINotFoundException");
        } catch (AttachAPINotFoundException e) {
        // passed
        }
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    // stop the locator
    try {
        assertEquals(Status.STOPPED, dirLauncher.stop().getStatus());
        waitForPidToStop(pid, true);
        waitForFileToDelete(this.pidFile);
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
}
Also used : Builder(org.apache.geode.distributed.LocatorLauncher.Builder) ArrayList(java.util.ArrayList) File(java.io.File) AttachAPINotFoundException(org.apache.geode.lang.AttachAPINotFoundException) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

File (java.io.File)4 ArrayList (java.util.ArrayList)4 AttachAPINotFoundException (org.apache.geode.lang.AttachAPINotFoundException)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 Test (org.junit.Test)4 Builder (org.apache.geode.distributed.LocatorLauncher.Builder)2 Builder (org.apache.geode.distributed.ServerLauncher.Builder)2 ProcessStreamReader (org.apache.geode.internal.process.ProcessStreamReader)2