You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ji...@apache.org on 2019/04/05 15:08:25 UTC
[geode] branch develop updated: GEODE-5971: describe member failed
to display multiple cache servers (#3409)
This is an automated email from the ASF dual-hosted git repository.
jinmeiliao pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new a8eb419 GEODE-5971: describe member failed to display multiple cache servers (#3409)
a8eb419 is described below
commit a8eb419df9502e48c55bd083557c717df9a0fb4d
Author: jinmeiliao <ji...@pivotal.io>
AuthorDate: Fri Apr 5 08:08:15 2019 -0700
GEODE-5971: describe member failed to display multiple cache servers (#3409)
* add support for multiple cache servers in ServerStartupRule
---
.../commands/DescribeMembersCommandDUnitTest.java | 36 +++++++++----------
.../cli/commands/DescribeMemberCommand.java | 22 ++++++------
.../geode/test/junit/rules/ServerStarterRule.java | 42 +++++++++++++++++-----
3 files changed, 63 insertions(+), 37 deletions(-)
diff --git a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/DescribeMembersCommandDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/DescribeMembersCommandDUnitTest.java
index f433f85..da62f8c 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/DescribeMembersCommandDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/DescribeMembersCommandDUnitTest.java
@@ -28,6 +28,7 @@ import org.junit.experimental.categories.Category;
import org.apache.geode.management.internal.cli.result.CommandResult;
import org.apache.geode.test.dunit.rules.ClusterStartupRule;
import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.assertions.CommandResultAssert;
import org.apache.geode.test.junit.categories.JMXTest;
import org.apache.geode.test.junit.rules.GfshCommandRule;
@@ -43,7 +44,8 @@ public class DescribeMembersCommandDUnitTest {
@BeforeClass
public static void setup() throws Exception {
locator = lsRule.startLocatorVM(0);
- lsRule.startServerVM(1, locator.getPort());
+ int locatorPort = locator.getPort();
+ lsRule.startServerVM(1, s -> s.withConnectionToLocator(locatorPort).withServerCount(2));
}
@Test
@@ -81,25 +83,21 @@ public class DescribeMembersCommandDUnitTest {
@Test
public void describeServer() throws Exception {
gfsh.connectAndVerify(locator);
- CommandResult result = gfsh.executeAndAssertThat(DESCRIBE_MEMBER + " --name=server-1")
- .statusIsSuccess()
- .getCommandResult();
+ CommandResultAssert commandAssert =
+ gfsh.executeAndAssertThat(DESCRIBE_MEMBER + " --name=server-1").statusIsSuccess();
- Map<String, String> memberInfo = result.getMapFromSection("memberInfo");
- assertThat(memberInfo.get("Name")).isEqualTo("server-1");
- assertThat(memberInfo.get("Id")).contains("server-1");
- assertThat(memberInfo.get("Host")).as("Host").isNotBlank();
- assertThat(memberInfo.get("PID")).as("PID").isNotBlank();
- assertThat(memberInfo.get("Used Heap")).as("Used Heap").isNotBlank();
- assertThat(memberInfo.get("Max Heap")).as("Max Heap").isNotBlank();
- assertThat(memberInfo.get("Working Dir")).as("Working Dir").isNotBlank();
- assertThat(memberInfo.get("Log file")).as("Log File").isNotBlank();
- assertThat(memberInfo.get("Locators")).as("Locators").isNotBlank();
+ commandAssert.hasDataSection("memberInfo").hasContent()
+ .containsEntry("Name", "server-1")
+ .containsKeys("Id", "Host", "PID", "Used Heap", "Max Heap", "Working Dir", "Log file",
+ "Locators");
+
+ commandAssert.hasDataSection("connectionInfo").hasContent()
+ .containsEntry("Client Connections", "0");
+
+ commandAssert.hasDataSection("serverInfo0").hasContent()
+ .containsKeys("Server Bind", "Server Port", "Running");
- Map<String, String> cacheServerInfo = result.getMapFromSection("connectionInfo");
- assertThat(cacheServerInfo.get("Server Bind")).as("Server Bind").isBlank();
- assertThat(cacheServerInfo.get("Server Port")).as("Server Port").isNotBlank();
- assertThat(cacheServerInfo.get("Running")).as("Running").isEqualTo("true");
- assertThat(cacheServerInfo.get("Client Connections")).as("Client Connections").isEqualTo("0");
+ commandAssert.hasDataSection("serverInfo1").hasContent()
+ .containsKeys("Server Bind", "Server Port", "Running");
}
}
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DescribeMemberCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DescribeMemberCommand.java
index 919efbb..26aa3ac 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DescribeMemberCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DescribeMemberCommand.java
@@ -16,7 +16,6 @@
package org.apache.geode.management.internal.cli.commands;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
@@ -87,17 +86,20 @@ public class DescribeMemberCommand extends GfshCommand {
if (memberInformation.isServer()) {
List<CacheServerInfo> csList = memberInformation.getCacheServeInfo();
if (csList != null) {
- DataResultModel connectionInfo = result.addData("connectionInfo");
- Iterator<CacheServerInfo> iters = csList.iterator();
- connectionInfo.setHeader("Cache Server Information");
-
- while (iters.hasNext()) {
- CacheServerInfo cacheServerInfo = iters.next();
- connectionInfo.addData("Server Bind", cacheServerInfo.getBindAddress());
- connectionInfo.addData("Server Port", cacheServerInfo.getPort());
- connectionInfo.addData("Running", cacheServerInfo.isRunning());
+ int serverCount = 0;
+ for (CacheServerInfo cacheServerInfo : csList) {
+ DataResultModel serverInfo = result.addData("serverInfo" + serverCount++);
+ if (csList.size() == 1) {
+ serverInfo.setHeader("Cache Server Information");
+ } else {
+ serverInfo.setHeader("Cache Server " + serverCount + " Information");
+ }
+ serverInfo.addData("Server Bind", cacheServerInfo.getBindAddress());
+ serverInfo.addData("Server Port", cacheServerInfo.getPort());
+ serverInfo.addData("Running", cacheServerInfo.isRunning());
}
+ DataResultModel connectionInfo = result.addData("connectionInfo");
connectionInfo.addData("Client Connections", memberInformation.getClientCount());
}
}
diff --git a/geode-dunit/src/main/java/org/apache/geode/test/junit/rules/ServerStarterRule.java b/geode-dunit/src/main/java/org/apache/geode/test/junit/rules/ServerStarterRule.java
index 6f46b0b..cbe4ea7 100644
--- a/geode-dunit/src/main/java/org/apache/geode/test/junit/rules/ServerStarterRule.java
+++ b/geode-dunit/src/main/java/org/apache/geode/test/junit/rules/ServerStarterRule.java
@@ -19,7 +19,9 @@ import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_
import static org.apache.geode.distributed.ConfigurationProperties.START_DEV_REST_API;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -54,14 +56,15 @@ import org.apache.geode.pdx.PdxSerializer;
*/
public class ServerStarterRule extends MemberStarterRule<ServerStarterRule> implements Server {
private transient InternalCache cache;
- private transient CacheServer server;
+ private transient List<CacheServer> servers = new ArrayList<>();
private int embeddedLocatorPort = -1;
private boolean pdxPersistent = false;
private boolean pdxPersistentUserSet = false;
private PdxSerializer pdxSerializer = null;
private boolean pdxReadSerialized = false;
private boolean pdxReadSerializedUserSet = false;
- private boolean noCacheServer = false;
+ // By default we start one server per jvm
+ private int serverCount = 1;
private Map<String, RegionShortcut> regions = new HashMap<>();
@@ -72,7 +75,11 @@ public class ServerStarterRule extends MemberStarterRule<ServerStarterRule> impl
@Override
public CacheServer getServer() {
- return server;
+ return servers.get(0);
+ }
+
+ public List<CacheServer> getServers() {
+ return servers;
}
@Override
@@ -89,6 +96,9 @@ public class ServerStarterRule extends MemberStarterRule<ServerStarterRule> impl
@Override
public void stopMember() {
+ for (CacheServer server : servers) {
+ server.stop();
+ }
// make sure this cache is the one currently open. A server cache can be recreated due to
// importing a new set of cluster configuration.
cache = GemFireCacheImpl.getInstance();
@@ -100,7 +110,7 @@ public class ServerStarterRule extends MemberStarterRule<ServerStarterRule> impl
cache = null;
}
}
- server = null;
+ servers.clear();
}
public ServerStarterRule withPDXPersistent() {
@@ -124,7 +134,12 @@ public class ServerStarterRule extends MemberStarterRule<ServerStarterRule> impl
* If your only needs a cache and does not need a server for clients to connect
*/
public ServerStarterRule withNoCacheServer() {
- this.noCacheServer = true;
+ this.serverCount = 0;
+ return this;
+ }
+
+ public ServerStarterRule withServerCount(int serverCount) {
+ this.serverCount = serverCount;
return this;
}
@@ -185,17 +200,28 @@ public class ServerStarterRule extends MemberStarterRule<ServerStarterRule> impl
jmxPort = config.getJmxManagerPort();
httpPort = config.getHttpServicePort();
- if (!noCacheServer) {
- server = cache.addCacheServer();
+ if (serverCount > 1 && memberPort != 0) {
+ throw new IllegalStateException("can't specify a member port when you have multiple port");
+ }
+
+ for (int i = 0; i < serverCount; i++) {
+ CacheServer server = cache.addCacheServer();
// memberPort is by default zero, which translates to "randomly select an available port,"
// which is why it is updated after this try block
- server.setPort(memberPort);
+ if (serverCount == 1) {
+ server.setPort(memberPort);
+ } else {
+ server.setPort(0);
+ }
try {
server.start();
} catch (IOException e) {
throw new RuntimeException("unable to start server", e);
}
+ // if this member has multiple cache servers, the memberPort will be the last server's port
+ // started.
memberPort = server.getPort();
+ servers.add(server);
}
}