Search in sources :

Example 1 with Builder

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

the class HostedLocatorsDUnitTest method testGetAllHostedLocatorsUsingPortZero.

@Test
public void testGetAllHostedLocatorsUsingPortZero() throws Exception {
    final InternalDistributedSystem system = getSystem();
    final String dunitLocator = system.getConfig().getLocators();
    assertNotNull(dunitLocator);
    assertFalse(dunitLocator.isEmpty());
    // This will eventually contain the ports used by locators
    final int[] ports = new int[] { 0, 0, 0, 0 };
    final String uniqueName = getUniqueName();
    for (int i = 0; i < 4; i++) {
        final int whichvm = i;
        Integer port = (Integer) Host.getHost(0).getVM(whichvm).invoke(new SerializableCallable() {

            @Override
            public Object call() throws Exception {
                try {
                    System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "locators", dunitLocator);
                    System.setProperty(DistributionConfig.GEMFIRE_PREFIX + MCAST_PORT, "0");
                    final String name = uniqueName + "-" + whichvm;
                    final File subdir = new File(name);
                    subdir.mkdir();
                    assertTrue(subdir.exists() && subdir.isDirectory());
                    final Builder builder = new Builder().setMemberName(name).setPort(ports[whichvm]).setRedirectOutput(true).setWorkingDirectory(name);
                    launcher = builder.build();
                    assertEquals(Status.ONLINE, launcher.start().getStatus());
                    waitForLocatorToStart(launcher, TIMEOUT_MILLISECONDS, 10, true);
                    return launcher.getPort();
                } finally {
                    System.clearProperty(DistributionConfig.GEMFIRE_PREFIX + "locators");
                    System.clearProperty(DistributionConfig.GEMFIRE_PREFIX + MCAST_PORT);
                }
            }
        });
        ports[i] = port;
    }
    final String host = SocketCreator.getLocalHost().getHostAddress();
    final Set<String> locators = new HashSet<String>();
    locators.add(host + "[" + dunitLocator.substring(dunitLocator.indexOf("[") + 1, dunitLocator.indexOf("]")) + "]");
    for (int port : ports) {
        locators.add(host + "[" + port + "]");
    }
    // validation within non-locator
    final DistributionManager dm = (DistributionManager) system.getDistributionManager();
    final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
    assertEquals(5, locatorIds.size());
    final Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
    assertTrue(!hostedLocators.isEmpty());
    assertEquals(5, hostedLocators.size());
    for (InternalDistributedMember member : hostedLocators.keySet()) {
        assertEquals(1, hostedLocators.get(member).size());
        final String hostedLocator = hostedLocators.get(member).iterator().next();
        assertTrue(locators + " does not contain " + hostedLocator, locators.contains(hostedLocator));
    }
    // validate fix for #46324
    for (int whichvm = 0; whichvm < 4; whichvm++) {
        Host.getHost(0).getVM(whichvm).invoke(new SerializableRunnable() {

            @Override
            public void run() {
                final DistributionManager dm = (DistributionManager) InternalDistributedSystem.getAnyInstance().getDistributionManager();
                final InternalDistributedMember self = dm.getDistributionManagerId();
                final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
                assertTrue(locatorIds.contains(self));
                final Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
                assertTrue("hit bug #46324: " + hostedLocators + " is missing " + InternalLocator.getLocatorStrings() + " for " + self, hostedLocators.containsKey(self));
            }
        });
    }
    // validation with locators
    for (int whichvm = 0; whichvm < 4; whichvm++) {
        Host.getHost(0).getVM(whichvm).invoke(new SerializableRunnable() {

            @Override
            public void run() {
                final DistributionManager dm = (DistributionManager) InternalDistributedSystem.getAnyInstance().getDistributionManager();
                final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
                assertEquals(5, locatorIds.size());
                final Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
                assertTrue(!hostedLocators.isEmpty());
                assertEquals(5, hostedLocators.size());
                for (InternalDistributedMember member : hostedLocators.keySet()) {
                    assertEquals(1, hostedLocators.get(member).size());
                    final String hostedLocator = hostedLocators.get(member).iterator().next();
                    assertTrue(locators + " does not contain " + hostedLocator, locators.contains(hostedLocator));
                }
            }
        });
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Builder(org.apache.geode.distributed.LocatorLauncher.Builder) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Collection(java.util.Collection) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) File(java.io.File) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Map(java.util.Map) HashSet(java.util.HashSet) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 2 with Builder

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

the class LocatorLauncherRemoteIntegrationTest method testStopUsingPid.

@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;
    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
        this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.LOCATOR.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());
        // validate the status
        final LocatorState status = pidLauncher.status();
        assertNotNull(status);
        assertEquals(Status.ONLINE, status.getStatus());
        assertEquals(pid, status.getPid().intValue());
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    // stop the locator
    try {
        if (pidLauncher == null) {
            assertEquals(Status.STOPPED, dirLauncher.stop().getStatus());
        } else {
            assertEquals(Status.STOPPED, pidLauncher.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) LocatorState(org.apache.geode.distributed.LocatorLauncher.LocatorState) File(java.io.File) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with Builder

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

the class LocatorLauncherRemoteIntegrationTest method testStartCreatesPidFile.

/*
                          * // TODO: fix up this test
                          * 
                          * this.temporaryFolder.getRoot() = new File(getUniqueName());
                          * this.temporaryFolder.getRoot().mkdir();
                          * assertTrue(this.temporaryFolder.getRoot().isDirectory() &&
                          * this.temporaryFolder.getRoot().canWrite());
                          * 
                          * // launch LocatorLauncherForkingProcess which then launches the GemFire
                          * Locator 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(LocatorLauncherRemoteDUnitTest.class.getName().concat("$").
                          * concat(LocatorLauncherForkingProcess.class.getSimpleName()));
                          * command.add(String.valueOf(this.locatorPort));
                          * 
                          * 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();
                          * 
                          * Thread waiting = new Thread(new Runnable() { public void run() { try {
                          * assertIndexDetailsEquals(0, process.waitFor()); } catch
                          * (InterruptedException ignore) {
                          * logger.error("Interrupted while waiting for process!", ignore); } } });
                          * 
                          * try { waiting.start(); waiting.join(TIMEOUT_MILLISECONDS);
                          * assertFalse("Process took too long and timed out!", waiting.isAlive());
                          * } finally { if (waiting.isAlive()) { waiting.interrupt(); } }
                          * 
                          * LocatorLauncher locatorLauncher = new
                          * Builder().setWorkingDirectory(this.temporaryFolder.getRoot().
                          * getCanonicalPath()).build();
                          * 
                          * assertIndexDetailsEquals(Status.ONLINE,
                          * locatorLauncher.status().getStatus());
                          * assertIndexDetailsEquals(Status.STOPPED,
                          * locatorLauncher.stop().getStatus()); }
                          */
// GEODE-473: random ports, BindException, forks JVM, uses
@Category(FlakyTest.class)
// ErrorCollector
@Test
public void testStartCreatesPidFile() throws Throwable {
    // build and start the locator
    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();
    int pid = 0;
    this.launcher = new LocatorLauncher.Builder().setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath()).build();
    try {
        waitForLocatorToStart(this.launcher);
        // validate the pid file and its contents
        this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.LOCATOR.getPidFileName());
        assertTrue(this.pidFile.exists());
        pid = readPid(this.pidFile);
        assertTrue(pid > 0);
        assertTrue(ProcessUtils.isProcessAlive(pid));
        final String logFileName = getUniqueName() + ".log";
        assertTrue("Log file should exist: " + logFileName, new File(this.temporaryFolder.getRoot(), logFileName).exists());
        // check the status
        final LocatorState locatorState = this.launcher.status();
        assertNotNull(locatorState);
        assertEquals(Status.ONLINE, locatorState.getStatus());
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    // stop the locator
    try {
        assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
        waitForPidToStop(pid);
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
}
Also used : Builder(org.apache.geode.distributed.LocatorLauncher.Builder) Builder(org.apache.geode.distributed.LocatorLauncher.Builder) ArrayList(java.util.ArrayList) LocatorState(org.apache.geode.distributed.LocatorLauncher.LocatorState) File(java.io.File) Category(org.junit.experimental.categories.Category) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with Builder

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

the class LocatorLauncherTest method testBuild.

@Test
public void testBuild() throws Exception {
    Builder builder = new Builder();
    LocatorLauncher launcher = builder.setCommand(Command.START).setDebug(true).setHostnameForClients("beanstock.vmware.com").setMemberName("Beanstock").setPort(8192).build();
    assertThat(launcher).isNotNull();
    assertEquals(builder.getCommand(), launcher.getCommand());
    assertTrue(launcher.isDebugging());
    assertEquals(builder.getHostnameForClients(), launcher.getHostnameForClients());
    assertEquals(builder.getMemberName(), launcher.getMemberName());
    assertEquals(builder.getPort(), launcher.getPort());
    assertEquals(builder.getWorkingDirectory(), launcher.getWorkingDirectory());
    assertFalse(launcher.isHelping());
    assertFalse(launcher.isRunning());
}
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 5 with Builder

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

the class LocatorLauncherTest method testForceSetToTrue.

@Test
public void testForceSetToTrue() {
    Builder builder = new Builder();
    builder.parseArguments("start", "--force");
    assertTrue(Boolean.TRUE.equals(builder.getForce()));
}
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)

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