http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/management/internal/configuration/SharedConfigurationUsingDirDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/configuration/SharedConfigurationUsingDirDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/configuration/SharedConfigurationUsingDirDUnitTest.java index 70f3e70..9cbb12c 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/configuration/SharedConfigurationUsingDirDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/configuration/SharedConfigurationUsingDirDUnitTest.java @@ -16,22 +16,12 @@ */ package com.gemstone.gemfire.management.internal.configuration; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.distributed.Locator; -import com.gemstone.gemfire.distributed.internal.DistributionConfig; -import com.gemstone.gemfire.distributed.internal.InternalLocator; -import com.gemstone.gemfire.distributed.internal.SharedConfiguration; -import com.gemstone.gemfire.internal.AvailablePortHelper; -import com.gemstone.gemfire.test.dunit.Host; -import com.gemstone.gemfire.test.dunit.VM; -import com.gemstone.gemfire.test.dunit.cache.internal.JUnit4CacheTestCase; -import com.gemstone.gemfire.test.junit.categories.DistributedTest; -import com.gemstone.gemfire.test.junit.categories.FlakyTest; -import com.gemstone.gemfire.util.test.TestUtil; -import com.jayway.awaitility.Awaitility; -import org.junit.After; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import static com.gemstone.gemfire.distributed.internal.DistributionConfig.*; +import static com.gemstone.gemfire.internal.AvailablePortHelper.*; +import static com.gemstone.gemfire.test.dunit.Host.*; +import static com.jayway.awaitility.Awaitility.*; +import static java.util.stream.Collectors.*; +import static org.junit.Assert.*; import java.io.File; import java.io.FileInputStream; @@ -43,17 +33,27 @@ import java.util.Arrays; import java.util.Properties; import java.util.concurrent.TimeUnit; -import static java.util.stream.Collectors.joining; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import org.junit.After; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.distributed.Locator; +import com.gemstone.gemfire.distributed.internal.InternalLocator; +import com.gemstone.gemfire.distributed.internal.SharedConfiguration; +import com.gemstone.gemfire.test.dunit.VM; +import com.gemstone.gemfire.test.dunit.cache.internal.JUnit4CacheTestCase; +import com.gemstone.gemfire.test.junit.categories.DistributedTest; +import com.gemstone.gemfire.test.junit.categories.FlakyTest; +import com.gemstone.gemfire.util.test.TestUtil; @Category(DistributedTest.class) public class SharedConfigurationUsingDirDUnitTest extends JUnit4CacheTestCase { - @After - public void teardown() throws Exception { + @Override + public final void preTearDownCacheTestCase() throws Exception { for (int i = 0; i < 2; i++) { - VM vm = Host.getHost(0).getVM(i); + VM vm = getHost(0).getVM(i); vm.invoke("Removing shared configuration", () -> { InternalLocator locator = InternalLocator.getLocator(); if (locator == null) { @@ -62,7 +62,7 @@ public class SharedConfigurationUsingDirDUnitTest extends JUnit4CacheTestCase { SharedConfiguration sharedConfig = locator.getSharedConfiguration(); if (sharedConfig != null) { - sharedConfig.destroySharedConfiguration(); + sharedConfig.destroySharedConfiguration_forTestsOnly(); } }); } @@ -70,44 +70,44 @@ public class SharedConfigurationUsingDirDUnitTest extends JUnit4CacheTestCase { @Test public void basicClusterConfigDirWithOneLocator() throws Exception { - final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(1); + final int[] ports = getRandomAvailableTCPPorts(1); final int locatorCount = ports.length; for (int i = 0; i < locatorCount; i++) { - VM vm = Host.getHost(0).getVM(i); + VM vm = getHost(0).getVM(i); copyClusterXml(vm, "cluster-region.xml"); startLocator(vm, i, ports); waitForSharedConfiguration(vm); } for (int i = 2; i < 4; i++) { - VM vm = Host.getHost(0).getVM(i); + VM vm = getHost(0).getVM(i); restartCache(vm, i, ports); vm.invoke("Checking for region presence", () -> { - Awaitility.waitAtMost(15, TimeUnit.SECONDS).until(() -> getRootRegion("newReplicatedRegion") != null); + waitAtMost(15, TimeUnit.SECONDS).until(() -> getRootRegion("newReplicatedRegion") != null); }); } } @Test public void basicClusterConfigDirWithTwoLocators() throws Exception { - final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2); + final int[] ports = getRandomAvailableTCPPorts(2); final int locatorCount = ports.length; for (int i = 0; i < locatorCount; i++) { - VM vm = Host.getHost(0).getVM(i); + VM vm = getHost(0).getVM(i); copyClusterXml(vm, "cluster-region.xml"); startLocator(vm, i, ports); waitForSharedConfiguration(vm); } for (int i = 2; i < 4; i++) { - VM vm = Host.getHost(0).getVM(i); + VM vm = getHost(0).getVM(i); restartCache(vm, i, ports); vm.invoke("Checking for region presence", () -> { - Awaitility.waitAtMost(15, TimeUnit.SECONDS).until(() -> getRootRegion("newReplicatedRegion") != null); + waitAtMost(15, TimeUnit.SECONDS).until(() -> getRootRegion("newReplicatedRegion") != null); }); } } @@ -115,18 +115,18 @@ public class SharedConfigurationUsingDirDUnitTest extends JUnit4CacheTestCase { @Category(FlakyTest.class) // GEODE-1165: random ports, BindException, time sensitive, awaitility @Test public void updateClusterConfigDirWithTwoLocatorsNoRollingServerRestart() throws Exception { - final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2); + final int[] ports = getRandomAvailableTCPPorts(2); final int locatorCount = ports.length; for (int i = 0; i < locatorCount; i++) { - VM vm = Host.getHost(0).getVM(i); + VM vm = getHost(0).getVM(i); copyClusterXml(vm, "cluster-empty.xml"); startLocator(vm, i, ports); waitForSharedConfiguration(vm); } for (int i = 2; i < 4; i++) { - VM vm = Host.getHost(0).getVM(i); + VM vm = getHost(0).getVM(i); restartCache(vm, i, ports); vm.invoke("Checking for region absence", () -> { @@ -139,46 +139,46 @@ public class SharedConfigurationUsingDirDUnitTest extends JUnit4CacheTestCase { // Unless we start them asynchronously, the older one will want to wait for a new diskstore // to become available and will time out. for (int i = locatorCount; i > 0; i--) { - VM vm = Host.getHost(0).getVM(i - 1); + VM vm = getHost(0).getVM(i - 1); stopLocator(vm); } for (int i = 0; i < locatorCount; i++) { - VM vm = Host.getHost(0).getVM(i); + VM vm = getHost(0).getVM(i); copyClusterXml(vm, "cluster-region.xml"); startLocator(vm, i, ports); waitForSharedConfiguration(vm); } for (int i = 2; i < 4; i++) { - VM vm = Host.getHost(0).getVM(i); + VM vm = getHost(0).getVM(i); vm.invoke(() -> disconnectFromDS()); } for (int i = 2; i < 4; i++) { - VM vm = Host.getHost(0).getVM(i); + VM vm = getHost(0).getVM(i); restartCache(vm, i, ports); vm.invoke("Checking for region presence", () -> { - Awaitility.waitAtMost(15, TimeUnit.SECONDS).until(() -> getRootRegion("newReplicatedRegion") != null); + waitAtMost(15, TimeUnit.SECONDS).until(() -> getRootRegion("newReplicatedRegion") != null); }); } } @Test public void updateClusterConfigDirWithTwoLocatorsAndRollingServerRestart() throws Exception { - final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2); + final int[] ports = getRandomAvailableTCPPorts(2); final int locatorCount = ports.length; for (int i = 0; i < locatorCount; i++) { - VM vm = Host.getHost(0).getVM(i); + VM vm = getHost(0).getVM(i); copyClusterXml(vm, "cluster-empty.xml"); startLocator(vm, i, ports); waitForSharedConfiguration(vm); } for (int i = 2; i < 4; i++) { - VM vm = Host.getHost(0).getVM(i); + VM vm = getHost(0).getVM(i); restartCache(vm, i, ports); vm.invoke("Checking for region absence", () -> { @@ -191,41 +191,41 @@ public class SharedConfigurationUsingDirDUnitTest extends JUnit4CacheTestCase { // Unless we start them asynchronously, the older one will want to wait for a new diskstore // to become available and will time out. for (int i = locatorCount; i > 0; i--) { - VM vm = Host.getHost(0).getVM(i - 1); + VM vm = getHost(0).getVM(i - 1); stopLocator(vm); } for (int i = 0; i < locatorCount; i++) { - VM vm = Host.getHost(0).getVM(i); + VM vm = getHost(0).getVM(i); copyClusterXml(vm, "cluster-region.xml"); startLocator(vm, i, ports); waitForSharedConfiguration(vm); } for (int i = 2; i < 4; i++) { - VM vm = Host.getHost(0).getVM(i); + VM vm = getHost(0).getVM(i); restartCache(vm, i, ports); vm.invoke("Checking for region presence", () -> { - Awaitility.waitAtMost(15, TimeUnit.SECONDS).until(() -> getRootRegion("newReplicatedRegion") != null); + waitAtMost(15, TimeUnit.SECONDS).until(() -> getRootRegion("newReplicatedRegion") != null); }); } } @Test public void updateClusterConfigDirWithTwoLocatorsRollingRestartAndRollingServerRestart() throws Exception { - final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2); + final int[] ports = getRandomAvailableTCPPorts(2); final int locatorCount = ports.length; for (int i = 0; i < locatorCount; i++) { - VM vm = Host.getHost(0).getVM(i); + VM vm = getHost(0).getVM(i); copyClusterXml(vm, "cluster-empty.xml"); startLocator(vm, i, ports); waitForSharedConfiguration(vm); } for (int i = 2; i < 4; i++) { - VM vm = Host.getHost(0).getVM(i); + VM vm = getHost(0).getVM(i); restartCache(vm, i, ports); vm.invoke("Checking for region absence", () -> { @@ -236,7 +236,7 @@ public class SharedConfigurationUsingDirDUnitTest extends JUnit4CacheTestCase { // Roll the locators for (int i = locatorCount - 1; i >= 0; i--) { - VM vm = Host.getHost(0).getVM(i); + VM vm = getHost(0).getVM(i); stopLocator(vm); copyClusterXml(vm, "cluster-region.xml"); startLocator(vm, i, ports); @@ -245,11 +245,11 @@ public class SharedConfigurationUsingDirDUnitTest extends JUnit4CacheTestCase { // Roll the servers for (int i = 2; i < 4; i++) { - VM vm = Host.getHost(0).getVM(i); + VM vm = getHost(0).getVM(i); restartCache(vm, i, ports); vm.invoke("Checking for region presence", () -> { - Awaitility.waitAtMost(15, TimeUnit.SECONDS).until(() -> getRootRegion("newReplicatedRegion") != null); + waitAtMost(15, TimeUnit.SECONDS).until(() -> getRootRegion("newReplicatedRegion") != null); }); } } @@ -269,14 +269,14 @@ public class SharedConfigurationUsingDirDUnitTest extends JUnit4CacheTestCase { final String locatorName = "locator" + i; final File logFile = new File("locator-" + i + ".log"); final Properties props = new Properties(); - props.setProperty(DistributionConfig.NAME_NAME, locatorName); - props.setProperty(DistributionConfig.MCAST_PORT_NAME, "0"); - props.setProperty(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "true"); - props.setProperty(DistributionConfig.LOAD_CLUSTER_CONFIG_FROM_DIR_NAME, "true"); + props.setProperty(NAME_NAME, locatorName); + props.setProperty(MCAST_PORT_NAME, "0"); + props.setProperty(ENABLE_CLUSTER_CONFIGURATION_NAME, "true"); + props.setProperty(LOAD_CLUSTER_CONFIG_FROM_DIR_NAME, "true"); if (locatorPorts.length > 1) { int otherLocatorPort = locatorPorts[(i + 1) % locatorPorts.length]; - props.setProperty(DistributionConfig.LOCATORS_NAME, "localhost[" + otherLocatorPort + "]"); + props.setProperty(LOCATORS_NAME, "localhost[" + otherLocatorPort + "]"); } Locator.startLocatorAndDS(locatorPorts[i], logFile, props); @@ -286,7 +286,7 @@ public class SharedConfigurationUsingDirDUnitTest extends JUnit4CacheTestCase { private void waitForSharedConfiguration(final VM vm) { vm.invoke("Waiting for shared configuration", () -> { final InternalLocator locator = InternalLocator.getLocator(); - Awaitility.waitAtMost(15, TimeUnit.SECONDS).until(() -> { + waitAtMost(15, TimeUnit.SECONDS).until(() -> { return locator.isSharedConfigurationRunning(); }); }); @@ -306,12 +306,12 @@ public class SharedConfigurationUsingDirDUnitTest extends JUnit4CacheTestCase { disconnectFromDS(); final Properties props = new Properties(); - props.setProperty(DistributionConfig.NAME_NAME, "member" + i); - props.setProperty(DistributionConfig.MCAST_PORT_NAME, "0"); - props.setProperty(DistributionConfig.LOCATORS_NAME, getLocatorStr(locatorPorts)); - props.setProperty(DistributionConfig.LOG_FILE_NAME, "server-" + i + ".log"); - props.setProperty(DistributionConfig.USE_CLUSTER_CONFIGURATION_NAME, "true"); - props.setProperty(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "true"); + props.setProperty(NAME_NAME, "member" + i); + props.setProperty(MCAST_PORT_NAME, "0"); + props.setProperty(LOCATORS_NAME, getLocatorStr(locatorPorts)); + props.setProperty(LOG_FILE_NAME, "server-" + i + ".log"); + props.setProperty(USE_CLUSTER_CONFIGURATION_NAME, "true"); + props.setProperty(ENABLE_CLUSTER_CONFIGURATION_NAME, "true"); getSystem(props); getCache();
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/GfshShellConnectionRule.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/GfshShellConnectionRule.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/GfshShellConnectionRule.java index 17549d5..d0f33d9 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/GfshShellConnectionRule.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/GfshShellConnectionRule.java @@ -16,6 +16,8 @@ */ package com.gemstone.gemfire.management.internal.security; +import org.junit.runner.Description; + import com.gemstone.gemfire.management.internal.cli.CliUtil; import com.gemstone.gemfire.management.internal.cli.HeadlessGfsh; import com.gemstone.gemfire.management.internal.cli.i18n.CliStrings; @@ -24,12 +26,10 @@ import com.gemstone.gemfire.management.internal.cli.result.ErrorResultData; import com.gemstone.gemfire.management.internal.cli.result.ResultBuilder; import com.gemstone.gemfire.management.internal.cli.util.CommandStringBuilder; import com.gemstone.gemfire.test.junit.rules.DescribedExternalResource; -import org.junit.runner.Description; /** * Class which eases the creation of MBeans for security testing. When combined with {@link JMXConnectionConfiguration} * it allows for the creation of per-test connections with different user/password combinations. - * */ public class GfshShellConnectionRule extends DescribedExternalResource { @@ -38,9 +38,9 @@ public class GfshShellConnectionRule extends DescribedExternalResource { private boolean useHttp = false; private HeadlessGfsh gfsh; private boolean authenticated; + /** * Rule constructor - * */ public GfshShellConnectionRule(int jmxPort, int httpPort, boolean useHttp) { this.jmxPort = jmxPort; @@ -55,7 +55,7 @@ public class GfshShellConnectionRule extends DescribedExternalResource { CliUtil.isGfshVM = true; String shellId = getClass().getSimpleName() + "_" + description.getMethodName(); - gfsh = new HeadlessGfsh(shellId, 30); + gfsh = new HeadlessGfsh(shellId, 30, "gfsh_files"); // TODO: move to TemporaryFolder final CommandStringBuilder connectCommand = new CommandStringBuilder(CliStrings.CONNECT); connectCommand.addOption(CliStrings.CONNECT__USERNAME, config.user()); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/resources/com/gemstone/gemfire/internal/logging/log4j/custom/log4j2-custom.xml ---------------------------------------------------------------------- diff --git a/geode-core/src/test/resources/com/gemstone/gemfire/internal/logging/log4j/custom/log4j2-custom.xml b/geode-core/src/test/resources/com/gemstone/gemfire/internal/logging/log4j/custom/log4j2-custom.xml new file mode 100644 index 0000000..dbdd402 --- /dev/null +++ b/geode-core/src/test/resources/com/gemstone/gemfire/internal/logging/log4j/custom/log4j2-custom.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Configuration status="FATAL" shutdownHook="disable" packages="com.gemstone.gemfire.internal.logging.log4j.custom"> + <Properties> + <Property name="custom-pattern">CUSTOM: level=%level time=%date{yyyy/MM/dd HH:mm:ss.SSS z} message=%message%nthrowable=%throwable%n</Property> + </Properties> + <Appenders> + <Console name="STDOUT" target="SYSTEM_OUT"> + <PatternLayout pattern="${custom-pattern}"/> + </Console> + <Basic name="CUSTOM"> + <PatternLayout pattern="${custom-pattern}"/> + </Basic> + </Appenders> + <Loggers> + <Logger name="com.gemstone" level="INFO" additivity="true"> + <filters> + <MarkerFilter marker="GEMFIRE_VERBOSE" onMatch="DENY" onMismatch="NEUTRAL"/> + </filters> + </Logger> + <Logger name="org.jgroups" level="FATAL" additivity="true"/> + <Logger name="com.gemstone.gemfire.internal.logging.log4j.custom" level="DEBUG" additivity="true"/> + <Root level="INFO"> + <AppenderRef ref="CUSTOM"/> + <AppenderRef ref="STDOUT"/> + </Root> + </Loggers> +</Configuration> http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-pulse/src/main/java/com/vmware/gemfire/tools/pulse/internal/data/JMXDataUpdater.java ---------------------------------------------------------------------- diff --git a/geode-pulse/src/main/java/com/vmware/gemfire/tools/pulse/internal/data/JMXDataUpdater.java b/geode-pulse/src/main/java/com/vmware/gemfire/tools/pulse/internal/data/JMXDataUpdater.java index 47ff69e..4a95c91 100644 --- a/geode-pulse/src/main/java/com/vmware/gemfire/tools/pulse/internal/data/JMXDataUpdater.java +++ b/geode-pulse/src/main/java/com/vmware/gemfire/tools/pulse/internal/data/JMXDataUpdater.java @@ -200,7 +200,6 @@ public class JMXDataUpdater implements IClusterUpdater, NotificationListener { /** * Default connection is Pulse which uses configured userName and password - * @return */ public JMXConnector getJMXConnection() { return getJMXConnection(true); @@ -209,8 +208,6 @@ public class JMXDataUpdater implements IClusterUpdater, NotificationListener { /** * Get connection for given userName and password. This is used for DataBrowser * queries which has to be fired using credentials provided at pulse login page - * - * @return */ public JMXConnector getJMXConnection(final boolean registerURL) { JMXConnector connection = null; http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/wancommand/WANCommandTestBase.java ---------------------------------------------------------------------- diff --git a/geode-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/wancommand/WANCommandTestBase.java b/geode-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/wancommand/WANCommandTestBase.java index 49a978c..71b5910 100644 --- a/geode-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/wancommand/WANCommandTestBase.java +++ b/geode-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/wancommand/WANCommandTestBase.java @@ -79,7 +79,7 @@ public abstract class WANCommandTestBase extends CliCommandTestBase { static VM vm7; @Override - public final void postSetUp() throws Exception { + public final void postSetUpCliCommandTestBase() throws Exception { final Host host = Host.getHost(0); vm0 = host.getVM(0); vm1 = host.getVM(1); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-wan/src/test/java/com/gemstone/gemfire/management/internal/configuration/ClusterConfigurationDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-wan/src/test/java/com/gemstone/gemfire/management/internal/configuration/ClusterConfigurationDUnitTest.java b/geode-wan/src/test/java/com/gemstone/gemfire/management/internal/configuration/ClusterConfigurationDUnitTest.java index 4ff9a73..62bb793 100644 --- a/geode-wan/src/test/java/com/gemstone/gemfire/management/internal/configuration/ClusterConfigurationDUnitTest.java +++ b/geode-wan/src/test/java/com/gemstone/gemfire/management/internal/configuration/ClusterConfigurationDUnitTest.java @@ -16,8 +16,16 @@ */ package com.gemstone.gemfire.management.internal.configuration; +import static com.gemstone.gemfire.distributed.internal.DistributionConfig.*; +import static com.gemstone.gemfire.internal.AvailablePortHelper.*; +import static com.gemstone.gemfire.internal.FileUtil.*; +import static com.gemstone.gemfire.internal.lang.StringUtils.*; +import static com.gemstone.gemfire.management.internal.cli.CliUtil.*; import static com.gemstone.gemfire.test.dunit.Assert.*; +import static com.gemstone.gemfire.test.dunit.Host.*; +import static com.gemstone.gemfire.test.dunit.IgnoredException.*; import static com.gemstone.gemfire.test.dunit.Wait.*; +import static org.apache.commons.io.FileUtils.*; import java.io.File; import java.io.IOException; @@ -32,12 +40,10 @@ import java.util.Map.Entry; import java.util.Properties; import java.util.Set; -import org.apache.commons.io.FileUtils; import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; -import com.gemstone.gemfire.LogWriter; import com.gemstone.gemfire.cache.Cache; import com.gemstone.gemfire.cache.CacheFactory; import com.gemstone.gemfire.cache.Region; @@ -48,11 +54,8 @@ import com.gemstone.gemfire.cache.wan.GatewayReceiver; import com.gemstone.gemfire.cache.wan.GatewaySender; import com.gemstone.gemfire.cache.wan.GatewaySender.OrderPolicy; import com.gemstone.gemfire.distributed.Locator; -import com.gemstone.gemfire.distributed.internal.DistributionConfig; import com.gemstone.gemfire.distributed.internal.InternalLocator; -import com.gemstone.gemfire.internal.AvailablePortHelper; import com.gemstone.gemfire.internal.ClassBuilder; -import com.gemstone.gemfire.internal.FileUtil; import com.gemstone.gemfire.internal.JarClassLoader; import com.gemstone.gemfire.internal.JarDeployer; import com.gemstone.gemfire.internal.admin.remote.ShutdownAllRequest; @@ -65,17 +68,13 @@ import com.gemstone.gemfire.internal.cache.extension.mock.MockExtensionCommands; import com.gemstone.gemfire.internal.cache.extension.mock.MockRegionExtension; import com.gemstone.gemfire.internal.cache.xmlcache.XmlGenerator; import com.gemstone.gemfire.internal.cache.xmlcache.XmlParser; -import com.gemstone.gemfire.internal.lang.StringUtils; import com.gemstone.gemfire.management.cli.Result.Status; -import com.gemstone.gemfire.management.internal.cli.CliUtil; import com.gemstone.gemfire.management.internal.cli.HeadlessGfsh; import com.gemstone.gemfire.management.internal.cli.commands.CliCommandTestBase; import com.gemstone.gemfire.management.internal.cli.i18n.CliStrings; import com.gemstone.gemfire.management.internal.cli.result.CommandResult; import com.gemstone.gemfire.management.internal.cli.util.CommandStringBuilder; import com.gemstone.gemfire.management.internal.configuration.domain.XmlEntity; -import com.gemstone.gemfire.test.dunit.Host; -import com.gemstone.gemfire.test.dunit.IgnoredException; import com.gemstone.gemfire.test.dunit.SerializableCallable; import com.gemstone.gemfire.test.dunit.VM; import com.gemstone.gemfire.test.dunit.WaitCriterion; @@ -83,8 +82,10 @@ import com.gemstone.gemfire.test.junit.categories.DistributedTest; @Category(DistributedTest.class) public class ClusterConfigurationDUnitTest extends CliCommandTestBase { + private static final int TIMEOUT = 10000; private static final int INTERVAL = 500; + private static final String REPLICATE_REGION = "ReplicateRegion1"; private static final String PARTITION_REGION = "PartitionRegion1"; private static final String DISK_REGION1 = "DR1"; @@ -96,225 +97,235 @@ public class ClusterConfigurationDUnitTest extends CliCommandTestBase { private static final String JAR2 = "D2.jar"; private static final String JAR3 = "D3.jar"; private static final String AsyncEventQueue1 = "Q1"; - + + private static final String dataMember = "DataMember"; + private static final String newMember = "NewMember"; + + private static Set<String> serverNames = new HashSet<>(); + private static Set<String> jarFileNames = new HashSet<>(); + private transient ClassBuilder classBuilder = new ClassBuilder(); - - public static Set<String> serverNames = new HashSet<String>(); - public static Set<String> jarFileNames = new HashSet<String>(); - - public static String dataMember = "DataMember"; - public static String newMember = "NewMember"; - - private static final long serialVersionUID = 1L; + + @Override + public final void postSetUpCliCommandTestBase() throws Exception { + disconnectAllFromDS(); + } + + @Override + public final void preTearDownCliCommandTestBase() throws Exception { + shutdownAll(); + + serverNames.clear(); + jarFileNames.clear(); + } @Test - public void testConfigDistribution() throws IOException { - IgnoredException.addIgnoredException("could not get remote locator"); - try { - Object[] result = setup(); - IgnoredException.addIgnoredException("EntryDestroyedException"); - final int locatorPort = (Integer) result[0]; - final String jmxHost = (String) result[1]; - final int jmxPort = (Integer) result[2]; - final int httpPort = (Integer) result[3]; - final String locatorString = "localHost[" + locatorPort + "]"; - - String gatewayRecieverStartPort = "10000"; - String gatewayRecieverEndPort = "20000"; - final String gsId = "GatewaySender1"; - final String batchSize = "1000"; - final String dispatcherThreads = "5"; - final String enableConflation = "false"; - final String manualStart = "false"; - final String receiverManualStart = "true"; - final String alertThreshold = "1000"; - final String batchTimeInterval = "20"; - final String maxQueueMemory = "100"; - final String orderPolicy = OrderPolicy.KEY.toString(); - final String parallel = "true"; - final String rmDsId = "250"; - final String socketBufferSize = String.valueOf(GatewaySender.MINIMUM_SOCKET_READ_TIMEOUT + 1000); - final String socketReadTimeout = String.valueOf(GatewaySender.MINIMUM_SOCKET_READ_TIMEOUT+200); - final String DESTROY_REGION = "regionToBeDestroyed"; - - createRegion(REPLICATE_REGION, RegionShortcut.REPLICATE, null); - createRegion(PARTITION_REGION, RegionShortcut.PARTITION, null); - createRegion(DESTROY_REGION, RegionShortcut.REPLICATE, null); - createIndex(INDEX1 , "AAPL", REPLICATE_REGION, null); - createIndex(INDEX2, "VMW", PARTITION_REGION, null); - createAndDeployJar(JAR1, null); - createAndDeployJar(JAR2, null); - createAndDeployJar(JAR3, null); - createAsyncEventQueue(AsyncEventQueue1, "false", null, "1000", "1000", null); - destroyRegion(DESTROY_REGION); - destroyIndex(INDEX2, PARTITION_REGION, null); - undeployJar(JAR3, null); - alterRuntime("true", "", "", ""); - createGatewayReceiver(receiverManualStart, "", gatewayRecieverStartPort, gatewayRecieverEndPort, "20", ""); - createGatewaySender(gsId, batchSize, alertThreshold, batchTimeInterval, dispatcherThreads, enableConflation, manualStart, maxQueueMemory, orderPolicy, parallel, rmDsId, socketBufferSize, socketReadTimeout); - //alterRegion(PARTITION_REGION, "false", AsyncEventQueue1, "", "", "", "", "", "", gsId); - //Start a new member which receives the shared configuration - //Verify the config creation on this member - VM newMember = Host.getHost(0).getVM(2); - - newMember.invoke(new SerializableCallable() { - @Override - public Object call() throws IOException { - Properties localProps = new Properties(); - - File workingDir = new File(ClusterConfigurationDUnitTest.newMember); - workingDir.mkdirs(); - workingDir.deleteOnExit(); - - localProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0"); - localProps.setProperty(DistributionConfig.LOCATORS_NAME, "localhost:" + locatorPort); - localProps.setProperty(DistributionConfig.NAME_NAME, ClusterConfigurationDUnitTest.newMember); - localProps.setProperty(DistributionConfig.USE_CLUSTER_CONFIGURATION_NAME, "true"); - localProps.setProperty(DistributionConfig.DEPLOY_WORKING_DIR, workingDir.getCanonicalPath()); - - getSystem(localProps); - Cache cache = getCache(); - - assertNotNull(cache); - assertTrue(cache.getCopyOnRead()); - - Region region1 = cache.getRegion(REPLICATE_REGION); - assertNotNull(region1); - Region region2 = cache.getRegion(PARTITION_REGION); - assertNotNull(region2); - - Region region3 = cache.getRegion(DESTROY_REGION); - assertNull(region3); - - //Index verfication - Index index1 = cache.getQueryService().getIndex(region1, INDEX1); - assertNotNull(index1); - assertNull(cache.getQueryService().getIndex(region2, INDEX2)); - - LogWriter logger = cache.getLogger(); - final JarDeployer jarDeployer = new JarDeployer(((GemFireCacheImpl) cache).getDistributedSystem().getConfig().getDeployWorkingDir()); - - final List<JarClassLoader> jarClassLoaders = jarDeployer.findJarClassLoaders(); - - Set<String> jarNames = new HashSet<String>(); - - for (JarClassLoader jarClassLoader : jarClassLoaders) { - jarNames.add(jarClassLoader.getJarName()); - } - - assertTrue(jarNames.contains(JAR1)); - assertTrue(jarNames.contains(JAR2)); - assertFalse(jarNames.contains(JAR3)); - - //ASYNC-EVENT-QUEUE verification - AsyncEventQueue aeq = cache.getAsyncEventQueue(AsyncEventQueue1); - assertNotNull(aeq); - assertFalse(aeq.isPersistent()); - assertTrue(aeq.getBatchSize() == 1000); - assertTrue(aeq.getMaximumQueueMemory() == 1000); - - //GatewayReviever verification - Set<GatewayReceiver> gatewayReceivers = cache.getGatewayReceivers(); - assertFalse(gatewayReceivers.isEmpty()); - assertTrue(gatewayReceivers.size() == 1); - - //Gateway Sender verfication - GatewaySender gs = cache.getGatewaySender(gsId); - assertNotNull(gs); - assertTrue(alertThreshold.equals(Integer.toString(gs.getAlertThreshold()))); - assertTrue(batchSize.equals(Integer.toString(gs.getBatchSize()))); - assertTrue(dispatcherThreads.equals(Integer.toString(gs.getDispatcherThreads()))); - assertTrue(enableConflation.equals(Boolean.toString(gs.isBatchConflationEnabled()))); - assertTrue(manualStart.equals(Boolean.toString(gs.isManualStart()))); - assertTrue(alertThreshold.equals(Integer.toString(gs.getAlertThreshold()))); - assertTrue(batchTimeInterval.equals(Integer.toString(gs.getBatchTimeInterval()))); - assertTrue(maxQueueMemory.equals(Integer.toString(gs.getMaximumQueueMemory()))); - assertTrue(orderPolicy.equals(gs.getOrderPolicy().toString())); - assertTrue(parallel.equals(Boolean.toString(gs.isParallel()))); - assertTrue(rmDsId.equals(Integer.toString(gs.getRemoteDSId()))); - assertTrue(socketBufferSize.equals(Integer.toString(gs.getSocketBufferSize()))); - assertTrue(socketReadTimeout.equals(Integer.toString(gs.getSocketReadTimeout()))); - - return CliUtil.getAllNormalMembers(cache); + public void testConfigDistribution() throws Exception { + addIgnoredException("could not get remote locator"); + addIgnoredException("EntryDestroyedException"); + + String workingDir = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator; + + Object[] result = setup(); + final int locatorPort = (Integer) result[0]; + final String jmxHost = (String) result[1]; + final int jmxPort = (Integer) result[2]; + final int httpPort = (Integer) result[3]; + final String locatorString = "localHost[" + locatorPort + "]"; + + String gatewayReceiverStartPort = "10000"; + String gatewayReceiverEndPort = "20000"; + final String gsId = "GatewaySender1"; + final String batchSize = "1000"; + final String dispatcherThreads = "5"; + final String enableConflation = "false"; + final String manualStart = "false"; + final String receiverManualStart = "true"; + final String alertThreshold = "1000"; + final String batchTimeInterval = "20"; + final String maxQueueMemory = "100"; + final String orderPolicy = OrderPolicy.KEY.toString(); + final String parallel = "true"; + final String rmDsId = "250"; + final String socketBufferSize = String.valueOf(GatewaySender.MINIMUM_SOCKET_READ_TIMEOUT + 1000); + final String socketReadTimeout = String.valueOf(GatewaySender.MINIMUM_SOCKET_READ_TIMEOUT+200); + final String DESTROY_REGION = "regionToBeDestroyed"; + + createRegion(REPLICATE_REGION, RegionShortcut.REPLICATE, null); + createRegion(PARTITION_REGION, RegionShortcut.PARTITION, null); + createRegion(DESTROY_REGION, RegionShortcut.REPLICATE, null); + createIndex(INDEX1, "AAPL", REPLICATE_REGION, null); + createIndex(INDEX2, "VMW", PARTITION_REGION, null); + + createAndDeployJar(workingDir + JAR1, null); + createAndDeployJar(workingDir + JAR2, null); + createAndDeployJar(workingDir + JAR3, null); + + createAsyncEventQueue(AsyncEventQueue1, "false", null, "1000", "1000", null); + destroyRegion(DESTROY_REGION); + destroyIndex(INDEX2, PARTITION_REGION, null); + + undeployJar(JAR3, null); + + alterRuntime("true", "", "", ""); + createGatewayReceiver(receiverManualStart, "", gatewayReceiverStartPort, gatewayReceiverEndPort, "20", ""); + createGatewaySender(gsId, batchSize, alertThreshold, batchTimeInterval, dispatcherThreads, enableConflation, manualStart, maxQueueMemory, orderPolicy, parallel, rmDsId, socketBufferSize, socketReadTimeout); + + //alterRegion(PARTITION_REGION, "false", AsyncEventQueue1, "", "", "", "", "", "", gsId); + //Start a new member which receives the shared configuration + //Verify the config creation on this member + + final String newMemberWorkingDir = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + newMember; + + VM newMember = getHost(0).getVM(2); + newMember.invoke(new SerializableCallable() { + @Override + public Object call() throws IOException { + Properties localProps = new Properties(); + + File workingDir = new File(newMemberWorkingDir); + workingDir.mkdirs(); + + localProps.setProperty(MCAST_PORT_NAME, "0"); + localProps.setProperty(LOCATORS_NAME, "localhost:" + locatorPort); + localProps.setProperty(NAME_NAME, ClusterConfigurationDUnitTest.newMember); + localProps.setProperty(USE_CLUSTER_CONFIGURATION_NAME, "true"); + localProps.setProperty(DEPLOY_WORKING_DIR, workingDir.getCanonicalPath()); + + getSystem(localProps); + Cache cache = getCache(); + + assertNotNull(cache); + assertTrue(cache.getCopyOnRead()); + + Region region1 = cache.getRegion(REPLICATE_REGION); + assertNotNull(region1); + Region region2 = cache.getRegion(PARTITION_REGION); + assertNotNull(region2); + + Region region3 = cache.getRegion(DESTROY_REGION); + assertNull(region3); + + //Index verfication + Index index1 = cache.getQueryService().getIndex(region1, INDEX1); + assertNotNull(index1); + assertNull(cache.getQueryService().getIndex(region2, INDEX2)); + + final JarDeployer jarDeployer = new JarDeployer(((GemFireCacheImpl) cache).getDistributedSystem().getConfig().getDeployWorkingDir()); + + final List<JarClassLoader> jarClassLoaders = jarDeployer.findJarClassLoaders(); + + Set<String> jarNames = new HashSet<String>(); + + for (JarClassLoader jarClassLoader : jarClassLoaders) { + jarNames.add(jarClassLoader.getJarName()); } - }); - } finally { - shutdownAll(); - } + + assertTrue(jarNames.contains(JAR1)); + assertTrue(jarNames.contains(JAR2)); + assertFalse(jarNames.contains(JAR3)); + + //ASYNC-EVENT-QUEUE verification + AsyncEventQueue aeq = cache.getAsyncEventQueue(AsyncEventQueue1); + assertNotNull(aeq); + assertFalse(aeq.isPersistent()); + assertTrue(aeq.getBatchSize() == 1000); + assertTrue(aeq.getMaximumQueueMemory() == 1000); + + //GatewayReceiver verification + Set<GatewayReceiver> gatewayReceivers = cache.getGatewayReceivers(); + assertFalse(gatewayReceivers.isEmpty()); + assertTrue(gatewayReceivers.size() == 1); + + //Gateway Sender verification + GatewaySender gs = cache.getGatewaySender(gsId); + assertNotNull(gs); + assertTrue(alertThreshold.equals(Integer.toString(gs.getAlertThreshold()))); + assertTrue(batchSize.equals(Integer.toString(gs.getBatchSize()))); + assertTrue(dispatcherThreads.equals(Integer.toString(gs.getDispatcherThreads()))); + assertTrue(enableConflation.equals(Boolean.toString(gs.isBatchConflationEnabled()))); + assertTrue(manualStart.equals(Boolean.toString(gs.isManualStart()))); + assertTrue(alertThreshold.equals(Integer.toString(gs.getAlertThreshold()))); + assertTrue(batchTimeInterval.equals(Integer.toString(gs.getBatchTimeInterval()))); + assertTrue(maxQueueMemory.equals(Integer.toString(gs.getMaximumQueueMemory()))); + assertTrue(orderPolicy.equals(gs.getOrderPolicy().toString())); + assertTrue(parallel.equals(Boolean.toString(gs.isParallel()))); + assertTrue(rmDsId.equals(Integer.toString(gs.getRemoteDSId()))); + assertTrue(socketBufferSize.equals(Integer.toString(gs.getSocketBufferSize()))); + assertTrue(socketReadTimeout.equals(Integer.toString(gs.getSocketReadTimeout()))); + + return getAllNormalMembers(cache); + } + }); } /** * Tests for {@link Extension}, {@link Extensible}, {@link XmlParser}, * {@link XmlGenerator}, {@link XmlEntity} as it applies to Extensions. - * Asserts that Mock Entension is created and altered on region and cache. + * Asserts that Mock Extension is created and altered on region and cache. * - * @throws IOException * @since 8.1 */ @Test - public void testCreateExtensions() throws IOException { - - try { - Object[] result = setup(); - final int locatorPort = (Integer) result[0]; - - createRegion(REPLICATE_REGION, RegionShortcut.REPLICATE, null); - createMockRegionExtension(REPLICATE_REGION, "value1"); - alterMockRegionExtension(REPLICATE_REGION, "value2"); - createMockCacheExtension("value1"); - alterMockCacheExtension("value2"); - - //Start a new member which receives the shared configuration - //Verify the config creation on this member - VM newMember = Host.getHost(0).getVM(2); - - newMember.invoke(new SerializableCallable() { - private static final long serialVersionUID = 1L; - - @Override - public Object call() throws IOException { - Properties localProps = new Properties(); - - File workingDir = new File(ClusterConfigurationDUnitTest.newMember); - workingDir.mkdirs(); - workingDir.deleteOnExit(); - - localProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0"); - localProps.setProperty(DistributionConfig.LOCATORS_NAME, "localhost:" + locatorPort); - localProps.setProperty(DistributionConfig.NAME_NAME, ClusterConfigurationDUnitTest.newMember); - localProps.setProperty(DistributionConfig.USE_CLUSTER_CONFIGURATION_NAME, "true"); - localProps.setProperty(DistributionConfig.DEPLOY_WORKING_DIR, workingDir.getCanonicalPath()); - - getSystem(localProps); - Cache cache = getCache(); - - assertNotNull(cache); - - Region<?, ?> region1 = cache.getRegion(REPLICATE_REGION); - assertNotNull(region1); - - //MockRegionExtension verification - @SuppressWarnings("unchecked") - // should only be one region extension - final MockRegionExtension mockRegionExtension = (MockRegionExtension) ((Extensible<Region<?,?>>) region1).getExtensionPoint().getExtensions().iterator().next(); - assertNotNull(mockRegionExtension); - assertEquals(1, mockRegionExtension.onCreateCounter.get()); - assertEquals("value2", mockRegionExtension.getValue()); - - //MockCacheExtension verification - @SuppressWarnings("unchecked") - // should only be one cache extension - final MockCacheExtension mockCacheExtension = (MockCacheExtension) ((Extensible<Cache>) cache).getExtensionPoint().getExtensions().iterator().next(); - assertNotNull(mockCacheExtension); - assertEquals(1, mockCacheExtension.onCreateCounter.get()); - assertEquals("value2", mockCacheExtension.getValue()); - - return CliUtil.getAllNormalMembers(cache); - } - }); - } finally { - shutdownAll(); - } + public void testCreateExtensions() throws Exception { + Object[] result = setup(); + final int locatorPort = (Integer) result[0]; + + createRegion(REPLICATE_REGION, RegionShortcut.REPLICATE, null); + createMockRegionExtension(REPLICATE_REGION, "value1"); + alterMockRegionExtension(REPLICATE_REGION, "value2"); + createMockCacheExtension("value1"); + alterMockCacheExtension("value2"); + + //Start a new member which receives the shared configuration + //Verify the config creation on this member + + final String newMemberWorkDir = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + newMember; + + VM newMember = getHost(0).getVM(2); + newMember.invoke(new SerializableCallable() { + private static final long serialVersionUID = 1L; + + @Override + public Object call() throws IOException { + Properties localProps = new Properties(); + + File workingDir = new File(newMemberWorkDir); + workingDir.mkdirs(); + + localProps.setProperty(MCAST_PORT_NAME, "0"); + localProps.setProperty(LOCATORS_NAME, "localhost:" + locatorPort); + localProps.setProperty(NAME_NAME, ClusterConfigurationDUnitTest.newMember); + localProps.setProperty(USE_CLUSTER_CONFIGURATION_NAME, "true"); + localProps.setProperty(DEPLOY_WORKING_DIR, workingDir.getCanonicalPath()); + + getSystem(localProps); + Cache cache = getCache(); + + assertNotNull(cache); + + Region<?, ?> region1 = cache.getRegion(REPLICATE_REGION); + assertNotNull(region1); + + //MockRegionExtension verification + @SuppressWarnings("unchecked") + // should only be one region extension + final MockRegionExtension mockRegionExtension = (MockRegionExtension) ((Extensible<Region<?,?>>) region1).getExtensionPoint().getExtensions().iterator().next(); + assertNotNull(mockRegionExtension); + assertEquals(1, mockRegionExtension.onCreateCounter.get()); + assertEquals("value2", mockRegionExtension.getValue()); + + //MockCacheExtension verification + @SuppressWarnings("unchecked") + // should only be one cache extension + final MockCacheExtension mockCacheExtension = (MockCacheExtension) ((Extensible<Cache>) cache).getExtensionPoint().getExtensions().iterator().next(); + assertNotNull(mockCacheExtension); + assertEquals(1, mockCacheExtension.onCreateCounter.get()); + assertEquals("value2", mockCacheExtension.getValue()); + + return getAllNormalMembers(cache); + } + }); } /** @@ -322,246 +333,208 @@ public class ClusterConfigurationDUnitTest extends CliCommandTestBase { * {@link XmlGenerator}, {@link XmlEntity} as it applies to Extensions. * Asserts that Mock Entension is created and destroyed on region and cache. * - * @throws IOException * @since 8.1 */ @Test - public void testDestroyExtensions() throws IOException { - - try { - Object[] result = setup(); - final int locatorPort = (Integer) result[0]; - - createRegion(REPLICATE_REGION, RegionShortcut.REPLICATE, null); - createMockRegionExtension(REPLICATE_REGION, "value1"); - destroyMockRegionExtension(REPLICATE_REGION); - createMockCacheExtension("value1"); - destroyMockCacheExtension(); - - //Start a new member which receives the shared configuration - //Verify the config creation on this member - VM newMember = Host.getHost(0).getVM(2); - - newMember.invoke(new SerializableCallable() { - private static final long serialVersionUID = 1L; - - @Override - public Object call() throws IOException { - Properties localProps = new Properties(); - - File workingDir = new File(ClusterConfigurationDUnitTest.newMember); - workingDir.mkdirs(); - workingDir.deleteOnExit(); - - localProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0"); - localProps.setProperty(DistributionConfig.LOCATORS_NAME, "localhost:" + locatorPort); - localProps.setProperty(DistributionConfig.NAME_NAME, ClusterConfigurationDUnitTest.newMember); - localProps.setProperty(DistributionConfig.USE_CLUSTER_CONFIGURATION_NAME, "true"); - localProps.setProperty(DistributionConfig.DEPLOY_WORKING_DIR, workingDir.getCanonicalPath()); - - getSystem(localProps); - Cache cache = getCache(); - - assertNotNull(cache); - - Region<?, ?> region1 = cache.getRegion(REPLICATE_REGION); - assertNotNull(region1); - - //MockRegionExtension verification - @SuppressWarnings("unchecked") - final Extensible<Region<?, ?>> extensibleRegion = (Extensible<Region<?,?>>) region1; - // Should not be any region extensions - assertTrue(!extensibleRegion.getExtensionPoint().getExtensions().iterator().hasNext()); - - //MockCacheExtension verification - @SuppressWarnings("unchecked") - final Extensible<Cache> extensibleCache = (Extensible<Cache>) cache; - // Should not be any cache extensions - assertTrue(!extensibleCache.getExtensionPoint().getExtensions().iterator().hasNext()); - - return CliUtil.getAllNormalMembers(cache); - } - }); - } finally { - shutdownAll(); - } + public void testDestroyExtensions() throws Exception { + Object[] result = setup(); + final int locatorPort = (Integer) result[0]; + + createRegion(REPLICATE_REGION, RegionShortcut.REPLICATE, null); + createMockRegionExtension(REPLICATE_REGION, "value1"); + destroyMockRegionExtension(REPLICATE_REGION); + createMockCacheExtension("value1"); + destroyMockCacheExtension(); + + //Start a new member which receives the shared configuration + //Verify the config creation on this member + + final String newMemberWorkingDir = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + newMember; + + VM newMember = getHost(0).getVM(2); + newMember.invoke(new SerializableCallable() { + + @Override + public Object call() throws IOException { + Properties localProps = new Properties(); + + File workingDir = new File(newMemberWorkingDir); + workingDir.mkdirs(); + + localProps.setProperty(MCAST_PORT_NAME, "0"); + localProps.setProperty(LOCATORS_NAME, "localhost:" + locatorPort); + localProps.setProperty(NAME_NAME, ClusterConfigurationDUnitTest.newMember); + localProps.setProperty(USE_CLUSTER_CONFIGURATION_NAME, "true"); + localProps.setProperty(DEPLOY_WORKING_DIR, workingDir.getCanonicalPath()); + + getSystem(localProps); + Cache cache = getCache(); + + assertNotNull(cache); + + Region<?, ?> region1 = cache.getRegion(REPLICATE_REGION); + assertNotNull(region1); + + //MockRegionExtension verification + @SuppressWarnings("unchecked") + final Extensible<Region<?, ?>> extensibleRegion = (Extensible<Region<?,?>>) region1; + // Should not be any region extensions + assertTrue(!extensibleRegion.getExtensionPoint().getExtensions().iterator().hasNext()); + + //MockCacheExtension verification + @SuppressWarnings("unchecked") + final Extensible<Cache> extensibleCache = (Extensible<Cache>) cache; + // Should not be any cache extensions + assertTrue(!extensibleCache.getExtensionPoint().getExtensions().iterator().hasNext()); + + return getAllNormalMembers(cache); + } + }); } - @Ignore("disabled for unknown reason") + @Ignore("disabled for unknown reason") // this passes when @Ignore is removed @Test - public void testCreateDiskStore () throws IOException { - try { - Object[] result = setup(); - final int locatorPort = (Integer) result[0]; - final String jmxHost = (String) result[1]; - final int jmxPort = (Integer) result[2]; - final int httpPort = (Integer) result[3]; - final String locatorString = "localHost[" + locatorPort + "]"; - - final String diskStoreName = "clusterConfigTestDiskStore"; - final String diskDirs = "dir1"; - //final String - //createPersistentRegion(persRegion, RegionShortcut.PARTITION_PERSISTENT, "", diskStoreName); - final String autoCompact = "true"; - final String allowForceCompaction = "true"; - final String compactionThreshold = "50"; - final String duCritical = "90"; - final String duWarning = "85"; - final String maxOplogSize = "1000"; - final String queueSize = "300"; - final String timeInterval = "10"; - final String writeBufferSize="100"; - createDiskStore(diskStoreName, diskDirs, autoCompact, allowForceCompaction, compactionThreshold, duCritical, duWarning, maxOplogSize, queueSize, timeInterval, writeBufferSize); - - //createAsyncEventQueue(id, persistent, diskStoreName, batchSize, maxQueueMemory, group) - //Stop the existing data member - VM dataMember = Host.getHost(0).getVM(1); - dataMember.invoke(new SerializableCallable() { - @Override - public Object call() throws IOException { - - CacheFactory cf = new CacheFactory(); - GemFireCacheImpl cache = (GemFireCacheImpl)getCache(); - File []diskDirs = null; - Collection<DiskStoreImpl> diskStoreList = cache.listDiskStores(); - - assertFalse(diskStoreList.isEmpty()); - assertTrue(diskStoreList.size() == 1); - - for (DiskStoreImpl diskStore : diskStoreList) { - diskDirs = diskStore.getDiskDirs(); - break; - } - - assertNotNull(diskDirs); - assertTrue(diskDirs.length > 0); - - //close the cache - cache.close(); - - //Delete the disk-store files - for (File diskDir : diskDirs) { - FileUtils.deleteDirectory(diskDir); - } - return CliUtil.getAllNormalMembers(cache); + public void testCreateDiskStore () throws Exception { + Object[] result = setup(); + final int locatorPort = (Integer) result[0]; + final String jmxHost = (String) result[1]; + final int jmxPort = (Integer) result[2]; + final int httpPort = (Integer) result[3]; + final String locatorString = "localHost[" + locatorPort + "]"; + + final String diskStoreName = "clusterConfigTestDiskStore"; + final String diskDirs = "dir1"; + + //final String + //createPersistentRegion(persRegion, RegionShortcut.PARTITION_PERSISTENT, "", diskStoreName); + + final String autoCompact = "true"; + final String allowForceCompaction = "true"; + final String compactionThreshold = "50"; + final String duCritical = "90"; + final String duWarning = "85"; + final String maxOplogSize = "1000"; + final String queueSize = "300"; + final String timeInterval = "10"; + final String writeBufferSize="100"; + + createDiskStore(diskStoreName, diskDirs, autoCompact, allowForceCompaction, compactionThreshold, duCritical, duWarning, maxOplogSize, queueSize, timeInterval, writeBufferSize); + + //createAsyncEventQueue(id, persistent, diskStoreName, batchSize, maxQueueMemory, group) + + //Stop the existing data member + VM dataMember = getHost(0).getVM(1); + dataMember.invoke(new SerializableCallable() { + @Override + public Object call() throws IOException { + + CacheFactory cf = new CacheFactory(); + GemFireCacheImpl cache = (GemFireCacheImpl)getCache(); + File[] diskDirs = null; + Collection<DiskStoreImpl> diskStoreList = cache.listDiskStores(); + + assertFalse(diskStoreList.isEmpty()); + assertTrue(diskStoreList.size() == 1); + + for (DiskStoreImpl diskStore : diskStoreList) { + diskDirs = diskStore.getDiskDirs(); + break; } - }); - - - //Now start the new data member and it should create all the disk-store artifacts - VM newMember = Host.getHost(0).getVM(2); - newMember.invoke(new SerializableCallable() { - @Override - public Object call() throws IOException { - Properties localProps = new Properties(); - - File workingDir = new File(ClusterConfigurationDUnitTest.newMember); - workingDir.mkdirs(); - workingDir.deleteOnExit(); - - localProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0"); - localProps.setProperty(DistributionConfig.LOCATORS_NAME, "localhost:" + locatorPort); - localProps.setProperty(DistributionConfig.NAME_NAME, ClusterConfigurationDUnitTest.newMember); - localProps.setProperty(DistributionConfig.USE_CLUSTER_CONFIGURATION_NAME, "true"); - localProps.setProperty(DistributionConfig.DEPLOY_WORKING_DIR, workingDir.getCanonicalPath()); - - getSystem(localProps); - GemFireCacheImpl cache = (GemFireCacheImpl)getCache(); - assertNotNull(cache); - - - Collection<DiskStoreImpl> diskStoreList = cache.listDiskStores(); - - assertFalse(diskStoreList.isEmpty()); - assertTrue(diskStoreList.size() == 1); - - for (DiskStoreImpl diskStore : diskStoreList) { - assertTrue(diskStore.getName().equals(diskStoreName)); - assertTrue(Boolean.toString(diskStore.getAutoCompact()).equals(autoCompact)); - assertTrue(Boolean.toString(diskStore.getAllowForceCompaction()).equals(allowForceCompaction)); - assertTrue(Integer.toString(diskStore.getCompactionThreshold()).equals(compactionThreshold)); - assertTrue(Long.toString(diskStore.getMaxOplogSize()).equals(maxOplogSize)); - assertTrue(Integer.toString(diskStore.getQueueSize()).equals(queueSize)); - assertTrue(Integer.toString(diskStore.getWriteBufferSize()).equals(writeBufferSize)); - assertTrue(Long.toString(diskStore.getTimeInterval()).equals(timeInterval)); - break; - } - cache.close(); - return null; + + assertNotNull(diskDirs); + assertTrue(diskDirs.length > 0); + + //close the cache + cache.close(); + + //Delete the disk-store files + for (File diskDir : diskDirs) { + deleteDirectory(diskDir); } - }); - } finally { - shutdownAll(); - } - - } + return getAllNormalMembers(cache); + } + }); - @Ignore("disabled for unknown reason") - @Test - public void testConfigurePDX() throws IOException { - try { - Object[] result = setup(); - final int locatorPort = (Integer) result[0]; - final String jmxHost = (String) result[1]; - final int jmxPort = (Integer) result[2]; - final int httpPort = (Integer) result[3]; - final String locatorString = "localHost[" + locatorPort + "]"; - - configurePDX("com.foo.*", "true", "true", null, "true"); - - VM dataMember = Host.getHost(0).getVM(1); - - dataMember.invoke(new SerializableCallable() { - - @Override - public Object call() throws IOException { - GemFireCacheImpl cache = (GemFireCacheImpl)getCache(); - assertTrue(cache.getPdxReadSerialized()); - assertTrue(cache.getPdxIgnoreUnreadFields()); - assertTrue(cache.getPdxPersistent()); - return null; + final String newMemberWorkingDir = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + newMember; + + //Now start the new data member and it should create all the disk-store artifacts + VM newMember = getHost(0).getVM(2); + newMember.invoke(new SerializableCallable() { + @Override + public Object call() throws IOException { + Properties localProps = new Properties(); + + File workingDir = new File(newMemberWorkingDir); + workingDir.mkdirs(); + + localProps.setProperty(MCAST_PORT_NAME, "0"); + localProps.setProperty(LOCATORS_NAME, "localhost:" + locatorPort); + localProps.setProperty(NAME_NAME, ClusterConfigurationDUnitTest.newMember); + localProps.setProperty(USE_CLUSTER_CONFIGURATION_NAME, "true"); + localProps.setProperty(DEPLOY_WORKING_DIR, workingDir.getCanonicalPath()); + + getSystem(localProps); + GemFireCacheImpl cache = (GemFireCacheImpl)getCache(); + assertNotNull(cache); + + + Collection<DiskStoreImpl> diskStoreList = cache.listDiskStores(); + + assertFalse(diskStoreList.isEmpty()); + assertTrue(diskStoreList.size() == 1); + + for (DiskStoreImpl diskStore : diskStoreList) { + assertTrue(diskStore.getName().equals(diskStoreName)); + assertTrue(Boolean.toString(diskStore.getAutoCompact()).equals(autoCompact)); + assertTrue(Boolean.toString(diskStore.getAllowForceCompaction()).equals(allowForceCompaction)); + assertTrue(Integer.toString(diskStore.getCompactionThreshold()).equals(compactionThreshold)); + assertTrue(Long.toString(diskStore.getMaxOplogSize()).equals(maxOplogSize)); + assertTrue(Integer.toString(diskStore.getQueueSize()).equals(queueSize)); + assertTrue(Integer.toString(diskStore.getWriteBufferSize()).equals(writeBufferSize)); + assertTrue(Long.toString(diskStore.getTimeInterval()).equals(timeInterval)); + break; } - }); - } finally { - shutdownAll(); - } + cache.close(); + return null; + } + }); } - - private void shutdownAll() throws IOException { - VM locatorAndMgr = Host.getHost(0).getVM(3); - locatorAndMgr.invoke(new SerializableCallable() { - /** - * - */ - private static final long serialVersionUID = 1L; + @Ignore("disabled for unknown reason") // this fails in configurePDX when @Ignore is removed + @Test + public void testConfigurePDX() throws Exception { + Object[] result = setup(); + final int locatorPort = (Integer) result[0]; + final String jmxHost = (String) result[1]; + final int jmxPort = (Integer) result[2]; + final int httpPort = (Integer) result[3]; + final String locatorString = "localHost[" + locatorPort + "]"; + + configurePDX("com.foo.*", "true", "true", null, "true"); + + VM dataMember = getHost(0).getVM(1); + dataMember.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - GemFireCacheImpl cache = (GemFireCacheImpl)CacheFactory.getAnyInstance(); - ShutdownAllRequest.send(cache.getDistributedSystem().getDistributionManager(), -1); + public Object call() throws IOException { + GemFireCacheImpl cache = (GemFireCacheImpl)getCache(); + assertTrue(cache.getPdxReadSerialized()); + assertTrue(cache.getPdxIgnoreUnreadFields()); + assertTrue(cache.getPdxPersistent()); return null; } }); - - locatorAndMgr.invoke(SharedConfigurationDUnitTest.locatorCleanup); - //Clean up the directories - if (serverNames != null && !serverNames.isEmpty()) { - for (String serverName : serverNames) { - final File serverDir = new File(serverName); - FileUtils.cleanDirectory(serverDir); - FileUtils.deleteDirectory(serverDir); - } - } } - + @Test - public void testClusterConfigDir() { - disconnectAllFromDS(); - final int [] ports = AvailablePortHelper.getRandomAvailableTCPPorts(3); + public void testClusterConfigDir() throws Exception { + final int [] ports = getRandomAvailableTCPPorts(3); final int locator1Port = ports[0]; final String locator1Name = "locator1-" + locator1Port; - VM locatorAndMgr = Host.getHost(0).getVM(3); - + + final String locatorLogPath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + "locator-" + locator1Port + ".log"; + final String clusterConfigPath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + "userSpecifiedDir"; + + VM locatorAndMgr = getHost(0).getVM(3); Object[] result = (Object[]) locatorAndMgr.invoke(new SerializableCallable() { @Override public Object call() throws IOException { @@ -571,55 +544,47 @@ public class ClusterConfigurationDUnitTest extends CliCommandTestBase { try { jmxHost = InetAddress.getLocalHost().getHostName(); - } - catch (UnknownHostException ignore) { + } catch (UnknownHostException ignore) { jmxHost = "localhost"; } - final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2); + final int[] ports = getRandomAvailableTCPPorts(2); jmxPort = ports[0]; httpPort = ports[1]; - - final File locatorLogFile = new File("locator-" + locator1Port + ".log"); + final File locatorLogFile = new File(locatorLogPath); final Properties locatorProps = new Properties(); - locatorProps.setProperty(DistributionConfig.NAME_NAME, locator1Name); - locatorProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0"); - locatorProps.setProperty(DistributionConfig.LOG_LEVEL_NAME, "config"); - locatorProps.setProperty(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "true"); - locatorProps.setProperty(DistributionConfig.JMX_MANAGER_NAME, "true"); - locatorProps.setProperty(DistributionConfig.JMX_MANAGER_START_NAME, "true"); - locatorProps.setProperty(DistributionConfig.JMX_MANAGER_BIND_ADDRESS_NAME, String.valueOf(jmxHost)); - locatorProps.setProperty(DistributionConfig.JMX_MANAGER_PORT_NAME, String.valueOf(jmxPort)); + locatorProps.setProperty(NAME_NAME, locator1Name); + locatorProps.setProperty(MCAST_PORT_NAME, "0"); + locatorProps.setProperty(LOG_LEVEL_NAME, "config"); + locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION_NAME, "true"); + locatorProps.setProperty(JMX_MANAGER_NAME, "true"); + locatorProps.setProperty(JMX_MANAGER_START_NAME, "true"); + locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS_NAME, String.valueOf(jmxHost)); + locatorProps.setProperty(JMX_MANAGER_PORT_NAME, String.valueOf(jmxPort)); - File clusterConfigDir = new File("userSpecifiedDir"); + File clusterConfigDir = new File(clusterConfigPath); assertTrue(clusterConfigDir.mkdir()); - locatorProps.setProperty(DistributionConfig.CLUSTER_CONFIGURATION_DIR, clusterConfigDir.getCanonicalPath()); - - locatorProps.setProperty(DistributionConfig.HTTP_SERVICE_PORT_NAME, String.valueOf(httpPort)); + locatorProps.setProperty(CLUSTER_CONFIGURATION_DIR, clusterConfigDir.getCanonicalPath()); + locatorProps.setProperty(HTTP_SERVICE_PORT_NAME, 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); - try { - 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); - } catch (IOException ioex) { - fail("Unable to create a locator with a shared configuration"); - } - assertTrue(clusterConfigDir.list().length > 0); final Object[] result = new Object[4]; @@ -632,64 +597,57 @@ public class ClusterConfigurationDUnitTest extends CliCommandTestBase { }); } - public Object[] setup() { - disconnectAllFromDS(); - final int [] ports = AvailablePortHelper.getRandomAvailableTCPPorts(3); + private Object[] setup() throws IOException { + final int [] ports = getRandomAvailableTCPPorts(3); final int locator1Port = ports[0]; final String locator1Name = "locator1-" + locator1Port; - VM locatorAndMgr = Host.getHost(0).getVM(3); - + final String locatorLogPath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + "locator-" + locator1Port + ".log"; + + VM locatorAndMgr = getHost(0).getVM(3); Object[] result = (Object[]) locatorAndMgr.invoke(new SerializableCallable() { @Override - public Object call() { + public Object call() throws IOException { int httpPort; int jmxPort; String jmxHost; try { jmxHost = InetAddress.getLocalHost().getHostName(); - } - catch (UnknownHostException ignore) { + } catch (UnknownHostException ignore) { jmxHost = "localhost"; } - final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2); + final int[] ports = getRandomAvailableTCPPorts(2); jmxPort = ports[0]; httpPort = ports[1]; - - final File locatorLogFile = new File("locator-" + locator1Port + ".log"); + final File locatorLogFile = new File(locatorLogPath); final Properties locatorProps = new Properties(); - locatorProps.setProperty(DistributionConfig.NAME_NAME, locator1Name); - locatorProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0"); - locatorProps.setProperty(DistributionConfig.LOG_LEVEL_NAME, "config"); - locatorProps.setProperty(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "true"); - locatorProps.setProperty(DistributionConfig.JMX_MANAGER_NAME, "true"); - locatorProps.setProperty(DistributionConfig.JMX_MANAGER_START_NAME, "true"); - locatorProps.setProperty(DistributionConfig.JMX_MANAGER_BIND_ADDRESS_NAME, String.valueOf(jmxHost)); - locatorProps.setProperty(DistributionConfig.JMX_MANAGER_PORT_NAME, String.valueOf(jmxPort)); - locatorProps.setProperty(DistributionConfig.HTTP_SERVICE_PORT_NAME, String.valueOf(httpPort)); - - try { - 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); - } catch (IOException ioex) { - fail("Unable to create a locator with a shared configuration"); - } + locatorProps.setProperty(NAME_NAME, locator1Name); + locatorProps.setProperty(MCAST_PORT_NAME, "0"); + locatorProps.setProperty(LOG_LEVEL_NAME, "config"); + locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION_NAME, "true"); + locatorProps.setProperty(JMX_MANAGER_NAME, "true"); + locatorProps.setProperty(JMX_MANAGER_START_NAME, "true"); + locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS_NAME, String.valueOf(jmxHost)); + locatorProps.setProperty(JMX_MANAGER_PORT_NAME, String.valueOf(jmxPort)); + locatorProps.setProperty(HTTP_SERVICE_PORT_NAME, 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[] result = new Object[4]; result[0] = locator1Port; @@ -706,36 +664,34 @@ public class ClusterConfigurationDUnitTest extends CliCommandTestBase { int httpPort = (Integer)result[3]; shellConnect(jmxHost, jmxPort, httpPort, gfsh); + + final String dataMemberWorkingDir = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + dataMember; + // Create a cache in VM 1 - VM dataMember = Host.getHost(0).getVM(1); + VM dataMember = getHost(0).getVM(1); dataMember.invoke(new SerializableCallable() { @Override public Object call() throws IOException { Properties localProps = new Properties(); - File workingDir = new File(ClusterConfigurationDUnitTest.dataMember); + File workingDir = new File(dataMemberWorkingDir); workingDir.mkdirs(); - workingDir.deleteOnExit(); - localProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0"); - localProps.setProperty(DistributionConfig.LOCATORS_NAME, "localhost:" + locator1Port); - localProps.setProperty(DistributionConfig.NAME_NAME, ClusterConfigurationDUnitTest.dataMember); - localProps.setProperty(DistributionConfig.USE_CLUSTER_CONFIGURATION_NAME, "true"); - localProps.setProperty(DistributionConfig.DEPLOY_WORKING_DIR, workingDir.getCanonicalPath()); + localProps.setProperty(MCAST_PORT_NAME, "0"); + localProps.setProperty(LOCATORS_NAME, "localhost:" + locator1Port); + localProps.setProperty(NAME_NAME, ClusterConfigurationDUnitTest.dataMember); + localProps.setProperty(USE_CLUSTER_CONFIGURATION_NAME, "true"); + localProps.setProperty(DEPLOY_WORKING_DIR, workingDir.getCanonicalPath()); getSystem(localProps); Cache cache = getCache(); assertNotNull(cache); - return CliUtil.getAllNormalMembers(cache); + return getAllNormalMembers(cache); } }); + return result; } - - /********************************* - * Region commands - */ - private void createRegion(String regionName, RegionShortcut regionShortCut, String group) { CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_REGION); csb.addOption(CliStrings.CREATE_REGION__REGION, regionName); @@ -781,32 +737,6 @@ public class ClusterConfigurationDUnitTest extends CliCommandTestBase { executeAndVerifyCommand(csb.toString()); } - class CommandBuilder { - private CommandStringBuilder csb; - - public CommandBuilder(String commandName, Map<String, String> options) { - csb = new CommandStringBuilder(commandName); - - Set<Entry<String, String>> entries = options.entrySet(); - - Iterator<Entry<String, String>> iter = entries.iterator(); - - while (iter.hasNext()) { - Entry<String, String> entry = iter.next(); - String option = entry.getKey(); - - if (StringUtils.isBlank(option)) { - csb.addOption(option, entry.getValue()); - } - } - } - - public String getCommandString() { - return csb.toString(); - } - } - - private void createPersistentRegion(String regionName, RegionShortcut regionShortCut, String group, String diskStoreName) { CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_REGION); csb.addOptionWithValueCheck(CliStrings.CREATE_REGION__REGION, regionName); @@ -823,15 +753,16 @@ public class ClusterConfigurationDUnitTest extends CliCommandTestBase { } private void alterRegion(String regionName, - String cloningEnabled, - String aeqId, - String cacheListener, - String cacheWriter, - String cacheLoader, - String entryExpIdleTime, - String entryExpIdleTimeAction, - String evictionMax, - String gsId) { + String cloningEnabled, + String aeqId, + String cacheListener, + String cacheWriter, + String cacheLoader, + String entryExpIdleTime, + String entryExpIdleTimeAction, + String evictionMax, + String gsId) { + CommandStringBuilder csb = new CommandStringBuilder(CliStrings.ALTER_REGION); csb.addOptionWithValueCheck(CliStrings.ALTER_REGION__CLONINGENABLED, "false"); csb.addOptionWithValueCheck(CliStrings.ALTER_REGION__ASYNCEVENTQUEUEID, aeqId); @@ -846,7 +777,8 @@ public class ClusterConfigurationDUnitTest extends CliCommandTestBase { executeAndVerifyCommand(csb.getCommandString()); } - protected void executeAndVerifyCommand(String commandString) { + + private void executeAndVerifyCommand(String commandString) { CommandResult cmdResult = executeCommand(commandString); com.gemstone.gemfire.test.dunit.LogWriterUtils.getLogWriter().info("Command : " + commandString); com.gemstone.gemfire.test.dunit.LogWriterUtils.getLogWriter().info("Command Result : " + commandResultToString(cmdResult)); @@ -854,21 +786,16 @@ public class ClusterConfigurationDUnitTest extends CliCommandTestBase { assertFalse(cmdResult.failedToPersist()); } - - /**************** - * CREATE/DESTROY INDEX - */ - - public void createIndex(String indexName, String expression, String regionName, String group) { + private void createIndex(String indexName, String expression, String regionName, String group) { CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_INDEX); csb.addOption(CliStrings.CREATE_INDEX__NAME, indexName); csb.addOption(CliStrings.CREATE_INDEX__EXPRESSION, expression); csb.addOption(CliStrings.CREATE_INDEX__REGION, regionName); executeAndVerifyCommand(csb.getCommandString()); } - - public void destroyIndex(String indexName, String regionName, String group) { - if (StringUtils.isBlank(indexName) && StringUtils.isBlank(regionName) && StringUtils.isBlank(group)) { + + private void destroyIndex(String indexName, String regionName, String group) { + if (isBlank(indexName) && isBlank(regionName) && isBlank(group)) { return; } CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DESTROY_INDEX); @@ -878,20 +805,18 @@ public class ClusterConfigurationDUnitTest extends CliCommandTestBase { executeAndVerifyCommand(csb.getCommandString()); } - /******* - * CREATE/DESTROY DISK-STORE - */ - private void createDiskStore(String diskStoreName, - String diskDirs, - String autoCompact, - String allowForceCompaction, - String compactionThreshold, - String duCritical, - String duWarning, - String maxOplogSize, - String queueSize, - String timeInterval, - String writeBufferSize) { + private void createDiskStore(String diskStoreName, + String diskDirs, + String autoCompact, + String allowForceCompaction, + String compactionThreshold, + String duCritical, + String duWarning, + String maxOplogSize, + String queueSize, + String timeInterval, + String writeBufferSize) { + CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_DISK_STORE); csb.addOption(CliStrings.CREATE_DISK_STORE__NAME, diskStoreName); csb.addOption(CliStrings.CREATE_DISK_STORE__DIRECTORY_AND_SIZE, diskDirs); @@ -914,14 +839,7 @@ public class ClusterConfigurationDUnitTest extends CliCommandTestBase { executeAndVerifyCommand(csb.toString()); } - /********* - * - * CREATE GATEWAY-RECEIVER - * - */ - - private void createGatewayReceiver(String manualStart, String bindAddress, - String startPort, String endPort, String maxTimeBetweenPings, String group) { + private void createGatewayReceiver(String manualStart, String bindAddress, String startPort, String endPort, String maxTimeBetweenPings, String group) { CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_GATEWAYRECEIVER); csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYRECEIVER__MANUALSTART, manualStart); csb.addOption(CliStrings.CREATE_GATEWAYRECEIVER__STARTPORT, startPort); @@ -933,18 +851,18 @@ public class ClusterConfigurationDUnitTest extends CliCommandTestBase { } private void createGatewaySender(String id, - String batchSize, - String alertThreshold, - String batchTimeInterval, - String dispatcherThreads, - String enableConflation, - String manualStart, - String maxQueueMemory, - String orderPolicy, - String parallel, - String rmDsId, - String socketBufferSize, - String socketReadTimeout) { + String batchSize, + String alertThreshold, + String batchTimeInterval, + String dispatcherThreads, + String enableConflation, + String manualStart, + String maxQueueMemory, + String orderPolicy, + String parallel, + String rmDsId, + String socketBufferSize, + String socketReadTimeout) { CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_GATEWAYSENDER); csb.addOptionWithValueCheck(CliStrings.CREATE_GATEWAYSENDER__ID, id); @@ -964,13 +882,8 @@ public class ClusterConfigurationDUnitTest extends CliCommandTestBase { executeAndVerifyCommand(csb.getCommandString()); } - - /******* - * CREATE ASYNC-EVENT-QUEUE - */ - - public void createAsyncEventQueue(String id, String persistent , String diskStoreName, String batchSize, String maxQueueMemory, String group) { - String queueCommandsJarName = "testEndToEndSC-QueueCommands.jar"; + private void createAsyncEventQueue(String id, String persistent , String diskStoreName, String batchSize, String maxQueueMemory, String group) throws IOException { + String queueCommandsJarName = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + "testEndToEndSC-QueueCommands.jar"; final File jarFile = new File(queueCommandsJarName); try { @@ -987,7 +900,7 @@ public class ClusterConfigurationDUnitTest extends CliCommandTestBase { "public void init(final Properties props) {this.props = props;}" + "public Properties getConfig() {return this.props;}}"); - FileUtils.writeByteArrayToFile(jarFile, jarBytes); + writeByteArrayToFile(jarFile, jarBytes); CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DEPLOY); csb.addOption(CliStrings.DEPLOY__JAR, queueCommandsJarName); executeAndVerifyCommand(csb.getCommandString()); @@ -1002,14 +915,12 @@ public class ClusterConfigurationDUnitTest extends CliCommandTestBase { csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__MAXIMUM_QUEUE_MEMORY, maxQueueMemory); executeAndVerifyCommand(csb.getCommandString()); - } catch (IOException e) { - e.printStackTrace(); } finally { - FileUtils.deleteQuietly(jarFile); + deleteQuietly(jarFile); } } - - public void configurePDX(String autoSerializerClasses, String ignoreUnreadFields, String persistent, String portableAutoSerializerClasses, String readSerialized) { + + private void configurePDX(String autoSerializerClasses, String ignoreUnreadFields, String persistent, String portableAutoSerializerClasses, String readSerialized) { CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CONFIGURE_PDX); csb.addOptionWithValueCheck(CliStrings.CONFIGURE_PDX__AUTO__SERIALIZER__CLASSES, autoSerializerClasses); csb.addOptionWithValueCheck(CliStrings.CONFIGURE_PDX__IGNORE__UNREAD_FIELDS, ignoreUnreadFields); @@ -1018,36 +929,31 @@ public class ClusterConfigurationDUnitTest extends CliCommandTestBase { csb.addOptionWithValueCheck(CliStrings.CONFIGURE_PDX__READ__SERIALIZED, readSerialized); executeAndVerifyCommand(csb.getCommandString()); } - - //DEPLOY AND UNDEPLOY JAR - public void createAndDeployJar(String jarName, String group) { + + private void createAndDeployJar(String jarName, String group) throws IOException { File newDeployableJarFile = new File(jarName); - try { - this.classBuilder.writeJarFromName("ShareConfigClass", newDeployableJarFile); - CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DEPLOY); - csb.addOption(CliStrings.DEPLOY__JAR, jarName); - if (!StringUtils.isBlank(group)) { - csb.addOption(CliStrings.DEPLOY__GROUP, group); - } - executeAndVerifyCommand(csb.getCommandString()); - jarFileNames.add(jarName); - } catch (IOException e) { - e.printStackTrace(); + this.classBuilder.writeJarFromName("ShareConfigClass", newDeployableJarFile); + CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DEPLOY); + csb.addOption(CliStrings.DEPLOY__JAR, jarName); + if (!isBlank(group)) { + csb.addOption(CliStrings.DEPLOY__GROUP, group); } + executeAndVerifyCommand(csb.getCommandString()); + jarFileNames.add(jarName); } - - public void undeployJar(String jarName, String group) { + + private void undeployJar(String jarName, String group) { CommandStringBuilder csb = new CommandStringBuilder(CliStrings.UNDEPLOY); - if (!StringUtils.isBlank(jarName)) { + if (!isBlank(jarName)) { csb.addOption(CliStrings.UNDEPLOY__JAR, jarName); } - if (!StringUtils.isBlank(group)) { + if (!isBlank(group)) { csb.addOption(CliStrings.UNDEPLOY__GROUP, group); } executeAndVerifyCommand(csb.getCommandString()); } - - public void alterRuntime(String copyOnRead, String lockLease, String lockTimeout, String messageSyncInterval) { + + private void alterRuntime(String copyOnRead, String lockLease, String lockTimeout, String messageSyncInterval) { CommandStringBuilder csb = new CommandStringBuilder(CliStrings.ALTER_RUNTIME_CONFIG); csb.addOptionWithValueCheck(CliStrings.ALTER_RUNTIME_CONFIG__COPY__ON__READ, copyOnRead); csb.addOptionWithValueCheck(CliStrings.ALTER_RUNTIME_CONFIG__LOCK__LEASE, lockLease); @@ -1055,13 +961,57 @@ public class ClusterConfigurationDUnitTest extends CliCommandTestBase { csb.addOptionWithValueCheck(CliStrings.ALTER_RUNTIME_CONFIG__MESSAGE__SYNC__INTERVAL, messageSyncInterval); executeAndVerifyCommand(csb.toString()); } - public void deleteSavedJarFiles() { - try { - FileUtil.deleteMatching(new File("."), "^" + JarDeployer.JAR_PREFIX + "Deploy1.*#\\d++$"); - FileUtil.delete(new File("Deploy1.jar")); - } catch (IOException ioe) { - ioe.printStackTrace(); + + private void deleteSavedJarFiles() throws IOException { + deleteMatching(new File("."), "^" + JarDeployer.JAR_PREFIX + "Deploy1.*#\\d++$"); + delete(new File("Deploy1.jar")); + } + + private void shutdownAll() throws IOException { + VM locatorAndMgr = getHost(0).getVM(3); + locatorAndMgr.invoke(new SerializableCallable() { + @Override + public Object call() throws Exception { + GemFireCacheImpl cache = (GemFireCacheImpl)CacheFactory.getAnyInstance(); + ShutdownAllRequest.send(cache.getDistributedSystem().getDistributionManager(), -1); + return null; + } + }); + + locatorAndMgr.invoke(SharedConfigurationTestUtils.cleanupLocator); + //Clean up the directories + if (serverNames != null && !serverNames.isEmpty()) { + for (String serverName : serverNames) { + final File serverDir = new File(serverName); + cleanDirectory(serverDir); + deleteDirectory(serverDir); + } + } + } + + private static class CommandBuilder { + + private CommandStringBuilder csb; + + public CommandBuilder(String commandName, Map<String, String> options) { + csb = new CommandStringBuilder(commandName); + + Set<Entry<String, String>> entries = options.entrySet(); + + Iterator<Entry<String, String>> iter = entries.iterator(); + + while (iter.hasNext()) { + Entry<String, String> entry = iter.next(); + String option = entry.getKey(); + + if (isBlank(option)) { + csb.addOption(option, entry.getValue()); + } + } + } + + public String getCommandString() { + return csb.toString(); } } - }