Search in sources :

Example 11 with Builder

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

the class LocatorLauncherLocalIntegrationTest method testBuilderSetProperties.

@Test
public void testBuilderSetProperties() throws Throwable {
    this.launcher = new Builder().setForce(true).setMemberName(getUniqueName()).setPort(this.locatorPort).setWorkingDirectory(this.workingDirectory).set(CLUSTER_CONFIGURATION_DIR, this.clusterConfigDirectory).set(DISABLE_AUTO_RECONNECT, "true").set(LOG_LEVEL, "config").set(MCAST_PORT, "0").build();
    try {
        assertEquals(Status.ONLINE, this.launcher.start().getStatus());
        waitForLocatorToStart(this.launcher, true);
        final InternalLocator locator = this.launcher.getLocator();
        assertNotNull(locator);
        final DistributedSystem distributedSystem = locator.getDistributedSystem();
        assertNotNull(distributedSystem);
        assertEquals("true", distributedSystem.getProperties().getProperty(DISABLE_AUTO_RECONNECT));
        assertEquals("0", distributedSystem.getProperties().getProperty(MCAST_PORT));
        assertEquals("config", distributedSystem.getProperties().getProperty(LOG_LEVEL));
        assertEquals(getUniqueName(), distributedSystem.getProperties().getProperty(NAME));
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    try {
        assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
        assertNull(this.launcher.getLocator());
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
}
Also used : InternalLocator(org.apache.geode.distributed.internal.InternalLocator) Builder(org.apache.geode.distributed.LocatorLauncher.Builder) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 12 with Builder

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

the class LocatorLauncherLocalIntegrationTest method testStartUsingPortInUseFails.

@Test
public void testStartUsingPortInUseFails() throws Throwable {
    // Test makes no sense in this case
    if (this.locatorPort == 0) {
        return;
    }
    // generate one free port and then use it instead of default
    this.socket = SocketCreatorFactory.getSocketCreatorForComponent(SecurableCommunicationChannel.CLUSTER).createServerSocket(this.locatorPort, 50, null, -1);
    this.launcher = new Builder().setMemberName(getUniqueName()).setPort(this.locatorPort).setRedirectOutput(true).setWorkingDirectory(this.workingDirectory).set(CLUSTER_CONFIGURATION_DIR, this.clusterConfigDirectory).set(LOG_LEVEL, "config").build();
    RuntimeException expected = null;
    try {
        this.launcher.start();
        fail("LocatorLauncher start should have thrown RuntimeException caused by BindException");
    } catch (RuntimeException e) {
        expected = e;
        assertNotNull(expected.getMessage());
    // BindException string varies by platform
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    try {
        assertNotNull(expected);
        final Throwable cause = expected.getCause();
        assertNotNull(cause);
        assertTrue(cause instanceof BindException);
    // BindException string varies by platform
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    try {
        this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.LOCATOR.getPidFileName());
        assertFalse("Pid file should not exist: " + this.pidFile, this.pidFile.exists());
        // creation of log file seems to be random -- look into why sometime
        final String logFileName = getUniqueName() + ".log";
        assertFalse("Log file should not exist: " + logFileName, new File(this.temporaryFolder.getRoot(), logFileName).exists());
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    // just in case the launcher started...
    LocatorState status = null;
    try {
        status = this.launcher.stop();
    } catch (Throwable t) {
    // ignore
    }
    try {
        waitForFileToDelete(this.pidFile);
        assertEquals(getExpectedStopStatusForNotRunning(), status.getStatus());
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
}
Also used : Builder(org.apache.geode.distributed.LocatorLauncher.Builder) BindException(java.net.BindException) LocatorState(org.apache.geode.distributed.LocatorLauncher.LocatorState) File(java.io.File) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 13 with Builder

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

the class LocatorLauncherLocalIntegrationTest method testStartWithDefaultPortInUseFails.

/*
   * assertTrue(getUniqueName() + " is broken if PID == Integer.MAX_VALUE",
   * ProcessUtils.identifyPid() != Integer.MAX_VALUE);
   * 
   * // create existing pid file this.pidFile = new File(ProcessType.LOCATOR.getPidFileName());
   * final int realPid = Host.getHost(0).getVM(3).invoke(() -> ProcessUtils.identifyPid());
   * assertFalse(realPid == ProcessUtils.identifyPid()); writePid(this.pidFile, realPid);
   * 
   * // build and start the locator final Builder builder = new Builder() .setForce(true)
   * .setMemberName(getUniqueName()) .setPort(this.locatorPort) .setRedirectOutput(true)
   * 
   * assertTrue(builder.getForce()); this.launcher = builder.build();
   * assertTrue(this.launcher.isForcing()); this.launcher.start();
   * 
   * // collect and throw the FIRST failure Throwable failure = null;
   * 
   * try { waitForLocatorToStart(this.launcher);
   * 
   * // validate the pid file and its contents assertTrue(this.pidFile.exists()); final int pid =
   * readPid(this.pidFile); assertTrue(pid > 0); assertTrue(ProcessUtils.isProcessAlive(pid));
   * assertIndexDetailsEquals(getPid(), pid);
   * 
   * // validate log file was created final String logFileName = getUniqueName()+".log";
   * assertTrue("Log file should exist: " + logFileName, new File(logFileName).exists());
   * 
   * } catch (Throwable e) { logger.error(e); if (failure == null) { failure = e; } }
   * 
   * try { assertIndexDetailsEquals(Status.STOPPED, this.launcher.stop().getStatus());
   * waitForFileToDelete(this.pidFile); } catch (Throwable e) { logger.error(e); if (failure ==
   * null) { failure = e; } }
   * 
   * if (failure != null) { throw failure; } } // testStartUsingForceOverwritesExistingPidFile
   */
@Test
public void testStartWithDefaultPortInUseFails() throws Throwable {
    // Test makes no sense in this case
    if (this.locatorPort == 0) {
        return;
    }
    this.socket = SocketCreatorFactory.getSocketCreatorForComponent(SecurableCommunicationChannel.CLUSTER).createServerSocket(this.locatorPort, 50, null, -1);
    assertTrue(this.socket.isBound());
    assertFalse(this.socket.isClosed());
    assertFalse(AvailablePort.isPortAvailable(this.locatorPort, AvailablePort.SOCKET));
    assertNotNull(System.getProperty(DistributionLocator.TEST_OVERRIDE_DEFAULT_PORT_PROPERTY));
    assertEquals(this.locatorPort, Integer.valueOf(System.getProperty(DistributionLocator.TEST_OVERRIDE_DEFAULT_PORT_PROPERTY)).intValue());
    assertFalse(AvailablePort.isPortAvailable(this.locatorPort, AvailablePort.SOCKET));
    this.launcher = new Builder().setMemberName(getUniqueName()).setRedirectOutput(true).setWorkingDirectory(this.workingDirectory).set(CLUSTER_CONFIGURATION_DIR, this.clusterConfigDirectory).set(LOG_LEVEL, "config").build();
    assertEquals(this.locatorPort, this.launcher.getPort().intValue());
    RuntimeException expected = null;
    try {
        this.launcher.start();
        // why did it not fail like it's supposed to?
        final String property = System.getProperty(DistributionLocator.TEST_OVERRIDE_DEFAULT_PORT_PROPERTY);
        assertNotNull(property);
        assertEquals(this.locatorPort, Integer.valueOf(property).intValue());
        assertFalse(AvailablePort.isPortAvailable(this.locatorPort, AvailablePort.SOCKET));
        assertEquals(this.locatorPort, this.launcher.getPort().intValue());
        assertEquals(this.locatorPort, this.socket.getLocalPort());
        assertTrue(this.socket.isBound());
        assertFalse(this.socket.isClosed());
        fail("LocatorLauncher start should have thrown RuntimeException caused by BindException");
    } catch (RuntimeException e) {
        expected = e;
        assertNotNull(expected.getMessage());
    // BindException text varies by platform
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    try {
        assertNotNull(expected);
        final Throwable cause = expected.getCause();
        assertNotNull(cause);
        assertTrue(cause instanceof BindException);
    // BindException string varies by platform
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    try {
        this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.LOCATOR.getPidFileName());
        assertFalse("Pid file should not exist: " + this.pidFile, this.pidFile.exists());
        // creation of log file seems to be random -- look into why sometime
        final String logFileName = getUniqueName() + ".log";
        assertFalse("Log file should not exist: " + logFileName, new File(this.temporaryFolder.getRoot(), logFileName).exists());
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    // just in case the launcher started...
    LocatorState status = null;
    try {
        status = this.launcher.stop();
    } catch (Throwable t) {
    // ignore
    }
    try {
        waitForFileToDelete(this.pidFile);
        assertEquals(getExpectedStopStatusForNotRunning(), status.getStatus());
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
}
Also used : Builder(org.apache.geode.distributed.LocatorLauncher.Builder) BindException(java.net.BindException) LocatorState(org.apache.geode.distributed.LocatorLauncher.LocatorState) File(java.io.File) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 14 with Builder

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

the class LocatorLauncherLocalIntegrationTest method testStopUsingWorkingDirectory.

@Test
public void testStopUsingWorkingDirectory() 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);
        // validate the pid file and its contents
        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());
        // stop the locator
        final LocatorState locatorState = dirLauncher.stop();
        assertNotNull(locatorState);
        assertEquals(Status.STOPPED, locatorState.getStatus());
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    try {
        this.launcher.stop();
    } catch (Throwable e) {
    // ignore
    }
    try {
        // verify the PID file was deleted
        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 15 with Builder

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

the class LocatorLauncherLocalIntegrationTest method testStopUsingPid.

@Test
public void testStopUsingPid() 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 pidLauncher = null;
    try {
        this.launcher.start();
        waitForLocatorToStart(this.launcher);
        // validate the pid file and its contents
        this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.LOCATOR.getPidFileName());
        assertTrue(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());
        // stop the locator
        final LocatorState locatorState = pidLauncher.stop();
        assertNotNull(locatorState);
        assertEquals(Status.STOPPED, locatorState.getStatus());
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    try {
        this.launcher.stop();
    } catch (Throwable e) {
    // ignore
    }
    try {
        // verify the PID file was deleted
        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

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