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/02 18:58:37 UTC
[02/12] incubator-geode git commit: Fixing tests
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cd02af01/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherTest.java
new file mode 100755
index 0000000..c8e1882
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherTest.java
@@ -0,0 +1,903 @@
+/*
+ * 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.distributed;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Collections;
+import java.util.Properties;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.server.CacheServer;
+import com.gemstone.gemfire.distributed.ServerLauncher.Builder;
+import com.gemstone.gemfire.distributed.ServerLauncher.Command;
+import com.gemstone.gemfire.distributed.internal.DistributionConfig;
+import com.gemstone.gemfire.distributed.support.DistributedSystemAdapter;
+import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
+import edu.umd.cs.mtc.MultithreadedTestCase;
+import edu.umd.cs.mtc.TestFramework;
+
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.lib.concurrent.Synchroniser;
+import org.jmock.lib.legacy.ClassImposteriser;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.RestoreSystemProperties;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+/**
+ * The ServerLauncherTest class is a test suite of unit tests testing the contract, functionality and invariants
+ * of the ServerLauncher class.
+ *
+ * @see com.gemstone.gemfire.distributed.ServerLauncher
+ * @see com.gemstone.gemfire.distributed.ServerLauncher.Builder
+ * @see com.gemstone.gemfire.distributed.ServerLauncher.Command
+ * @see org.junit.Assert
+ * @see org.junit.Test
+ * @since 7.0
+ */
+@SuppressWarnings({"deprecation", "unused"})
+@Category(UnitTest.class)
+public class ServerLauncherTest {
+
+ private Mockery mockContext;
+
+ @Rule
+ public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+
+ @Rule
+ public final TestName testName = new TestName();
+
+ @Before
+ public void setup() {
+ mockContext = new Mockery() {{
+ setImposteriser(ClassImposteriser.INSTANCE);
+ setThreadingPolicy(new Synchroniser());
+ }};
+ }
+
+ @After
+ public void tearDown() {
+ mockContext.assertIsSatisfied();
+ mockContext = null;
+ }
+
+ @Test
+ public void testParseCommand() {
+ Builder builder = new Builder();
+
+ assertEquals(Builder.DEFAULT_COMMAND, builder.getCommand());
+
+ builder.parseCommand((String[]) null);
+
+ assertEquals(Builder.DEFAULT_COMMAND, builder.getCommand());
+
+ builder.parseCommand(); // empty String array
+
+ assertEquals(Builder.DEFAULT_COMMAND, builder.getCommand());
+
+ builder.parseCommand(Command.START.getName());
+
+ assertEquals(Command.START, builder.getCommand());
+
+ builder.parseCommand("Status");
+
+ assertEquals(Command.STATUS, builder.getCommand());
+
+ builder.parseCommand("sToP");
+
+ assertEquals(Command.STOP, builder.getCommand());
+
+ builder.parseCommand("--opt", "START", "-o", Command.STATUS.getName());
+
+ assertEquals(Command.START, builder.getCommand());
+
+ builder.setCommand(null);
+ builder.parseCommand("badCommandName", "--start", "stat");
+
+ assertEquals(Builder.DEFAULT_COMMAND, builder.getCommand());
+ }
+
+ @Test
+ public void testParseMemberName() {
+ Builder builder = new Builder();
+
+ assertNull(builder.getMemberName());
+
+ builder.parseMemberName((String[]) null);
+
+ assertNull(builder.getMemberName());
+
+ builder.parseMemberName(); // empty String array
+
+ assertNull(builder.getMemberName());
+
+ builder.parseMemberName(Command.START.getName(), "--opt", "-o");
+
+ assertNull(builder.getMemberName());
+
+ builder.parseMemberName("memberOne");
+
+ assertEquals("memberOne", builder.getMemberName());
+ }
+
+ @Test
+ public void testSetAndGetCommand() {
+ Builder builder = new Builder();
+
+ assertEquals(Builder.DEFAULT_COMMAND, builder.getCommand());
+ assertSame(builder, builder.setCommand(Command.STATUS));
+ assertEquals(Command.STATUS, builder.getCommand());
+ assertSame(builder, builder.setCommand(null));
+ assertEquals(Builder.DEFAULT_COMMAND, builder.getCommand());
+ }
+
+ @Test
+ public void testSetAndGetMemberName() {
+ Builder builder = new Builder();
+
+ assertNull(builder.getMemberName());
+ assertSame(builder, builder.setMemberName("serverOne"));
+ assertEquals("serverOne", builder.getMemberName());
+ assertSame(builder, builder.setMemberName(null));
+ assertNull(builder.getMemberName());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetMemberNameToBlankString() {
+ try {
+ new Builder().setMemberName(" ");
+ }
+ catch (IllegalArgumentException expected) {
+ assertEquals(LocalizedStrings.Launcher_Builder_MEMBER_NAME_ERROR_MESSAGE.toLocalizedString("Server"),
+ expected.getMessage());
+ throw expected;
+ }
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetMemberNameToEmptyString() {
+ try {
+ new Builder().setMemberName("");
+ }
+ catch (IllegalArgumentException expected) {
+ assertEquals(LocalizedStrings.Launcher_Builder_MEMBER_NAME_ERROR_MESSAGE.toLocalizedString("Server"),
+ expected.getMessage());
+ throw expected;
+ }
+ }
+
+ @Test
+ public void testSetAndGetPid() {
+ Builder builder = new Builder();
+
+ assertNull(builder.getPid());
+ assertSame(builder, builder.setPid(0));
+ assertEquals(0, builder.getPid().intValue());
+ assertSame(builder, builder.setPid(1));
+ assertEquals(1, builder.getPid().intValue());
+ assertSame(builder, builder.setPid(1024));
+ assertEquals(1024, builder.getPid().intValue());
+ assertSame(builder, builder.setPid(12345));
+ assertEquals(12345, builder.getPid().intValue());
+ assertSame(builder, builder.setPid(null));
+ assertNull(builder.getPid());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetPidToInvalidValue() {
+ try {
+ new Builder().setPid(-1);
+ }
+ catch (IllegalArgumentException expected) {
+ assertEquals(LocalizedStrings.Launcher_Builder_PID_ERROR_MESSAGE.toLocalizedString(), expected.getMessage());
+ throw expected;
+ }
+ }
+
+ @Test
+ public void testSetAndGetServerBindAddress() throws Exception {
+ Builder builder = new Builder();
+
+ assertNull(builder.getServerBindAddress());
+ assertSame(builder, builder.setServerBindAddress(null));
+ assertNull(builder.getServerBindAddress());
+ assertSame(builder, builder.setServerBindAddress(""));
+ assertNull(builder.getServerBindAddress());
+ assertSame(builder, builder.setServerBindAddress(" "));
+ assertNull(builder.getServerBindAddress());
+ assertSame(builder, builder.setServerBindAddress(InetAddress.getLocalHost().getCanonicalHostName()));
+ assertEquals(InetAddress.getLocalHost(), builder.getServerBindAddress());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetServerBindAddressToUnknownHost() {
+ try {
+ new Builder().setServerBindAddress("badHostName.badCompany.com");
+ }
+ catch (IllegalArgumentException expected) {
+ final String expectedMessage1 = LocalizedStrings.Launcher_Builder_UNKNOWN_HOST_ERROR_MESSAGE.toLocalizedString("Server");
+ final String expectedMessage2 = "badHostName.badCompany.com is not an address for this machine.";
+ assertTrue(expected.getMessage().equals(expectedMessage1) || expected.getMessage().equals(expectedMessage2));
+ if (expected.getMessage().equals(expectedMessage1)) {
+ assertTrue(expected.getCause() instanceof UnknownHostException);
+ }
+ throw expected;
+ }
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetServerBindAddressToNonLocalHost() {
+ try {
+ new Builder().setServerBindAddress("yahoo.com");
+ }
+ catch (IllegalArgumentException expected) {
+ final String expectedMessage = "yahoo.com is not an address for this machine.";
+ assertEquals(expectedMessage, expected.getMessage());
+ throw expected;
+ }
+ }
+
+ @Test
+ public void testSetServerBindAddressToLocalHost() throws Exception {
+ String host = InetAddress.getLocalHost().getHostName();
+ new Builder().setServerBindAddress(host);
+ }
+
+ @Test
+ public void testSetAndGetHostnameForClients() {
+ final Builder builder = new Builder();
+
+ assertNull(builder.getHostNameForClients());
+ assertSame(builder, builder.setHostNameForClients("Pegasus"));
+ assertEquals("Pegasus", builder.getHostNameForClients());
+ assertSame(builder, builder.setHostNameForClients(null));
+ assertNull(builder.getHostNameForClients());
+ }
+
+ @Test
+ public void testSetAndGetServerPort() {
+ Builder builder = new Builder();
+
+ assertEquals(ServerLauncher.DEFAULT_SERVER_PORT, builder.getServerPort());
+ assertSame(builder, builder.setServerPort(0));
+ assertEquals(0, builder.getServerPort().intValue());
+ assertSame(builder, builder.setServerPort(1));
+ assertEquals(1, builder.getServerPort().intValue());
+ assertSame(builder, builder.setServerPort(80));
+ assertEquals(80, builder.getServerPort().intValue());
+ assertSame(builder, builder.setServerPort(1024));
+ assertEquals(1024, builder.getServerPort().intValue());
+ assertSame(builder, builder.setServerPort(65535));
+ assertEquals(65535, builder.getServerPort().intValue());
+ assertSame(builder, builder.setServerPort(null));
+ assertEquals(ServerLauncher.DEFAULT_SERVER_PORT, builder.getServerPort());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetServerPortToOverflow() {
+ try {
+ new Builder().setServerPort(65536);
+ }
+ catch (IllegalArgumentException expected) {
+ assertEquals(LocalizedStrings.Launcher_Builder_INVALID_PORT_ERROR_MESSAGE.toLocalizedString("Server"),
+ expected.getMessage());
+ throw expected;
+ }
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetServerPortToUnderflow() {
+ try {
+ new Builder().setServerPort(-1);
+ }
+ catch (IllegalArgumentException expected) {
+ assertEquals(LocalizedStrings.Launcher_Builder_INVALID_PORT_ERROR_MESSAGE.toLocalizedString("Server"),
+ expected.getMessage());
+ throw expected;
+ }
+ }
+
+ @Test
+ public void testSetAndGetCriticalHeapPercentage() {
+ Builder builder = new Builder();
+
+ assertNull(builder.getCriticalHeapPercentage());
+ assertSame(builder, builder.setCriticalHeapPercentage(55.5f));
+ assertEquals(55.5f, builder.getCriticalHeapPercentage().floatValue(), 0.0f);
+ assertSame(builder, builder.setCriticalHeapPercentage(null));
+ assertNull(builder.getCriticalHeapPercentage());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetCriticalHeapPercentageToOverflow() {
+ try {
+ new Builder().setCriticalHeapPercentage(100.01f);
+ }
+ catch (IllegalArgumentException expected) {
+ assertEquals("Critical heap percentage (100.01) must be between 0 and 100!", expected.getMessage());
+ throw expected;
+ }
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetCriticalHeapPercentageToUnderflow() {
+ try {
+ new Builder().setCriticalHeapPercentage(-0.01f);
+ }
+ catch (IllegalArgumentException expected) {
+ assertEquals("Critical heap percentage (-0.01) must be between 0 and 100!", expected.getMessage());
+ throw expected;
+ }
+ }
+
+ @Test
+ public void testSetAndGetEvictionHeapPercentage() {
+ Builder builder = new Builder();
+
+ assertNull(builder.getEvictionHeapPercentage());
+ assertSame(builder, builder.setEvictionHeapPercentage(55.55f));
+ assertEquals(55.55f, builder.getEvictionHeapPercentage().floatValue(), 0.0f);
+ assertSame(builder, builder.setEvictionHeapPercentage(null));
+ assertNull(builder.getEvictionHeapPercentage());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetEvictionHeapPercentageToOverflow() {
+ try {
+ new Builder().setEvictionHeapPercentage(101.0f);
+ }
+ catch (IllegalArgumentException expected) {
+ assertEquals("Eviction heap percentage (101.0) must be between 0 and 100!", expected.getMessage());
+ throw expected;
+ }
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetEvictionHeapPercentageToUnderflow() {
+ try {
+ new Builder().setEvictionHeapPercentage(-10.0f);
+ }
+ catch (IllegalArgumentException expected) {
+ assertEquals("Eviction heap percentage (-10.0) must be between 0 and 100!", expected.getMessage());
+ throw expected;
+ }
+ }
+
+ @Test
+ public void testSetAndGetMaxConnections() {
+ Builder builder = new Builder();
+
+ assertNull(builder.getMaxConnections());
+ assertSame(builder, builder.setMaxConnections(1000));
+ assertEquals(1000, builder.getMaxConnections().intValue());
+ assertSame(builder, builder.setMaxConnections(null));
+ assertNull(builder.getMaxConnections());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetMaxConnectionsWithIllegalValue() {
+ try {
+ new Builder().setMaxConnections(-10);
+ }
+ catch (IllegalArgumentException expected) {
+ assertEquals("Max Connections (-10) must be greater than 0!", expected.getMessage());
+ throw expected;
+ }
+ }
+
+ @Test
+ public void testSetAndGetMaxMessageCount() {
+ Builder builder = new Builder();
+
+ assertNull(builder.getMaxMessageCount());
+ assertSame(builder, builder.setMaxMessageCount(50));
+ assertEquals(50, builder.getMaxMessageCount().intValue());
+ assertSame(builder, builder.setMaxMessageCount(null));
+ assertNull(builder.getMaxMessageCount());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetMaxMessageCountWithIllegalValue() {
+ try {
+ new Builder().setMaxMessageCount(0);
+ }
+ catch (IllegalArgumentException expected) {
+ assertEquals("Max Message Count (0) must be greater than 0!", expected.getMessage());
+ throw expected;
+ }
+ }
+
+ @Test
+ public void testSetAndGetMaxThreads() {
+ Builder builder = new Builder();
+
+ assertNull(builder.getMaxThreads());
+ assertSame(builder, builder.setMaxThreads(16));
+ assertEquals(16, builder.getMaxThreads().intValue());
+ assertSame(builder, builder.setMaxThreads(null));
+ assertNull(builder.getMaxThreads());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetMaxThreadsWithIllegalValue() {
+ try {
+ new Builder().setMaxThreads(-4);
+ }
+ catch (IllegalArgumentException expected) {
+ assertEquals("Max Threads (-4) must be greater than 0!", expected.getMessage());
+ throw expected;
+ }
+ }
+
+ @Test
+ public void testSetAndGetMessageTimeToLive() {
+ Builder builder = new Builder();
+
+ assertNull(builder.getMessageTimeToLive());
+ assertSame(builder, builder.setMessageTimeToLive(30000));
+ assertEquals(30000, builder.getMessageTimeToLive().intValue());
+ assertSame(builder, builder.setMessageTimeToLive(null));
+ assertNull(builder.getMessageTimeToLive());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetMessageTimeToLiveWithIllegalValue() {
+ try {
+ new Builder().setMessageTimeToLive(0);
+ }
+ catch (IllegalArgumentException expected) {
+ assertEquals("Message Time To Live (0) must be greater than 0!", expected.getMessage());
+ throw expected;
+ }
+ }
+
+ @Test
+ public void testSetAndGetSocketBufferSize() {
+ Builder builder = new Builder();
+
+ assertNull(builder.getSocketBufferSize());
+ assertSame(builder, builder.setSocketBufferSize(32768));
+ assertEquals(32768, builder.getSocketBufferSize().intValue());
+ assertSame(builder, builder.setSocketBufferSize(null));
+ assertNull(builder.getSocketBufferSize());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetSocketBufferSizeWithIllegalValue() {
+ try {
+ new Builder().setSocketBufferSize(-8192);
+ }
+ catch (IllegalArgumentException expected) {
+ assertEquals("The Server's Socket Buffer Size (-8192) must be greater than 0!", expected.getMessage());
+ throw expected;
+ }
+ }
+
+ @Test
+ public void testBuildWithMemberNameSetInApiPropertiesOnStart() {
+ ServerLauncher launcher = new Builder()
+ .setCommand(ServerLauncher.Command.START)
+ .setMemberName(null)
+ .set(DistributionConfig.NAME_NAME, "serverABC")
+ .build();
+
+ assertNotNull(launcher);
+ assertEquals(ServerLauncher.Command.START, launcher.getCommand());
+ assertNull(launcher.getMemberName());
+ assertEquals("serverABC", launcher.getProperties().getProperty(DistributionConfig.NAME_NAME));
+ }
+
+ @Test
+ public void testBuildWithMemberNameSetInSystemPropertiesOnStart() {
+ System.setProperty(DistributionConfig.GEMFIRE_PREFIX + DistributionConfig.NAME_NAME, "serverXYZ");
+
+ ServerLauncher launcher = new Builder()
+ .setCommand(ServerLauncher.Command.START)
+ .setMemberName(null)
+ .build();
+
+ assertNotNull(launcher);
+ assertEquals(ServerLauncher.Command.START, launcher.getCommand());
+ assertNull(launcher.getMemberName());
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testBuildNoMemberNameOnStart() {
+ try {
+ new Builder().setCommand(Command.START).build();
+ }
+ catch (IllegalStateException expected) {
+ assertEquals(LocalizedStrings.Launcher_Builder_MEMBER_NAME_VALIDATION_ERROR_MESSAGE.toLocalizedString("Server"),
+ expected.getMessage());
+ throw expected;
+ }
+ }
+
+ @Test
+ public void testIsServing() {
+ final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+ final CacheServer mockCacheServer = mockContext.mock(CacheServer.class, "CacheServer");
+
+ mockContext.checking(new Expectations() {{
+ oneOf(mockCache).getCacheServers();
+ will(returnValue(Collections.singletonList(mockCacheServer)));
+ }});
+
+ final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").build();
+
+ assertNotNull(serverLauncher);
+ assertEquals("serverOne", serverLauncher.getMemberName());
+ assertTrue(serverLauncher.isServing(mockCache));
+ }
+
+ @Test
+ public void testIsServingWhenNoCacheServersExist() {
+ final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+
+ mockContext.checking(new Expectations() {{
+ oneOf(mockCache).getCacheServers();
+ will(returnValue(Collections.emptyList()));
+ }});
+
+ final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").build();
+
+ assertNotNull(serverLauncher);
+ assertEquals("serverOne", serverLauncher.getMemberName());
+ assertFalse(serverLauncher.isServing(mockCache));
+ }
+
+ @Test
+ public void reconnectedCacheIsDiscovered() throws Exception {
+ final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+ final Cache mockReconnectedCache = mockContext.mock(Cache.class, "ReconnectedCache");
+
+ mockContext.checking(new Expectations() {{
+ exactly(2).of(mockCache).isReconnecting();
+ will(returnValue(Boolean.FALSE));
+
+ oneOf(mockCache).getCacheServers();
+ will(returnValue(Collections.emptyList()));
+
+ oneOf(mockCache).isReconnecting();
+ will(returnValue(Boolean.TRUE));
+
+ oneOf(mockCache).getReconnectedCache();
+ will(returnValue(mockReconnectedCache));
+
+ oneOf(mockReconnectedCache).close();
+
+ }});
+
+ final ServerLauncher serverLauncher =
+ new Builder()
+ .setMemberName("serverOne")
+ .setCache(mockCache)
+ .build();
+
+ assertNotNull(serverLauncher);
+ serverLauncher.waitOnServer();
+ }
+
+ @Test
+ public void reconnectingDistributedSystemIsDisconnectedOnStop() throws Exception {
+ final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+ final DistributedSystem mockDistributedSystem = mockContext.mock(DistributedSystem.class, "DistributedSystem");
+ final Cache mockReconnectedCache = mockContext.mock(Cache.class, "ReconnectedCache");
+
+ mockContext.checking(new Expectations() {{
+ exactly(1).of(mockCache).isReconnecting();
+ will(returnValue(Boolean.TRUE));
+
+ exactly(1).of(mockCache).getReconnectedCache();
+ will(returnValue(mockReconnectedCache));
+
+ exactly(2).of(mockReconnectedCache).isReconnecting();
+ will(returnValue(Boolean.TRUE));
+
+ exactly(1).of(mockReconnectedCache).getReconnectedCache();
+ will(returnValue(null));
+
+ oneOf(mockReconnectedCache).getDistributedSystem();
+ will(returnValue(mockDistributedSystem));
+
+ oneOf(mockDistributedSystem).stopReconnecting();
+
+ oneOf(mockReconnectedCache).close();
+ }});
+
+ final ServerLauncher serverLauncher =
+ new Builder()
+ .setMemberName("serverOne")
+ .setCache(mockCache)
+ .build();
+
+ assertNotNull(serverLauncher);
+ serverLauncher.setIsRunningForTest();
+ serverLauncher.stop();
+ }
+
+ @Test
+ public void testIsWaiting() {
+ final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+ final DistributedSystem mockDistributedSystem = mockContext.mock(DistributedSystem.class, "DistributedSystem");
+
+ mockContext.checking(new Expectations() {{
+ oneOf(mockCache).getDistributedSystem();
+ will(returnValue(mockDistributedSystem));
+ oneOf(mockDistributedSystem).isConnected();
+ will(returnValue(true));
+ }});
+
+ final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").build();
+
+ assertNotNull(serverLauncher);
+ assertEquals("serverOne", serverLauncher.getMemberName());
+
+ serverLauncher.running.set(true);
+
+ assertTrue(serverLauncher.isRunning());
+ assertTrue(serverLauncher.isWaiting(mockCache));
+ }
+
+ @Test
+ public void testIsWaitingWhenNotConnected() {
+ final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+ final DistributedSystem mockDistributedSystem = mockContext.mock(DistributedSystem.class, "DistributedSystem");
+
+ mockContext.checking(new Expectations() {{
+ oneOf(mockCache).getDistributedSystem();
+ will(returnValue(mockDistributedSystem));
+ oneOf(mockDistributedSystem).isConnected();
+ will(returnValue(false));
+ oneOf(mockCache).isReconnecting();
+ will(returnValue(Boolean.FALSE));
+ }});
+
+ final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").build();
+
+ assertNotNull(serverLauncher);
+ assertEquals("serverOne", serverLauncher.getMemberName());
+
+ serverLauncher.running.set(true);
+
+ assertTrue(serverLauncher.isRunning());
+ assertFalse(serverLauncher.isWaiting(mockCache));
+ }
+
+ @Test
+ public void testIsWaitingWhenNotRunning() {
+ ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").build();
+
+ assertNotNull(serverLauncher);
+ assertEquals("serverOne", serverLauncher.getMemberName());
+
+ serverLauncher.running.set(false);
+
+ assertFalse(serverLauncher.isRunning());
+ assertFalse(serverLauncher.isWaiting(null));
+ }
+
+ @Test
+ public void testWaitOnServer() throws Throwable {
+ TestFramework.runOnce(new ServerWaitMultiThreadedTestCase());
+ }
+
+ @Test
+ public void testIsDefaultServerEnabled() {
+ final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+
+ mockContext.checking(new Expectations() {{
+ oneOf(mockCache).getCacheServers();
+ will(returnValue(Collections.emptyList()));
+ }});
+
+ ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").build();
+
+ assertNotNull(serverLauncher);
+ assertEquals("serverOne", serverLauncher.getMemberName());
+ assertFalse(serverLauncher.isDisableDefaultServer());
+ assertTrue(serverLauncher.isDefaultServerEnabled(mockCache));
+ }
+
+ @Test
+ public void testIsDefaultServerEnabledWhenCacheServersExist() {
+ final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+ final CacheServer mockCacheServer = mockContext.mock(CacheServer.class, "CacheServer");
+
+ mockContext.checking(new Expectations() {{
+ oneOf(mockCache).getCacheServers();
+ will(returnValue(Collections.singletonList(mockCacheServer)));
+ }});
+
+ final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").setDisableDefaultServer(false).build();
+
+ assertNotNull(serverLauncher);
+ assertEquals("serverOne", serverLauncher.getMemberName());
+ assertFalse(serverLauncher.isDisableDefaultServer());
+ assertFalse(serverLauncher.isDefaultServerEnabled(mockCache));
+ }
+ @Test
+ public void testIsDefaultServerEnabledWhenNoCacheServersExistAndDefaultServerDisabled() {
+ final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+
+ mockContext.checking(new Expectations() {{
+ oneOf(mockCache).getCacheServers();
+ will(returnValue(Collections.emptyList()));
+ }});
+
+ final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").setDisableDefaultServer(true).build();
+
+ assertNotNull(serverLauncher);
+ assertEquals("serverOne", serverLauncher.getMemberName());
+ assertTrue(serverLauncher.isDisableDefaultServer());
+ assertFalse(serverLauncher.isDefaultServerEnabled(mockCache));
+ }
+
+ @Test
+ public void testStartCacheServer() throws IOException {
+ final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+ final CacheServer mockCacheServer = mockContext.mock(CacheServer.class, "CacheServer");
+
+ mockContext.checking(new Expectations() {{
+ oneOf(mockCache).getCacheServers();
+ will(returnValue(Collections.emptyList()));
+ oneOf(mockCache).addCacheServer();
+ will(returnValue(mockCacheServer));
+ oneOf(mockCacheServer).setBindAddress(with(aNull(String.class)));
+ oneOf(mockCacheServer).setPort(with(equal(11235)));
+ oneOf(mockCacheServer).start();
+ }});
+
+ final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne")
+ .setServerBindAddress(null)
+ .setServerPort(11235)
+ .setDisableDefaultServer(false)
+ .build();
+
+ assertNotNull(serverLauncher);
+ assertEquals("serverOne", serverLauncher.getMemberName());
+ assertFalse(serverLauncher.isDisableDefaultServer());
+
+ serverLauncher.startCacheServer(mockCache);
+ }
+
+ @Test
+ public void testStartCacheServerWhenDefaultServerDisabled() throws IOException {
+ final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+
+ mockContext.checking(new Expectations() {{
+ oneOf(mockCache).getCacheServers();
+ will(returnValue(Collections.emptyList()));
+ }});
+
+ final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").setDisableDefaultServer(true).build();
+
+ assertNotNull(serverLauncher);
+ assertEquals("serverOne", serverLauncher.getMemberName());
+ assertTrue(serverLauncher.isDisableDefaultServer());
+
+ serverLauncher.startCacheServer(mockCache);
+ }
+
+ @Test
+ public void testStartCacheServerWithExistingCacheServer() throws IOException {
+ final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+ final CacheServer mockCacheServer = mockContext.mock(CacheServer.class, "CacheServer");
+
+ mockContext.checking(new Expectations() {{
+ oneOf(mockCache).getCacheServers();
+ will(returnValue(Collections.singletonList(mockCacheServer)));
+ }});
+
+ final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").setDisableDefaultServer(false).build();
+
+ assertNotNull(serverLauncher);
+ assertEquals("serverOne", serverLauncher.getMemberName());
+ assertFalse(serverLauncher.isDisableDefaultServer());
+
+ serverLauncher.startCacheServer(mockCache);
+ }
+
+ public static void main(final String... args) {
+ System.err.printf("Thread (%1$s) is daemon (%2$s)%n", Thread.currentThread().getName(),
+ Thread.currentThread().isDaemon());
+ new Builder(args).setCommand(Command.START).build().run();
+ }
+
+ private final class ServerWaitMultiThreadedTestCase extends MultithreadedTestCase {
+
+ private final AtomicBoolean connectionStateHolder = new AtomicBoolean(true);
+
+ private ServerLauncher serverLauncher;
+
+ @Override
+ public void initialize() {
+ super.initialize();
+
+ final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+
+ final DistributedSystem mockDistributedSystem = new DistributedSystemAdapter() {
+ @Override public boolean isConnected() {
+ return connectionStateHolder.get();
+ }
+ };
+
+ mockContext.checking(new Expectations() {{
+ allowing(mockCache).getDistributedSystem();
+ will(returnValue(mockDistributedSystem));
+ allowing(mockCache).isReconnecting();
+ will(returnValue(Boolean.FALSE));
+ allowing(mockCache).getCacheServers();
+ will(returnValue(Collections.emptyList()));
+ oneOf(mockCache).close();
+ }});
+
+ this.serverLauncher = new Builder().setMemberName("dataMember").setDisableDefaultServer(true)
+ .setCache(mockCache).build();
+
+ assertNotNull(this.serverLauncher);
+ assertEquals("dataMember", this.serverLauncher.getMemberName());
+ assertTrue(this.serverLauncher.isDisableDefaultServer());
+ assertTrue(connectionStateHolder.get());
+ }
+
+ public void thread1() {
+ assertTick(0);
+
+ Thread.currentThread().setName("GemFire Data Member 'main' Thread");
+ this.serverLauncher.running.set(true);
+
+ assertTrue(this.serverLauncher.isRunning());
+ assertFalse(this.serverLauncher.isServing(this.serverLauncher.getCache()));
+ assertTrue(this.serverLauncher.isWaiting(this.serverLauncher.getCache()));
+
+ this.serverLauncher.waitOnServer();
+
+ assertTick(1); // NOTE the tick does not advance when the other Thread terminates
+ }
+
+ public void thread2() {
+ waitForTick(1);
+
+ Thread.currentThread().setName("GemFire 'shutdown' Thread");
+
+ assertTrue(this.serverLauncher.isRunning());
+
+ this.connectionStateHolder.set(false);
+ }
+
+ @Override
+ public void finish() {
+ super.finish();
+ assertFalse(this.serverLauncher.isRunning());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cd02af01/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherWithProviderIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherWithProviderIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherWithProviderIntegrationTest.java
new file mode 100644
index 0000000..f04c7cf
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherWithProviderIntegrationTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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.distributed;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.mockito.Mockito;
+
+import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.distributed.AbstractLauncher.Status;
+import com.gemstone.gemfire.distributed.ServerLauncher.Builder;
+import com.gemstone.gemfire.distributed.internal.DistributionConfig;
+import com.gemstone.gemfire.internal.process.ProcessType;
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+
+/**
+ * Extracted from ServerLauncherLocalIntegrationTest.
+ */
+@Category(IntegrationTest.class)
+public class ServerLauncherWithProviderIntegrationTest extends AbstractServerLauncherIntegrationTestCase {
+
+ @Before
+ public final void setUpServerLauncherWithSpringTest() throws Exception {
+ disconnectFromDS();
+ System.setProperty(ProcessType.TEST_PREFIX_PROPERTY, getUniqueName()+"-");
+ }
+
+ @After
+ public final void tearDownServerLauncherWithSpringTest() throws Exception {
+ MockServerLauncherCacheProvider.setCache(null);
+ disconnectFromDS();
+
+ }
+
+ // NOTE make sure bugs like Trac #51201 never happen again!!!
+ @Test
+ public void testBootstrapGemFireServerWithProvider() throws Throwable {
+ Cache mockCache = Mockito.mock(Cache.class);
+ MockServerLauncherCacheProvider.setCache(mockCache);
+ this.launcher = new Builder()
+ .setDisableDefaultServer(true)
+ .setForce(true)
+ .setMemberName(getUniqueName())
+ .setSpringXmlLocation("spring/spring-gemfire-context.xml")
+ .set(DistributionConfig.MCAST_PORT_NAME, "0")
+ .build();
+
+ assertNotNull(this.launcher);
+
+ try {
+ assertEquals(Status.ONLINE, this.launcher.start().getStatus());
+
+ waitForServerToStart(this.launcher);
+
+ Cache cache = this.launcher.getCache();
+
+ assertEquals(mockCache, cache);
+ }
+ catch (Throwable e) {
+ this.errorCollector.addError(e);
+ }
+
+ try {
+ assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
+ assertNull(this.launcher.getCache());
+ }
+ catch (Throwable e) {
+ this.errorCollector.addError(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cd02af01/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherWithProviderJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherWithProviderJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherWithProviderJUnitTest.java
deleted file mode 100644
index 9728485..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherWithProviderJUnitTest.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * 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.distributed;
-
-import static org.junit.Assert.*;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.mockito.Mockito;
-
-import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.distributed.AbstractLauncher.Status;
-import com.gemstone.gemfire.distributed.ServerLauncher.Builder;
-import com.gemstone.gemfire.distributed.internal.DistributionConfig;
-import com.gemstone.gemfire.internal.process.ProcessType;
-import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
-
-/**
- * Extracted from ServerLauncherLocalJUnitTest.
- *
- */
-@Category(IntegrationTest.class)
-public class ServerLauncherWithProviderJUnitTest extends AbstractServerLauncherJUnitTestCase {
-
- @Before
- public final void setUpServerLauncherWithSpringTest() throws Exception {
- disconnectFromDS();
- System.setProperty(ProcessType.TEST_PREFIX_PROPERTY, getUniqueName()+"-");
- }
-
- @After
- public final void tearDownServerLauncherWithSpringTest() throws Exception {
- MockServerLauncherCacheProvider.setCache(null);
- disconnectFromDS();
-
- }
-
- // NOTE make sure bugs like Trac #51201 never happen again!!!
- @Test
- public void testBootstrapGemFireServerWithProvider() throws Throwable {
- Cache mockCache = Mockito.mock(Cache.class);
- MockServerLauncherCacheProvider.setCache(mockCache);
- this.launcher = new Builder()
- .setDisableDefaultServer(true)
- .setForce(true)
- .setMemberName(getUniqueName())
- .setSpringXmlLocation("spring/spring-gemfire-context.xml")
- .set(DistributionConfig.MCAST_PORT_NAME, "0")
- .build();
-
- assertNotNull(this.launcher);
-
- try {
- assertEquals(Status.ONLINE, this.launcher.start().getStatus());
-
- waitForServerToStart(this.launcher);
-
- Cache cache = this.launcher.getCache();
-
- assertEquals(mockCache, cache);
- }
- catch (Throwable e) {
- this.errorCollector.addError(e);
- }
-
- try {
- assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
- assertNull(this.launcher.getCache());
- }
- catch (Throwable e) {
- this.errorCollector.addError(e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cd02af01/geode-core/src/test/java/com/gemstone/gemfire/internal/process/FileProcessControllerIntegrationJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/process/FileProcessControllerIntegrationJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/process/FileProcessControllerIntegrationJUnitTest.java
index 6255af1..660716c 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/process/FileProcessControllerIntegrationJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/process/FileProcessControllerIntegrationJUnitTest.java
@@ -40,7 +40,6 @@ import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestName;
import com.gemstone.gemfire.distributed.LocatorLauncher;
-import com.gemstone.gemfire.distributed.LocatorStateJUnitTest;
import com.gemstone.gemfire.distributed.AbstractLauncher.Status;
import com.gemstone.gemfire.distributed.LocatorLauncher.Builder;
import com.gemstone.gemfire.distributed.LocatorLauncher.LocatorState;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cd02af01/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/SharedConfigurationCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/SharedConfigurationCommandsDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/SharedConfigurationCommandsDUnitTest.java
index d3e004b..84dc977 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/SharedConfigurationCommandsDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/SharedConfigurationCommandsDUnitTest.java
@@ -16,7 +16,10 @@
*/
package com.gemstone.gemfire.management.internal.cli.commands;
+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.LogWriterUtils.*;
import static com.gemstone.gemfire.test.dunit.Wait.*;
@@ -35,43 +38,45 @@ import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheFactory;
import com.gemstone.gemfire.distributed.DistributedMember;
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.internal.ClassBuilder;
import com.gemstone.gemfire.management.cli.Result;
import com.gemstone.gemfire.management.cli.Result.Status;
-import com.gemstone.gemfire.management.internal.cli.CliUtil;
+import static com.gemstone.gemfire.management.internal.cli.CliUtil.*;
import com.gemstone.gemfire.management.internal.cli.HeadlessGfsh;
-import com.gemstone.gemfire.management.internal.cli.i18n.CliStrings;
+import static 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.SharedConfigurationDUnitTest;
+import com.gemstone.gemfire.management.internal.configuration.SharedConfigurationTestUtils;
import com.gemstone.gemfire.management.internal.configuration.domain.Configuration;
-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.WaitCriterion;
import com.gemstone.gemfire.test.junit.categories.DistributedTest;
-/***
+/**
* DUnit test to test export and import of shared configuration.
*/
@Category(DistributedTest.class)
-@SuppressWarnings("unchecked")
public class SharedConfigurationCommandsDUnitTest extends CliCommandTestBase {
- private static final long serialVersionUID = 1L;
private static final int TIMEOUT = 10000;
private static final int INTERVAL = 500;
- File newDeployableJarFile = new File("DeployCommandsDUnit1.jar");
+ private File newDeployableJarFile = new File("DeployCommandsDUnit1.jar");
private transient ClassBuilder classBuilder = new ClassBuilder();
+ @Override
+ public final void postTearDownCacheTestCase() throws Exception {
+ for (int i = 0; i < 4; i++) {
+ getHost(0).getVM(i).invoke(SharedConfigurationTestUtils.cleanupLocator);
+ }
+ }
+
@Test
- public void testExportImportSharedConfiguration() {
+ public void testExportImportSharedConfiguration() throws IOException {
disconnectAllFromDS();
final String region1Name = "r1";
@@ -81,15 +86,16 @@ public class SharedConfigurationCommandsDUnitTest extends CliCommandTestBase {
final String deployedJarName = "DeployCommandsDUnit1.jar";
final String logLevel = "info";
final String startArchiveFileName = "stats.gfs";
- final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(3);
+ final int[] ports = getRandomAvailableTCPPorts(3);
// TODO Sourabh - the code below is similar to CliCommandTestBase.createDefaultSetup(..); we may want to consider
// refactoring this and combine the duplicate code blocks using either the Template Method and/or Strategy design
// patterns. We can talk about this.
// Start the Locator and wait for shared configuration to be available
+
final int locator1Port = ports[0];
final String locator1Name = "locator1-" + locator1Port;
- VM locatorAndMgr = Host.getHost(0).getVM(3);
+ VM locatorAndMgr = getHost(0).getVM(3);
Object[] result = (Object[]) locatorAndMgr.invoke(new SerializableCallable() {
@Override
public Object call() {
@@ -103,7 +109,7 @@ public class SharedConfigurationCommandsDUnitTest extends CliCommandTestBase {
jmxHost = "localhost";
}
- final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
+ final int[] ports = getRandomAvailableTCPPorts(2);
jmxPort = ports[0];
httpPort = ports[1];
@@ -111,19 +117,18 @@ public class SharedConfigurationCommandsDUnitTest extends CliCommandTestBase {
final File locatorLogFile = new File("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, "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));
+ 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));
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() {
@@ -136,15 +141,15 @@ public class SharedConfigurationCommandsDUnitTest extends CliCommandTestBase {
}
};
waitForCriterion(wc, TIMEOUT, INTERVAL, 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);
}
final Object[] result = new Object[4];
result[0] = jmxHost;
result[1] = jmxPort;
result[2] = httpPort;
- result[3] = CliUtil.getAllNormalMembers(CacheFactory.getAnyInstance());
+ result[3] = getAllNormalMembers(CacheFactory.getAnyInstance());
return result;
}
@@ -154,63 +159,60 @@ public class SharedConfigurationCommandsDUnitTest extends CliCommandTestBase {
String jmxHost = (String) result[0];
int jmxPort = (Integer) result[1];
int httpPort = (Integer) result[2];
- Set<DistributedMember> normalMembers1 = (Set<DistributedMember>) result[3];
+ Set<DistributedMember> normalMembers1 = (Set<DistributedMember>) result[3]; // TODO: never used
shellConnect(jmxHost, jmxPort, httpPort, gfsh);
// Create a cache in VM 1
- VM dataMember = Host.getHost(0).getVM(1);
+ VM dataMember = getHost(0).getVM(1);
normalMembers1 = (Set<DistributedMember>) dataMember.invoke(new SerializableCallable() {
@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, groupName);
- localProps.setProperty(DistributionConfig.NAME_NAME, "DataMember");
+ localProps.setProperty(MCAST_PORT_NAME, "0");
+ localProps.setProperty(LOCATORS_NAME, "localhost:" + locator1Port);
+ localProps.setProperty(GROUPS_NAME, groupName);
+ localProps.setProperty(NAME_NAME, "DataMember");
getSystem(localProps);
Cache cache = getCache();
assertNotNull(cache);
- return CliUtil.getAllNormalMembers(cache);
+ return getAllNormalMembers(cache);
}
});
+
// Create a JAR file
- try {
- this.classBuilder.writeJarFromName("DeployCommandsDUnitA", this.newDeployableJarFile);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ this.classBuilder.writeJarFromName("DeployCommandsDUnitA", this.newDeployableJarFile);
// Deploy the JAR
CommandResult cmdResult = executeCommand("deploy --jar=" + deployedJarName);
assertEquals(Result.Status.OK, cmdResult.getStatus());
+
//Create the region1 on the group
- CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_REGION);
- commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGION, region1Name);
- commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, "REPLICATE");
- commandStringBuilder.addOption(CliStrings.CREATE_REGION__STATISTICSENABLED, "true");
- commandStringBuilder.addOption(CliStrings.CREATE_REGION__GROUP, groupName);
+ CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CREATE_REGION);
+ commandStringBuilder.addOption(CREATE_REGION__REGION, region1Name);
+ commandStringBuilder.addOption(CREATE_REGION__REGIONSHORTCUT, "REPLICATE");
+ commandStringBuilder.addOption(CREATE_REGION__STATISTICSENABLED, "true");
+ commandStringBuilder.addOption(CREATE_REGION__GROUP, groupName);
cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
- commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_REGION);
- commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGION, region2Name);
- commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, "PARTITION");
- commandStringBuilder.addOption(CliStrings.CREATE_REGION__STATISTICSENABLED, "true");
+ commandStringBuilder = new CommandStringBuilder(CREATE_REGION);
+ commandStringBuilder.addOption(CREATE_REGION__REGION, region2Name);
+ commandStringBuilder.addOption(CREATE_REGION__REGIONSHORTCUT, "PARTITION");
+ commandStringBuilder.addOption(CREATE_REGION__STATISTICSENABLED, "true");
cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
- //Alter runtime configuration
- commandStringBuilder = new CommandStringBuilder(CliStrings.ALTER_RUNTIME_CONFIG);
- commandStringBuilder.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__LEVEL, logLevel);
- commandStringBuilder.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__FILE__SIZE__LIMIT, "50");
- commandStringBuilder.addOption(CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__DISK__SPACE__LIMIT, "32");
- commandStringBuilder.addOption(CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__FILE__SIZE__LIMIT, "49");
- commandStringBuilder.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLE__RATE, "120");
- commandStringBuilder.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE, startArchiveFileName);
- commandStringBuilder.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLING__ENABLED, "true");
- commandStringBuilder.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT, "10");
+ //Alter runtime configuration
+ commandStringBuilder = new CommandStringBuilder(ALTER_RUNTIME_CONFIG);
+ commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__LOG__LEVEL, logLevel);
+ commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__LOG__FILE__SIZE__LIMIT, "50");
+ commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__ARCHIVE__DISK__SPACE__LIMIT, "32");
+ commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__ARCHIVE__FILE__SIZE__LIMIT, "49");
+ commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLE__RATE, "120");
+ commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE, startArchiveFileName);
+ commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLING__ENABLED, "true");
+ commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT, "10");
cmdResult = executeCommand(commandStringBuilder.getCommandString());
String resultString = commandResultToString(cmdResult);
@@ -218,15 +220,15 @@ public class SharedConfigurationCommandsDUnitTest extends CliCommandTestBase {
getLogWriter().info(resultString);
assertEquals(true, cmdResult.getStatus().equals(Status.OK));
- commandStringBuilder = new CommandStringBuilder(CliStrings.STATUS_SHARED_CONFIG);
+ commandStringBuilder = new CommandStringBuilder(STATUS_SHARED_CONFIG);
cmdResult = executeCommand(commandStringBuilder.getCommandString());
resultString = commandResultToString(cmdResult);
getLogWriter().info("#SB Result\n");
getLogWriter().info(resultString);
assertEquals(Status.OK, cmdResult.getStatus());
- commandStringBuilder = new CommandStringBuilder(CliStrings.EXPORT_SHARED_CONFIG);
- commandStringBuilder.addOption(CliStrings.EXPORT_SHARED_CONFIG__FILE, sharedConfigZipFileName);
+ commandStringBuilder = new CommandStringBuilder(EXPORT_SHARED_CONFIG);
+ commandStringBuilder.addOption(EXPORT_SHARED_CONFIG__FILE, sharedConfigZipFileName);
cmdResult = executeCommand(commandStringBuilder.getCommandString());
resultString = commandResultToString(cmdResult);
getLogWriter().info("#SB Result\n");
@@ -234,8 +236,8 @@ public class SharedConfigurationCommandsDUnitTest extends CliCommandTestBase {
assertEquals(Status.OK, cmdResult.getStatus());
//Import into a running system should fail
- commandStringBuilder = new CommandStringBuilder(CliStrings.IMPORT_SHARED_CONFIG);
- commandStringBuilder.addOption(CliStrings.IMPORT_SHARED_CONFIG__ZIP, sharedConfigZipFileName);
+ commandStringBuilder = new CommandStringBuilder(IMPORT_SHARED_CONFIG);
+ commandStringBuilder.addOption(IMPORT_SHARED_CONFIG__ZIP, sharedConfigZipFileName);
cmdResult = executeCommand(commandStringBuilder.getCommandString());
assertEquals(Status.ERROR, cmdResult.getStatus());
@@ -263,15 +265,15 @@ public class SharedConfigurationCommandsDUnitTest extends CliCommandTestBase {
}
});
- //Now execute import shared configuration
+ //Now execute import shared configuration
//Now import the shared configuration and it should succeed.
- commandStringBuilder = new CommandStringBuilder(CliStrings.IMPORT_SHARED_CONFIG);
- commandStringBuilder.addOption(CliStrings.IMPORT_SHARED_CONFIG__ZIP, sharedConfigZipFileName);
+ commandStringBuilder = new CommandStringBuilder(IMPORT_SHARED_CONFIG);
+ commandStringBuilder.addOption(IMPORT_SHARED_CONFIG__ZIP, sharedConfigZipFileName);
cmdResult = executeCommand(commandStringBuilder.getCommandString());
assertEquals(Status.OK, cmdResult.getStatus());
//Start a new locator , test if it has all the imported shared configuration artifacts
- VM newLocator = Host.getHost(0).getVM(2);
+ VM newLocator = getHost(0).getVM(2);
final int locator2Port = ports[1];
final String locator2Name = "Locator2-" + locator2Port;
@@ -280,22 +282,20 @@ public class SharedConfigurationCommandsDUnitTest extends CliCommandTestBase {
public void run() {
final File locatorLogFile = new File("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.ENABLE_CLUSTER_CONFIGURATION_NAME, "true");
- locatorProps.setProperty(DistributionConfig.LOCATORS_NAME, "localhost:" + locator1Port);
+ locatorProps.setProperty(NAME_NAME, locator2Name);
+ locatorProps.setProperty(MCAST_PORT_NAME, "0");
+ locatorProps.setProperty(LOG_LEVEL_NAME, "fine");
+ 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";
@@ -313,29 +313,20 @@ public class SharedConfigurationCommandsDUnitTest extends CliCommandTestBase {
assertNotNull(clusterConfig);
assertTrue(clusterConfig.getCacheXmlContent().contains(region2Name));
assertTrue(clusterConfig.getJarNames().contains(deployedJarName));
- assertTrue(
- clusterConfig.getGemfireProperties().getProperty(DistributionConfig.LOG_LEVEL_NAME).equals(logLevel));
- assertTrue(
- clusterConfig.getGemfireProperties().getProperty(DistributionConfig.STATISTIC_ARCHIVE_FILE_NAME).equals(
- startArchiveFileName));
- } catch (IOException ioex) {
- fail("Unable to create a locator with a shared configuration");
+ assertTrue(clusterConfig.getGemfireProperties().getProperty(LOG_LEVEL_NAME).equals(logLevel));
+ assertTrue(clusterConfig.getGemfireProperties().getProperty(STATISTIC_ARCHIVE_FILE_NAME).equals(startArchiveFileName));
+
+ } catch (IOException e) {
+ fail("Unable to create a locator with a shared configuration", e);
} catch (Exception e) {
fail("Error occurred in cluster configuration service", e);
}
}
});
- //Clean up
+ //Clean up -- TODO: move to tearDown
File sharedConfigZipFile = new File(sharedConfigZipFileName);
FileUtils.deleteQuietly(sharedConfigZipFile);
FileUtils.deleteQuietly(newDeployableJarFile);
}
-
- @Override
- public final void postTearDownCacheTestCase() throws Exception {
- for (int i = 0; i < 4; i++) {
- Host.getHost(0).getVM(i).invoke(SharedConfigurationDUnitTest.locatorCleanup);
- }
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cd02af01/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..0ef3c3f 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,6 +16,12 @@
*/
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;
@@ -27,112 +33,95 @@ 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 {
+@Category(DistributedTest.class)
+public class SharedConfigurationDUnitTest extends JUnit4CacheTestCase {
+
private static final long serialVersionUID = 1L;
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);
}
-
- public void testGetHostedLocatorsWithSharedConfiguration() {
- disconnectAllFromDS();
- final VM locator1Vm = Host.getHost(0).getVM(1);
- final VM locator2Vm = Host.getHost(0).getVM(2);
+
+ @Test
+ public void testGetHostedLocatorsWithSharedConfiguration() throws Exception {
+ final VM locator1Vm = getHost(0).getVM(1);
+ final VM locator2Vm = getHost(0).getVM(2);
final String testName = "testGetHostedLocatorsWithSharedConfiguration";
-// final VM locator3Vm = Host.getHost(0).getVM(3);
-
- final int []ports = AvailablePortHelper.getRandomAvailableTCPPorts(3);
+
+ 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");
- try {
- final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator1Port, locatorLogFile, null,
- locatorProps);
+ 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);
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();
@@ -147,7 +136,6 @@ public class SharedConfigurationDUnitTest extends CacheTestCase {
}
});
- //final int locator2Port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
final int locator2Port = ports[1];
final String locator2Name = "locator2" + locator2Port;
@@ -156,13 +144,12 @@ public class SharedConfigurationDUnitTest extends CacheTestCase {
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();
@@ -193,7 +180,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,32 +203,20 @@ 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 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() {
@@ -249,10 +224,10 @@ public class SharedConfigurationDUnitTest extends CacheTestCase {
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);
@@ -267,9 +242,9 @@ public class SharedConfigurationDUnitTest extends CacheTestCase {
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,9 +255,9 @@ 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);
@@ -305,7 +280,7 @@ 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");
@@ -313,7 +288,7 @@ public class SharedConfigurationDUnitTest extends CacheTestCase {
//assertTrue(scw.modifyProperties(clusterProperties, null));
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
@@ -338,11 +313,11 @@ public class SharedConfigurationDUnitTest extends CacheTestCase {
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);
@@ -358,7 +333,7 @@ public class SharedConfigurationDUnitTest extends CacheTestCase {
return "Waiting for shared configuration to be started";
}
};
- Wait.waitForCriterion(wc, TIMEOUT, INTERVAL, true);
+ waitForCriterion(wc, TIMEOUT, INTERVAL, true);
} catch (IOException ioex) {
fail("Unable to create a locator with a shared configuration");
}
@@ -370,14 +345,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));
@@ -412,13 +387,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 +407,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