Search in sources :

Example 36 with Builder

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

the class LocatorLauncherLocalIntegrationTest method testStartOverwritesStalePidFile.

@Test
public void testStartOverwritesStalePidFile() throws Throwable {
    // create existing pid file
    this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.LOCATOR.getPidFileName());
    assertFalse("Integer.MAX_VALUE shouldn't be the same as local pid " + Integer.MAX_VALUE, Integer.MAX_VALUE == ProcessUtils.identifyPid());
    writePid(this.pidFile, Integer.MAX_VALUE);
    // 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());
    this.launcher.start();
    try {
        waitForLocatorToStart(this.launcher);
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    try {
        // validate the pid file and its contents
        assertTrue(this.pidFile.exists());
        final int pid = readPid(this.pidFile);
        assertTrue(pid > 0);
        assertTrue(ProcessUtils.isProcessAlive(pid));
        assertEquals(getPid(), pid);
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    try {
        assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
        waitForFileToDelete(this.pidFile);
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
}
Also used : Builder(org.apache.geode.distributed.LocatorLauncher.Builder) File(java.io.File) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 37 with Builder

use of org.apache.geode.distributed.LocatorLauncher.Builder 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)

Example 38 with Builder

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

the class LocatorLauncherIntegrationTest method testBuildWithMemberNameSetInGemFirePropertiesOnStart.

@Test
public void testBuildWithMemberNameSetInGemFirePropertiesOnStart() throws Exception {
    // given: gemfire.properties with a name
    Properties gemfireProperties = new Properties();
    gemfireProperties.setProperty(NAME, "locator123");
    useGemFirePropertiesFileInTemporaryFolder(DistributionConfig.GEMFIRE_PREFIX + "properties", gemfireProperties);
    // when: starting with null MemberName
    LocatorLauncher 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.LocatorLauncher.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 39 with Builder

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

the class LocatorLauncherIntegrationTest method testBuildWithNoMemberNameOnStart.

@Test
public void testBuildWithNoMemberNameOnStart() throws Exception {
    // given: gemfire.properties with no name
    useGemFirePropertiesFileInTemporaryFolder(DistributionConfig.GEMFIRE_PREFIX + "properties", new Properties());
    // when: no MemberName is specified
    when(new Builder().setCommand(Command.START)).build();
    // then: throw IllegalStateException
    then(caughtException()).isExactlyInstanceOf(IllegalStateException.class).hasMessage(LocalizedStrings.Launcher_Builder_MEMBER_NAME_VALIDATION_ERROR_MESSAGE.toLocalizedString("Locator"));
}
Also used : Builder(org.apache.geode.distributed.LocatorLauncher.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 40 with Builder

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

the class LocatorLauncherIntegrationTest method testBuilderSetWorkingDirectoryToNonExistingDirectory.

@Test
public void testBuilderSetWorkingDirectoryToNonExistingDirectory() {
    // when: setting WorkingDirectory to non-existing directory
    when(new Builder()).setWorkingDirectory("/path/to/non_existing/directory");
    // then: throw IllegalArgumentException
    then(caughtException()).isExactlyInstanceOf(IllegalArgumentException.class).hasMessage(LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_NOT_FOUND_ERROR_MESSAGE.toLocalizedString("Locator")).hasCause(new FileNotFoundException("/path/to/non_existing/directory"));
}
Also used : Builder(org.apache.geode.distributed.LocatorLauncher.Builder) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

Builder (org.apache.geode.distributed.LocatorLauncher.Builder)42 Test (org.junit.Test)40 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)26 File (java.io.File)21 LocatorState (org.apache.geode.distributed.LocatorLauncher.LocatorState)13 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)13 UnitTest (org.apache.geode.test.junit.categories.UnitTest)10 ArrayList (java.util.ArrayList)5 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)4 LocatorLauncher (org.apache.geode.distributed.LocatorLauncher)3 FileNotFoundException (java.io.FileNotFoundException)2 BindException (java.net.BindException)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Properties (java.util.Properties)2 Set (java.util.Set)2 DistributionManager (org.apache.geode.distributed.internal.DistributionManager)2 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)2 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)2