Search in sources :

Example 11 with HeadlessGfsh

use of org.apache.geode.management.internal.cli.HeadlessGfsh in project geode by apache.

the class ClusterConfigurationDUnitTest method setup.

private Object[] setup() throws IOException {
    final int locator1Port = getRandomAvailableTCPPort();
    final String locator1Name = "locator1-" + locator1Port;
    final String locatorLogPath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + "locator-" + locator1Port + ".log";
    VM locatorAndMgr = getHost(0).getVM(3);
    Object[] result = (Object[]) locatorAndMgr.invoke(() -> {
        int httpPort;
        int jmxPort;
        String jmxHost;
        try {
            jmxHost = InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException ignore) {
            jmxHost = "localhost";
        }
        final int[] ports = getRandomAvailableTCPPorts(2);
        jmxPort = ports[0];
        httpPort = ports[1];
        final File locatorLogFile = new File(locatorLogPath);
        final Properties locatorProps = new Properties();
        locatorProps.setProperty(NAME, locator1Name);
        locatorProps.setProperty(MCAST_PORT, "0");
        locatorProps.setProperty(LOG_LEVEL, "config");
        locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
        locatorProps.setProperty(JMX_MANAGER, "true");
        locatorProps.setProperty(JMX_MANAGER_START, "true");
        locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
        locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
        locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
        final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator1Port, locatorLogFile, null, locatorProps);
        WaitCriterion wc = new WaitCriterion() {

            @Override
            public boolean done() {
                return locator.isSharedConfigurationRunning();
            }

            @Override
            public String description() {
                return "Waiting for shared configuration to be started";
            }
        };
        waitForCriterion(wc, TIMEOUT, INTERVAL, true);
        final Object[] results = new Object[4];
        results[0] = locator1Port;
        results[1] = jmxHost;
        results[2] = jmxPort;
        results[3] = httpPort;
        return results;
    });
    HeadlessGfsh gfsh = getDefaultShell();
    String jmxHost = (String) result[1];
    int jmxPort = (Integer) result[2];
    int httpPort = (Integer) result[3];
    connect(jmxHost, jmxPort, httpPort, gfsh);
    final String dataMemberWorkingDir = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + dataMember;
    // Create a cache in VM 1
    VM dataMember = getHost(0).getVM(1);
    dataMember.invoke(() -> {
        Properties localProps = new Properties();
        File workingDir = new File(dataMemberWorkingDir);
        workingDir.mkdirs();
        localProps.setProperty(MCAST_PORT, "0");
        localProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
        localProps.setProperty(NAME, ClusterConfigurationDUnitTest.dataMember);
        localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
        localProps.setProperty(DEPLOY_WORKING_DIR, workingDir.getCanonicalPath());
        getSystem(localProps);
        InternalCache cache = getCache();
        assertNotNull(cache);
        return getAllNormalMembers(cache);
    });
    return result;
}
Also used : UnknownHostException(java.net.UnknownHostException) HeadlessGfsh(org.apache.geode.management.internal.cli.HeadlessGfsh) InternalCache(org.apache.geode.internal.cache.InternalCache) Properties(java.util.Properties) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) VM(org.apache.geode.test.dunit.VM) File(java.io.File)

Aggregations

HeadlessGfsh (org.apache.geode.management.internal.cli.HeadlessGfsh)11 Properties (java.util.Properties)5 VM (org.apache.geode.test.dunit.VM)4 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)4 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)4 Test (org.junit.Test)4 InternalCache (org.apache.geode.internal.cache.InternalCache)3 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)3 Category (org.junit.experimental.categories.Category)3 File (java.io.File)2 UnknownHostException (java.net.UnknownHostException)2 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)2 InternalLocator (org.apache.geode.distributed.internal.InternalLocator)2 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)2 IOException (java.io.IOException)1 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)1 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)1 Region (org.apache.geode.cache.Region)1 RegionFactory (org.apache.geode.cache.RegionFactory)1 DistributedRegionMXBean (org.apache.geode.management.DistributedRegionMXBean)1