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:41 UTC
[06/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/ServerLauncherIntegrationJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherIntegrationJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherIntegrationJUnitTest.java
deleted file mode 100755
index b61f89d..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherIntegrationJUnitTest.java
+++ /dev/null
@@ -1,312 +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 com.googlecode.catchexception.apis.BDDCatchException.caughtException;
-import static com.googlecode.catchexception.apis.BDDCatchException.when;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.BDDAssertions.*;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileWriter;
-import java.net.InetAddress;
-import java.util.Properties;
-
-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.TemporaryFolder;
-import org.junit.rules.TestName;
-
-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.internal.i18n.LocalizedStrings;
-import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
-
-/**
- * Integration tests for ServerLauncher class. These tests may require file system and/or network I/O.
- */
-@Category(IntegrationTest.class)
-public class ServerLauncherIntegrationJUnitTest {
-
- @Rule
- public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
-
- @Rule
- public final TemporaryFolder temporaryFolder = new TemporaryFolder();
-
- @Rule
- public final TestName testName = new TestName();
-
- @Test
- public void testBuildWithManyArguments() throws Exception {
- // given
- String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
-
- // when
- ServerLauncher launcher = new Builder()
- .setCommand(Command.STOP)
- .setAssignBuckets(true)
- .setForce(true)
- .setMemberName("serverOne")
- .setRebalance(true)
- .setServerBindAddress(InetAddress.getLocalHost().getHostAddress())
- .setServerPort(11235)
- .setWorkingDirectory(rootFolder)
- .setCriticalHeapPercentage(90.0f)
- .setEvictionHeapPercentage(75.0f)
- .setMaxConnections(100)
- .setMaxMessageCount(512)
- .setMaxThreads(8)
- .setMessageTimeToLive(120000)
- .setSocketBufferSize(32768)
- .build();
-
- // then
- assertThat(launcher).isNotNull();
- assertThat(launcher.isAssignBuckets()).isTrue();
- assertThat(launcher.isDebugging()).isFalse();
- assertThat(launcher.isDisableDefaultServer()).isFalse();
- assertThat(launcher.isForcing()).isTrue();
- assertThat(launcher.isHelping()).isFalse();
- assertThat(launcher.isRebalancing()).isTrue();
- assertThat(launcher.isRunning()).isFalse();
- assertThat(launcher.getCommand()).isEqualTo(Command.STOP);
- assertThat(launcher.getMemberName()).isEqualTo("serverOne");
- assertThat(launcher.getServerBindAddress()).isEqualTo(InetAddress.getLocalHost());
- assertThat(launcher.getServerPort().intValue()).isEqualTo(11235);
- assertThat(launcher.getWorkingDirectory()).isEqualTo(rootFolder);
- assertThat(launcher.getCriticalHeapPercentage().floatValue()).isEqualTo(90.0f);
- assertThat(launcher.getEvictionHeapPercentage().floatValue()).isEqualTo(75.0f);
- assertThat(launcher.getMaxConnections().intValue()).isEqualTo(100);
- assertThat(launcher.getMaxMessageCount().intValue()).isEqualTo(512);
- assertThat(launcher.getMaxThreads().intValue()).isEqualTo(8);
- assertThat(launcher.getMessageTimeToLive().intValue()).isEqualTo(120000);
- assertThat(launcher.getSocketBufferSize().intValue()).isEqualTo(32768);
- }
-
- @Test
- public void testBuilderParseArgumentsWithValuesSeparatedWithCommas() throws Exception {
- // given a new builder and a directory
- String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
- Builder builder = new Builder();
-
- // when: parsing many arguments
- builder.parseArguments(
- "start",
- "serverOne",
- "--assign-buckets",
- "--disable-default-server",
- "--debug",
- "--force",
- "--rebalance",
- "--redirect-output",
- "--dir", rootFolder,
- "--pid", "1234",
- "--server-bind-address", InetAddress.getLocalHost().getHostAddress(),
- "--server-port", "11235",
- "--hostname-for-clients", "192.168.99.100");
-
- // then: the getters should return properly parsed values
- assertThat(builder.getCommand()).isEqualTo(Command.START);
- assertThat(builder.getMemberName()).isEqualTo("serverOne");
- assertThat(builder.getHostNameForClients()).isEqualTo("192.168.99.100");
- assertThat(builder.getAssignBuckets()).isTrue();
- assertThat(builder.getDisableDefaultServer()).isTrue();
- assertThat(builder.getDebug()).isTrue();
- assertThat(builder.getForce()).isTrue();
- assertThat(builder.getHelp()).isFalse();
- assertThat(builder.getRebalance()).isTrue();
- assertThat(builder.getRedirectOutput()).isTrue();
- assertThat(builder.getWorkingDirectory()).isEqualTo(rootFolder);
- assertThat(builder.getPid().intValue()).isEqualTo(1234);
- assertThat(builder.getServerBindAddress()).isEqualTo(InetAddress.getLocalHost());
- assertThat(builder.getServerPort().intValue()).isEqualTo(11235);
- }
-
- @Test
- public void testBuilderParseArgumentsWithValuesSeparatedWithEquals() throws Exception {
- // given a new builder and a directory
- String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
- Builder builder = new Builder();
-
- // when: parsing many arguments
- builder.parseArguments(
- "start",
- "serverOne",
- "--assign-buckets",
- "--disable-default-server",
- "--debug",
- "--force",
- "--rebalance",
- "--redirect-output",
- "--dir=" + rootFolder,
- "--pid=1234",
- "--server-bind-address=" + InetAddress.getLocalHost().getHostAddress(),
- "--server-port=11235",
- "--hostname-for-clients=192.168.99.100");
-
- // then: the getters should return properly parsed values
- assertThat(builder.getCommand()).isEqualTo(Command.START);
- assertThat(builder.getMemberName()).isEqualTo("serverOne");
- assertThat(builder.getHostNameForClients()).isEqualTo("192.168.99.100");
- assertThat(builder.getAssignBuckets()).isTrue();
- assertThat(builder.getDisableDefaultServer()).isTrue();
- assertThat(builder.getDebug()).isTrue();
- assertThat(builder.getForce()).isTrue();
- assertThat(builder.getHelp()).isFalse();
- assertThat(builder.getRebalance()).isTrue();
- assertThat(builder.getRedirectOutput()).isTrue();
- assertThat(builder.getWorkingDirectory()).isEqualTo(rootFolder);
- assertThat(builder.getPid().intValue()).isEqualTo(1234);
- assertThat(builder.getServerBindAddress()).isEqualTo(InetAddress.getLocalHost());
- assertThat(builder.getServerPort().intValue()).isEqualTo(11235);
- }
-
- @Test
- public void testBuildWithMemberNameSetInGemFirePropertiesOnStart() throws Exception {
- // given: gemfire.properties with a name
- Properties gemfireProperties = new Properties();
- gemfireProperties.setProperty(DistributionConfig.NAME_NAME, "server123");
- useGemFirePropertiesFileInTemporaryFolder("gemfire.properties", gemfireProperties);
-
- // when: starting with null MemberName
- ServerLauncher launcher = new Builder()
- .setCommand(Command.START)
- .setMemberName(null)
- .build();
-
- // then: name in gemfire.properties file should be used for MemberName
- assertThat(launcher).isNotNull();
- assertThat(launcher.getCommand()).isEqualTo(Command.START);
- assertThat(launcher.getMemberName()).isNull();
- }
-
- @Test
- public void testBuildWithNoMemberNameOnStart() throws Exception {
- // given: gemfire.properties with no name
- useGemFirePropertiesFileInTemporaryFolder("gemfire.properties", new Properties());
-
- // when: no MemberName is specified
- when(new Builder()
- .setCommand(Command.START))
- .build();
-
- // then: throw IllegalStateException
- then(caughtException())
- .isExactlyInstanceOf(IllegalStateException.class)
- .hasMessage(LocalizedStrings.Launcher_Builder_MEMBER_NAME_VALIDATION_ERROR_MESSAGE.toLocalizedString("Server"));
- }
-
- @Test
- public void testBuilderSetAndGetWorkingDirectory() throws Exception {
- // given: a new builder and a directory
- String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
- Builder builder = new Builder();
-
- // when: not setting WorkingDirectory
- // then: getWorkingDirectory returns default
- assertThat(builder.getWorkingDirectory()).isEqualTo(ServerLauncher.DEFAULT_WORKING_DIRECTORY);
-
- // when: setting WorkingDirectory to null
- assertThat(builder.setWorkingDirectory(null)).isSameAs(builder);
- // then: getWorkingDirectory returns default
- assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY);
-
- // when: setting WorkingDirectory to empty string
- assertThat(builder.setWorkingDirectory("")).isSameAs(builder);
- // then: getWorkingDirectory returns default
- assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY);
-
- // when: setting WorkingDirectory to white space
- assertThat(builder.setWorkingDirectory(" ")).isSameAs(builder);
- // then: getWorkingDirectory returns default
- assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY);
-
- // when: setting WorkingDirectory to a directory
- assertThat(builder.setWorkingDirectory(rootFolder)).isSameAs(builder);
- // then: getWorkingDirectory returns that directory
- assertThat(builder.getWorkingDirectory()).isEqualTo(rootFolder);
-
- // when: setting WorkingDirectory to null (again)
- assertThat(builder.setWorkingDirectory(null)).isSameAs(builder);
- // then: getWorkingDirectory returns default
- assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY);
- }
-
- @Test
- public void testBuilderSetWorkingDirectoryToFile() throws Exception {
- // given: a file instead of a directory
- File tmpFile = this.temporaryFolder.newFile();
-
- // when: setting WorkingDirectory to that file
- when(new Builder())
- .setWorkingDirectory(tmpFile.getAbsolutePath());
-
- // then: throw IllegalArgumentException
- then(caughtException())
- .hasMessage(LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_NOT_FOUND_ERROR_MESSAGE.toLocalizedString("Server"))
- .hasCause(new FileNotFoundException(tmpFile.getAbsolutePath()));
- }
-
- @Test
- public void testBuildSetWorkingDirectoryToNonCurrentDirectoryOnStart() throws Exception {
- // given: using ServerLauncher in-process
-
- // when: setting WorkingDirectory to non-current directory
- when(new Builder()
- .setCommand(Command.START)
- .setMemberName("serverOne")
- .setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath()))
- .build();
-
- // then: throw IllegalStateException
- then(caughtException())
- .isExactlyInstanceOf(IllegalStateException.class)
- .hasMessage(LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_OPTION_NOT_VALID_ERROR_MESSAGE.toLocalizedString("Server"));
- }
-
- @Test
- public void testBuilderSetWorkingDirectoryToNonExistingDirectory() {
- // when: setting WorkingDirectory to non-existing directory
- when(new Builder())
- .setWorkingDirectory("/path/to/non_existing/directory");
-
- // then: throw IllegalArgumentException
- then(caughtException())
- .hasMessage(LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_NOT_FOUND_ERROR_MESSAGE.toLocalizedString("Server"))
- .hasCause(new FileNotFoundException("/path/to/non_existing/directory"));
- }
-
- /**
- * Creates a gemfire properties file in temporaryFolder:
- * <li>creates <code>fileName</code> in <code>temporaryFolder</code>
- * <li>sets "gemfirePropertyFile" system property
- * <li>writes <code>gemfireProperties</code> to the file
- */
- private void useGemFirePropertiesFileInTemporaryFolder(final String fileName, final Properties gemfireProperties) throws Exception {
- File propertiesFile = new File(this.temporaryFolder.getRoot().getCanonicalPath(), fileName);
- System.setProperty(DistributedSystem.PROPERTIES_FILE_PROPERTY, propertiesFile.getCanonicalPath());
-
- gemfireProperties.store(new FileWriter(propertiesFile, false), this.testName.getMethodName());
- assertThat(propertiesFile.isFile()).isTrue();
- assertThat(propertiesFile.exists()).isTrue();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cd02af01/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherIntegrationTest.java
new file mode 100755
index 0000000..98c8ce6
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherIntegrationTest.java
@@ -0,0 +1,312 @@
+/*
+ * 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 com.googlecode.catchexception.apis.BDDCatchException.caughtException;
+import static com.googlecode.catchexception.apis.BDDCatchException.when;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.BDDAssertions.*;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.net.InetAddress;
+import java.util.Properties;
+
+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.TemporaryFolder;
+import org.junit.rules.TestName;
+
+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.internal.i18n.LocalizedStrings;
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+
+/**
+ * Integration tests for ServerLauncher class. These tests may require file system and/or network I/O.
+ */
+@Category(IntegrationTest.class)
+public class ServerLauncherIntegrationTest {
+
+ @Rule
+ public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+
+ @Rule
+ public final TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+ @Rule
+ public final TestName testName = new TestName();
+
+ @Test
+ public void testBuildWithManyArguments() throws Exception {
+ // given
+ String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+
+ // when
+ ServerLauncher launcher = new Builder()
+ .setCommand(Command.STOP)
+ .setAssignBuckets(true)
+ .setForce(true)
+ .setMemberName("serverOne")
+ .setRebalance(true)
+ .setServerBindAddress(InetAddress.getLocalHost().getHostAddress())
+ .setServerPort(11235)
+ .setWorkingDirectory(rootFolder)
+ .setCriticalHeapPercentage(90.0f)
+ .setEvictionHeapPercentage(75.0f)
+ .setMaxConnections(100)
+ .setMaxMessageCount(512)
+ .setMaxThreads(8)
+ .setMessageTimeToLive(120000)
+ .setSocketBufferSize(32768)
+ .build();
+
+ // then
+ assertThat(launcher).isNotNull();
+ assertThat(launcher.isAssignBuckets()).isTrue();
+ assertThat(launcher.isDebugging()).isFalse();
+ assertThat(launcher.isDisableDefaultServer()).isFalse();
+ assertThat(launcher.isForcing()).isTrue();
+ assertThat(launcher.isHelping()).isFalse();
+ assertThat(launcher.isRebalancing()).isTrue();
+ assertThat(launcher.isRunning()).isFalse();
+ assertThat(launcher.getCommand()).isEqualTo(Command.STOP);
+ assertThat(launcher.getMemberName()).isEqualTo("serverOne");
+ assertThat(launcher.getServerBindAddress()).isEqualTo(InetAddress.getLocalHost());
+ assertThat(launcher.getServerPort().intValue()).isEqualTo(11235);
+ assertThat(launcher.getWorkingDirectory()).isEqualTo(rootFolder);
+ assertThat(launcher.getCriticalHeapPercentage().floatValue()).isEqualTo(90.0f);
+ assertThat(launcher.getEvictionHeapPercentage().floatValue()).isEqualTo(75.0f);
+ assertThat(launcher.getMaxConnections().intValue()).isEqualTo(100);
+ assertThat(launcher.getMaxMessageCount().intValue()).isEqualTo(512);
+ assertThat(launcher.getMaxThreads().intValue()).isEqualTo(8);
+ assertThat(launcher.getMessageTimeToLive().intValue()).isEqualTo(120000);
+ assertThat(launcher.getSocketBufferSize().intValue()).isEqualTo(32768);
+ }
+
+ @Test
+ public void testBuilderParseArgumentsWithValuesSeparatedWithCommas() throws Exception {
+ // given a new builder and a directory
+ String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+ Builder builder = new Builder();
+
+ // when: parsing many arguments
+ builder.parseArguments(
+ "start",
+ "serverOne",
+ "--assign-buckets",
+ "--disable-default-server",
+ "--debug",
+ "--force",
+ "--rebalance",
+ "--redirect-output",
+ "--dir", rootFolder,
+ "--pid", "1234",
+ "--server-bind-address", InetAddress.getLocalHost().getHostAddress(),
+ "--server-port", "11235",
+ "--hostname-for-clients", "192.168.99.100");
+
+ // then: the getters should return properly parsed values
+ assertThat(builder.getCommand()).isEqualTo(Command.START);
+ assertThat(builder.getMemberName()).isEqualTo("serverOne");
+ assertThat(builder.getHostNameForClients()).isEqualTo("192.168.99.100");
+ assertThat(builder.getAssignBuckets()).isTrue();
+ assertThat(builder.getDisableDefaultServer()).isTrue();
+ assertThat(builder.getDebug()).isTrue();
+ assertThat(builder.getForce()).isTrue();
+ assertThat(builder.getHelp()).isFalse();
+ assertThat(builder.getRebalance()).isTrue();
+ assertThat(builder.getRedirectOutput()).isTrue();
+ assertThat(builder.getWorkingDirectory()).isEqualTo(rootFolder);
+ assertThat(builder.getPid().intValue()).isEqualTo(1234);
+ assertThat(builder.getServerBindAddress()).isEqualTo(InetAddress.getLocalHost());
+ assertThat(builder.getServerPort().intValue()).isEqualTo(11235);
+ }
+
+ @Test
+ public void testBuilderParseArgumentsWithValuesSeparatedWithEquals() throws Exception {
+ // given a new builder and a directory
+ String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+ Builder builder = new Builder();
+
+ // when: parsing many arguments
+ builder.parseArguments(
+ "start",
+ "serverOne",
+ "--assign-buckets",
+ "--disable-default-server",
+ "--debug",
+ "--force",
+ "--rebalance",
+ "--redirect-output",
+ "--dir=" + rootFolder,
+ "--pid=1234",
+ "--server-bind-address=" + InetAddress.getLocalHost().getHostAddress(),
+ "--server-port=11235",
+ "--hostname-for-clients=192.168.99.100");
+
+ // then: the getters should return properly parsed values
+ assertThat(builder.getCommand()).isEqualTo(Command.START);
+ assertThat(builder.getMemberName()).isEqualTo("serverOne");
+ assertThat(builder.getHostNameForClients()).isEqualTo("192.168.99.100");
+ assertThat(builder.getAssignBuckets()).isTrue();
+ assertThat(builder.getDisableDefaultServer()).isTrue();
+ assertThat(builder.getDebug()).isTrue();
+ assertThat(builder.getForce()).isTrue();
+ assertThat(builder.getHelp()).isFalse();
+ assertThat(builder.getRebalance()).isTrue();
+ assertThat(builder.getRedirectOutput()).isTrue();
+ assertThat(builder.getWorkingDirectory()).isEqualTo(rootFolder);
+ assertThat(builder.getPid().intValue()).isEqualTo(1234);
+ assertThat(builder.getServerBindAddress()).isEqualTo(InetAddress.getLocalHost());
+ assertThat(builder.getServerPort().intValue()).isEqualTo(11235);
+ }
+
+ @Test
+ public void testBuildWithMemberNameSetInGemFirePropertiesOnStart() throws Exception {
+ // given: gemfire.properties with a name
+ Properties gemfireProperties = new Properties();
+ gemfireProperties.setProperty(DistributionConfig.NAME_NAME, "server123");
+ useGemFirePropertiesFileInTemporaryFolder("gemfire.properties", gemfireProperties);
+
+ // when: starting with null MemberName
+ ServerLauncher launcher = new Builder()
+ .setCommand(Command.START)
+ .setMemberName(null)
+ .build();
+
+ // then: name in gemfire.properties file should be used for MemberName
+ assertThat(launcher).isNotNull();
+ assertThat(launcher.getCommand()).isEqualTo(Command.START);
+ assertThat(launcher.getMemberName()).isNull();
+ }
+
+ @Test
+ public void testBuildWithNoMemberNameOnStart() throws Exception {
+ // given: gemfire.properties with no name
+ useGemFirePropertiesFileInTemporaryFolder("gemfire.properties", new Properties());
+
+ // when: no MemberName is specified
+ when(new Builder()
+ .setCommand(Command.START))
+ .build();
+
+ // then: throw IllegalStateException
+ then(caughtException())
+ .isExactlyInstanceOf(IllegalStateException.class)
+ .hasMessage(LocalizedStrings.Launcher_Builder_MEMBER_NAME_VALIDATION_ERROR_MESSAGE.toLocalizedString("Server"));
+ }
+
+ @Test
+ public void testBuilderSetAndGetWorkingDirectory() throws Exception {
+ // given: a new builder and a directory
+ String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+ Builder builder = new Builder();
+
+ // when: not setting WorkingDirectory
+ // then: getWorkingDirectory returns default
+ assertThat(builder.getWorkingDirectory()).isEqualTo(ServerLauncher.DEFAULT_WORKING_DIRECTORY);
+
+ // when: setting WorkingDirectory to null
+ assertThat(builder.setWorkingDirectory(null)).isSameAs(builder);
+ // then: getWorkingDirectory returns default
+ assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY);
+
+ // when: setting WorkingDirectory to empty string
+ assertThat(builder.setWorkingDirectory("")).isSameAs(builder);
+ // then: getWorkingDirectory returns default
+ assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY);
+
+ // when: setting WorkingDirectory to white space
+ assertThat(builder.setWorkingDirectory(" ")).isSameAs(builder);
+ // then: getWorkingDirectory returns default
+ assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY);
+
+ // when: setting WorkingDirectory to a directory
+ assertThat(builder.setWorkingDirectory(rootFolder)).isSameAs(builder);
+ // then: getWorkingDirectory returns that directory
+ assertThat(builder.getWorkingDirectory()).isEqualTo(rootFolder);
+
+ // when: setting WorkingDirectory to null (again)
+ assertThat(builder.setWorkingDirectory(null)).isSameAs(builder);
+ // then: getWorkingDirectory returns default
+ assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY);
+ }
+
+ @Test
+ public void testBuilderSetWorkingDirectoryToFile() throws Exception {
+ // given: a file instead of a directory
+ File tmpFile = this.temporaryFolder.newFile();
+
+ // when: setting WorkingDirectory to that file
+ when(new Builder())
+ .setWorkingDirectory(tmpFile.getAbsolutePath());
+
+ // then: throw IllegalArgumentException
+ then(caughtException())
+ .hasMessage(LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_NOT_FOUND_ERROR_MESSAGE.toLocalizedString("Server"))
+ .hasCause(new FileNotFoundException(tmpFile.getAbsolutePath()));
+ }
+
+ @Test
+ public void testBuildSetWorkingDirectoryToNonCurrentDirectoryOnStart() throws Exception {
+ // given: using ServerLauncher in-process
+
+ // when: setting WorkingDirectory to non-current directory
+ when(new Builder()
+ .setCommand(Command.START)
+ .setMemberName("serverOne")
+ .setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath()))
+ .build();
+
+ // then: throw IllegalStateException
+ then(caughtException())
+ .isExactlyInstanceOf(IllegalStateException.class)
+ .hasMessage(LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_OPTION_NOT_VALID_ERROR_MESSAGE.toLocalizedString("Server"));
+ }
+
+ @Test
+ public void testBuilderSetWorkingDirectoryToNonExistingDirectory() {
+ // when: setting WorkingDirectory to non-existing directory
+ when(new Builder())
+ .setWorkingDirectory("/path/to/non_existing/directory");
+
+ // then: throw IllegalArgumentException
+ then(caughtException())
+ .hasMessage(LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_NOT_FOUND_ERROR_MESSAGE.toLocalizedString("Server"))
+ .hasCause(new FileNotFoundException("/path/to/non_existing/directory"));
+ }
+
+ /**
+ * Creates a gemfire properties file in temporaryFolder:
+ * <li>creates <code>fileName</code> in <code>temporaryFolder</code>
+ * <li>sets "gemfirePropertyFile" system property
+ * <li>writes <code>gemfireProperties</code> to the file
+ */
+ private void useGemFirePropertiesFileInTemporaryFolder(final String fileName, final Properties gemfireProperties) throws Exception {
+ File propertiesFile = new File(this.temporaryFolder.getRoot().getCanonicalPath(), fileName);
+ System.setProperty(DistributedSystem.PROPERTIES_FILE_PROPERTY, propertiesFile.getCanonicalPath());
+
+ gemfireProperties.store(new FileWriter(propertiesFile, false), this.testName.getMethodName());
+ assertThat(propertiesFile.isFile()).isTrue();
+ assertThat(propertiesFile.exists()).isTrue();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cd02af01/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherJUnitTest.java
deleted file mode 100755
index 395a9e6..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherJUnitTest.java
+++ /dev/null
@@ -1,903 +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 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 ServerLauncherJUnitTest 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 ServerLauncherJUnitTest {
-
- 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/ServerLauncherLocalFileIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalFileIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalFileIntegrationTest.java
new file mode 100755
index 0000000..5a457a7
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalFileIntegrationTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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 com.gemstone.gemfire.internal.process.ProcessControllerFactory;
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+
+/**
+ * Subclass of ServerLauncherLocalDUnitTest which forces the code to not find
+ * the Attach API which is in the JDK tools.jar. As a result ServerLauncher
+ * ends up using the FileProcessController implementation.
+ *
+ * @since 8.0
+ */
+@Category(IntegrationTest.class)
+public class ServerLauncherLocalFileIntegrationTest extends ServerLauncherLocalIntegrationTest {
+
+ @Before
+ public final void setUpServerLauncherLocalFileTest() throws Exception {
+ System.setProperty(ProcessControllerFactory.PROPERTY_DISABLE_ATTACH_API, "true");
+ }
+
+ @After
+ public final void tearDownServerLauncherLocalFileTest() throws Exception {
+ }
+
+ @Override
+ @Test
+ public void testIsAttachAPIFound() throws Exception {
+ final ProcessControllerFactory factory = new ProcessControllerFactory();
+ assertFalse(factory.isAttachAPIFound());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cd02af01/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalFileJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalFileJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalFileJUnitTest.java
deleted file mode 100755
index bda05c4..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalFileJUnitTest.java
+++ /dev/null
@@ -1,54 +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 com.gemstone.gemfire.internal.process.ProcessControllerFactory;
-import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
-
-/**
- * Subclass of ServerLauncherLocalDUnitTest which forces the code to not find
- * the Attach API which is in the JDK tools.jar. As a result ServerLauncher
- * ends up using the FileProcessController implementation.
- *
- * @since 8.0
- */
-@Category(IntegrationTest.class)
-public class ServerLauncherLocalFileJUnitTest extends ServerLauncherLocalJUnitTest {
-
- @Before
- public final void setUpServerLauncherLocalFileTest() throws Exception {
- System.setProperty(ProcessControllerFactory.PROPERTY_DISABLE_ATTACH_API, "true");
- }
-
- @After
- public final void tearDownServerLauncherLocalFileTest() throws Exception {
- }
-
- @Override
- @Test
- public void testIsAttachAPIFound() throws Exception {
- final ProcessControllerFactory factory = new ProcessControllerFactory();
- assertFalse(factory.isAttachAPIFound());
- }
-}