You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by zh...@apache.org on 2017/08/11 17:26:45 UTC
[15/23] geode git commit: GEODE-3413: overhaul launcher and process
classes and tests
http://git-wip-us.apache.org/repos/asf/geode/blob/894f3ee7/geode-core/src/test/java/org/apache/geode/distributed/LocatorStateTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/LocatorStateTest.java b/geode-core/src/test/java/org/apache/geode/distributed/LocatorStateTest.java
index 5cb7dea..7ef3ff0 100755
--- a/geode-core/src/test/java/org/apache/geode/distributed/LocatorStateTest.java
+++ b/geode-core/src/test/java/org/apache/geode/distributed/LocatorStateTest.java
@@ -14,14 +14,16 @@
*/
package org.apache.geode.distributed;
-import static com.googlecode.catchexception.CatchException.*;
-import static org.assertj.core.api.Assertions.*;
+import static com.googlecode.catchexception.CatchException.caughtException;
+import static com.googlecode.catchexception.CatchException.verifyException;
+import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -33,26 +35,45 @@ import org.apache.geode.management.internal.cli.json.GfJsonObject;
import org.apache.geode.test.junit.categories.UnitTest;
/**
- * Unit tests for LocatorLauncher.LocatorState
+ * Unit tests for {@link LocatorLauncher.LocatorState}.
*/
@Category(UnitTest.class)
public class LocatorStateTest {
- private String classpath = "test_classpath";
- private String gemFireVersion = "test_gemfireversion";
- private String host = "test_host";
- private String javaVersion = "test_javaversion";
- private String jvmArguments = "test_jvmarguments";
- private String serviceLocation = "test_location";
- private String logFile = "test_logfile";
- private String memberName = "test_membername";
- private Integer pid = 6396;
- private String port = "test_port";
- private String statusDescription = Status.NOT_RESPONDING.getDescription();
- private String statusMessage = "test_statusmessage";
- private Long timestampTime = 1450728233024L;
- private Long uptime = 1629L;
- private String workingDirectory = "test_workingdirectory";
+ private String classpath;
+ private String gemFireVersion;
+ private String host;
+ private String javaVersion;
+ private String jvmArguments;
+ private String serviceLocation;
+ private String logFile;
+ private String memberName;
+ private Integer pid;
+ private String port;
+ private String statusDescription;
+ private String statusMessage;
+ private Long timestampTime;
+ private Long uptime;
+ private String workingDirectory;
+
+ @Before
+ public void before() throws Exception {
+ classpath = "test_classpath";
+ gemFireVersion = "test_gemfireVersion";
+ host = "test_host";
+ javaVersion = "test_javaVersion";
+ jvmArguments = "test_jvmArguments";
+ serviceLocation = "test_location";
+ logFile = "test_logfile";
+ memberName = "test_memberName";
+ pid = 6396;
+ port = "test_port";
+ statusDescription = Status.NOT_RESPONDING.getDescription();
+ statusMessage = "test_statusMessage";
+ timestampTime = 1450728233024L;
+ uptime = 1629L;
+ workingDirectory = "test_workingDirectory";
+ }
@Test
public void fromJsonWithEmptyStringThrowsIllegalArgumentException() throws Exception {
@@ -65,7 +86,6 @@ public class LocatorStateTest {
// then: throws IllegalArgumentException with cause of GfJsonException
assertThat((Exception) caughtException()).isInstanceOf(IllegalArgumentException.class)
.hasCauseInstanceOf(GfJsonException.class);
-
assertThat(caughtException().getCause()).isInstanceOf(GfJsonException.class).hasNoCause();
}
@@ -80,7 +100,6 @@ public class LocatorStateTest {
// then: throws IllegalArgumentException with cause of GfJsonException
assertThat((Exception) caughtException()).isInstanceOf(IllegalArgumentException.class)
.hasCauseInstanceOf(GfJsonException.class);
-
assertThat(caughtException().getCause()).isInstanceOf(GfJsonException.class).hasNoCause();
}
@@ -106,107 +125,53 @@ public class LocatorStateTest {
// then: return valid instance of LocatorState
assertThat(value).isInstanceOf(LocatorState.class);
-
- assertThat(value.getClasspath()).isEqualTo(getClasspath());
- assertThat(value.getGemFireVersion()).isEqualTo(getGemFireVersion());
- assertThat(value.getHost()).isEqualTo(getHost());
- assertThat(value.getJavaVersion()).isEqualTo(getJavaVersion());
+ assertThat(value.getClasspath()).isEqualTo(classpath);
+ assertThat(value.getGemFireVersion()).isEqualTo(gemFireVersion);
+ assertThat(value.getHost()).isEqualTo(host);
+ assertThat(value.getJavaVersion()).isEqualTo(javaVersion);
assertThat(value.getJvmArguments()).isEqualTo(getJvmArguments());
- assertThat(value.getServiceLocation()).isEqualTo(getServiceLocation());
- assertThat(value.getLogFile()).isEqualTo(getLogFile());
- assertThat(value.getMemberName()).isEqualTo(getMemberName());
- assertThat(value.getPid()).isEqualTo(getPid());
- assertThat(value.getPort()).isEqualTo(getPort());
- assertThat(value.getStatus().getDescription()).isEqualTo(getStatusDescription());
- assertThat(value.getStatusMessage()).isEqualTo(getStatusMessage());
- assertThat(value.getTimestamp().getTime()).isEqualTo(getTimestampTime());
- assertThat(value.getUptime()).isEqualTo(getUptime());
- assertThat(value.getWorkingDirectory()).isEqualTo(getWorkingDirectory());
- }
-
+ assertThat(value.getLogFile()).isEqualTo(logFile);
+ assertThat(value.getMemberName()).isEqualTo(memberName);
+ assertThat(value.getPid()).isEqualTo(pid);
+ assertThat(value.getPort()).isEqualTo(port);
+ assertThat(value.getServiceLocation()).isEqualTo(serviceLocation);
+ assertThat(value.getStatus().getDescription()).isEqualTo(statusDescription);
+ assertThat(value.getStatusMessage()).isEqualTo(statusMessage);
+ assertThat(value.getTimestamp().getTime()).isEqualTo(timestampTime);
+ assertThat(value.getUptime()).isEqualTo(uptime);
+ assertThat(value.getWorkingDirectory()).isEqualTo(workingDirectory);
+ }
+
+ /**
+ * NOTE: Must be protected for CatchException.
+ */
protected LocatorState fromJson(final String value) {
return LocatorState.fromJson(value);
}
- private String getClasspath() {
- return this.classpath;
- }
-
- private String getGemFireVersion() {
- return this.gemFireVersion;
- }
-
- private String getHost() {
- return this.host;
- }
-
- private String getJavaVersion() {
- return this.javaVersion;
- }
-
private List<String> getJvmArguments() {
- List<String> list = new ArrayList<String>();
- list.add(this.jvmArguments);
+ List<String> list = new ArrayList<>();
+ list.add(jvmArguments);
return list;
}
- private String getServiceLocation() {
- return this.serviceLocation;
- }
-
- private String getLogFile() {
- return this.logFile;
- }
-
- private String getMemberName() {
- return this.memberName;
- }
-
- private Integer getPid() {
- return this.pid;
- }
-
- private String getPort() {
- return this.port;
- }
-
- private String getStatusDescription() {
- return this.statusDescription;
- }
-
- private String getStatusMessage() {
- return this.statusMessage;
- }
-
- private Long getTimestampTime() {
- return this.timestampTime;
- }
-
- private Long getUptime() {
- return this.uptime;
- }
-
- private String getWorkingDirectory() {
- return this.workingDirectory;
- }
-
private String createStatusJson() {
- final Map<String, Object> map = new HashMap<String, Object>();
- map.put(ServiceState.JSON_CLASSPATH, getClasspath());
- map.put(ServiceState.JSON_GEMFIREVERSION, getGemFireVersion());
- map.put(ServiceState.JSON_HOST, getHost());
- map.put(ServiceState.JSON_JAVAVERSION, getJavaVersion());
+ Map<String, Object> map = new HashMap<>();
+ map.put(ServiceState.JSON_CLASSPATH, classpath);
+ map.put(ServiceState.JSON_GEMFIREVERSION, gemFireVersion);
+ map.put(ServiceState.JSON_HOST, host);
+ map.put(ServiceState.JSON_JAVAVERSION, javaVersion);
map.put(ServiceState.JSON_JVMARGUMENTS, getJvmArguments());
- map.put(ServiceState.JSON_LOCATION, getServiceLocation());
- map.put(ServiceState.JSON_LOGFILE, getLogFile());
- map.put(ServiceState.JSON_MEMBERNAME, getMemberName());
- map.put(ServiceState.JSON_PID, getPid());
- map.put(ServiceState.JSON_PORT, getPort());
- map.put(ServiceState.JSON_STATUS, getStatusDescription());
- map.put(ServiceState.JSON_STATUSMESSAGE, getStatusMessage());
- map.put(ServiceState.JSON_TIMESTAMP, getTimestampTime());
- map.put(ServiceState.JSON_UPTIME, getUptime());
- map.put(ServiceState.JSON_WORKINGDIRECTORY, getWorkingDirectory());
+ map.put(ServiceState.JSON_LOCATION, serviceLocation);
+ map.put(ServiceState.JSON_LOGFILE, logFile);
+ map.put(ServiceState.JSON_MEMBERNAME, memberName);
+ map.put(ServiceState.JSON_PID, pid);
+ map.put(ServiceState.JSON_PORT, port);
+ map.put(ServiceState.JSON_STATUS, statusDescription);
+ map.put(ServiceState.JSON_STATUSMESSAGE, statusMessage);
+ map.put(ServiceState.JSON_TIMESTAMP, timestampTime);
+ map.put(ServiceState.JSON_UPTIME, uptime);
+ map.put(ServiceState.JSON_WORKINGDIRECTORY, workingDirectory);
return new GfJsonObject(map).toString();
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/894f3ee7/geode-core/src/test/java/org/apache/geode/distributed/MockServerLauncherCacheProvider.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/MockServerLauncherCacheProvider.java b/geode-core/src/test/java/org/apache/geode/distributed/MockServerLauncherCacheProvider.java
deleted file mode 100644
index 768cc89..0000000
--- a/geode-core/src/test/java/org/apache/geode/distributed/MockServerLauncherCacheProvider.java
+++ /dev/null
@@ -1,38 +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 org.apache.geode.distributed;
-
-import java.util.Properties;
-
-import org.apache.geode.cache.Cache;
-
-public class MockServerLauncherCacheProvider implements ServerLauncherCacheProvider {
-
- private static Cache cache;
-
- public static Cache getCache() {
- return cache;
- }
-
- public static void setCache(Cache cache) {
- MockServerLauncherCacheProvider.cache = cache;
- }
-
- @Override
- public Cache createCache(Properties gemfireProperties, ServerLauncher serverLauncher) {
- return cache;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/894f3ee7/geode-core/src/test/java/org/apache/geode/distributed/ServerCommand.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/ServerCommand.java b/geode-core/src/test/java/org/apache/geode/distributed/ServerCommand.java
new file mode 100644
index 0000000..ca1bfd9
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/distributed/ServerCommand.java
@@ -0,0 +1,120 @@
+/*
+ * 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 org.apache.geode.distributed;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.geode.distributed.ServerLauncher.Command;
+
+public class ServerCommand {
+
+ private String javaPath;
+ private List<String> jvmArguments = new ArrayList<>();
+ private String classPath;
+ private Command command;
+ private String name;
+ private boolean disableDefaultServer;
+ private boolean force;
+ private int serverPort;
+
+ public ServerCommand() {
+ // do nothing
+ }
+
+ public ServerCommand(final UsesServerCommand user) {
+ this.javaPath = user.getJavaPath();
+ this.jvmArguments = user.getJvmArguments();
+ this.classPath = user.getClassPath();
+ this.name = user.getName();
+ this.disableDefaultServer = user.getDisableDefaultServer();
+ this.command = Command.START;
+ }
+
+ public ServerCommand withJavaPath(final String javaPath) {
+ this.javaPath = javaPath;
+ return this;
+ }
+
+ public ServerCommand withJvmArguments(final List<String> jvmArguments) {
+ this.jvmArguments = jvmArguments;
+ return this;
+ }
+
+ public ServerCommand addJvmArgument(final String arg) {
+ this.jvmArguments.add(arg);
+ return this;
+ }
+
+ public ServerCommand withClassPath(final String classPath) {
+ this.classPath = classPath;
+ return this;
+ }
+
+ public ServerCommand withCommand(final Command command) {
+ this.command = command;
+ return this;
+ }
+
+ public ServerCommand withName(final String name) {
+ this.name = name;
+ return this;
+ }
+
+ public ServerCommand disableDefaultServer() {
+ return disableDefaultServer(true);
+ }
+
+ public ServerCommand disableDefaultServer(final boolean value) {
+ this.disableDefaultServer = value;
+ return this;
+ }
+
+ public ServerCommand force() {
+ return force(true);
+ }
+
+ public ServerCommand force(final boolean value) {
+ this.force = value;
+ return this;
+ }
+
+ public ServerCommand withServerPort(final int serverPort) {
+ this.serverPort = serverPort;
+ return disableDefaultServer(false);
+ }
+
+ public List<String> create() {
+ List<String> cmd = new ArrayList<>();
+ cmd.add(javaPath);
+ cmd.addAll(jvmArguments);
+ cmd.add("-cp");
+ cmd.add(classPath);
+ cmd.add(ServerLauncher.class.getName());
+ cmd.add(command.getName());
+ cmd.add(name);
+ if (disableDefaultServer) {
+ cmd.add("--disable-default-server");
+ }
+ if (force) {
+ cmd.add("--force");
+ }
+ cmd.add("--redirect-output");
+ if (serverPort > 0) {
+ cmd.add("--server-port=" + serverPort);
+ }
+ return cmd;
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/894f3ee7/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherBuilderTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherBuilderTest.java b/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherBuilderTest.java
new file mode 100644
index 0000000..b7a6fcd
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherBuilderTest.java
@@ -0,0 +1,845 @@
+/*
+ * 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 org.apache.geode.distributed;
+
+import static org.apache.geode.distributed.ConfigurationProperties.NAME;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import joptsimple.OptionException;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.RestoreSystemProperties;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.server.CacheServer;
+import org.apache.geode.distributed.ServerLauncher.Builder;
+import org.apache.geode.distributed.ServerLauncher.Command;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+/**
+ * Unit tests for {@link ServerLauncher.Builder}. Extracted from {@link ServerLauncherTest}.
+ */
+@Category(UnitTest.class)
+public class ServerLauncherBuilderTest {
+
+ private InetAddress localHost;
+ private String localHostName;
+
+ @Rule
+ public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+
+ @Before
+ public void before() throws Exception {
+ localHost = InetAddress.getLocalHost();
+ localHostName = localHost.getCanonicalHostName();
+ }
+
+ @Test
+ public void defaultCommandIsUnspecified() throws Exception {
+ assertThat(Builder.DEFAULT_COMMAND).isEqualTo(Command.UNSPECIFIED);
+ }
+
+ @Test
+ public void getCommandReturnsUnspecifiedByDefault() throws Exception {
+ assertThat(new Builder().getCommand()).isEqualTo(Builder.DEFAULT_COMMAND);
+ }
+
+ @Test
+ public void getCriticalHeapPercentageReturnsNullByDefault() throws Exception {
+ assertThat(new Builder().getCriticalHeapPercentage()).isNull();
+ }
+
+ @Test
+ public void getEvictionHeapPercentageReturnsNullByDefault() throws Exception {
+ assertThat(new Builder().getEvictionHeapPercentage()).isNull();
+ }
+
+ @Test
+ public void getForceReturnsFalseByDefault() {
+ assertThat(new Builder().getForce()).isFalse();
+ }
+
+ @Test
+ public void getHostNameForClientsReturnsNullByDefault() throws Exception {
+ Builder builder = new Builder();
+
+ assertThat(builder.getHostNameForClients()).isNull();
+ }
+
+ @Test
+ public void getMaxConnectionsReturnsNullByDefault() throws Exception {
+ assertThat(new Builder().getMaxConnections()).isNull();
+ }
+
+ @Test
+ public void getMaxMessageCountReturnsNullByDefault() throws Exception {
+ assertThat(new Builder().getMaxMessageCount()).isNull();
+ }
+
+ @Test
+ public void getMaxThreadsReturnsNullByDefault() throws Exception {
+ assertThat(new Builder().getMaxThreads()).isNull();
+ }
+
+ @Test
+ public void getMessageTimeToLiveReturnsNullByDefault() throws Exception {
+ assertThat(new Builder().getMessageTimeToLive()).isNull();
+ }
+
+ @Test
+ public void getMemberNameReturnsNullByDefault() throws Exception {
+ assertThat(new Builder().getMemberName()).isNull();
+ }
+
+ @Test
+ public void getPidReturnsNullByDefault() throws Exception {
+ assertThat(new Builder().getPid()).isNull();
+ }
+
+ @Test
+ public void getServerBindAddressReturnsNullByDefault() throws Exception {
+ assertThat(new Builder().getServerBindAddress()).isNull();
+ }
+
+ @Test
+ public void getServerPortReturnsDefaultPortByDefault() throws Exception {
+ assertThat(new Builder().getServerPort()).isEqualTo(Integer.valueOf(CacheServer.DEFAULT_PORT));
+ }
+
+ @Test
+ public void getSocketBufferSizeReturnsNullByDefault() throws Exception {
+ assertThat(new Builder().getSocketBufferSize()).isNull();
+ }
+
+ @Test
+ public void setCommandReturnsBuilderInstance() throws Exception {
+ Builder builder = new Builder();
+
+ assertThat(builder.setCommand(Command.STATUS)).isSameAs(builder);
+ }
+
+ @Test
+ public void setCriticalHeapPercentageReturnsBuilderInstance() throws Exception {
+ Builder builder = new Builder();
+
+ assertThat(builder.setCriticalHeapPercentage(55.5f)).isSameAs(builder);
+ }
+
+ @Test
+ public void setEvictionHeapPercentageReturnsBuilderInstance() throws Exception {
+ Builder builder = new Builder();
+
+ assertThat(builder.setEvictionHeapPercentage(55.55f)).isSameAs(builder);
+ }
+
+ @Test
+ public void setForceReturnsBuilderInstance() throws Exception {
+ Builder builder = new Builder();
+
+ assertThat(builder.setForce(true)).isSameAs(builder);
+ }
+
+ @Test
+ public void setHostNameForClientsReturnsBuilderInstance() throws Exception {
+ Builder builder = new Builder();
+
+ assertThat(builder.setHostNameForClients("Pegasus")).isSameAs(builder);
+ }
+
+ @Test
+ public void setMaxConnectionsReturnsBuilderInstance() throws Exception {
+ Builder builder = new Builder();
+
+ assertThat(builder.setMaxConnections(1000)).isSameAs(builder);
+ }
+
+ @Test
+ public void setMaxMessageCountReturnsBuilderInstance() throws Exception {
+ Builder builder = new Builder();
+
+ assertThat(builder.setMaxMessageCount(50)).isSameAs(builder);
+ }
+
+ @Test
+ public void setMaxThreadsReturnsBuilderInstance() throws Exception {
+ Builder builder = new Builder();
+
+ assertThat(builder.setMaxThreads(16)).isSameAs(builder);
+ }
+
+ @Test
+ public void setMemberNameReturnsBuilderInstance() throws Exception {
+ Builder builder = new Builder();
+
+ assertThat(builder.setMemberName("serverOne")).isSameAs(builder);
+ }
+
+ @Test
+ public void setPidReturnsBuilderInstance() throws Exception {
+ Builder builder = new Builder();
+
+ assertThat(builder.setPid(0)).isSameAs(builder);
+ }
+
+ @Test
+ public void setServerBindAddressReturnsBuilderInstance() throws Exception {
+ Builder builder = new Builder();
+
+ assertThat(builder.setServerBindAddress(null)).isSameAs(builder);
+ }
+
+ @Test
+ public void setServerPortReturnsBuilderInstance() throws Exception {
+ Builder builder = new Builder();
+
+ assertThat(builder.setServerPort(null)).isSameAs(builder);
+ }
+
+ @Test
+ public void setMessageTimeToLiveReturnsBuilderInstance() throws Exception {
+ Builder builder = new Builder();
+
+ assertThat(builder.setMessageTimeToLive(30000)).isSameAs(builder);
+ }
+
+ @Test
+ public void setSocketBufferSizeReturnsBuilderInstance() throws Exception {
+ Builder builder = new Builder();
+
+ assertThat(builder.setSocketBufferSize(32768)).isSameAs(builder);
+ }
+
+ @Test
+ public void setCommandWithNullResultsInDefaultCommand() throws Exception {
+ Builder builder = new Builder();
+
+ new Builder().setCommand(null);
+
+ assertThat(builder.getCommand()).isEqualTo(Builder.DEFAULT_COMMAND);
+ }
+
+ @Test
+ public void setCommandToStatusResultsInStatus() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setCommand(Command.STATUS);
+
+ assertThat(builder.getCommand()).isEqualTo(Command.STATUS);
+ }
+
+ @Test
+ public void setCriticalHeapPercentageToPercentileUsesValue() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setCriticalHeapPercentage(55.5f);
+
+ assertThat(builder.getCriticalHeapPercentage().floatValue()).isEqualTo(55.5f);
+ }
+
+ @Test
+ public void setCriticalHeapPercentageToNullResultsInNull() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setCriticalHeapPercentage(null);
+
+ assertThat(builder.getCriticalHeapPercentage()).isNull();
+ }
+
+ @Test
+ public void setCriticalHeapPercentageAbove100ThrowsIllegalArgumentException() throws Exception {
+ assertThatThrownBy(() -> new Builder().setCriticalHeapPercentage(100.01f))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void setCriticalHeapPercentageBelowZeroThrowsIllegalArgumentException() throws Exception {
+ assertThatThrownBy(() -> new Builder().setCriticalHeapPercentage(-0.01f))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void setEvictionHeapPercentageToPercentileUsesValue() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setEvictionHeapPercentage(55.55f);
+
+ assertThat(builder.getEvictionHeapPercentage().floatValue()).isEqualTo(55.55f);
+ }
+
+ @Test
+ public void setEvictionHeapPercentageToNullResultsInNull() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setEvictionHeapPercentage(null);
+
+ assertThat(builder.getEvictionHeapPercentage()).isNull();
+ }
+
+ @Test
+ public void setEvictionHeapPercentageAboveO100ThrowsIllegalArgumentException() throws Exception {
+ assertThatThrownBy(() -> new Builder().setEvictionHeapPercentage(101.0f))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void setEvictionHeapPercentageBelowZeroThrowsIllegalArgumentException() throws Exception {
+ assertThatThrownBy(() -> new Builder().setEvictionHeapPercentage(-10.0f))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void setForceToTrueUsesValue() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setForce(true);
+
+ assertThat(builder.getForce()).isTrue();
+ }
+
+ @Test
+ public void setHostNameForClientsToStringUsesValue() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setHostNameForClients("Pegasus");
+
+ assertThat(builder.getHostNameForClients()).isEqualTo("Pegasus");
+ }
+
+ @Test
+ public void setHostNameForClientsToBlankStringThrowsIllegalArgumentException() {
+ assertThatThrownBy(() -> new Builder().setHostNameForClients(" "))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void setHostNameForClientsToEmptyStringThrowsIllegalArgumentException() {
+ assertThatThrownBy(() -> new Builder().setHostNameForClients(""))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void setHostNameForClientsToNullThrowsIllegalArgumentException() {
+ assertThatThrownBy(() -> new Builder().setHostNameForClients(null))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void setMaxConnectionsToPositiveIntegerUsesValue() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setMaxConnections(1000);
+
+ assertThat(builder.getMaxConnections().intValue()).isEqualTo(1000);
+ }
+
+ @Test
+ public void setMaxConnectionsToNullResultsInNull() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setMaxConnections(null);
+
+ assertThat(builder.getMaxConnections()).isNull();
+ }
+
+ @Test
+ public void setMaxConnectionsToNegativeValueThrowsIllegalArgumentException() throws Exception {
+ assertThatThrownBy(() -> new Builder().setMaxConnections(-10))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void setMaxMessageCountToPositiveIntegerUsesValue() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setMaxMessageCount(50);
+
+ assertThat(builder.getMaxMessageCount().intValue()).isEqualTo(50);
+ }
+
+ @Test
+ public void setMaxMessageCountToNullResultsInNull() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setMaxMessageCount(null);
+
+ assertThat(builder.getMaxMessageCount()).isNull();
+ }
+
+ @Test
+ public void setMaxMessageCountToZeroResultsInIllegalArgumentException() throws Exception {
+ assertThatThrownBy(() -> new Builder().setMaxMessageCount(0))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void setMaxThreadsToPositiveIntegerUsesValue() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setMaxThreads(16);
+
+ assertThat(builder.getMaxThreads().intValue()).isEqualTo(16);
+ }
+
+ @Test
+ public void setMaxThreadsToNullResultsInNull() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setMaxThreads(null);
+
+ assertThat(builder.getMaxThreads()).isNull();
+ }
+
+ @Test
+ public void setMaxThreadsToNegativeValueThrowsIllegalArgumentException() throws Exception {
+ assertThatThrownBy(() -> new Builder().setMaxThreads(-4))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void setMemberNameToStringUsesValue() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setMemberName("serverOne");
+
+ assertThat(builder.getMemberName()).isEqualTo("serverOne");
+ }
+
+ @Test
+ public void setMemberNameToBlankStringThrowsIllegalArgumentException() throws Exception {
+ assertThatThrownBy(() -> new Builder().setMemberName(" "))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void setMemberNameToEmptyStringThrowsIllegalArgumentException() throws Exception {
+ assertThatThrownBy(() -> new Builder().setMemberName(""))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void setMemberNameToNullStringThrowsIllegalArgumentException() throws Exception {
+ assertThatThrownBy(() -> new Builder().setMemberName(null))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void setMessageTimeToLiveToPositiveIntegerUsesValue() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setMessageTimeToLive(30000);
+
+ assertThat(builder.getMessageTimeToLive().intValue()).isEqualTo(30000);
+ }
+
+ @Test
+ public void setMessageTimeToNullResultsInNull() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setMessageTimeToLive(null);
+
+ assertThat(builder.getMessageTimeToLive()).isNull();
+ }
+
+ @Test
+ public void setMessageTimeToLiveToZeroThrowsIllegalArgumentException() throws Exception {
+ assertThatThrownBy(() -> new Builder().setMessageTimeToLive(0))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void setPidToZeroOrGreaterUsesValue() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setPid(0);
+ assertThat(builder.getPid().intValue()).isEqualTo(0);
+
+ builder.setPid(1);
+ assertThat(builder.getPid().intValue()).isEqualTo(1);
+
+ builder.setPid(1024);
+ assertThat(builder.getPid().intValue()).isEqualTo(1024);
+
+ builder.setPid(12345);
+ assertThat(builder.getPid().intValue()).isEqualTo(12345);
+ }
+
+ @Test
+ public void setPidToNullResultsInNull() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setPid(null);
+
+ assertThat(builder.getPid()).isNull();
+ }
+
+ @Test
+ public void setPidToNegativeValueThrowsIllegalArgumentException() throws Exception {
+ assertThatThrownBy(() -> new Builder().setPid(-1)).isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void setServerBindAddressToNullResultsInNull() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setServerBindAddress(null);
+
+ assertThat(builder.getServerBindAddress()).isNull();
+ }
+
+ @Test
+ public void setServerBindAddressToEmptyStringResultsInNull() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setServerBindAddress("");
+
+ assertThat(builder.getServerBindAddress()).isNull();
+ }
+
+ @Test
+ public void setServerBindAddressToBlankStringResultsInNull() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setServerBindAddress(" ");
+
+ assertThat(builder.getServerBindAddress()).isNull();
+ }
+
+ @Test
+ public void setServerBindAddressToCanonicalLocalHostUsesValue() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setServerBindAddress(localHostName);
+
+ assertThat(builder.getServerBindAddress()).isEqualTo(localHost);
+ }
+
+ @Test
+ public void setServerBindAddressToLocalHostNameUsesValue() throws Exception {
+ String host = InetAddress.getLocalHost().getHostName();
+
+ Builder builder = new Builder().setServerBindAddress(host);
+
+ assertThat(builder.getServerBindAddress()).isEqualTo(localHost);
+ }
+
+ @Test
+ public void setServerBindAddressToUnknownHostThrowsIllegalArgumentException() throws Exception {
+ assertThatThrownBy(() -> new Builder().setServerBindAddress("badHostName.badCompany.com"))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasCauseInstanceOf(UnknownHostException.class);
+ }
+
+ @Test
+ public void setServerBindAddressToNonLocalHostThrowsIllegalArgumentException() throws Exception {
+ assertThatThrownBy(() -> new Builder().setServerBindAddress("yahoo.com"))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void setServerPortToNullResultsInDefaultPort() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setServerPort(null);
+
+ assertThat(builder.getServerPort()).isEqualTo(Integer.valueOf(CacheServer.DEFAULT_PORT));
+ }
+
+ @Test
+ public void setServerPortToZeroOrGreaterUsesValue() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setServerPort(0);
+ assertThat(builder.getServerPort().intValue()).isEqualTo(0);
+
+ builder.setServerPort(1);
+ assertThat(builder.getServerPort().intValue()).isEqualTo(1);
+
+ builder.setServerPort(80);
+ assertThat(builder.getServerPort().intValue()).isEqualTo(80);
+
+ builder.setServerPort(1024);
+ assertThat(builder.getServerPort().intValue()).isEqualTo(1024);
+
+ builder.setServerPort(65535);
+ assertThat(builder.getServerPort().intValue()).isEqualTo(65535);
+ }
+
+ @Test
+ public void setServerPortAboveMaxValueThrowsIllegalArgumentException() throws Exception {
+ assertThatThrownBy(() -> new Builder().setServerPort(65536))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void setServerPortToNegativeValueThrowsIllegalArgumentException() throws Exception {
+ assertThatThrownBy(() -> new Builder().setServerPort(-1))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void setSocketBufferSizeToPositiveIntegerUsesValue() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setSocketBufferSize(32768);
+
+ assertThat(builder.getSocketBufferSize().intValue()).isEqualTo(32768);
+ }
+
+ @Test
+ public void setSocketBufferSizeToNullResultsInNull() throws Exception {
+ Builder builder = new Builder();
+
+ builder.setSocketBufferSize(null);
+
+ assertThat(builder.getSocketBufferSize()).isNull();
+ }
+
+ @Test
+ public void setSocketBufferSizeToNegativeValueThrowsIllegalArgumentException() throws Exception {
+ assertThatThrownBy(() -> new Builder().setSocketBufferSize(-8192))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void parseArgumentsWithForceSetsForceToTrue() throws Exception {
+ Builder builder = new Builder();
+
+ builder.parseArguments("start", "--force");
+
+ assertThat(builder.getForce()).isTrue();
+ }
+
+ @Test
+ public void parseArgumentsWithNonNumericPortThrowsIllegalArgumentException() {
+ assertThatThrownBy(
+ () -> new Builder().parseArguments("start", "server1", "--server-port", "oneTwoThree"))
+ .isInstanceOf(IllegalArgumentException.class).hasCauseInstanceOf(OptionException.class);
+ }
+
+ @Test
+ public void parseArgumentsParsesValuesSeparatedWithCommas() throws Exception {
+ // given: fresh builder
+ Builder builder = new Builder();
+
+ // when: parsing comma-separated arguments
+ builder.parseArguments("start", "serverOne", "--assign-buckets", "--disable-default-server",
+ "--debug", "--force", "--rebalance", "--redirect-output", "--pid", "1234",
+ "--server-bind-address", InetAddress.getLocalHost().getHostAddress(), "--server-port",
+ "11235", "--hostname-for-clients", "192.168.99.100");
+
+ // then: getters should return 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.getPid().intValue()).isEqualTo(1234);
+ assertThat(builder.getServerBindAddress()).isEqualTo(InetAddress.getLocalHost());
+ assertThat(builder.getServerPort().intValue()).isEqualTo(11235);
+ }
+
+ @Test
+ public void parseArgumentsParsesValuesSeparatedWithEquals() throws Exception {
+ // given: fresh builder
+ Builder builder = new Builder();
+
+ // when: parsing equals-separated arguments
+ builder.parseArguments("start", "serverOne", "--assign-buckets", "--disable-default-server",
+ "--debug", "--force", "--rebalance", "--redirect-output", "--pid=1234",
+ "--server-bind-address=" + InetAddress.getLocalHost().getHostAddress(),
+ "--server-port=11235", "--hostname-for-clients=192.168.99.100");
+
+ // then: getters should return 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.getPid().intValue()).isEqualTo(1234);
+ assertThat(builder.getServerBindAddress()).isEqualTo(InetAddress.getLocalHost());
+ assertThat(builder.getServerPort().intValue()).isEqualTo(11235);
+ }
+
+ @Test
+ public void parseCommandWithNullStringArrayResultsInDefaultCommand() throws Exception {
+ Builder builder = new Builder();
+
+ builder.parseCommand((String[]) null);
+
+ assertThat(builder.getCommand()).isEqualTo(Builder.DEFAULT_COMMAND);
+ }
+
+ @Test
+ public void parseCommandWithEmptyStringArrayResultsInDefaultCommand() throws Exception {
+ Builder builder = new Builder();
+
+ builder.parseCommand(); // empty String array
+
+ assertThat(builder.getCommand()).isEqualTo(Builder.DEFAULT_COMMAND);
+ }
+
+ @Test
+ public void parseCommandWithStartResultsInStartCommand() throws Exception {
+ Builder builder = new Builder();
+
+ builder.parseCommand(Command.START.getName());
+
+ assertThat(builder.getCommand()).isEqualTo(Command.START);
+ }
+
+ @Test
+ public void parseCommandWithStatusResultsInStatusCommand() throws Exception {
+ Builder builder = new Builder();
+
+ builder.parseCommand("Status");
+
+ assertThat(builder.getCommand()).isEqualTo(Command.STATUS);
+ }
+
+ @Test
+ public void parseCommandWithMixedCaseResultsInCorrectCase() throws Exception {
+ Builder builder = new Builder();
+
+ builder.parseCommand("sToP");
+
+ assertThat(builder.getCommand()).isEqualTo(Command.STOP);
+ }
+
+ @Test
+ public void parseCommandWithTwoCommandsWithSwitchesUsesFirstCommand() throws Exception {
+ Builder builder = new Builder();
+
+ builder.parseCommand("--opt", "START", "-o", Command.STATUS.getName());
+
+ assertThat(builder.getCommand()).isEqualTo(Command.START);
+ }
+
+ @Test
+ public void parseCommandWithTwoCommandsWithoutSwitchesUsesFirstCommand() throws Exception {
+ Builder builder = new Builder();
+
+ builder.parseCommand("START", Command.STATUS.getName());
+
+ assertThat(builder.getCommand()).isEqualTo(Command.START);
+ }
+
+ @Test
+ public void parseCommandWithBadInputResultsInDefaultCommand() throws Exception {
+ Builder builder = new Builder();
+
+ builder.parseCommand("badCommandName", "--start", "stat");
+
+ assertThat(builder.getCommand()).isEqualTo(Builder.DEFAULT_COMMAND);
+ }
+
+ @Test
+ public void parseMemberNameWithNullStringArrayResultsInNull() throws Exception {
+ Builder builder = new Builder();
+
+ builder.parseMemberName((String[]) null);
+
+ assertThat(builder.getMemberName()).isNull();
+ }
+
+ @Test
+ public void parseMemberNameWithEmptyStringArrayResultsInNull() throws Exception {
+ Builder builder = new Builder();
+
+ builder.parseMemberName(); // empty String array
+
+ assertThat(builder.getMemberName()).isNull();
+ }
+
+ @Test
+ public void parseMemberNameWithCommandAndOptionsResultsInNull() throws Exception {
+ Builder builder = new Builder();
+
+ builder.parseMemberName(Command.START.getName(), "--opt", "-o");
+
+ assertThat(builder.getMemberName()).isNull();
+ }
+
+ @Test
+ public void parseMemberNameWithStringUsesValue() throws Exception {
+ Builder builder = new Builder();
+
+ builder.parseMemberName("memberOne");
+
+ assertThat(builder.getMemberName()).isEqualTo("memberOne");
+ }
+
+ @Test
+ public void buildCreatesServerLauncherWithBuilderValues() throws Exception {
+ ServerLauncher launcher = new Builder().setCommand(Command.STOP).setAssignBuckets(true)
+ .setForce(true).setMemberName("serverOne").setRebalance(true)
+ .setServerBindAddress(InetAddress.getLocalHost().getHostAddress()).setServerPort(11235)
+ .setCriticalHeapPercentage(90.0f).setEvictionHeapPercentage(75.0f).setMaxConnections(100)
+ .setMaxMessageCount(512).setMaxThreads(8).setMessageTimeToLive(120000)
+ .setSocketBufferSize(32768).build();
+
+ 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.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);
+ 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();
+ }
+
+ @Test
+ public void buildUsesMemberNameSetInApiProperties() throws Exception {
+ ServerLauncher launcher =
+ new Builder().setCommand(ServerLauncher.Command.START).set(NAME, "serverABC").build();
+
+ assertThat(launcher.getMemberName()).isNull();
+ assertThat(launcher.getProperties().getProperty(NAME)).isEqualTo("serverABC");
+ }
+
+ @Test
+ public void buildUsesMemberNameSetInSystemProperties() throws Exception {
+ System.setProperty(DistributionConfig.GEMFIRE_PREFIX + NAME, "serverXYZ");
+
+ ServerLauncher launcher = new Builder().setCommand(ServerLauncher.Command.START).build();
+
+ assertThat(launcher.getMemberName()).isNull();
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/894f3ee7/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherIntegrationTest.java b/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherIntegrationTest.java
index d3c1200..6ce9be6 100755
--- a/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherIntegrationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherIntegrationTest.java
@@ -17,14 +17,20 @@ package org.apache.geode.distributed;
import static com.googlecode.catchexception.apis.BDDCatchException.caughtException;
import static com.googlecode.catchexception.apis.BDDCatchException.when;
import static org.apache.geode.distributed.ConfigurationProperties.NAME;
+import static org.apache.geode.distributed.DistributedSystem.PROPERTIES_FILE_PROPERTY;
+import static org.apache.geode.distributed.internal.DistributionConfig.GEMFIRE_PREFIX;
+import static org.apache.geode.internal.cache.AbstractCacheServer.TEST_OVERRIDE_DEFAULT_PORT_PROPERTY;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.BDDAssertions.then;
-import org.apache.geode.distributed.ServerLauncher.Builder;
-import org.apache.geode.distributed.ServerLauncher.Command;
-import org.apache.geode.distributed.internal.DistributionConfig;
-import org.apache.geode.internal.i18n.LocalizedStrings;
-import org.apache.geode.test.junit.categories.IntegrationTest;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.net.InetAddress;
+import java.util.Properties;
+
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
@@ -32,19 +38,20 @@ import org.junit.experimental.categories.Category;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestName;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileWriter;
-import java.net.InetAddress;
-import java.util.Properties;
+import org.apache.geode.distributed.ServerLauncher.Builder;
+import org.apache.geode.distributed.ServerLauncher.Command;
+import org.apache.geode.internal.AvailablePortHelper;
+import org.apache.geode.internal.i18n.LocalizedStrings;
+import org.apache.geode.test.junit.categories.IntegrationTest;
/**
- * Integration tests for ServerLauncher class. These tests may require file system and/or network
- * I/O.
+ * Integration tests for using {@link ServerLauncher} as an in-process API within an existing JVM.
*/
@Category(IntegrationTest.class)
public class ServerLauncherIntegrationTest {
+ private static final String CURRENT_DIRECTORY = System.getProperty("user.dir");
+
@Rule
public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
@@ -55,222 +62,242 @@ public class ServerLauncherIntegrationTest {
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);
+ public void buildWithMemberNameSetInGemFireProperties() throws Exception {
+ // given: gemfire.properties containing a name
+ givenGemFirePropertiesFile(withMemberName());
+
+ // when: starting with null MemberName
+ ServerLauncher launcher = new Builder().setCommand(Command.START).build();
+
+ // then: name in gemfire.properties file should be used for MemberName
+ assertThat(launcher.getMemberName()).isNull(); // name will be read during start()
}
@Test
- public void testBuilderParseArgumentsWithValuesSeparatedWithCommas() throws Exception {
- // given a new builder and a directory
- String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+ public void buildWithoutMemberNameThrowsIllegalStateException() throws Exception {
+ // given: gemfire.properties with no name
+ givenGemFirePropertiesFile(withoutMemberName());
+
+ // when: no MemberName is specified
+ when(new Builder().setCommand(Command.START)).build();
+
+ // then: throw IllegalStateException
+ then(caughtException()).isExactlyInstanceOf(IllegalStateException.class)
+ .hasMessage(memberNameValidationErrorMessage());
+ }
+
+ @Test
+ public void buildWithWorkingDirectoryNotEqualToCurrentDirectoryThrowsIllegalStateException()
+ throws Exception {
+ // given: using LocatorLauncher in-process
+
+ // when: setting WorkingDirectory to non-current directory
+ when(new Builder().setCommand(Command.START).setMemberName("memberOne")
+ .setWorkingDirectory(getWorkingDirectoryPath())).build();
+
+ // then: throw IllegalStateException
+ then(caughtException()).isExactlyInstanceOf(IllegalStateException.class)
+ .hasMessage(workingDirectoryOptionNotValidErrorMessage());
+ }
+
+ @Test
+ public void parseArgumentsParsesValuesSeparatedByCommas() throws Exception {
+ // given: a new builder
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");
+ builder.parseArguments("start", "memberOne", "--server-bind-address",
+ InetAddress.getLocalHost().getHostAddress(), "--dir", getWorkingDirectoryPath(),
+ "--hostname-for-clients", "Tucows", "--pid", "1234", "--server-port", "11235",
+ "--redirect-output", "--force", "--debug");
// 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.getHostNameForClients()).isEqualTo("Tucows");
assertThat(builder.getPid().intValue()).isEqualTo(1234);
assertThat(builder.getServerBindAddress()).isEqualTo(InetAddress.getLocalHost());
assertThat(builder.getServerPort().intValue()).isEqualTo(11235);
+ assertThat(builder.getRedirectOutput()).isTrue();
+ assertThat(builder.getWorkingDirectory()).isEqualTo(getWorkingDirectoryPath());
}
@Test
- public void testBuilderParseArgumentsWithValuesSeparatedWithEquals() throws Exception {
- // given a new builder and a directory
- String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+ public void parseArgumentsParsesValuesSeparatedByEquals() throws Exception {
+ // given: a new builder
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");
+ // when: parsing arguments with values separated by equals
+ builder.parseArguments("start", "--dir=" + getWorkingDirectoryPath(),
+ "--server-port=" + "12345", "memberOne");
// 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.getDebug()).isFalse();
+ assertThat(builder.getForce()).isFalse();
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);
+ assertThat(builder.getHostNameForClients()).isNull();
+ assertThat(builder.getMemberName()).isEqualTo("memberOne");
+ assertThat(builder.getPid()).isNull();
+ assertThat(builder.getServerBindAddress()).isNull();
+ assertThat(builder.getServerPort().intValue()).isEqualTo(12345);
+ assertThat(builder.getWorkingDirectory()).isEqualTo(getWorkingDirectoryPath());
}
@Test
- public void testBuildWithMemberNameSetInGemFirePropertiesOnStart() throws Exception {
- // given: gemfire.properties with a name
- Properties gemfireProperties = new Properties();
- gemfireProperties.setProperty(NAME, "server123");
- useGemFirePropertiesFileInTemporaryFolder(DistributionConfig.GEMFIRE_PREFIX + "properties",
- gemfireProperties);
+ public void getWorkingDirectoryReturnsCurrentDirectoryByDefault() throws Exception {
+ // given:
- // when: starting with null MemberName
- ServerLauncher launcher = new Builder().setCommand(Command.START).build();
+ // when: not setting WorkingDirectory
- // then: name in gemfire.properties file should be used for MemberName
- assertThat(launcher).isNotNull();
- assertThat(launcher.getCommand()).isEqualTo(Command.START);
- assertThat(launcher.getMemberName()).isNull();
+ // then: getDirectory returns default
+ assertThat(new Builder().getWorkingDirectory()).isEqualTo(CURRENT_DIRECTORY);
}
@Test
- public void testBuildWithNoMemberNameOnStart() throws Exception {
- // given: gemfire.properties with no name
- useGemFirePropertiesFileInTemporaryFolder(DistributionConfig.GEMFIRE_PREFIX + "properties",
- new Properties());
+ public void setWorkingDirectoryToNullUsesCurrentDirectory() throws Exception {
+ // given: a new builder
+ Builder builder = new Builder();
- // when: no MemberName is specified
- when(new Builder().setCommand(Command.START)).build();
+ // when: setting WorkingDirectory to null
+ assertThat(builder.setWorkingDirectory(null)).isSameAs(builder);
- // then: throw IllegalStateException
- then(caughtException()).isExactlyInstanceOf(IllegalStateException.class)
- .hasMessage(LocalizedStrings.Launcher_Builder_MEMBER_NAME_VALIDATION_ERROR_MESSAGE
- .toLocalizedString("Server"));
+ // then: getDirectory returns default
+ assertThat(builder.getWorkingDirectory()).isEqualTo(CURRENT_DIRECTORY);
}
@Test
- public void testBuilderSetAndGetWorkingDirectory() throws Exception {
- // given: a new builder and a directory
- String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+ public void setWorkingDirectoryToEmptyStringUsesCurrentDirectory() throws Exception {
+ // given: a new builder
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);
+
+ // then: getDirectory returns default
+ assertThat(builder.getWorkingDirectory()).isEqualTo(CURRENT_DIRECTORY);
+ }
+
+ @Test
+ public void setWorkingDirectoryToBlankStringUsesCurrentDirectory() throws Exception {
+ // given: a new builder
+ Builder builder = new Builder();
// when: setting WorkingDirectory to white space
assertThat(builder.setWorkingDirectory(" ")).isSameAs(builder);
- // then: getWorkingDirectory returns default
- assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY);
+
+ // then: getDirectory returns default
+ assertThat(builder.getWorkingDirectory()).isEqualTo(CURRENT_DIRECTORY);
+ }
+
+ @Test
+ public void setWorkingDirectoryToExistingDirectory() throws Exception {
+ // given: a new builder
+ Builder builder = new Builder();
// when: setting WorkingDirectory to a directory
- assertThat(builder.setWorkingDirectory(rootFolder)).isSameAs(builder);
- // then: getWorkingDirectory returns that directory
- assertThat(builder.getWorkingDirectory()).isEqualTo(rootFolder);
+ assertThat(builder.setWorkingDirectory(getWorkingDirectoryPath())).isSameAs(builder);
- // when: setting WorkingDirectory to null (again)
- assertThat(builder.setWorkingDirectory(null)).isSameAs(builder);
- // then: getWorkingDirectory returns default
- assertThat(builder.getWorkingDirectory()).isEqualTo(AbstractLauncher.DEFAULT_WORKING_DIRECTORY);
+ // then: getDirectory returns that directory
+ assertThat(builder.getWorkingDirectory()).isEqualTo(getWorkingDirectoryPath());
}
@Test
- public void testBuilderSetWorkingDirectoryToFile() throws Exception {
+ public void setWorkingDirectoryToExistingFileThrowsIllegalArgumentException() throws Exception {
// given: a file instead of a directory
- File tmpFile = this.temporaryFolder.newFile();
+ File nonDirectory = temporaryFolder.newFile();
// when: setting WorkingDirectory to that file
- when(new Builder()).setWorkingDirectory(tmpFile.getAbsolutePath());
+ when(new Builder()).setWorkingDirectory(nonDirectory.getCanonicalPath());
// then: throw IllegalArgumentException
- then(caughtException())
- .hasMessage(LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_NOT_FOUND_ERROR_MESSAGE
- .toLocalizedString("Server"))
- .hasCause(new FileNotFoundException(tmpFile.getAbsolutePath()));
+ then(caughtException()).isExactlyInstanceOf(IllegalArgumentException.class)
+ .hasMessage(workingDirectoryNotFoundErrorMessage())
+ .hasCause(new FileNotFoundException(nonDirectory.getCanonicalPath()));
}
@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();
+ public void setWorkingDirectoryToNonExistingDirectory() throws Exception {
+ // given:
- // 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"))
+ then(caughtException()).isExactlyInstanceOf(IllegalArgumentException.class)
+ .hasMessage(workingDirectoryNotFoundErrorMessage())
.hasCause(new FileNotFoundException("/path/to/non_existing/directory"));
}
+ @Test
+ public void serverPortCanBeOverriddenBySystemProperty() throws Exception {
+ // given: overridden default port
+ int overriddenPort = AvailablePortHelper.getRandomAvailableTCPPort();
+ System.setProperty(TEST_OVERRIDE_DEFAULT_PORT_PROPERTY, String.valueOf(overriddenPort));
+
+ // when: creating new ServerLauncher
+ ServerLauncher launcher = new Builder().build();
+
+ // then: server port should be the overridden default port
+ assertThat(launcher.getServerPort()).isEqualTo(overriddenPort);
+ }
+
+ private String memberNameValidationErrorMessage() {
+ return LocalizedStrings.Launcher_Builder_MEMBER_NAME_VALIDATION_ERROR_MESSAGE
+ .toLocalizedString("Server");
+ }
+
+ private String workingDirectoryOptionNotValidErrorMessage() {
+ return LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_OPTION_NOT_VALID_ERROR_MESSAGE
+ .toLocalizedString("Server");
+ }
+
+ private String workingDirectoryNotFoundErrorMessage() {
+ return LocalizedStrings.Launcher_Builder_WORKING_DIRECTORY_NOT_FOUND_ERROR_MESSAGE
+ .toLocalizedString("Server");
+ }
+
+ private File getWorkingDirectory() {
+ return temporaryFolder.getRoot();
+ }
+
+ private String getWorkingDirectoryPath() {
+ try {
+ return temporaryFolder.getRoot().getCanonicalPath();
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+
+ private Properties withoutMemberName() {
+ return new Properties();
+ }
+
+ private Properties withMemberName() {
+ Properties properties = new Properties();
+ properties.setProperty(NAME, "locator123");
+ return properties;
+ }
+
/**
* 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
+ * <ol>
+ * <li>creates gemfire.properties in <code>temporaryFolder</code></li>
+ * <li>writes config to the file</li>
+ * <li>sets "gemfirePropertyFile" system property</li>
+ * </ol>
*/
- 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();
+ private void givenGemFirePropertiesFile(final Properties config) {
+ try {
+ String name = GEMFIRE_PREFIX + "properties";
+ File file = new File(getWorkingDirectory(), name);
+ config.store(new FileWriter(file, false), testName.getMethodName());
+ assertThat(file).isFile().exists();
+
+ System.setProperty(PROPERTIES_FILE_PROPERTY, file.getCanonicalPath());
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/894f3ee7/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherIntegrationTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherIntegrationTestCase.java b/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherIntegrationTestCase.java
new file mode 100755
index 0000000..ed443f5
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherIntegrationTestCase.java
@@ -0,0 +1,204 @@
+/*
+ * 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 org.apache.geode.distributed;
+
+import static java.util.concurrent.TimeUnit.MINUTES;
+import static org.apache.geode.distributed.ConfigurationProperties.CACHE_XML_FILE;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.distributed.internal.DistributionConfig.GEMFIRE_PREFIX;
+import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts;
+import static org.apache.geode.internal.cache.AbstractCacheServer.TEST_OVERRIDE_DEFAULT_PORT_PROPERTY;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.UncheckedIOException;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.rules.ErrorCollector;
+
+import org.apache.geode.cache.DataPolicy;
+import org.apache.geode.cache.Scope;
+import org.apache.geode.distributed.AbstractLauncher.Status;
+import org.apache.geode.distributed.ServerLauncher.Builder;
+import org.apache.geode.distributed.ServerLauncher.ServerState;
+import org.apache.geode.internal.cache.xmlcache.CacheCreation;
+import org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator;
+import org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation;
+import org.apache.geode.internal.process.ProcessType;
+
+/**
+ * Abstract base class for integration tests of {@link ServerLauncher}.
+ *
+ * @since GemFire 8.0
+ */
+public abstract class ServerLauncherIntegrationTestCase extends LauncherIntegrationTestCase {
+
+ protected volatile int defaultServerPort;
+ protected volatile int nonDefaultServerPort;
+ protected volatile int unusedServerPort;
+ protected volatile ServerLauncher launcher;
+ protected volatile String workingDirectory;
+ protected volatile File cacheXmlFile;
+
+ @Rule
+ public ErrorCollector errorCollector = new ErrorCollector();
+
+ @Before
+ public void setUpAbstractServerLauncherIntegrationTestCase() throws Exception {
+ System.setProperty(GEMFIRE_PREFIX + MCAST_PORT, Integer.toString(0));
+
+ workingDirectory = temporaryFolder.getRoot().getCanonicalPath();
+
+ int[] ports = getRandomAvailableTCPPorts(3);
+ defaultServerPort = ports[0];
+ nonDefaultServerPort = ports[1];
+ unusedServerPort = ports[2];
+ System.setProperty(TEST_OVERRIDE_DEFAULT_PORT_PROPERTY, String.valueOf(defaultServerPort));
+ }
+
+ @After
+ public void tearDownAbstractServerLauncherIntegrationTestCase() throws Exception {
+ if (launcher != null) {
+ launcher.stop();
+ }
+ }
+
+ @Override
+ protected ProcessType getProcessType() {
+ return ProcessType.SERVER;
+ }
+
+ protected ServerLauncher awaitStart(final ServerLauncher launcher) {
+ await().atMost(2, MINUTES).until(() -> assertThat(isLauncherOnline()).isTrue());
+ return launcher;
+ }
+
+ protected ServerLauncher awaitStart(final Builder builder) {
+ launcher = builder.build();
+ assertThat(launcher.start().getStatus()).isEqualTo(Status.ONLINE);
+ return awaitStart(launcher);
+ }
+
+ /**
+ * Returns a new Builder with helpful defaults for safe testing. If you need a Builder in a test
+ * without any of these defaults then simply use {@code new Builder()} instead.
+ */
+ protected Builder newBuilder() {
+ return new Builder().setMemberName(getUniqueName()).setRedirectOutput(true)
+ .setWorkingDirectory(getWorkingDirectoryPath()).set(LOG_LEVEL, "config")
+ .set(MCAST_PORT, "0");
+ }
+
+ protected ServerLauncher givenServerLauncher() {
+ return givenServerLauncher(newBuilder());
+ }
+
+ protected ServerLauncher givenServerLauncher(final Builder builder) {
+ return builder.build();
+ }
+
+ protected ServerLauncher givenRunningServer() {
+ return givenRunningServer(newBuilder());
+ }
+
+ protected ServerLauncher givenRunningServer(final Builder builder) {
+ return awaitStart(builder);
+ }
+
+ protected ServerLauncher startServer() {
+ return awaitStart(newBuilder());
+ }
+
+ protected ServerLauncher startServer(final Builder builder) {
+ return awaitStart(builder);
+ }
+
+ protected File givenCacheXmlFileWithServerPort(final int cacheXmlPort) {
+ try {
+ cacheXmlFile = writeCacheXml(cacheXmlPort);
+ System.setProperty(CACHE_XML_FILE, cacheXmlFile.getCanonicalPath());
+ return cacheXmlFile;
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+
+ protected File givenCacheXmlFile() {
+ try {
+ cacheXmlFile = writeCacheXml();
+ System.setProperty(CACHE_XML_FILE, cacheXmlFile.getCanonicalPath());
+ return cacheXmlFile;
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+
+ protected File getCacheXmlFile() {
+ return cacheXmlFile;
+ }
+
+ protected String getCacheXmlFilePath() {
+ try {
+ return cacheXmlFile.getCanonicalPath();
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+
+ private File writeCacheXml(final int serverPort) throws IOException {
+ CacheCreation creation = new CacheCreation();
+ RegionAttributesCreation attrs = new RegionAttributesCreation(creation);
+ attrs.setScope(Scope.DISTRIBUTED_ACK);
+ attrs.setDataPolicy(DataPolicy.REPLICATE);
+ creation.createRegion(getUniqueName(), attrs);
+ creation.addCacheServer().setPort(serverPort);
+
+ File cacheXmlFile = new File(getWorkingDirectory(), getUniqueName() + ".xml");
+ PrintWriter pw = new PrintWriter(new FileWriter(cacheXmlFile), true);
+ CacheXmlGenerator.generate(creation, pw);
+ pw.close();
+
+ return cacheXmlFile;
+ }
+
+ private File writeCacheXml() throws IOException {
+ CacheCreation creation = new CacheCreation();
+ RegionAttributesCreation attrs = new RegionAttributesCreation(creation);
+ attrs.setScope(Scope.DISTRIBUTED_ACK);
+ attrs.setDataPolicy(DataPolicy.REPLICATE);
+ creation.createRegion(getUniqueName(), attrs);
+ creation.addCacheServer();
+
+ File cacheXmlFile = new File(getWorkingDirectory(), getUniqueName() + ".xml");
+ PrintWriter pw = new PrintWriter(new FileWriter(cacheXmlFile), true);
+ CacheXmlGenerator.generate(creation, pw);
+ pw.close();
+
+ return cacheXmlFile;
+ }
+
+ private boolean isLauncherOnline() {
+ ServerState serverState = launcher.status();
+ assertNotNull(serverState);
+ return Status.ONLINE.equals(serverState.getStatus());
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/894f3ee7/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherLocalFileIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherLocalFileIntegrationTest.java b/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherLocalFileIntegrationTest.java
index 0955465..84545f4 100755
--- a/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherLocalFileIntegrationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/distributed/ServerLauncherLocalFileIntegrationTest.java
@@ -14,20 +14,19 @@
*/
package org.apache.geode.distributed;
-import static org.junit.Assert.*;
+import static org.assertj.core.api.Assertions.assertThat;
-import org.junit.After;
import org.junit.Before;
-import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.apache.geode.internal.process.ProcessControllerFactory;
import org.apache.geode.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.
+ * Integration tests for using {@link ServerLauncher} as an in-process API within an existing JVM.
+ *
+ * Sets {@link ProcessControllerFactory#PROPERTY_DISABLE_ATTACH_API} to force {@code ServerLauncher}
+ * to use the FileProcessController implementation.
*
* @since GemFire 8.0
*/
@@ -35,17 +34,8 @@ import org.apache.geode.test.junit.categories.IntegrationTest;
public class ServerLauncherLocalFileIntegrationTest extends ServerLauncherLocalIntegrationTest {
@Before
- public final void setUpServerLauncherLocalFileTest() throws Exception {
+ public 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());
+ assertThat(new ProcessControllerFactory().isAttachAPIFound()).isFalse();
}
}