Search in sources :

Example 11 with Builder

use of org.apache.geode.distributed.ServerLauncher.Builder 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 12 with Builder

use of org.apache.geode.distributed.ServerLauncher.Builder in project geode by apache.

the class ServerLauncherIntegrationTest method testBuilderSetAndGetWorkingDirectory.

@Test
public void testBuilderSetAndGetWorkingDirectory() throws Exception {
    // given: a new builder and a directory
    String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
    Builder builder = new Builder();
    // when: not setting WorkingDirectory
    // then: getWorkingDirectory returns default
    assertThat(builder.getWorkingDirectory()).isEqualTo(ServerLauncher.DEFAULT_WORKING_DIRECTORY);
    // when: setting WorkingDirectory to null
    assertThat(builder.setWorkingDirectory(null)).isSameAs(builder);
    // then: getWorkingDirectory returns default
    assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY);
    // when: setting WorkingDirectory to empty string
    assertThat(builder.setWorkingDirectory("")).isSameAs(builder);
    // then: getWorkingDirectory returns default
    assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY);
    // when: setting WorkingDirectory to white space
    assertThat(builder.setWorkingDirectory("  ")).isSameAs(builder);
    // then: getWorkingDirectory returns default
    assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY);
    // when: setting WorkingDirectory to a directory
    assertThat(builder.setWorkingDirectory(rootFolder)).isSameAs(builder);
    // then: getWorkingDirectory returns that directory
    assertThat(builder.getWorkingDirectory()).isEqualTo(rootFolder);
    // when: setting WorkingDirectory to null (again)
    assertThat(builder.setWorkingDirectory(null)).isSameAs(builder);
    // then: getWorkingDirectory returns default
    assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY);
}
Also used : Builder(org.apache.geode.distributed.ServerLauncher.Builder) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 13 with Builder

use of org.apache.geode.distributed.ServerLauncher.Builder in project geode by apache.

the class ServerLauncherIntegrationTest method testBuilderParseArgumentsWithValuesSeparatedWithCommas.

@Test
public void testBuilderParseArgumentsWithValuesSeparatedWithCommas() throws Exception {
    // given a new builder and a directory
    String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
    Builder builder = new Builder();
    // when: parsing many arguments
    builder.parseArguments("start", "serverOne", "--assign-buckets", "--disable-default-server", "--debug", "--force", "--rebalance", "--redirect-output", "--dir", rootFolder, "--pid", "1234", "--server-bind-address", InetAddress.getLocalHost().getHostAddress(), "--server-port", "11235", "--hostname-for-clients", "192.168.99.100");
    // then: the getters should return properly parsed values
    assertThat(builder.getCommand()).isEqualTo(Command.START);
    assertThat(builder.getMemberName()).isEqualTo("serverOne");
    assertThat(builder.getHostNameForClients()).isEqualTo("192.168.99.100");
    assertThat(builder.getAssignBuckets()).isTrue();
    assertThat(builder.getDisableDefaultServer()).isTrue();
    assertThat(builder.getDebug()).isTrue();
    assertThat(builder.getForce()).isTrue();
    assertThat(builder.getHelp()).isFalse();
    assertThat(builder.getRebalance()).isTrue();
    assertThat(builder.getRedirectOutput()).isTrue();
    assertThat(builder.getWorkingDirectory()).isEqualTo(rootFolder);
    assertThat(builder.getPid().intValue()).isEqualTo(1234);
    assertThat(builder.getServerBindAddress()).isEqualTo(InetAddress.getLocalHost());
    assertThat(builder.getServerPort().intValue()).isEqualTo(11235);
}
Also used : Builder(org.apache.geode.distributed.ServerLauncher.Builder) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 14 with Builder

use of org.apache.geode.distributed.ServerLauncher.Builder in project geode by apache.

the class ServerLauncherIntegrationTest method testBuildWithMemberNameSetInGemFirePropertiesOnStart.

@Test
public void testBuildWithMemberNameSetInGemFirePropertiesOnStart() throws Exception {
    // given: gemfire.properties with a name
    Properties gemfireProperties = new Properties();
    gemfireProperties.setProperty(NAME, "server123");
    useGemFirePropertiesFileInTemporaryFolder(DistributionConfig.GEMFIRE_PREFIX + "properties", gemfireProperties);
    // when: starting with null MemberName
    ServerLauncher launcher = new Builder().setCommand(Command.START).build();
    // then: name in gemfire.properties file should be used for MemberName
    assertThat(launcher).isNotNull();
    assertThat(launcher.getCommand()).isEqualTo(Command.START);
    assertThat(launcher.getMemberName()).isNull();
}
Also used : Builder(org.apache.geode.distributed.ServerLauncher.Builder) Properties(java.util.Properties) RestoreSystemProperties(org.junit.contrib.java.lang.system.RestoreSystemProperties) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 15 with Builder

use of org.apache.geode.distributed.ServerLauncher.Builder in project geode by apache.

the class ServerLauncherIntegrationTest method testBuilderParseArgumentsWithValuesSeparatedWithEquals.

@Test
public void testBuilderParseArgumentsWithValuesSeparatedWithEquals() throws Exception {
    // given a new builder and a directory
    String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
    Builder builder = new Builder();
    // when: parsing many arguments
    builder.parseArguments("start", "serverOne", "--assign-buckets", "--disable-default-server", "--debug", "--force", "--rebalance", "--redirect-output", "--dir=" + rootFolder, "--pid=1234", "--server-bind-address=" + InetAddress.getLocalHost().getHostAddress(), "--server-port=11235", "--hostname-for-clients=192.168.99.100");
    // then: the getters should return properly parsed values
    assertThat(builder.getCommand()).isEqualTo(Command.START);
    assertThat(builder.getMemberName()).isEqualTo("serverOne");
    assertThat(builder.getHostNameForClients()).isEqualTo("192.168.99.100");
    assertThat(builder.getAssignBuckets()).isTrue();
    assertThat(builder.getDisableDefaultServer()).isTrue();
    assertThat(builder.getDebug()).isTrue();
    assertThat(builder.getForce()).isTrue();
    assertThat(builder.getHelp()).isFalse();
    assertThat(builder.getRebalance()).isTrue();
    assertThat(builder.getRedirectOutput()).isTrue();
    assertThat(builder.getWorkingDirectory()).isEqualTo(rootFolder);
    assertThat(builder.getPid().intValue()).isEqualTo(1234);
    assertThat(builder.getServerBindAddress()).isEqualTo(InetAddress.getLocalHost());
    assertThat(builder.getServerPort().intValue()).isEqualTo(11235);
}
Also used : Builder(org.apache.geode.distributed.ServerLauncher.Builder) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

Builder (org.apache.geode.distributed.ServerLauncher.Builder)56 Test (org.junit.Test)56 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)31 UnitTest (org.apache.geode.test.junit.categories.UnitTest)29 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)27 File (java.io.File)18 Cache (org.apache.geode.cache.Cache)14 Expectations (org.jmock.Expectations)12 ServerState (org.apache.geode.distributed.ServerLauncher.ServerState)11 ArrayList (java.util.ArrayList)4 CacheServer (org.apache.geode.cache.server.CacheServer)4 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)3 FileNotFoundException (java.io.FileNotFoundException)2 FileWriter (java.io.FileWriter)2 PrintWriter (java.io.PrintWriter)2 BindException (java.net.BindException)2 Properties (java.util.Properties)2 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)2 RegionAttributesCreation (org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation)2 ProcessStreamReader (org.apache.geode.internal.process.ProcessStreamReader)2