Search in sources :

Example 21 with Builder

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

the class LocatorLauncherTest method testSetAndGetBindAddress.

@Test
public void testSetAndGetBindAddress() throws UnknownHostException {
    final Builder builder = new Builder();
    assertNull(builder.getBindAddress());
    assertSame(builder, builder.setBindAddress(null));
    assertNull(builder.getBindAddress());
    assertSame(builder, builder.setBindAddress(""));
    assertNull(builder.getBindAddress());
    assertSame(builder, builder.setBindAddress("  "));
    assertNull(builder.getBindAddress());
    assertSame(builder, builder.setBindAddress(InetAddress.getLocalHost().getCanonicalHostName()));
    assertEquals(InetAddress.getLocalHost(), builder.getBindAddress());
}
Also used : Builder(org.apache.geode.distributed.LocatorLauncher.Builder) UnitTest(org.apache.geode.test.junit.categories.UnitTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 22 with Builder

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

the class LocatorLauncherAssemblyIntegrationTest method testLocatorStopsWhenJmxPortIsNonZero.

/*
   * This test addresses GEODE-528
   */
@Test
public void testLocatorStopsWhenJmxPortIsNonZero() throws Throwable {
    String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
    final int jmxPort = AvailablePortHelper.getRandomAvailableTCPPorts(1)[0];
    final Builder builder = new Builder().setMemberName(getUniqueName()).setPort(this.locatorPort).setRedirectOutput(false).setWorkingDirectory(rootFolder).set(LOG_LEVEL, "config").set(ENABLE_CLUSTER_CONFIGURATION, "false").set(JMX_MANAGER, "true").set(JMX_MANAGER_START, "true").set(JMX_MANAGER_PORT, Integer.toString(jmxPort));
    performTest(builder);
}
Also used : Builder(org.apache.geode.distributed.LocatorLauncher.Builder) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 23 with Builder

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

the class LocatorLauncherAssemblyIntegrationTest method testLocatorStopsWhenJmxPortIsZero.

/*
   * This test addresses GEODE-528
   */
@Test
public void testLocatorStopsWhenJmxPortIsZero() throws Throwable {
    String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
    final Builder builder = new Builder().setMemberName(getUniqueName()).setPort(this.locatorPort).setRedirectOutput(false).setWorkingDirectory(rootFolder).set(LOG_LEVEL, "config").set(ENABLE_CLUSTER_CONFIGURATION, "false").set(JMX_MANAGER, "true").set(JMX_MANAGER_START, "true").set(JMX_MANAGER_PORT, "0");
    performTest(builder);
}
Also used : Builder(org.apache.geode.distributed.LocatorLauncher.Builder) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 24 with Builder

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

the class LauncherLifecycleCommandsDUnitTest method test011StopLocatorUsingMemberName.

@Test
public void test011StopLocatorUsingMemberName() throws IOException {
    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
    final int jmxManagerPort = ports[0];
    final int locatorPort = ports[1];
    String pathname = (getClass().getSimpleName() + "_" + getTestMethodName());
    File workingDirectory = temporaryFolder.newFolder(pathname);
    try {
        assertTrue(workingDirectory.isDirectory() || workingDirectory.mkdir());
        CommandStringBuilder command = new CommandStringBuilder(CliStrings.START_LOCATOR);
        command.addOption(CliStrings.START_LOCATOR__MEMBER_NAME, pathname);
        command.addOption(CliStrings.START_LOCATOR__CONNECT, Boolean.FALSE.toString());
        command.addOption(CliStrings.START_LOCATOR__DIR, workingDirectory.getCanonicalPath());
        command.addOption(CliStrings.START_LOCATOR__PORT, String.valueOf(locatorPort));
        command.addOption(CliStrings.START_LOCATOR__ENABLE__SHARED__CONFIGURATION, Boolean.FALSE.toString());
        command.addOption(CliStrings.START_LOCATOR__FORCE, Boolean.TRUE.toString());
        command.addOption(CliStrings.START_LOCATOR__J, "-D" + DistributionConfig.GEMFIRE_PREFIX + "http-service-port=0");
        command.addOption(CliStrings.START_LOCATOR__J, "-D" + DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-port=" + jmxManagerPort);
        CommandResult result = executeCommand(command.toString());
        assertNotNull(result);
        assertEquals(Result.Status.OK, result.getStatus());
        final LocatorLauncher locatorLauncher = new Builder().setCommand(Command.STOP).setBindAddress(null).setPort(locatorPort).setWorkingDirectory(workingDirectory.getPath()).build();
        assertNotNull(locatorLauncher);
        LocatorState locatorStatus = locatorLauncher.waitOnStatusResponse(60, 10, TimeUnit.SECONDS);
        assertNotNull(locatorStatus);
        assertEquals(Status.ONLINE, locatorStatus.getStatus());
        result = executeCommand(String.format("%1$s --locator=localhost[%2$d]", CliStrings.CONNECT, locatorPort));
        assertNotNull(result);
        assertEquals(Result.Status.OK, result.getStatus());
        result = executeCommand(String.format("%1$s --name=invalidLocatorMemberName", CliStrings.STOP_LOCATOR));
        assertNotNull(result);
        assertEquals(Result.Status.ERROR, result.getStatus());
        assertEquals(CliStrings.format(CliStrings.STOP_LOCATOR__NO_LOCATOR_FOUND_FOR_MEMBER_ERROR_MESSAGE, "invalidLocatorMemberName"), StringUtils.trim(toString(result)));
        locatorStatus = locatorLauncher.status();
        assertNotNull(locatorStatus);
        assertEquals(Status.ONLINE, locatorStatus.getStatus());
        result = executeCommand(String.format("%1$s --name=%2$s", CliStrings.STOP_LOCATOR, pathname));
        assertNotNull(result);
        assertEquals(Result.Status.OK, result.getStatus());
        // TODO figure out what output to assert and validate on now that 'stop locator' uses Gfsh's
        // logger
        // and standard err/out...
        // assertIndexDetailsEquals(CliStrings.format(CliStrings.STOP_LOCATOR__SHUTDOWN_MEMBER_MESSAGE,
        // pathname),
        // StringUtils.trim(toString(result)));
        WaitCriterion waitCriteria = new WaitCriterion() {

            @Override
            public boolean done() {
                final LocatorState locatorStatus = locatorLauncher.status();
                return (locatorStatus != null && Status.NOT_RESPONDING.equals(locatorStatus.getStatus()));
            }

            @Override
            public String description() {
                return "wait for the Locator to stop; the Locator will no longer respond after it stops";
            }
        };
        waitForCriterion(waitCriteria, 15 * 1000, 5000, true);
        locatorStatus = locatorLauncher.status();
        assertNotNull(locatorStatus);
        assertEquals(Status.NOT_RESPONDING, locatorStatus.getStatus());
    } finally {
    }
}
Also used : LocatorLauncher(org.apache.geode.distributed.LocatorLauncher) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) Builder(org.apache.geode.distributed.LocatorLauncher.Builder) LocatorState(org.apache.geode.distributed.LocatorLauncher.LocatorState) File(java.io.File) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 25 with Builder

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

the class LauncherLifecycleCommandsDUnitTest method test012StopLocatorUsingMemberId.

// @see Trac Bug # 46760
@Test
public void test012StopLocatorUsingMemberId() throws Exception {
    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
    final int jmxManagerPort = ports[0];
    final int locatorPort = ports[1];
    String pathname = (getClass().getSimpleName() + "_" + getTestMethodName());
    File workingDirectory = temporaryFolder.newFolder(pathname);
    try {
        assertTrue(workingDirectory.isDirectory() || workingDirectory.mkdir());
        CommandStringBuilder command = new CommandStringBuilder(CliStrings.START_LOCATOR);
        command.addOption(CliStrings.START_LOCATOR__MEMBER_NAME, pathname);
        command.addOption(CliStrings.START_LOCATOR__CONNECT, Boolean.FALSE.toString());
        command.addOption(CliStrings.START_LOCATOR__DIR, workingDirectory.getCanonicalPath());
        command.addOption(CliStrings.START_LOCATOR__PORT, String.valueOf(locatorPort));
        command.addOption(CliStrings.START_LOCATOR__ENABLE__SHARED__CONFIGURATION, Boolean.FALSE.toString());
        command.addOption(CliStrings.START_LOCATOR__FORCE, Boolean.TRUE.toString());
        command.addOption(CliStrings.START_LOCATOR__J, "-D" + DistributionConfig.GEMFIRE_PREFIX + "http-service-port=0");
        command.addOption(CliStrings.START_LOCATOR__J, "-D" + DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-port=" + jmxManagerPort);
        CommandResult result = executeCommand(command.toString());
        assertNotNull(result);
        assertEquals(Result.Status.OK, result.getStatus());
        final LocatorLauncher locatorLauncher = new Builder().setCommand(Command.STOP).setBindAddress(null).setPort(locatorPort).setWorkingDirectory(workingDirectory.getPath()).build();
        assertNotNull(locatorLauncher);
        LocatorState locatorState = locatorLauncher.waitOnStatusResponse(60, 10, TimeUnit.SECONDS);
        assertNotNull(locatorState);
        assertEquals(Status.ONLINE, locatorState.getStatus());
        result = executeCommand(String.format("%1$s --locator=localhost[%2$d]", CliStrings.CONNECT, locatorPort));
        assertNotNull(result);
        assertEquals(Result.Status.OK, result.getStatus());
        String memberId = getMemberId(jmxManagerPort, pathname);
        result = executeCommand(String.format("%1$s --name=%2$s", CliStrings.STOP_LOCATOR, memberId));
        assertNotNull(result);
        assertEquals(Result.Status.OK, result.getStatus());
        // TODO figure out what output to assert and validate on now that 'stop locator' uses Gfsh's
        // logger
        // and standard err/out...
        // assertIndexDetailsEquals(CliStrings.format(CliStrings.STOP_LOCATOR__SHUTDOWN_MEMBER_MESSAGE,
        // memberId),
        // StringUtils.trim(toString(result)));
        WaitCriterion waitCriteria = new WaitCriterion() {

            @Override
            public boolean done() {
                LocatorState locatorState = locatorLauncher.status();
                return (locatorState != null && Status.NOT_RESPONDING.equals(locatorState.getStatus()));
            }

            @Override
            public String description() {
                return "wait for the Locator to stop; the Locator will no longer respond after it stops";
            }
        };
        waitForCriterion(waitCriteria, 15 * 1000, 5000, true);
        locatorState = locatorLauncher.status();
        assertNotNull(locatorState);
        assertEquals(Status.NOT_RESPONDING, locatorState.getStatus());
    } finally {
    }
}
Also used : LocatorLauncher(org.apache.geode.distributed.LocatorLauncher) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) Builder(org.apache.geode.distributed.LocatorLauncher.Builder) LocatorState(org.apache.geode.distributed.LocatorLauncher.LocatorState) File(java.io.File) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

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