You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2016/05/06 21:40:38 UTC
[07/37] incubator-geode git commit: GEODE-1255: Add test coverage for
using a custom log4j2.xml with Geode
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ConnectCommandWithHttpAndSSLDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ConnectCommandWithHttpAndSSLDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ConnectCommandWithHttpAndSSLDUnitTest.java
new file mode 100644
index 0000000..2e0897d
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ConnectCommandWithHttpAndSSLDUnitTest.java
@@ -0,0 +1,305 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.management.internal.cli.commands;
+
+import static com.gemstone.gemfire.distributed.internal.DistributionConfig.*;
+import static com.gemstone.gemfire.management.internal.cli.i18n.CliStrings.*;
+import static com.gemstone.gemfire.test.dunit.Assert.*;
+import static com.gemstone.gemfire.util.test.TestUtil.*;
+
+import java.io.File;
+import java.util.Properties;
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSession;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.management.internal.cli.HeadlessGfsh;
+import com.gemstone.gemfire.management.internal.cli.result.CommandResult;
+import com.gemstone.gemfire.management.internal.cli.util.CommandStringBuilder;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+import com.gemstone.gemfire.test.junit.categories.SecurityTest;
+
+/**
+ * @since 8.1
+ */
+@Category({ DistributedTest.class, SecurityTest.class })
+public class ConnectCommandWithHttpAndSSLDUnitTest extends CliCommandTestBase {
+
+ private static final ThreadLocal<Properties> sslInfoHolder = new ThreadLocal<>();
+
+ private File jks;
+
+ // TODO: should this test use @RunWith(Parameterized.class)?
+
+ @Override
+ public final void postSetUpCliCommandTestBase() throws Exception {
+ this.jks = new File(getResourcePath(getClass(), "/ssl/trusted.keystore"));
+ }
+
+ @Override
+ protected final void preTearDownCliCommandTestBase() throws Exception {
+ destroyDefaultSetup();
+ }
+
+ @Override
+ public final void postTearDownCacheTestCase() throws Exception {
+ sslInfoHolder.set(null);
+ }
+
+ @Test
+ public void testMutualAuthentication() throws Exception {
+ Properties localProps = new Properties();
+ localProps.setProperty(HTTP_SERVICE_SSL_ENABLED_NAME, "true");
+ localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_NAME, jks.getCanonicalPath());
+ localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_PASSWORD_NAME, "password");
+ localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_TYPE_NAME, "JKS");
+ localProps.setProperty(HTTP_SERVICE_SSL_PROTOCOLS_NAME, "SSL");
+ localProps.setProperty(HTTP_SERVICE_SSL_REQUIRE_AUTHENTICATION_NAME, "true");
+ localProps.setProperty(HTTP_SERVICE_SSL_TRUSTSTORE_NAME, jks.getCanonicalPath());
+ localProps.setProperty(HTTP_SERVICE_SSL_TRUSTSTORE_PASSWORD_NAME, "password");
+
+ Properties clientProps = new Properties();
+ clientProps.setProperty(CONNECT__KEY_STORE, jks.getCanonicalPath());
+ clientProps.setProperty(CONNECT__KEY_STORE_PASSWORD, "password");
+ clientProps.setProperty(CONNECT__SSL_PROTOCOLS, "SSL");
+ clientProps.setProperty(CONNECT__TRUST_STORE, jks.getCanonicalPath());
+ clientProps.setProperty(CONNECT__TRUST_STORE_PASSWORD, "password");
+
+ sslInfoHolder.set(clientProps);
+ setUpJmxManagerOnVm0ThenConnect(localProps);
+ }
+
+ @Test
+ public void testSimpleSSL() throws Exception {
+ Properties localProps = new Properties();
+ localProps.setProperty(HTTP_SERVICE_SSL_ENABLED_NAME, "true");
+ localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_NAME, jks.getCanonicalPath());
+ localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_PASSWORD_NAME, "password");
+ localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_TYPE_NAME, "JKS");
+
+ Properties clientProps = new Properties();
+ clientProps.setProperty(CONNECT__TRUST_STORE, jks.getCanonicalPath());
+ clientProps.setProperty(CONNECT__TRUST_STORE_PASSWORD, "password");
+
+ sslInfoHolder.set(clientProps);
+ setUpJmxManagerOnVm0ThenConnect(localProps);
+ }
+
+ @Test
+ public void testSSLWithoutKeyStoreType() throws Exception {
+ Properties localProps = new Properties();
+ localProps.setProperty(HTTP_SERVICE_SSL_ENABLED_NAME, "true");
+ localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_NAME, jks.getCanonicalPath());
+ localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_PASSWORD_NAME, "password");
+
+ Properties clientProps = new Properties();
+ clientProps.setProperty(CONNECT__TRUST_STORE, jks.getCanonicalPath());
+ clientProps.setProperty(CONNECT__TRUST_STORE_PASSWORD, "password");
+
+ sslInfoHolder.set(clientProps);
+ setUpJmxManagerOnVm0ThenConnect(localProps);
+ }
+
+ @Test
+ public void testSSLWithSSLProtocol() throws Exception {
+ Properties localProps = new Properties();
+ localProps.setProperty(HTTP_SERVICE_SSL_ENABLED_NAME, "true");
+ localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_NAME, jks.getCanonicalPath());
+ localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_PASSWORD_NAME, "password");
+ localProps.setProperty(HTTP_SERVICE_SSL_PROTOCOLS_NAME,"SSL");
+
+ Properties clientProps = new Properties();
+ clientProps.setProperty(CONNECT__TRUST_STORE, jks.getCanonicalPath());
+ clientProps.setProperty(CONNECT__TRUST_STORE_PASSWORD, "password");
+
+ sslInfoHolder.set(clientProps);
+ setUpJmxManagerOnVm0ThenConnect(localProps);
+ }
+
+ @Test
+ public void testSSLWithTLSProtocol() throws Exception {
+ Properties localProps = new Properties();
+ localProps.setProperty(HTTP_SERVICE_SSL_ENABLED_NAME, "true");
+ localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_NAME, jks.getCanonicalPath());
+ localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_PASSWORD_NAME, "password");
+ localProps.setProperty(HTTP_SERVICE_SSL_PROTOCOLS_NAME,"TLS");
+
+ Properties clientProps = new Properties();
+ clientProps.setProperty(CONNECT__TRUST_STORE, jks.getCanonicalPath());
+ clientProps.setProperty(CONNECT__TRUST_STORE_PASSWORD, "password");
+
+ sslInfoHolder.set(clientProps);
+ setUpJmxManagerOnVm0ThenConnect(localProps);
+ }
+
+ @Test
+ public void testSSLWithTLSv11Protocol() throws Exception {
+ Properties localProps = new Properties();
+ localProps.setProperty(HTTP_SERVICE_SSL_ENABLED_NAME, "true");
+ localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_NAME, jks.getCanonicalPath());
+ localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_PASSWORD_NAME, "password");
+ localProps.setProperty(HTTP_SERVICE_SSL_PROTOCOLS_NAME,"TLSv1.1");
+
+ Properties clientProps = new Properties();
+ clientProps.setProperty(CONNECT__TRUST_STORE, jks.getCanonicalPath());
+ clientProps.setProperty(CONNECT__TRUST_STORE_PASSWORD, "password");
+
+ sslInfoHolder.set(clientProps);
+ setUpJmxManagerOnVm0ThenConnect(localProps);
+ }
+
+ @Test
+ public void testSSLWithTLSv12Protocol() throws Exception {
+ Properties localProps = new Properties();
+ localProps.setProperty(HTTP_SERVICE_SSL_ENABLED_NAME, "true");
+ localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_NAME, jks.getCanonicalPath());
+ localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_PASSWORD_NAME, "password");
+ localProps.setProperty(HTTP_SERVICE_SSL_PROTOCOLS_NAME,"TLSv1.2");
+
+ Properties clientProps = new Properties();
+ clientProps.setProperty(CONNECT__TRUST_STORE, jks.getCanonicalPath());
+ clientProps.setProperty(CONNECT__TRUST_STORE_PASSWORD, "password");
+
+ sslInfoHolder.set(clientProps);
+ setUpJmxManagerOnVm0ThenConnect(localProps);
+ }
+
+ @Test
+ public void testWithMultipleProtocol() throws Exception {
+ Properties localProps = new Properties();
+ localProps.setProperty(HTTP_SERVICE_SSL_ENABLED_NAME, "true");
+ localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_NAME, jks.getCanonicalPath());
+ localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_PASSWORD_NAME, "password");
+ localProps.setProperty(HTTP_SERVICE_SSL_PROTOCOLS_NAME,"SSL,TLSv1.2");
+
+ Properties clientProps = new Properties();
+ clientProps.setProperty(CONNECT__TRUST_STORE, jks.getCanonicalPath());
+ clientProps.setProperty(CONNECT__TRUST_STORE_PASSWORD, "password");
+
+ sslInfoHolder.set(clientProps);
+ setUpJmxManagerOnVm0ThenConnect(localProps);
+ }
+
+ @Ignore("disabled for unknown reason")
+ @Test
+ public void testSSLWithCipherSuite() throws Exception {
+ Properties localProps = new Properties();
+ localProps.setProperty(HTTP_SERVICE_SSL_ENABLED_NAME, "true");
+ localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_NAME, jks.getCanonicalPath());
+ localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_PASSWORD_NAME, "password");
+ localProps.setProperty(HTTP_SERVICE_SSL_PROTOCOLS_NAME, "TLSv1.2");
+
+ //Its bad to hard code here. But using SocketFactory.getDefaultCiphers() somehow is not working with the option
+ //"https.cipherSuites" which is required to restrict cipher suite with HttpsURLConnection
+ //Keeping the below code for further investigation on different Java versions ( 7 & 8) @TODO
+
+ /*SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
+
+ sslContext.init(null, null, new java.security.SecureRandom());
+ String[] cipherSuites = sslContext.getSocketFactory().getSupportedCipherSuites();*/
+
+ localProps.setProperty(HTTP_SERVICE_SSL_CIPHERS_NAME,"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256");
+
+ Properties clientProps = new Properties();
+ clientProps.setProperty(CONNECT__TRUST_STORE, jks.getCanonicalPath());
+ clientProps.setProperty(CONNECT__TRUST_STORE_PASSWORD, "password");
+ clientProps.setProperty(CONNECT__SSL_CIPHERS, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256");
+ clientProps.setProperty(CONNECT__SSL_PROTOCOLS, "TLSv1.2");
+
+ sslInfoHolder.set(clientProps);
+ setUpJmxManagerOnVm0ThenConnect(localProps);
+ }
+
+ @Ignore("disabled for unknown reason")
+ @Test
+ public void testSSLWithMultipleCipherSuite() throws Exception {
+ System.setProperty("javax.net.debug", "ssl,handshake,failure");
+
+ Properties localProps = new Properties();
+ localProps.setProperty(HTTP_SERVICE_SSL_ENABLED_NAME, "true");
+ localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_NAME, jks.getCanonicalPath());
+ localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_PASSWORD_NAME, "password");
+ localProps.setProperty(HTTP_SERVICE_SSL_PROTOCOLS_NAME,"TLSv1.2");
+ localProps.setProperty(HTTP_SERVICE_SSL_CIPHERS_NAME,"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_EMPTY_RENEGOTIATION_INFO_SCSV");
+
+ Properties clientProps = new Properties();
+ clientProps.setProperty(CONNECT__TRUST_STORE, jks.getCanonicalPath());
+ clientProps.setProperty(CONNECT__TRUST_STORE_PASSWORD, "password");
+ clientProps.setProperty(CONNECT__SSL_PROTOCOLS, "TLSv1.2");
+
+ sslInfoHolder.set(clientProps);
+ setUpJmxManagerOnVm0ThenConnect(localProps);
+ }
+
+ @Override
+ protected void shellConnect(final String host, final int jmxPort, final int httpPort, final HeadlessGfsh shell) {
+ assertNotNull(host);
+ assertNotNull(shell);
+
+ final CommandStringBuilder command = new CommandStringBuilder(CONNECT);
+ String endpoint;
+
+ // This is for testing purpose only. If we remove this piece of code we will
+ // get a java.security.cert.CertificateException
+ // as matching hostname can not be obtained in all test environment.
+ HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
+ @Override
+ public boolean verify(String string, SSLSession ssls) {
+ return true;
+ }
+ });
+
+ endpoint = "https://" + host + ":" + httpPort + "/gemfire/v1";
+
+ command.addOption(CONNECT__USE_HTTP, Boolean.TRUE.toString());
+ command.addOption(CONNECT__URL, endpoint);
+ command.addOption(CONNECT__USE_SSL,Boolean.TRUE.toString());
+
+ if(sslInfoHolder.get().getProperty(CONNECT__KEY_STORE) != null){
+ command.addOption(CONNECT__KEY_STORE, sslInfoHolder.get().getProperty(CONNECT__KEY_STORE));
+ }
+ if(sslInfoHolder.get().getProperty(CONNECT__KEY_STORE_PASSWORD) != null){
+ command.addOption(CONNECT__KEY_STORE_PASSWORD, sslInfoHolder.get().getProperty(CONNECT__KEY_STORE_PASSWORD));
+ }
+ if(sslInfoHolder.get().getProperty(CONNECT__TRUST_STORE) != null){
+ command.addOption(CONNECT__TRUST_STORE, sslInfoHolder.get().getProperty(CONNECT__TRUST_STORE));
+ }
+ if(sslInfoHolder.get().getProperty(CONNECT__TRUST_STORE_PASSWORD) != null){
+ command.addOption(CONNECT__TRUST_STORE_PASSWORD, sslInfoHolder.get().getProperty(CONNECT__TRUST_STORE_PASSWORD));
+ }
+ if(sslInfoHolder.get().getProperty(CONNECT__SSL_PROTOCOLS) != null){
+ command.addOption(CONNECT__SSL_PROTOCOLS, sslInfoHolder.get().getProperty(CONNECT__SSL_PROTOCOLS));
+ }
+ if(sslInfoHolder.get().getProperty(CONNECT__SSL_CIPHERS) != null){
+ command.addOption(CONNECT__SSL_CIPHERS, sslInfoHolder.get().getProperty(CONNECT__SSL_CIPHERS));
+ }
+
+ CommandResult result = executeCommand(shell, command.toString());
+
+ if (!shell.isConnectedAndReady()) {
+ fail("Connect command failed to connect to manager " + endpoint + " result=" + commandResultToString(result));
+ }
+
+ info("Successfully connected to managing node using HTTPS");
+ assertEquals(true, shell.isConnectedAndReady());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/DeployCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/DeployCommandsDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/DeployCommandsDUnitTest.java
index 4bc92eb..88e7b30 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/DeployCommandsDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/DeployCommandsDUnitTest.java
@@ -24,6 +24,8 @@ import java.io.IOException;
import java.util.Properties;
import java.util.regex.Pattern;
+import org.junit.Test;
+
import com.gemstone.gemfire.distributed.Locator;
import com.gemstone.gemfire.distributed.internal.DistributionConfig;
import com.gemstone.gemfire.distributed.internal.DistributionManager;
@@ -43,27 +45,24 @@ import com.gemstone.gemfire.test.dunit.SerializableRunnable;
import com.gemstone.gemfire.test.dunit.VM;
import com.gemstone.gemfire.test.dunit.Wait;
import com.gemstone.gemfire.test.dunit.WaitCriterion;
-import com.gemstone.gemfire.test.junit.categories.DistributedTest;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
/**
* Unit tests for the DeployCommands class
*
* @since 7.0
*/
-@Category(DistributedTest.class)
@SuppressWarnings("serial")
public class DeployCommandsDUnitTest extends CliCommandTestBase {
- File newDeployableJarFile = new File("DeployCommandsDUnit1.jar");
-
- transient private ClassBuilder classBuilder = new ClassBuilder();
- transient private CommandProcessor commandProcessor;
+ private final Pattern pattern = Pattern.compile("^" + JarDeployer.JAR_PREFIX + "DeployCommandsDUnit.*#\\d++$");
+ private File newDeployableJarFile;
+ private transient ClassBuilder classBuilder;
+ private transient CommandProcessor commandProcessor;
@Override
- public final void postSetUp() throws Exception {
+ public final void postSetUpCliCommandTestBase() throws Exception {
+ this.newDeployableJarFile = new File(this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + "DeployCommandsDUnit1.jar");
+ this.classBuilder = new ClassBuilder();
this.commandProcessor = new CommandProcessor();
assertFalse(this.commandProcessor.isStopped());
@@ -93,7 +92,7 @@ public class DeployCommandsDUnitTest extends CliCommandTestBase {
}
@Test
- public void testDeploy() throws IOException {
+ public void testDeploy() throws Exception {
final Properties props = new Properties();
final Host host = Host.getHost(0);
final VM vm = host.getVM(0);
@@ -179,7 +178,7 @@ public class DeployCommandsDUnitTest extends CliCommandTestBase {
}
@Test
- public void testUndeploy() throws IOException {
+ public void testUndeploy() throws Exception {
final Properties props = new Properties();
final Host host = Host.getHost(0);
final VM vm = host.getVM(0);
@@ -256,7 +255,7 @@ public class DeployCommandsDUnitTest extends CliCommandTestBase {
}
@Test
- public void testListDeployed() throws IOException {
+ public void testListDeployed() throws Exception {
final Properties props = new Properties();
final Host host = Host.getHost(0);
final VM vm = host.getVM(0);
@@ -325,24 +324,27 @@ public class DeployCommandsDUnitTest extends CliCommandTestBase {
* Does an end-to-end test using the complete CLI framework while ensuring that the shared configuration is updated.
*/
@Test
- public void testEndToEnd() throws IOException {
- final String groupName = "testDeployEndToEndGroup";
+ public void testEndToEnd() throws Exception {
+ final String groupName = getName();
// Start the Locator and wait for shared configuration to be available
final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
+ final String locatorLogPath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + "locator-" + locatorPort + ".log";
+
Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
@Override
public void run() {
- final File locatorLogFile = new File("locator-" + locatorPort + ".log");
+ final File locatorLogFile = new File(locatorLogPath);
+
final Properties locatorProps = new Properties();
locatorProps.setProperty(DistributionConfig.NAME_NAME, "Locator");
locatorProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
locatorProps.setProperty(DistributionConfig.LOG_LEVEL_NAME, "fine");
locatorProps.setProperty(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "true");
+
try {
- final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort, locatorLogFile, null,
- locatorProps);
+ final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort, locatorLogFile, null, locatorProps);
WaitCriterion wc = new WaitCriterion() {
@Override
@@ -356,8 +358,9 @@ public class DeployCommandsDUnitTest extends CliCommandTestBase {
}
};
Wait.waitForCriterion(wc, 5000, 500, true);
- } catch (IOException ioex) {
- fail("Unable to create a locator with a shared configuration");
+
+ } catch (IOException e) {
+ fail("Unable to create a locator with a shared configuration", e);
}
}
});
@@ -373,7 +376,7 @@ public class DeployCommandsDUnitTest extends CliCommandTestBase {
this.classBuilder.writeJarFromName("DeployCommandsDUnitA", this.newDeployableJarFile);
// Deploy the JAR
- CommandResult cmdResult = executeCommand("deploy --jar=DeployCommandsDUnit1.jar");
+ CommandResult cmdResult = executeCommand("deploy --jar=" + this.newDeployableJarFile.getCanonicalPath());
assertEquals(Result.Status.OK, cmdResult.getStatus());
String stringResult = commandResultToString(cmdResult);
@@ -393,7 +396,7 @@ public class DeployCommandsDUnitTest extends CliCommandTestBase {
"Manager.*DeployCommandsDUnit1.jar.*" + JarDeployer.JAR_PREFIX + "DeployCommandsDUnit1.jar#1"));
// Deploy the JAR to a group
- cmdResult = executeCommand("deploy --jar=DeployCommandsDUnit1.jar --group=" + groupName);
+ cmdResult = executeCommand("deploy --jar=" + this.newDeployableJarFile.getCanonicalPath() + " --group=" + groupName);
assertEquals(Result.Status.OK, cmdResult.getStatus());
stringResult = commandResultToString(cmdResult);
@@ -454,12 +457,11 @@ public class DeployCommandsDUnitTest extends CliCommandTestBase {
assertTrue(commandResultToString(cmdResult).contains(CliStrings.LIST_DEPLOYED__NO_JARS_FOUND_MESSAGE));
}
- final Pattern pattern = Pattern.compile("^" + JarDeployer.JAR_PREFIX + "DeployCommandsDUnit.*#\\d++$");
-
- void deleteSavedJarFiles() {
+ private void deleteSavedJarFiles() {
this.newDeployableJarFile.delete();
File dirFile = new File(".");
+
// Find all deployed JAR files
File[] oldJarFiles = dirFile.listFiles(new FilenameFilter() {
@Override
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest.java
index 5674b83..2182301 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest.java
@@ -16,7 +16,9 @@
*/
package com.gemstone.gemfire.management.internal.cli.commands;
+import static com.gemstone.gemfire.distributed.internal.DistributionConfig.*;
import static com.gemstone.gemfire.test.dunit.Assert.*;
+import static com.gemstone.gemfire.test.dunit.Host.*;
import static com.gemstone.gemfire.test.dunit.LogWriterUtils.*;
import static com.gemstone.gemfire.test.dunit.Wait.*;
@@ -32,7 +34,6 @@ import com.gemstone.gemfire.cache.LoaderHelper;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionFactory;
import com.gemstone.gemfire.cache.RegionShortcut;
-import com.gemstone.gemfire.distributed.internal.DistributionConfig;
import com.gemstone.gemfire.management.DistributedRegionMXBean;
import com.gemstone.gemfire.management.ManagementService;
import com.gemstone.gemfire.management.ManagerMXBean;
@@ -43,7 +44,6 @@ import com.gemstone.gemfire.management.internal.cli.result.CommandResult;
import com.gemstone.gemfire.management.internal.cli.result.CompositeResultData;
import com.gemstone.gemfire.management.internal.cli.result.ResultData;
import com.gemstone.gemfire.management.internal.cli.util.CommandStringBuilder;
-import com.gemstone.gemfire.test.dunit.Host;
import com.gemstone.gemfire.test.dunit.SerializableRunnable;
import com.gemstone.gemfire.test.dunit.SerializableRunnableIF;
import com.gemstone.gemfire.test.dunit.VM;
@@ -56,7 +56,6 @@ import org.junit.experimental.categories.Category;
/**
* The GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest class is test suite of test cases testing the Gfsh
* 'get' data command when a cache miss occurs on data in a Region with a CacheLoader defined.
- * <p>
*
* @see com.gemstone.gemfire.management.internal.cli.commands.CliCommandTestBase
* @see com.gemstone.gemfire.management.internal.cli.commands.DataCommands
@@ -71,12 +70,63 @@ public class GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest extends C
private static final String GEMFIRE_LOG_LEVEL = System.getProperty("logLevel", "config");
private static final String USERS_REGION_NAME = "Users";
- protected static String getRegionPath(final String regionName) {
- return (regionName.startsWith(Region.SEPARATOR) ? regionName : String.format("%1$s%2$s", Region.SEPARATOR,
- regionName));
+ @Override
+ public final void postSetUpCliCommandTestBase() throws Exception {
+ Properties managerDistributedSystemProperties = createDistributedSystemProperties(GEMFIRE_MANAGER_NAME);
+ HeadlessGfsh gfsh = setUpJmxManagerOnVm0ThenConnect(managerDistributedSystemProperties);
+
+ assertNotNull(gfsh);
+ assertTrue(gfsh.isConnectedAndReady());
+
+ setupGemFire();
+ verifyGemFireSetup(createPeer(getHost(0).getVM(0), managerDistributedSystemProperties));
+ }
+
+ @Test
+ public void testGetOnCacheMiss() {
+ doHousekeeping();
+
+ CommandStringBuilder command = new CommandStringBuilder(CliStrings.GET);
+ command.addOption(CliStrings.GET__REGIONNAME, USERS_REGION_NAME);
+ command.addOption(CliStrings.GET__KEY, "jonbloom");
+
+ assertResult(true, runCommand(command.toString()));
+
+ command = new CommandStringBuilder(CliStrings.GET);
+ command.addOption(CliStrings.GET__REGIONNAME, USERS_REGION_NAME);
+ command.addOption(CliStrings.GET__KEY, "jondoe");
+ command.addOption(CliStrings.GET__LOAD, "false");
+
+ assertResult(false, runCommand(command.toString()));
+
+ command = new CommandStringBuilder(CliStrings.GET);
+ command.addOption(CliStrings.GET__REGIONNAME, USERS_REGION_NAME);
+ command.addOption(CliStrings.GET__KEY, "jondoe");
+ command.addOption(CliStrings.GET__LOAD, "true");
+
+ assertResult(true, runCommand(command.toString()));
+
+ // NOTE test the unspecified default value for the --load-on-cache-miss
+ command = new CommandStringBuilder(CliStrings.GET);
+ command.addOption(CliStrings.GET__REGIONNAME, USERS_REGION_NAME);
+ command.addOption(CliStrings.GET__KEY, "janedoe");
+
+ assertResult(true, runCommand(command.toString()));
+
+ // NOTE now test an absolute cache miss both for in the Region as well as the CacheLoader
+ command = new CommandStringBuilder(CliStrings.GET);
+ command.addOption(CliStrings.GET__REGIONNAME, USERS_REGION_NAME);
+ command.addOption(CliStrings.GET__KEY, "nonexistinguser");
+ command.addOption(CliStrings.GET__LOAD, "true");
+
+ assertResult(false, runCommand(command.toString()));
+ }
+
+ private static String getRegionPath(final String regionName) {
+ return (regionName.startsWith(Region.SEPARATOR) ? regionName : String.format("%1$s%2$s", Region.SEPARATOR, regionName));
}
- protected static String toString(final Result result) {
+ private static String toString(final Result result) {
assert result != null : "The Result object from the command execution was null!";
StringBuilder buffer = new StringBuilder(System.getProperty("line.separator"));
@@ -89,39 +139,25 @@ public class GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest extends C
return buffer.toString();
}
- @Override
- public final void postSetUp() throws Exception {
- Properties managerDistributedSystemProperties = createDistributedSystemProperties(GEMFIRE_MANAGER_NAME);
- HeadlessGfsh gfsh = setUpJmxManagerOnVm0ThenConnect(managerDistributedSystemProperties);
-
- assertNotNull(gfsh);
- assertTrue(gfsh.isConnectedAndReady());
-
- setupGemFire();
- verifyGemFireSetup(createPeer(Host.getHost(0).getVM(0), managerDistributedSystemProperties));
- }
-
private void setupGemFire() throws Exception {
- initializePeer(createPeer(Host.getHost(0).getVM(1), createDistributedSystemProperties(GEMFIRE_SERVER_NAME)));
+ initializePeer(createPeer(getHost(0).getVM(1), createDistributedSystemProperties(GEMFIRE_SERVER_NAME)));
}
- protected Properties createDistributedSystemProperties(final String gemfireName) {
+ private Properties createDistributedSystemProperties(final String gemfireName) {
Properties distributedSystemProperties = new Properties();
- distributedSystemProperties.setProperty(DistributionConfig.LOG_LEVEL_NAME, GEMFIRE_LOG_LEVEL);
- distributedSystemProperties.setProperty(DistributionConfig.NAME_NAME, gemfireName);
+ distributedSystemProperties.setProperty(LOG_LEVEL_NAME, GEMFIRE_LOG_LEVEL);
+ distributedSystemProperties.setProperty(NAME_NAME, gemfireName);
return distributedSystemProperties;
}
- protected Peer createPeer(final VM vm, final Properties distributedSystemProperties) {
+ private Peer createPeer(final VM vm, final Properties distributedSystemProperties) {
return new Peer(vm, distributedSystemProperties);
}
- protected void initializePeer(final Peer peer) throws Exception {
- peer.run(new SerializableRunnable(
- String.format("Initializes the '%1$s' with the '%2$s' Region having a CacheLoader.", GEMFIRE_SERVER_NAME,
- USERS_REGION_NAME)) {
+ private void initializePeer(final Peer peer) throws Exception {
+ peer.run(new SerializableRunnable(String.format("Initializes the '%1$s' with the '%2$s' Region having a CacheLoader.", GEMFIRE_SERVER_NAME, USERS_REGION_NAME)) {
@Override
public void run() {
// create the GemFire Distributed System with custom distribution configuration properties and settings
@@ -161,16 +197,14 @@ public class GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest extends C
@Override
public boolean done() {
ManagerMXBean managerBean = managementService.getManagerMXBean();
- DistributedRegionMXBean usersRegionBean = managementService.getDistributedRegionMXBean(
- getRegionPath(USERS_REGION_NAME));
+ DistributedRegionMXBean usersRegionBean = managementService.getDistributedRegionMXBean(getRegionPath(USERS_REGION_NAME));
return !(managerBean == null || usersRegionBean == null);
}
@Override
public String description() {
- return String.format("Probing for the GemFire Manager '%1$s' and '%2$s' Region MXBeans...",
- manager.getName(), USERS_REGION_NAME);
+ return String.format("Probing for the GemFire Manager '%1$s' and '%2$s' Region MXBeans...", manager.getName(), USERS_REGION_NAME);
}
};
@@ -179,7 +213,7 @@ public class GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest extends C
});
}
- protected void doHousekeeping() {
+ private void doHousekeeping() {
runCommand(CliStrings.LIST_MEMBER);
runCommand(new CommandStringBuilder(CliStrings.DESCRIBE_MEMBER).addOption(CliStrings.DESCRIBE_MEMBER__IDENTIFIER,
@@ -191,16 +225,16 @@ public class GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest extends C
USERS_REGION_NAME).toString());
}
- protected void log(final Result result) {
+ private void log(final Result result) {
log("Result", toString(result));
}
- protected void log(final String tag, final String message) {
+ private void log(final String tag, final String message) {
//System.out.printf("%1$s (%2$s)%n", tag, message);
getLogWriter().info(String.format("%1$s (%2$s)%n", tag, message));
}
- protected CommandResult runCommand(final String command) {
+ private CommandResult runCommand(final String command) {
CommandResult result = executeCommand(command);
assertNotNull(result);
@@ -211,57 +245,16 @@ public class GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest extends C
return result;
}
- protected void assertResult(final boolean expectedResult, final CommandResult commandResult) {
+ private void assertResult(final boolean expectedResult, final CommandResult commandResult) {
if (ResultData.TYPE_COMPOSITE.equals(commandResult.getType())) {
- boolean actualResult = (Boolean) ((CompositeResultData) commandResult.getResultData()).retrieveSectionByIndex(
- 0).retrieveObject("Result");
+ boolean actualResult = (Boolean) ((CompositeResultData) commandResult.getResultData()).retrieveSectionByIndex(0).retrieveObject("Result");
assertEquals(expectedResult, actualResult);
} else {
fail(String.format("Expected composite result data; but was '%1$s'!%n", commandResult.getType()));
}
}
- @Test
- public void testGetOnCacheMiss() {
- doHousekeeping();
-
- CommandStringBuilder command = new CommandStringBuilder(CliStrings.GET);
- command.addOption(CliStrings.GET__REGIONNAME, USERS_REGION_NAME);
- command.addOption(CliStrings.GET__KEY, "jonbloom");
-
- assertResult(true, runCommand(command.toString()));
-
- command = new CommandStringBuilder(CliStrings.GET);
- command.addOption(CliStrings.GET__REGIONNAME, USERS_REGION_NAME);
- command.addOption(CliStrings.GET__KEY, "jondoe");
- command.addOption(CliStrings.GET__LOAD, "false");
-
- assertResult(false, runCommand(command.toString()));
-
- command = new CommandStringBuilder(CliStrings.GET);
- command.addOption(CliStrings.GET__REGIONNAME, USERS_REGION_NAME);
- command.addOption(CliStrings.GET__KEY, "jondoe");
- command.addOption(CliStrings.GET__LOAD, "true");
-
- assertResult(true, runCommand(command.toString()));
-
- // NOTE test the unspecified default value for the --load-on-cache-miss
- command = new CommandStringBuilder(CliStrings.GET);
- command.addOption(CliStrings.GET__REGIONNAME, USERS_REGION_NAME);
- command.addOption(CliStrings.GET__KEY, "janedoe");
-
- assertResult(true, runCommand(command.toString()));
-
- // NOTE now test an absolute cache miss both for in the Region as well as the CacheLoader
- command = new CommandStringBuilder(CliStrings.GET);
- command.addOption(CliStrings.GET__REGIONNAME, USERS_REGION_NAME);
- command.addOption(CliStrings.GET__KEY, "nonexistinguser");
- command.addOption(CliStrings.GET__LOAD, "true");
-
- assertResult(false, runCommand(command.toString()));
- }
-
- protected static final class Peer implements Serializable {
+ private static final class Peer implements Serializable {
private final Properties distributedSystemProperties;
private final VM vm;
@@ -277,7 +270,7 @@ public class GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest extends C
}
public String getName() {
- return getConfiguration().getProperty(DistributionConfig.NAME_NAME);
+ return getConfiguration().getProperty(NAME_NAME);
}
public VM getVm() {
@@ -305,7 +298,7 @@ public class GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest extends C
}
}
- protected static class User implements Serializable {
+ private static class User implements Serializable {
private final String username;
@@ -346,7 +339,7 @@ public class GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest extends C
}
}
- protected static class UserDataStoreCacheLoader implements CacheLoader<String, User>, Serializable {
+ private static class UserDataStoreCacheLoader implements CacheLoader<String, User>, Serializable {
private static final Map<String, User> userDataStore = new HashMap<String, User>(5);
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ListAndDescribeDiskStoreCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ListAndDescribeDiskStoreCommandsDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ListAndDescribeDiskStoreCommandsDUnitTest.java
index 443c7c7..a61c717 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ListAndDescribeDiskStoreCommandsDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ListAndDescribeDiskStoreCommandsDUnitTest.java
@@ -16,7 +16,9 @@
*/
package com.gemstone.gemfire.management.internal.cli.commands;
+import static com.gemstone.gemfire.distributed.internal.DistributionConfig.*;
import static com.gemstone.gemfire.test.dunit.Assert.*;
+import static com.gemstone.gemfire.test.dunit.Host.*;
import static com.gemstone.gemfire.test.dunit.LogWriterUtils.*;
import java.io.Serializable;
@@ -28,10 +30,8 @@ import com.gemstone.gemfire.cache.DiskStore;
import com.gemstone.gemfire.cache.DiskStoreFactory;
import com.gemstone.gemfire.cache.RegionFactory;
import com.gemstone.gemfire.cache.Scope;
-import com.gemstone.gemfire.distributed.internal.DistributionConfig;
import com.gemstone.gemfire.management.cli.Result;
import com.gemstone.gemfire.management.internal.cli.i18n.CliStrings;
-import com.gemstone.gemfire.test.dunit.Host;
import com.gemstone.gemfire.test.dunit.SerializableRunnable;
import com.gemstone.gemfire.test.dunit.SerializableRunnableIF;
import com.gemstone.gemfire.test.dunit.VM;
@@ -51,7 +51,49 @@ import org.junit.experimental.categories.Category;
@Category(DistributedTest.class)
public class ListAndDescribeDiskStoreCommandsDUnitTest extends CliCommandTestBase {
- protected static String toString(final Result result) {
+ @Override
+ public final void postSetUpCliCommandTestBase() throws Exception {
+ setUpJmxManagerOnVm0ThenConnect(null);
+ setupGemFire();
+ }
+
+ @Test
+ public void testListDiskStore() throws Exception {
+ final Result result = executeCommand(CliStrings.LIST_DISK_STORE);
+
+ assertNotNull(result);
+ getLogWriter().info(toString(result));
+ assertEquals(Result.Status.OK, result.getStatus());
+ }
+
+ @Test
+ public void testDescribeDiskStore() throws Exception {
+ final Result result = executeCommand(CliStrings.DESCRIBE_DISK_STORE + " --member=producerServer --name=producerData");
+
+ assertNotNull(result);
+ getLogWriter().info(toString(result));
+ assertEquals(Result.Status.OK, result.getStatus());
+ }
+
+ @Test
+ public void testDescribeDiskStoreWithInvalidMemberName() throws Exception {
+ final Result commandResult = executeCommand(CliStrings.DESCRIBE_DISK_STORE + " --member=badMemberName --name=producerData");
+
+ assertNotNull(commandResult);
+ assertEquals(Result.Status.ERROR, commandResult.getStatus());
+ assertEquals(CliStrings.format(CliStrings.MEMBER_NOT_FOUND_ERROR_MESSAGE, "badMemberName"), toString(commandResult));
+ }
+
+ @Test
+ public void testDescribeDiskStoreWithInvalidDiskStoreName() {
+ final Result commandResult = executeCommand(CliStrings.DESCRIBE_DISK_STORE + " --member=producerServer --name=badDiskStoreName");
+
+ assertNotNull(commandResult);
+ assertEquals(Result.Status.ERROR, commandResult.getStatus());
+ assertEquals("A disk store with name (badDiskStoreName) was not found on member (producerServer).", toString(commandResult));
+ }
+
+ private static String toString(final Result result) {
assert result != null : "The Result object from the command execution cannot be null!";
final StringBuilder buffer = new StringBuilder(System.getProperty("line.separator"));
@@ -64,21 +106,13 @@ public class ListAndDescribeDiskStoreCommandsDUnitTest extends CliCommandTestBas
return buffer.toString().trim();
}
- @Override
- public final void postSetUp() throws Exception {
- setUpJmxManagerOnVm0ThenConnect(null);
- setupGemFire();
- }
-
- protected Peer createPeer(final Properties distributedSystemConfiguration, final VM vm) {
+ private Peer createPeer(final Properties distributedSystemConfiguration, final VM vm) {
return new Peer(distributedSystemConfiguration, vm);
}
- protected void setupGemFire() throws Exception {
- final Host host = Host.getHost(0);
-
- final VM vm1 = host.getVM(1);
- final VM vm2 = host.getVM(2);
+ private void setupGemFire() throws Exception {
+ final VM vm1 = getHost(0).getVM(1);
+ final VM vm2 = getHost(0).getVM(2);
final Peer peer1 = createPeer(createDistributedSystemProperties("consumerServer"), vm1);
final Peer peer2 = createPeer(createDistributedSystemProperties("producerServer"), vm2);
@@ -89,16 +123,16 @@ public class ListAndDescribeDiskStoreCommandsDUnitTest extends CliCommandTestBas
createPersistentRegion(peer2, "producer-factory", "producerData");
}
- protected Properties createDistributedSystemProperties(final String gemfireName) {
+ private Properties createDistributedSystemProperties(final String gemfireName) {
final Properties distributedSystemProperties = new Properties();
- distributedSystemProperties.setProperty(DistributionConfig.LOG_LEVEL_NAME, getDUnitLogLevel());
- distributedSystemProperties.setProperty(DistributionConfig.NAME_NAME, gemfireName);
+ distributedSystemProperties.setProperty(LOG_LEVEL_NAME, getDUnitLogLevel());
+ distributedSystemProperties.setProperty(NAME_NAME, gemfireName);
return distributedSystemProperties;
}
- protected void createPersistentRegion(final Peer peer, final String regionName, final String diskStoreName) throws Exception {
+ private void createPersistentRegion(final Peer peer, final String regionName, final String diskStoreName) throws Exception {
peer.run(new SerializableRunnable("Creating Persistent Region for Member " + peer.getName()) {
@Override
public void run() {
@@ -124,48 +158,7 @@ public class ListAndDescribeDiskStoreCommandsDUnitTest extends CliCommandTestBas
});
}
- @Test
- public void testListDiskStore() throws Exception {
- final Result result = executeCommand(CliStrings.LIST_DISK_STORE);
-
- assertNotNull(result);
- getLogWriter().info(toString(result));
- assertEquals(Result.Status.OK, result.getStatus());
- }
-
- @Test
- public void testDescribeDiskStore() throws Exception {
- final Result result = executeCommand(
- CliStrings.DESCRIBE_DISK_STORE + " --member=producerServer --name=producerData");
-
- assertNotNull(result);
- getLogWriter().info(toString(result));
- assertEquals(Result.Status.OK, result.getStatus());
- }
-
- @Test
- public void testDescribeDiskStoreWithInvalidMemberName() throws Exception {
- final Result commandResult = executeCommand(
- CliStrings.DESCRIBE_DISK_STORE + " --member=badMemberName --name=producerData");
-
- assertNotNull(commandResult);
- assertEquals(Result.Status.ERROR, commandResult.getStatus());
- assertEquals(CliStrings.format(CliStrings.MEMBER_NOT_FOUND_ERROR_MESSAGE, "badMemberName"),
- toString(commandResult));
- }
-
- @Test
- public void testDescribeDiskStoreWithInvalidDiskStoreName() {
- final Result commandResult = executeCommand(
- CliStrings.DESCRIBE_DISK_STORE + " --member=producerServer --name=badDiskStoreName");
-
- assertNotNull(commandResult);
- assertEquals(Result.Status.ERROR, commandResult.getStatus());
- assertEquals("A disk store with name (badDiskStoreName) was not found on member (producerServer).",
- toString(commandResult));
- }
-
- protected static class Peer implements Serializable {
+ private static class Peer implements Serializable {
private final Properties distributedSystemConfiguration;
private final VM vm;
@@ -181,7 +174,7 @@ public class ListAndDescribeDiskStoreCommandsDUnitTest extends CliCommandTestBas
}
public String getName() {
- return getDistributedSystemConfiguration().getProperty(DistributionConfig.NAME_NAME);
+ return getDistributedSystemConfiguration().getProperty(NAME_NAME);
}
public VM getVm() {
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ListIndexCommandDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ListIndexCommandDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ListIndexCommandDUnitTest.java
index e92d5bd..8947c22 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ListIndexCommandDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ListIndexCommandDUnitTest.java
@@ -31,6 +31,9 @@ import java.util.Random;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.Region;
@@ -53,12 +56,9 @@ import com.gemstone.gemfire.test.dunit.SerializableRunnableIF;
import com.gemstone.gemfire.test.dunit.VM;
import com.gemstone.gemfire.test.junit.categories.DistributedTest;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
/**
* The ListIndexCommandDUnitTest class is distributed test suite of test cases for testing the index-based GemFire shell
- * (Gfsh) commands. </p>
+ * (Gfsh) commands.
*
* @see com.gemstone.gemfire.management.internal.cli.commands.CliCommandTestBase
* @see com.gemstone.gemfire.management.internal.cli.commands.IndexCommands
@@ -68,11 +68,17 @@ import org.junit.experimental.categories.Category;
@Category(DistributedTest.class)
public class ListIndexCommandDUnitTest extends CliCommandTestBase {
- protected static final int DEFAULT_REGION_INITIAL_CAPACITY = 10000;
+ private static final int DEFAULT_REGION_INITIAL_CAPACITY = 10000;
private final AtomicLong idGenerator = new AtomicLong(0l);
- protected static String toString(final Result result) {
+ @Override
+ public final void postSetUpCliCommandTestBase() throws Exception {
+ setUpJmxManagerOnVm0ThenConnect(null);
+ setupGemFire();
+ }
+
+ private static String toString(final Result result) {
assert result != null : "The Result object from the command execution cannot be null!";
final StringBuilder buffer = new StringBuilder(System.getProperty("line.separator"));
@@ -85,48 +91,41 @@ public class ListIndexCommandDUnitTest extends CliCommandTestBase {
return buffer.toString();
}
- @Override
- public final void postSetUp() throws Exception {
- setUpJmxManagerOnVm0ThenConnect(null);
- setupGemFire();
- }
-
- protected Index createIndex(final String name, final String indexedExpression, final String fromClause) {
+ private Index createIndex(final String name, final String indexedExpression, final String fromClause) {
return createIndex(name, IndexType.FUNCTIONAL, indexedExpression, fromClause);
}
- protected Index createIndex(final String name, final IndexType type, final String indexedExpression,
- final String fromClause) {
+ private Index createIndex(final String name, final IndexType type, final String indexedExpression, final String fromClause) {
return new IndexAdapter(name, type, indexedExpression, fromClause);
}
- protected Peer createPeer(final VM vm, final Properties distributedSystemProperties,
- final RegionDefinition... regions) {
+ private Peer createPeer(final VM vm, final Properties distributedSystemProperties, final RegionDefinition... regions) {
final Peer peer = new Peer(vm, distributedSystemProperties);
peer.add(regions);
return peer;
}
- protected RegionDefinition createRegionDefinition(final String regionName, final Class<?> keyConstraint,
- final Class<?> valueConstraint, final Index... indexes) {
+ private RegionDefinition createRegionDefinition(final String regionName, final Class<?> keyConstraint, final Class<?> valueConstraint, final Index... indexes) {
final RegionDefinition regionDefinition = new RegionDefinition(regionName, keyConstraint, valueConstraint);
regionDefinition.add(indexes);
return regionDefinition;
}
- protected void setupGemFire() throws Exception {
+ private void setupGemFire() throws Exception {
final Host host = Host.getHost(0);
final VM vm1 = host.getVM(1);
final VM vm2 = host.getVM(2);
- final Peer peer1 = createPeer(vm1, createDistributedSystemProperties("consumerServer"),
- createRegionDefinition("consumers", Long.class, Consumer.class,
- createIndex("cidIdx", IndexType.PRIMARY_KEY, "id", "/consumers"),
- createIndex("cnameIdx", "name", "/consumers")));
+ final Peer peer1 = createPeer(vm1,
+ createDistributedSystemProperties("consumerServer"),
+ createRegionDefinition("consumers", Long.class, Consumer.class,
+ createIndex("cidIdx", IndexType.PRIMARY_KEY, "id", "/consumers"),
+ createIndex("cnameIdx", "name", "/consumers")));
- final Peer peer2 = createPeer(vm2, createDistributedSystemProperties("producerServer"),
- createRegionDefinition("producers", Long.class, Producer.class, createIndex("pidIdx", "id", "/producers")));
+ final Peer peer2 = createPeer(vm2,
+ createDistributedSystemProperties("producerServer"),
+ createRegionDefinition("producers", Long.class, Producer.class, createIndex("pidIdx", "id", "/producers")));
createRegionWithIndexes(peer1);
createRegionWithIndexes(peer2);
@@ -135,7 +134,7 @@ public class ListIndexCommandDUnitTest extends CliCommandTestBase {
loadProducerData(peer2, 10000);
}
- protected Properties createDistributedSystemProperties(final String gemfireName) {
+ private Properties createDistributedSystemProperties(final String gemfireName) {
final Properties distributedSystemProperties = new Properties();
distributedSystemProperties.setProperty(DistributionConfig.LOG_LEVEL_NAME, getDUnitLogLevel());
@@ -144,9 +143,8 @@ public class ListIndexCommandDUnitTest extends CliCommandTestBase {
return distributedSystemProperties;
}
- protected void createRegionWithIndexes(final Peer peer) throws Exception {
- peer.run(new SerializableRunnable(
- String.format("Creating Regions with Indexes on GemFire peer (%1$s).", peer.getName())) {
+ private void createRegionWithIndexes(final Peer peer) throws Exception {
+ peer.run(new SerializableRunnable(String.format("Creating Regions with Indexes on GemFire peer (%1$s).", peer.getName())) {
public void run() {
// create the GemFire distributed system with custom configuration properties...
getSystem(peer.getConfiguration());
@@ -176,16 +174,14 @@ public class ListIndexCommandDUnitTest extends CliCommandTestBase {
}
}
} catch (Exception e) {
- getLogWriter().error(
- String.format("Error occurred creating Index (%1$s) on Region (%2$s) - (%3$s)", indexName,
- region.getFullPath(), e.getMessage()));
+ getLogWriter().error(String.format("Error occurred creating Index (%1$s) on Region (%2$s) - (%3$s)", indexName, region.getFullPath(), e.getMessage()));
}
}
}
});
}
- protected void loadConsumerData(final Peer peer, final int operationsTotal) throws Exception {
+ private void loadConsumerData(final Peer peer, final int operationsTotal) throws Exception {
peer.run(new SerializableRunnable("Load /consumers Region with data") {
public void run() {
final Cache cache = getCache();
@@ -231,7 +227,7 @@ public class ListIndexCommandDUnitTest extends CliCommandTestBase {
});
}
- protected void loadProducerData(final Peer peer, final int operationsTotal) throws Exception {
+ private void loadProducerData(final Peer peer, final int operationsTotal) throws Exception {
peer.run(new SerializableRunnable("Load /producers Region with data") {
public void run() {
final Cache cache = getCache();
@@ -276,14 +272,13 @@ public class ListIndexCommandDUnitTest extends CliCommandTestBase {
}
@SuppressWarnings("unchecked")
- protected <T extends Comparable<T>, B extends AbstractBean<T>> B query(final Cache cache, final String queryString) {
+ private <T extends Comparable<T>, B extends AbstractBean<T>> B query(final Cache cache, final String queryString) {
try {
getLogWriter().info(String.format("Running Query (%1$s) in GemFire...", queryString));
final SelectResults<B> results = (SelectResults<B>) cache.getQueryService().newQuery(queryString).execute();
- getLogWriter().info(
- String.format("Running Query (%1$s) in GemFire returned (%2$d) result(s).", queryString, results.size()));
+ getLogWriter().info(String.format("Running Query (%1$s) in GemFire returned (%2$d) result(s).", queryString, results.size()));
return (results.iterator().hasNext() ? results.iterator().next() : null);
} catch (Exception e) {
@@ -291,23 +286,17 @@ public class ListIndexCommandDUnitTest extends CliCommandTestBase {
}
}
- protected <T extends Comparable<T>, B extends AbstractBean<T>> B query(final Region<T, B> region,
- final String queryPredicate) {
+ private <T extends Comparable<T>, B extends AbstractBean<T>> B query(final Region<T, B> region, final String queryPredicate) {
try {
- getLogWriter().info(
- String.format("Running Query (%1$s) on Region (%2$s)...", queryPredicate, region.getFullPath()));
+ getLogWriter().info(String.format("Running Query (%1$s) on Region (%2$s)...", queryPredicate, region.getFullPath()));
final SelectResults<B> results = region.query(queryPredicate);
- getLogWriter().info(
- String.format("Running Query (%1$s) on Region (%2$s) returned (%3$d) result(s).", queryPredicate,
- region.getFullPath(), results.size()));
+ getLogWriter().info(String.format("Running Query (%1$s) on Region (%2$s) returned (%3$d) result(s).", queryPredicate, region.getFullPath(), results.size()));
return (results.iterator().hasNext() ? results.iterator().next() : null);
} catch (Exception e) {
- throw new RuntimeException(
- String.format("An error occurred running Query (%1$s) on Region (%2$s)!", queryPredicate,
- region.getFullPath()), e);
+ throw new RuntimeException(String.format("An error occurred running Query (%1$s) on Region (%2$s)!", queryPredicate, region.getFullPath()), e);
}
}
@@ -320,7 +309,7 @@ public class ListIndexCommandDUnitTest extends CliCommandTestBase {
assertEquals(Result.Status.OK, result.getStatus());
}
- protected static class Peer implements Iterable<RegionDefinition>, Serializable {
+ private static class Peer implements Iterable<RegionDefinition>, Serializable {
private final Properties distributedSystemProperties;
@@ -350,6 +339,7 @@ public class ListIndexCommandDUnitTest extends CliCommandTestBase {
return (regionDefinitions != null && regions.addAll(Arrays.asList(regionDefinitions)));
}
+ @Override
public Iterator<RegionDefinition> iterator() {
return Collections.unmodifiableSet(regions).iterator();
}
@@ -377,7 +367,7 @@ public class ListIndexCommandDUnitTest extends CliCommandTestBase {
}
}
- protected static class IndexAdapter implements Index, Serializable {
+ private static class IndexAdapter implements Index, Serializable {
private final IndexDetails.IndexType type;
@@ -389,11 +379,9 @@ public class ListIndexCommandDUnitTest extends CliCommandTestBase {
this(name, IndexType.FUNCTIONAL, indexedExpression, fromClause);
}
- protected IndexAdapter(final String name, final IndexType type, final String indexedExpression,
- final String fromClause) {
+ protected IndexAdapter(final String name, final IndexType type, final String indexedExpression, final String fromClause) {
assert name != null : "The name of the Index cannot be null!";
- assert indexedExpression != null : String.format("The expression to index for Index (%1$s) cannot be null!",
- name);
+ assert indexedExpression != null : String.format("The expression to index for Index (%1$s) cannot be null!", name);
assert fromClause != null : String.format("The from clause for Index (%1$s) cannot be null!", name);
this.type = ObjectUtils.defaultIfNull(IndexDetails.IndexType.valueOf(type), IndexDetails.IndexType.FUNCTIONAL);
@@ -402,42 +390,52 @@ public class ListIndexCommandDUnitTest extends CliCommandTestBase {
this.fromClause = fromClause;
}
+ @Override
public String getName() {
return this.name;
}
+ @Override
public String getFromClause() {
return this.fromClause;
}
+ @Override
public String getCanonicalizedFromClause() {
return this.fromClause;
}
+ @Override
public String getIndexedExpression() {
return this.indexedExpression;
}
+ @Override
public String getCanonicalizedIndexedExpression() {
return this.indexedExpression;
}
+ @Override
public String getProjectionAttributes() {
throw new UnsupportedOperationException("Not Implemented!");
}
+ @Override
public String getCanonicalizedProjectionAttributes() {
throw new UnsupportedOperationException("Not Implemented!");
}
+ @Override
public Region<?, ?> getRegion() {
throw new UnsupportedOperationException("Not Implemented!");
}
+ @Override
public IndexStatistics getStatistics() {
throw new UnsupportedOperationException("Not Implemented!");
}
+ @Override
public IndexType getType() {
return type.getType();
}
@@ -454,7 +452,7 @@ public class ListIndexCommandDUnitTest extends CliCommandTestBase {
}
}
- protected static class RegionDefinition implements Iterable<Index>, Serializable {
+ private static class RegionDefinition implements Iterable<Index>, Serializable {
private final Class<?> keyConstraint;
private final Class<?> valueConstraint;
@@ -487,6 +485,7 @@ public class ListIndexCommandDUnitTest extends CliCommandTestBase {
return (indexes != null && this.indexes.addAll(Arrays.asList(indexes)));
}
+ @Override
public Iterator<Index> iterator() {
return Collections.unmodifiableSet(indexes).iterator();
}
@@ -528,7 +527,7 @@ public class ListIndexCommandDUnitTest extends CliCommandTestBase {
}
}
- protected static abstract class AbstractBean<T extends Comparable<T>> implements MutableIdentifiable<T>, Serializable {
+ private static abstract class AbstractBean<T extends Comparable<T>> implements MutableIdentifiable<T>, Serializable {
private T id;
private String name;
@@ -540,10 +539,12 @@ public class ListIndexCommandDUnitTest extends CliCommandTestBase {
this.id = id;
}
+ @Override
public T getId() {
return id;
}
+ @Override
public void setId(final T id) {
this.id = id;
}
@@ -588,7 +589,7 @@ public class ListIndexCommandDUnitTest extends CliCommandTestBase {
}
}
- public static class Consumer extends AbstractBean<Long> {
+ private static class Consumer extends AbstractBean<Long> {
private volatile int units;
@@ -608,7 +609,7 @@ public class ListIndexCommandDUnitTest extends CliCommandTestBase {
}
}
- public static class Producer extends AbstractBean<Long> {
+ private static class Producer extends AbstractBean<Long> {
private volatile int units;
@@ -628,7 +629,7 @@ public class ListIndexCommandDUnitTest extends CliCommandTestBase {
}
}
- public static class Proxy extends AbstractBean<Long> {
+ private static class Proxy extends AbstractBean<Long> {
private final AbstractBean<Long> bean;
private int unitsSnapshot;
@@ -661,7 +662,7 @@ public class ListIndexCommandDUnitTest extends CliCommandTestBase {
}
}
- protected static enum CrudOperation {
+ private static enum CrudOperation {
CREATE,
RETRIEVE,
UPDATE,
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ShellCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ShellCommandsDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ShellCommandsDUnitTest.java
index b60f78c..fec6c5e 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ShellCommandsDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ShellCommandsDUnitTest.java
@@ -46,7 +46,7 @@ public class ShellCommandsDUnitTest extends CliCommandTestBase {
private static final long serialVersionUID = 1L;
@Override
- public final void postSetUp() throws Exception {
+ public final void postSetUpCliCommandTestBase() throws Exception {
getDefaultShell();
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/UserCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/UserCommandsDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/UserCommandsDUnitTest.java
index 9ca6036..a234edb 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/UserCommandsDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/UserCommandsDUnitTest.java
@@ -53,7 +53,7 @@ public class UserCommandsDUnitTest extends CliCommandTestBase {
boolean deleteJarDirectory = false;
@Override
- public final void postSetUp() throws Exception {
+ public final void postSetUpCliCommandTestBase() throws Exception {
createUserCommandJarFile();
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/management/internal/configuration/SharedConfigurationDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/configuration/SharedConfigurationDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/configuration/SharedConfigurationDUnitTest.java
index 92fe1bc..c07eab7 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/configuration/SharedConfigurationDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/configuration/SharedConfigurationDUnitTest.java
@@ -16,10 +16,15 @@
*/
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.test.dunit.Assert.*;
+import static com.gemstone.gemfire.test.dunit.Host.*;
+import static com.gemstone.gemfire.test.dunit.Wait.*;
+
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
-import java.net.UnknownHostException;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -27,117 +32,104 @@ import java.util.Map;
import java.util.Properties;
import java.util.Set;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.DiskStoreFactory;
import com.gemstone.gemfire.cache.RegionFactory;
import com.gemstone.gemfire.cache.RegionShortcut;
-import com.gemstone.gemfire.cache30.CacheTestCase;
import com.gemstone.gemfire.distributed.Locator;
import com.gemstone.gemfire.distributed.internal.DM;
-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.distributed.internal.membership.InternalDistributedMember;
import com.gemstone.gemfire.distributed.internal.tcpserver.TcpClient;
-import com.gemstone.gemfire.internal.AvailablePort;
-import com.gemstone.gemfire.internal.AvailablePortHelper;
import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
import com.gemstone.gemfire.internal.cache.xmlcache.CacheXml;
import com.gemstone.gemfire.management.internal.configuration.domain.Configuration;
import com.gemstone.gemfire.management.internal.configuration.domain.XmlEntity;
-import com.gemstone.gemfire.management.internal.configuration.domain.XmlEntity.XmlEntityBuilder;
import com.gemstone.gemfire.management.internal.configuration.handlers.ConfigurationRequestHandler;
import com.gemstone.gemfire.management.internal.configuration.messages.ConfigurationRequest;
import com.gemstone.gemfire.management.internal.configuration.messages.ConfigurationResponse;
-import com.gemstone.gemfire.test.dunit.Host;
import com.gemstone.gemfire.test.dunit.SerializableCallable;
-import com.gemstone.gemfire.test.dunit.SerializableRunnable;
import com.gemstone.gemfire.test.dunit.VM;
-import com.gemstone.gemfire.test.dunit.Wait;
import com.gemstone.gemfire.test.dunit.WaitCriterion;
+import com.gemstone.gemfire.test.dunit.cache.internal.JUnit4CacheTestCase;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
-/***
+/**
* Tests the starting up of shared configuration, installation of {@link ConfigurationRequestHandler}
- *
- *
*/
-public class SharedConfigurationDUnitTest extends CacheTestCase {
- private static final long serialVersionUID = 1L;
+@Category(DistributedTest.class)
+public class SharedConfigurationDUnitTest extends JUnit4CacheTestCase {
+
private static final String REGION1 = "region1";
private static final int TIMEOUT = 10000;
private static final int INTERVAL = 500;
private static final String DISKSTORENAME = "diskStore1";
-// private static final VM locator1Vm = Host.getHost(0).getVM(1);
-// private static final VM locator2Vm = Host.getHost(0).getVM(2);
-// private static final VM dataMemberVm = Host.getHost(0).getVM(3);
+ @Override
+ public final void postSetUp() throws Exception {
+ disconnectAllFromDS();
+ }
- public static final SerializableRunnable locatorCleanup = new SerializableRunnable() {
- @Override
- public void run() {
- InternalLocator locator = InternalLocator.getLocator();
- if (locator != null) {
- SharedConfiguration sharedConfig = locator.getSharedConfiguration();
- if (sharedConfig != null) {
- sharedConfig.destroySharedConfiguration();
- }
- locator.stop();
- }
- disconnectAllFromDS();
+ @Override
+ public final void postTearDownCacheTestCase() throws Exception {
+ for (int i=0; i<4; i++) {
+ getHost(0).getVM(i).invoke(SharedConfigurationTestUtils.cleanupLocator);
}
- };
-
-
- public SharedConfigurationDUnitTest(String name) {
- super(name);
}
+
+ @Test
+ public void testGetHostedLocatorsWithSharedConfiguration() throws Exception {
+ final VM locator1Vm = getHost(0).getVM(1);
+ final VM locator2Vm = getHost(0).getVM(2);
- public void testGetHostedLocatorsWithSharedConfiguration() {
- disconnectAllFromDS();
- final VM locator1Vm = Host.getHost(0).getVM(1);
- final VM locator2Vm = Host.getHost(0).getVM(2);
-
- final String testName = "testGetHostedLocatorsWithSharedConfiguration";
-// final VM locator3Vm = Host.getHost(0).getVM(3);
-
- final int []ports = AvailablePortHelper.getRandomAvailableTCPPorts(3);
+ final String testName = getName();
+
+ final int[] ports = getRandomAvailableTCPPorts(3);
- //final int locator1Port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
final int locator1Port = ports[0];
final String locator1Name = "locator1" + locator1Port;
+
locator1Vm.invoke(new SerializableCallable() {
@Override
public Object call() {
final File locatorLogFile = new File(testName + "-locator-" + locator1Port + ".log");
+
final Properties locatorProps = new Properties();
- locatorProps.setProperty(DistributionConfig.NAME_NAME, locator1Name);
- locatorProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
- locatorProps.setProperty(DistributionConfig.LOG_LEVEL_NAME, "fine");
- locatorProps.setProperty(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "true");
+ locatorProps.setProperty(NAME_NAME, locator1Name);
+ locatorProps.setProperty(MCAST_PORT_NAME, "0");
+ locatorProps.setProperty(LOG_LEVEL_NAME, "fine");
+ locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION_NAME, "true");
+
try {
- final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator1Port, locatorLogFile, null,
- locatorProps);
+ 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";
}
};
- Wait.waitForCriterion(wc, TIMEOUT, INTERVAL, true);
- } catch (IOException ioex) {
- fail("Unable to create a locator with a shared configuration");
+ waitForCriterion(wc, TIMEOUT, INTERVAL, true);
+
+ } catch (IOException e) {
+ fail("Unable to create a locator with a shared configuration", e);
}
+
GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
InternalDistributedMember me = cache.getMyId();
DM dm = cache.getDistributionManager();
+
Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
assertFalse(hostedLocators.isEmpty());
+
Map<InternalDistributedMember, Collection<String>> hostedLocatorsWithSharedConfiguration = dm.getAllHostedLocatorsWithSharedConfiguration();
assertFalse(hostedLocatorsWithSharedConfiguration.isEmpty());
@@ -147,7 +139,6 @@ public class SharedConfigurationDUnitTest extends CacheTestCase {
}
});
- //final int locator2Port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
final int locator2Port = ports[1];
final String locator2Name = "locator2" + locator2Port;
@@ -155,20 +146,23 @@ public class SharedConfigurationDUnitTest extends CacheTestCase {
@Override
public Object call() throws IOException {
final File locatorLogFile = new File(testName + "-locator-" + locator2Port + ".log");
+
final Properties locatorProps = new Properties();
- locatorProps.setProperty(DistributionConfig.NAME_NAME, locator2Name);
- locatorProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
- locatorProps.setProperty(DistributionConfig.LOG_LEVEL_NAME, "fine");
- locatorProps.setProperty(DistributionConfig.LOCATORS_NAME, "localhost:" + locator1Port);
- locatorProps.setProperty(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "false");
- final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator2Port, locatorLogFile, null,
- locatorProps);
+ locatorProps.setProperty(NAME_NAME, locator2Name);
+ locatorProps.setProperty(MCAST_PORT_NAME, "0");
+ locatorProps.setProperty(LOG_LEVEL_NAME, "fine");
+ locatorProps.setProperty(LOCATORS_NAME, "localhost:" + locator1Port);
+ locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION_NAME, "false");
+
+ final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator2Port, locatorLogFile, null, locatorProps);
GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
InternalDistributedMember me = cache.getMyId();
DM dm = cache.getDistributionManager();
+
Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
assertFalse(hostedLocators.isEmpty());
+
Map<InternalDistributedMember, Collection<String>> hostedLocatorsWithSharedConfiguration = dm.getAllHostedLocatorsWithSharedConfiguration();
assertFalse(hostedLocatorsWithSharedConfiguration.isEmpty());
assertNotNull(hostedLocators.get(me));
@@ -193,7 +187,7 @@ public class SharedConfigurationDUnitTest extends CacheTestCase {
public Object call() {
InternalLocator locator = (InternalLocator) Locator.getLocator();
SharedConfiguration sharedConfig = locator.getSharedConfiguration();
- sharedConfig.destroySharedConfiguration();
+ sharedConfig.destroySharedConfiguration_forTestsOnly();
locator.stop();
return null;
}
@@ -216,60 +210,52 @@ public class SharedConfigurationDUnitTest extends CacheTestCase {
return null;
}
});
-
-// locator2Vm.invoke(new SerializableCallable() {
-// public Object call() {
-// InternalLocator locator = (InternalLocator) Locator.getLocator();
-// SharedConfiguration sharedConfig = locator.getSharedConfiguration();
-// if (sharedConfig != null) {
-// sharedConfig.destroySharedConfiguration();
-// }
-// locator.stop();
-// return null;
-// }
-// });
}
-
- public void testSharedConfigurationService() {
- disconnectAllFromDS();
+
+ @Test
+ public void testSharedConfigurationService() throws Exception {
// Start the Locator and wait for shared configuration to be available
final String testGroup = "G1";
final String clusterLogLevel = "error";
final String groupLogLevel = "fine";
- final String testName = "testSharedConfigurationService";
+
+ final String testName = getName();
- final VM locator1Vm = Host.getHost(0).getVM(1);
- final VM locator2Vm = Host.getHost(0).getVM(3);
- final VM dataMemberVm = Host.getHost(0).getVM(2);
- final int [] ports = AvailablePortHelper.getRandomAvailableTCPPorts(3);
+ final VM locator1Vm = getHost(0).getVM(1);
+ final VM locator2Vm = getHost(0).getVM(3);
+ final VM dataMemberVm = getHost(0).getVM(2);
+
+ final int [] ports = getRandomAvailableTCPPorts(3);
final int locator1Port = ports[0];
locator1Vm.invoke(new SerializableCallable() {
@Override
public Object call() {
final File locatorLogFile = new File(testName + "-locator-" + locator1Port + ".log");
+
final Properties locatorProps = new Properties();
- locatorProps.setProperty(DistributionConfig.NAME_NAME, "Locator1");
- locatorProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
- locatorProps.setProperty(DistributionConfig.LOG_LEVEL_NAME, "info");
- locatorProps.setProperty(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "true");
+ locatorProps.setProperty(NAME_NAME, "Locator1");
+ locatorProps.setProperty(MCAST_PORT_NAME, "0");
+ locatorProps.setProperty(LOG_LEVEL_NAME, "info");
+ locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION_NAME, "true");
+
try {
- final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator1Port, locatorLogFile, null,
- locatorProps);
+ 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";
}
};
- Wait.waitForCriterion(wc, TIMEOUT, INTERVAL, true);
- } catch (IOException ioex) {
- fail("Unable to create a locator with a shared configuration");
+ waitForCriterion(wc, TIMEOUT, INTERVAL, true);
+
+ } catch (IOException e) {
+ fail("Unable to create a locator with a shared configuration", e);
}
return null;
@@ -280,12 +266,14 @@ public class SharedConfigurationDUnitTest extends CacheTestCase {
@Override
public Object call() {
Properties localProps = new Properties();
- localProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
- localProps.setProperty(DistributionConfig.LOCATORS_NAME, "localhost:" + locator1Port);
- localProps.setProperty(DistributionConfig.GROUPS_NAME, testGroup);
+ localProps.setProperty(MCAST_PORT_NAME, "0");
+ localProps.setProperty(LOCATORS_NAME, "localhost:" + locator1Port);
+ localProps.setProperty(GROUPS_NAME, testGroup);
+
getSystem(localProps);
Cache cache = getCache();
assertNotNull(cache);
+
DiskStoreFactory dsFactory = cache.createDiskStoreFactory();
File dsDir = new File("dsDir");
if (!dsDir.exists()) {
@@ -305,15 +293,15 @@ public class SharedConfigurationDUnitTest extends CacheTestCase {
assertTrue(scw.addXmlEntity(xmlEntity, new String[] {testGroup}));
//Modify property and cache attributes
Properties clusterProperties = new Properties();
- clusterProperties.setProperty(DistributionConfig.LOG_LEVEL_NAME, clusterLogLevel);
+ clusterProperties.setProperty(LOG_LEVEL_NAME, clusterLogLevel);
XmlEntity cacheEntity = XmlEntity.builder().withType(CacheXml.CACHE).build();
Map<String, String> cacheAttributes = new HashMap<String, String>();
cacheAttributes.put(CacheXml.COPY_ON_READ, "true");
- //assertTrue(scw.modifyProperties(clusterProperties, null));
+ //assertTrue(scw.modifyProperties(clusterProperties, null)); // TODO: why is this commented out?
assertTrue(scw.modifyPropertiesAndCacheAttributes(clusterProperties, cacheEntity, null));
- clusterProperties.setProperty(DistributionConfig.LOG_LEVEL_NAME, groupLogLevel);
+ clusterProperties.setProperty(LOG_LEVEL_NAME, groupLogLevel);
assertTrue(scw.modifyPropertiesAndCacheAttributes(clusterProperties, cacheEntity, new String[]{testGroup}));
//Add a jar
@@ -335,32 +323,32 @@ public class SharedConfigurationDUnitTest extends CacheTestCase {
locator2Vm.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
-
final File locatorLogFile = new File(testName + "-locator-" + locator2Port + ".log");
+
final Properties locatorProps = new Properties();
- locatorProps.setProperty(DistributionConfig.NAME_NAME, "Locator2");
- locatorProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
- locatorProps.setProperty(DistributionConfig.LOG_LEVEL_NAME, "info");
- locatorProps.setProperty(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "true");
- locatorProps.setProperty(DistributionConfig.LOCATORS_NAME, "localhost:" + locator1Port);
+ locatorProps.setProperty(NAME_NAME, "Locator2");
+ locatorProps.setProperty(MCAST_PORT_NAME, "0");
+ locatorProps.setProperty(LOG_LEVEL_NAME, "info");
+ locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION_NAME, "true");
+ locatorProps.setProperty(LOCATORS_NAME, "localhost:" + locator1Port);
+
try {
- final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator2Port, locatorLogFile, null,
- locatorProps);
+ final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator2Port, 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";
}
};
- Wait.waitForCriterion(wc, TIMEOUT, INTERVAL, true);
- } catch (IOException ioex) {
- fail("Unable to create a locator with a shared configuration");
+ waitForCriterion(wc, TIMEOUT, INTERVAL, true);
+
+ } catch (IOException e) {
+ fail("Unable to create a locator with a shared configuration", e);
}
InternalLocator locator = (InternalLocator) Locator.getLocator();
@@ -370,14 +358,14 @@ public class SharedConfigurationDUnitTest extends CacheTestCase {
assertNotNull(clusterConfig);
assertNotNull(clusterConfig.getJarNames());
assertTrue(clusterConfig.getJarNames().contains("foo.jar"));
- assertTrue(clusterConfig.getGemfireProperties().getProperty(DistributionConfig.LOG_LEVEL_NAME).equals(clusterLogLevel));
+ assertTrue(clusterConfig.getGemfireProperties().getProperty(LOG_LEVEL_NAME).equals(clusterLogLevel));
assertNotNull(clusterConfig.getCacheXmlContent());
Configuration testGroupConfiguration = entireConfiguration.get(testGroup);
assertNotNull(testGroupConfiguration);
assertNotNull(testGroupConfiguration.getJarNames());
assertTrue(testGroupConfiguration.getJarNames().contains("bar.jar"));
- assertTrue(testGroupConfiguration.getGemfireProperties().getProperty(DistributionConfig.LOG_LEVEL_NAME).equals(groupLogLevel));
+ assertTrue(testGroupConfiguration.getGemfireProperties().getProperty(LOG_LEVEL_NAME).equals(groupLogLevel));
assertNotNull(testGroupConfiguration.getCacheXmlContent());
assertTrue(testGroupConfiguration.getCacheXmlContent().contains(REGION1));
@@ -394,7 +382,7 @@ public class SharedConfigurationDUnitTest extends CacheTestCase {
dataMemberVm.invoke(new SerializableCallable() {
@Override
- public Object call() throws UnknownHostException, IOException, ClassNotFoundException {
+ public Object call() throws IOException, ClassNotFoundException {
SharedConfigurationWriter scw = new SharedConfigurationWriter();
scw.deleteXmlEntity(new XmlEntity(CacheXml.REGION, "name", REGION1), new String[]{testGroup});
scw.deleteJars(new String []{"foo.jar"}, null);
@@ -412,13 +400,13 @@ public class SharedConfigurationDUnitTest extends CacheTestCase {
assertNull(configResponse.getJarNames());
assertNull(configResponse.getJars());
assertTrue(clusterConfiguration.getJarNames().isEmpty());
- assertTrue(clusterConfiguration.getGemfireProperties().getProperty(DistributionConfig.LOG_LEVEL_NAME).equals(clusterLogLevel));
+ assertTrue(clusterConfiguration.getGemfireProperties().getProperty(LOG_LEVEL_NAME).equals(clusterLogLevel));
Configuration testGroupConfiguration = requestedConfiguration.get(testGroup);
assertNotNull(testGroupConfiguration);
assertFalse(testGroupConfiguration.getCacheXmlContent().contains(REGION1));
assertTrue(testGroupConfiguration.getJarNames().isEmpty());
- assertTrue(testGroupConfiguration.getGemfireProperties().getProperty(DistributionConfig.LOG_LEVEL_NAME).equals(groupLogLevel));
+ assertTrue(testGroupConfiguration.getGemfireProperties().getProperty(LOG_LEVEL_NAME).equals(groupLogLevel));
GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
Map<InternalDistributedMember, Collection<String>> locatorsWithSharedConfiguration = cache.getDistributionManager().getAllHostedLocatorsWithSharedConfiguration();
@@ -432,11 +420,4 @@ public class SharedConfigurationDUnitTest extends CacheTestCase {
}
});
}
-
- @Override
- public final void postTearDownCacheTestCase() throws Exception {
- for (int i=0; i<4; i++) {
- Host.getHost(0).getVM(i).invoke(SharedConfigurationDUnitTest.locatorCleanup);
- }
- }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/management/internal/configuration/SharedConfigurationTestUtils.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/configuration/SharedConfigurationTestUtils.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/configuration/SharedConfigurationTestUtils.java
new file mode 100644
index 0000000..235f02e
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/configuration/SharedConfigurationTestUtils.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.management.internal.configuration;
+
+import com.gemstone.gemfire.distributed.internal.InternalLocator;
+import com.gemstone.gemfire.distributed.internal.SharedConfiguration;
+import com.gemstone.gemfire.test.dunit.SerializableRunnable;
+import com.gemstone.gemfire.test.dunit.internal.JUnit3DistributedTestCase;
+
+public class SharedConfigurationTestUtils {
+
+ public static final SerializableRunnable cleanupLocator = new SerializableRunnable() {
+ @Override
+ public void run() {
+ InternalLocator locator = InternalLocator.getLocator();
+ if (locator != null) {
+ SharedConfiguration sharedConfig = locator.getSharedConfiguration();
+ if (sharedConfig != null) {
+ sharedConfig.destroySharedConfiguration_forTestsOnly();
+ }
+ locator.stop();
+ }
+ JUnit3DistributedTestCase.disconnectAllFromDS();
+ }
+ };
+}