You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by sa...@apache.org on 2018/04/24 16:47:21 UTC

[geode] branch develop updated: GEODE-5070: Use a random member for describe & list jdbc connector commands (#1849)

This is an automated email from the ASF dual-hosted git repository.

sai_boorlagadda 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 2dcc082  GEODE-5070: Use a random member for describe & list jdbc connector commands (#1849)
2dcc082 is described below

commit 2dcc0820e823bf06e2b412c059e9d2d7d11cc4ca
Author: Sai Boorlagadda <sa...@gmail.com>
AuthorDate: Tue Apr 24 09:47:17 2018 -0700

    GEODE-5070: Use a random member for describe & list jdbc connector commands (#1849)
    
             Retrieves connections & mappings from CC(if running)
             or from a random member(if CC not running)
---
 .../internal/cli/DescribeConnectionCommand.java    | 76 +++++++++-----------
 .../jdbc/internal/cli/DescribeMappingCommand.java  | 60 +++++++---------
 .../jdbc/internal/cli/ListConnectionCommand.java   | 55 ++++++--------
 .../jdbc/internal/cli/ListMappingCommand.java      | 54 ++++++--------
 .../cli/DescribeConnectionCommandDUnitTest.java    | 70 +++++++++++-------
 .../cli/DescribeConnectionCommandTest.java         | 59 ++++++++-------
 .../cli/DescribeMappingCommandDUnitTest.java       | 68 +++++++++++-------
 .../internal/cli/DescribeMappingCommandTest.java   | 54 ++++++++------
 .../cli/ListConnectionCommandDUnitTest.java        | 79 +++++++++-----------
 .../internal/cli/ListConnectionCommandTest.java    | 48 +++++++------
 .../internal/cli/ListMappingCommandDUnitTest.java  | 84 +++++++++-------------
 .../jdbc/internal/cli/ListMappingCommandTest.java  | 50 +++++++------
 12 files changed, 382 insertions(+), 375 deletions(-)

diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeConnectionCommand.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeConnectionCommand.java
index 07ea5c8..0347c05 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeConnectionCommand.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeConnectionCommand.java
@@ -21,6 +21,7 @@ import static org.apache.geode.connectors.jdbc.internal.cli.CreateConnectionComm
 import static org.apache.geode.connectors.jdbc.internal.cli.CreateConnectionCommand.CREATE_CONNECTION__USER;
 
 import java.util.List;
+import java.util.Set;
 
 import org.apache.logging.log4j.Logger;
 import org.springframework.shell.core.annotation.CliCommand;
@@ -32,7 +33,6 @@ import org.apache.geode.distributed.ClusterConfigurationService;
 import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.internal.logging.LogService;
 import org.apache.geode.management.cli.CliMetaData;
-import org.apache.geode.management.cli.ConverterHint;
 import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.internal.cli.commands.InternalGfshCommand;
 import org.apache.geode.management.internal.cli.exceptions.EntityNotFoundException;
@@ -46,13 +46,10 @@ import org.apache.geode.security.ResourcePermission;
 public class DescribeConnectionCommand extends InternalGfshCommand {
   private static Logger logger = LogService.getLogger();
   static final String DESCRIBE_CONNECTION = "describe jdbc-connection";
-  static final String DESCRIBE_CONNECTION__HELP =
-      "Describe the specified jdbc connection found in cluster configuration.";
+  static final String DESCRIBE_CONNECTION__HELP = "Describe the specified jdbc connection.";
   static final String DESCRIBE_CONNECTION__NAME = "name";
   static final String DESCRIBE_CONNECTION__NAME__HELP =
       "Name of the jdbc connection to be described.";
-  static final String DESCRIBE_CONNECTION_MEMBER__HELP =
-      "Member(s) from which the specified jdbc connections is retrieved.";
 
   static final String OBSCURED_PASSWORD = "********";
   static final String RESULT_SECTION_NAME = "ConnectionDescription";
@@ -61,42 +58,32 @@ public class DescribeConnectionCommand extends InternalGfshCommand {
   @CliMetaData(relatedTopic = CliStrings.DEFAULT_TOPIC_GEODE)
   @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER,
       operation = ResourcePermission.Operation.MANAGE)
-  public Result describeConnection(
-      @CliOption(key = DESCRIBE_CONNECTION__NAME, mandatory = true,
-          help = DESCRIBE_CONNECTION__NAME__HELP) String name,
-      @CliOption(key = {CliStrings.MEMBER}, optionContext = ConverterHint.MEMBERIDNAME,
-          help = DESCRIBE_CONNECTION_MEMBER__HELP) String onMember) {
+  public Result describeConnection(@CliOption(key = DESCRIBE_CONNECTION__NAME, mandatory = true,
+      help = DESCRIBE_CONNECTION__NAME__HELP) String name) {
+    ConnectorService.Connection connection = null;
 
-    // when member is specified, we go to each member and describe what are on the members
-    if (onMember != null) {
-      DistributedMember member = getMember(onMember);
-      if (member == null) {
-        return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
+    // check if CC is available and use it to describe the connection
+    ClusterConfigurationService ccService = getConfigurationService();
+    if (ccService != null) {
+      ConnectorService service =
+          ccService.getCustomCacheElement("cluster", "connector-service", ConnectorService.class);
+      if (service != null) {
+        connection = CacheElement.findElement(service.getConnection(), name);
+      }
+    } else {
+      // otherwise get it from any member
+      Set<DistributedMember> members = findMembers(null, null);
+      if (members.size() > 0) {
+        DistributedMember targetMember = members.iterator().next();
+        List<?> result =
+            (List<?>) executeFunction(new DescribeConnectionFunction(), name, targetMember)
+                .getResult();
+        if (!result.isEmpty()) {
+          connection = (ConnectorService.Connection) result.get(0);
+        }
       }
-
-      List<?> result =
-          (List<?>) executeFunction(new DescribeConnectionFunction(), name, member).getResult();
-      ConnectorService.Connection connection = (ConnectorService.Connection) result.get(0);
-      CompositeResultData resultData = ResultBuilder.createCompositeResultData();
-      fillResultData(connection, resultData);
-
-      return ResultBuilder.buildResult(resultData);
     }
 
-    // otherwise, use cluster configuration to describe the connections
-    ClusterConfigurationService ccService = getConfigurationService();
-    if (ccService == null) {
-      return ResultBuilder.createInfoResult(
-          "cluster configuration service is not running. Use --member option to describe connections on specific members.");
-    }
-    // search for the connection that has this id to see if it exists
-    ConnectorService service =
-        ccService.getCustomCacheElement("cluster", "connector-service", ConnectorService.class);
-    if (service == null) {
-      throw new EntityNotFoundException("connection named '" + name + "' not found");
-    }
-    ConnectorService.Connection connection =
-        CacheElement.findElement(service.getConnection(), name);
     if (connection == null) {
       throw new EntityNotFoundException("connection named '" + name + "' not found");
     }
@@ -106,21 +93,22 @@ public class DescribeConnectionCommand extends InternalGfshCommand {
     return ResultBuilder.buildResult(resultData);
   }
 
-  private void fillResultData(ConnectorService.Connection config, CompositeResultData resultData) {
+  private void fillResultData(ConnectorService.Connection connection,
+      CompositeResultData resultData) {
     CompositeResultData.SectionResultData sectionResult =
         resultData.addSection(RESULT_SECTION_NAME);
     sectionResult.addSeparator('-');
-    sectionResult.addData(CREATE_CONNECTION__NAME, config.getName());
-    sectionResult.addData(CREATE_CONNECTION__URL, config.getUrl());
-    if (config.getUser() != null) {
-      sectionResult.addData(CREATE_CONNECTION__USER, config.getUser());
+    sectionResult.addData(CREATE_CONNECTION__NAME, connection.getName());
+    sectionResult.addData(CREATE_CONNECTION__URL, connection.getUrl());
+    if (connection.getUser() != null) {
+      sectionResult.addData(CREATE_CONNECTION__USER, connection.getUser());
     }
-    if (config.getPassword() != null) {
+    if (connection.getPassword() != null) {
       sectionResult.addData(CREATE_CONNECTION__PASSWORD, OBSCURED_PASSWORD);
     }
     TabularResultData tabularResultData = sectionResult.addTable(CREATE_CONNECTION__PARAMS);
     tabularResultData.setHeader("Additional connection parameters:");
-    config.getParameterMap().entrySet().forEach((entry) -> {
+    connection.getParameterMap().entrySet().forEach((entry) -> {
       tabularResultData.accumulate("Param Name", entry.getKey());
       tabularResultData.accumulate("Value", entry.getValue());
     });
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingCommand.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingCommand.java
index 49fd133..aac317e 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingCommand.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingCommand.java
@@ -21,6 +21,7 @@ import static org.apache.geode.connectors.jdbc.internal.cli.CreateMappingCommand
 import static org.apache.geode.connectors.jdbc.internal.cli.CreateMappingCommand.CREATE_MAPPING__VALUE_CONTAINS_PRIMARY_KEY;
 
 import java.util.List;
+import java.util.Set;
 
 import org.springframework.shell.core.annotation.CliCommand;
 import org.springframework.shell.core.annotation.CliOption;
@@ -30,7 +31,6 @@ import org.apache.geode.connectors.jdbc.internal.configuration.ConnectorService;
 import org.apache.geode.distributed.ClusterConfigurationService;
 import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.management.cli.CliMetaData;
-import org.apache.geode.management.cli.ConverterHint;
 import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.internal.cli.commands.InternalGfshCommand;
 import org.apache.geode.management.internal.cli.exceptions.EntityNotFoundException;
@@ -43,12 +43,10 @@ import org.apache.geode.security.ResourcePermission;
 
 public class DescribeMappingCommand extends InternalGfshCommand {
   static final String DESCRIBE_MAPPING = "describe jdbc-mapping";
-  static final String DESCRIBE_MAPPING__HELP = "Describe the jdbc mapping in cluster configuration";
+  static final String DESCRIBE_MAPPING__HELP = "Describe the specified jdbc mapping";
   static final String DESCRIBE_MAPPING__REGION_NAME = "region";
   static final String DESCRIBE_MAPPING__REGION_NAME__HELP =
       "Region name of the jdbc mapping to be described.";
-  static final String DESCRIBE_MAPPING_MEMBER__HELP =
-      "Member(s) from which the specified jdbc mapping is retrieved.";
 
   static final String RESULT_SECTION_NAME = "MappingDescription";
   static final String FIELD_TO_COLUMN_TABLE = "fieldToColumnTable";
@@ -57,42 +55,32 @@ public class DescribeMappingCommand extends InternalGfshCommand {
   @CliMetaData(relatedTopic = CliStrings.DEFAULT_TOPIC_GEODE)
   @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER,
       operation = ResourcePermission.Operation.MANAGE)
-  public Result describeMapping(
-      @CliOption(key = DESCRIBE_MAPPING__REGION_NAME, mandatory = true,
-          help = DESCRIBE_MAPPING__REGION_NAME__HELP) String regionName,
-      @CliOption(key = {CliStrings.MEMBER}, optionContext = ConverterHint.MEMBERIDNAME,
-          help = DESCRIBE_MAPPING_MEMBER__HELP) String onMember) {
+  public Result describeMapping(@CliOption(key = DESCRIBE_MAPPING__REGION_NAME, mandatory = true,
+      help = DESCRIBE_MAPPING__REGION_NAME__HELP) String regionName) {
+    ConnectorService.RegionMapping mapping = null;
 
-    // when member is specified, we go to each member and describe what are on the members
-    if (onMember != null) {
-      DistributedMember member = getMember(onMember);
-      if (member == null) {
-        return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
+    // check if CC is available and use it to describe the connection
+    ClusterConfigurationService ccService = getConfigurationService();
+    if (ccService != null) {
+      ConnectorService service =
+          ccService.getCustomCacheElement("cluster", "connector-service", ConnectorService.class);
+      if (service != null) {
+        mapping = CacheElement.findElement(service.getRegionMapping(), regionName);
+      }
+    } else {
+      // otherwise get it from any member
+      Set<DistributedMember> members = findMembers(null, null);
+      if (members.size() > 0) {
+        DistributedMember targetMember = members.iterator().next();
+        List<?> result =
+            (List<?>) executeFunction(new DescribeMappingFunction(), regionName, targetMember)
+                .getResult();
+        if (!result.isEmpty()) {
+          mapping = (ConnectorService.RegionMapping) result.get(0);
+        }
       }
-
-      List<?> result =
-          (List<?>) executeFunction(new DescribeMappingFunction(), regionName, member).getResult();
-      ConnectorService.RegionMapping mapping = (ConnectorService.RegionMapping) result.get(0);
-      CompositeResultData resultData = ResultBuilder.createCompositeResultData();
-      fillResultData(mapping, resultData);
-
-      return ResultBuilder.buildResult(resultData);
     }
 
-    // otherwise, use cluster configuration to describe the connections
-    ClusterConfigurationService ccService = getConfigurationService();
-    if (ccService == null) {
-      return ResultBuilder.createInfoResult(
-          "cluster configuration service is not running. Use --member option to describe mappings on specific members.");
-    }
-    // search for the connection that has this id to see if it exists
-    ConnectorService service =
-        ccService.getCustomCacheElement("cluster", "connector-service", ConnectorService.class);
-    if (service == null) {
-      throw new EntityNotFoundException("mapping for region '" + regionName + "' not found");
-    }
-    ConnectorService.RegionMapping mapping =
-        CacheElement.findElement(service.getRegionMapping(), regionName);
     if (mapping == null) {
       throw new EntityNotFoundException("mapping for region '" + regionName + "' not found");
     }
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionCommand.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionCommand.java
index 79a2756..832e309 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionCommand.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionCommand.java
@@ -19,13 +19,11 @@ import java.util.List;
 import java.util.Set;
 
 import org.springframework.shell.core.annotation.CliCommand;
-import org.springframework.shell.core.annotation.CliOption;
 
 import org.apache.geode.connectors.jdbc.internal.configuration.ConnectorService;
 import org.apache.geode.distributed.ClusterConfigurationService;
 import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.management.cli.CliMetaData;
-import org.apache.geode.management.cli.ConverterHint;
 import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.internal.cli.commands.InternalGfshCommand;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
@@ -41,50 +39,43 @@ public class ListConnectionCommand extends InternalGfshCommand {
 
   static final String LIST_OF_CONNECTIONS = "List of connections";
   static final String NO_CONNECTIONS_FOUND = "No connections found";
-  static final String LIST_CONNECTION_MEMBER__HELP =
-      "Member from which the jdbc connections are retrieved.";
 
   @CliCommand(value = LIST_JDBC_CONNECTION, help = LIST_JDBC_CONNECTION__HELP)
   @CliMetaData(relatedTopic = CliStrings.DEFAULT_TOPIC_GEODE)
   @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER,
       operation = ResourcePermission.Operation.MANAGE)
-  public Result listConnection(
-      @CliOption(key = {CliStrings.MEMBER}, optionContext = ConverterHint.MEMBERIDNAME,
-          help = LIST_CONNECTION_MEMBER__HELP) String onMember) {
+  public Result listConnection() {
 
-    // when member is specified, we go to each member and describe what are on the members
-    if (onMember != null) {
-      DistributedMember member = getMember(onMember);
-      if (member == null) {
-        return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
-      }
-
-      List<?> result =
-          (List<?>) executeFunction(new ListConnectionFunction(), null, member).getResult();
-      Set<ConnectorService.Connection> connections =
-          (Set<ConnectorService.Connection>) result.get(0);
-      TabularResultData tabularResultData = ResultBuilder.createTabularResultData();
-      boolean connectionsExist = fillTabularResultData(connections, tabularResultData);
-
-      return createResult(tabularResultData, connectionsExist);
-    }
+    Collection<ConnectorService.Connection> connections = null;
 
-    // otherwise, use cluster configuration to describe the connections
+    // check if CC is available and use it to describe the connection
     ClusterConfigurationService ccService = getConfigurationService();
-    if (ccService == null) {
-      return ResultBuilder.createInfoResult(
-          "cluster configuration service is not running. Use --member option to describe connections on specific members.");
+    if (ccService != null) {
+      ConnectorService service =
+          ccService.getCustomCacheElement("cluster", "connector-service", ConnectorService.class);
+      if (service != null) {
+        connections = service.getConnection();
+      }
+    } else {
+      // otherwise get it from any member
+      Set<DistributedMember> members = findMembers(null, null);
+      if (members.size() > 0) {
+        DistributedMember targetMember = members.iterator().next();
+        List<?> result =
+            (List<?>) executeFunction(new ListConnectionFunction(), null, targetMember).getResult();
+        if (!result.isEmpty()) {
+          connections = (Set<ConnectorService.Connection>) result.get(0);
+        }
+      }
     }
 
-    ConnectorService service =
-        ccService.getCustomCacheElement("cluster", "connector-service", ConnectorService.class);
-    if (service == null) {
-      return ResultBuilder.createInfoResult(NO_CONNECTIONS_FOUND);
+    if (connections == null) {
+      return ResultBuilder.createInfoResult("No connections found");
     }
 
     // output
     TabularResultData tabularResultData = ResultBuilder.createTabularResultData();
-    boolean connectionsExist = fillTabularResultData(service.getConnection(), tabularResultData);
+    boolean connectionsExist = fillTabularResultData(connections, tabularResultData);
     return createResult(tabularResultData, connectionsExist);
   }
 
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/ListMappingCommand.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/ListMappingCommand.java
index a24ef67..c30fcb6 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/ListMappingCommand.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/ListMappingCommand.java
@@ -19,13 +19,11 @@ import java.util.List;
 import java.util.Set;
 
 import org.springframework.shell.core.annotation.CliCommand;
-import org.springframework.shell.core.annotation.CliOption;
 
 import org.apache.geode.connectors.jdbc.internal.configuration.ConnectorService;
 import org.apache.geode.distributed.ClusterConfigurationService;
 import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.management.cli.CliMetaData;
-import org.apache.geode.management.cli.ConverterHint;
 import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.internal.cli.commands.InternalGfshCommand;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
@@ -48,43 +46,37 @@ public class ListMappingCommand extends InternalGfshCommand {
   @CliMetaData(relatedTopic = CliStrings.DEFAULT_TOPIC_GEODE)
   @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER,
       operation = ResourcePermission.Operation.MANAGE)
-  public Result listMapping(
-      @CliOption(key = {CliStrings.MEMBER}, optionContext = ConverterHint.MEMBERIDNAME,
-          help = LIST_MAPPINGS_MEMBER__HELP) String onMember) {
+  public Result listMapping() {
+    Collection<ConnectorService.RegionMapping> mappings = null;
 
-    // when member is specified, we go to each member and describe what are on the members
-    if (onMember != null) {
-      DistributedMember member = getMember(onMember);
-      if (member == null) {
-        return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
-      }
-
-      List<?> result =
-          (List<?>) executeFunction(new ListMappingFunction(), null, member).getResult();
-      Set<ConnectorService.RegionMapping> mappings =
-          (Set<ConnectorService.RegionMapping>) result.get(0);
-      TabularResultData tabularResultData = ResultBuilder.createTabularResultData();
-      boolean connectionsExist = fillTabularResultData(mappings, tabularResultData);
-
-      return createResult(tabularResultData, connectionsExist);
-    }
-
-    // otherwise, use cluster configuration to describe the connections
+    // check if CC is available and use it to describe the connection
     ClusterConfigurationService ccService = getConfigurationService();
-    if (ccService == null) {
-      return ResultBuilder.createInfoResult(
-          "cluster configuration service is not running. Use --member option to describe mappings on specific members.");
+    if (ccService != null) {
+      ConnectorService service =
+          ccService.getCustomCacheElement("cluster", "connector-service", ConnectorService.class);
+      if (service != null) {
+        mappings = service.getRegionMapping();
+      }
+    } else {
+      // otherwise get it from any member
+      Set<DistributedMember> members = findMembers(null, null);
+      if (members.size() > 0) {
+        DistributedMember targetMember = members.iterator().next();
+        List<?> result =
+            (List<?>) executeFunction(new ListMappingFunction(), null, targetMember).getResult();
+        if (!result.isEmpty()) {
+          mappings = (Collection<ConnectorService.RegionMapping>) result.get(0);
+        }
+      }
     }
 
-    ConnectorService service =
-        ccService.getCustomCacheElement("cluster", "connector-service", ConnectorService.class);
-    if (service == null) {
-      return ResultBuilder.createInfoResult(NO_MAPPINGS_FOUND);
+    if (mappings == null) {
+      return ResultBuilder.createInfoResult("No mappings found");
     }
 
     // output
     TabularResultData tabularResultData = ResultBuilder.createTabularResultData();
-    boolean mappingsExist = fillTabularResultData(service.getRegionMapping(), tabularResultData);
+    boolean mappingsExist = fillTabularResultData(mappings, tabularResultData);
     return createResult(tabularResultData, mappingsExist);
   }
 
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeConnectionCommandDUnitTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeConnectionCommandDUnitTest.java
index 85a13da..c520b9e 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeConnectionCommandDUnitTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeConnectionCommandDUnitTest.java
@@ -22,12 +22,20 @@ import static org.apache.geode.connectors.jdbc.internal.cli.CreateConnectionComm
 import static org.apache.geode.connectors.jdbc.internal.cli.CreateConnectionCommand.CREATE_CONNECTION__USER;
 import static org.apache.geode.connectors.jdbc.internal.cli.DescribeConnectionCommand.DESCRIBE_CONNECTION;
 import static org.apache.geode.connectors.jdbc.internal.cli.DescribeConnectionCommand.DESCRIBE_CONNECTION__NAME;
+import static org.assertj.core.api.Assertions.assertThat;
 
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
+import java.io.Serializable;
+import java.util.Properties;
+
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
+import org.apache.geode.connectors.jdbc.internal.ConnectionConfigExistsException;
+import org.apache.geode.connectors.jdbc.internal.JdbcConnectorService;
+import org.apache.geode.connectors.jdbc.internal.configuration.ConnectorService;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.internal.cache.InternalCache;
 import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
 import org.apache.geode.test.dunit.rules.ClusterStartupRule;
 import org.apache.geode.test.dunit.rules.MemberVM;
@@ -36,20 +44,20 @@ import org.apache.geode.test.junit.categories.DistributedTest;
 import org.apache.geode.test.junit.rules.GfshCommandRule;
 
 @Category(DistributedTest.class)
-public class DescribeConnectionCommandDUnitTest {
+public class DescribeConnectionCommandDUnitTest implements Serializable {
 
   private static final String CONNECTION_NAME = "connectionName";
 
-  @ClassRule
-  public static GfshCommandRule gfsh = new GfshCommandRule();
+  @Rule
+  public transient GfshCommandRule gfsh = new GfshCommandRule();
 
-  @ClassRule
-  public static ClusterStartupRule startupRule = new ClusterStartupRule();
+  @Rule
+  public transient ClusterStartupRule startupRule = new ClusterStartupRule();
 
-  private static MemberVM locator, server;
+  private MemberVM locator, server;
 
-  @BeforeClass
-  public static void before() throws Exception {
+  @Test
+  public void describesExistingConnection() throws Exception {
     locator = startupRule.startLocatorVM(0);
     server = startupRule.startServerVM(1, locator.getPort());
 
@@ -63,12 +71,9 @@ public class DescribeConnectionCommandDUnitTest {
     csb.addOption(CREATE_CONNECTION__PARAMS, "key1:value1,key2:value2");
 
     gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess();
-  }
 
-  @Test
-  public void describesExistingConnection() {
-    CommandStringBuilder csb = new CommandStringBuilder(DESCRIBE_CONNECTION)
-        .addOption(DESCRIBE_CONNECTION__NAME, CONNECTION_NAME);
+    csb = new CommandStringBuilder(DESCRIBE_CONNECTION).addOption(DESCRIBE_CONNECTION__NAME,
+        CONNECTION_NAME);
 
     CommandResultAssert commandResultAssert = gfsh.executeAndAssertThat(csb.toString());
 
@@ -81,35 +86,48 @@ public class DescribeConnectionCommandDUnitTest {
     commandResultAssert.containsOutput("value1");
     commandResultAssert.containsOutput("key2");
     commandResultAssert.containsOutput("value2");
-
   }
 
   @Test
-  public void reportsNoConfigurationFound() {
+  public void reportsNoConfigurationFound() throws Exception {
+    locator = startupRule.startLocatorVM(0);
+    server = startupRule.startServerVM(1, locator.getPort());
+    gfsh.connectAndVerify(locator);
+
     CommandStringBuilder csb = new CommandStringBuilder(DESCRIBE_CONNECTION)
         .addOption(DESCRIBE_CONNECTION__NAME, "nonExisting");
 
     CommandResultAssert commandResultAssert = gfsh.executeAndAssertThat(csb.toString());
-
     commandResultAssert.statusIsError();
     commandResultAssert.containsOutput(String.format("connection named 'nonExisting' not found"));
   }
 
   @Test
-  public void reportConfigurationFoundOnMember() {
+  public void reportConfigurationFoundOnMember() throws Exception {
+    Properties properties = new Properties();
+    properties.put(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "false");
+
+    locator = startupRule.startLocatorVM(0, properties);
+    server = startupRule.startServerVM(1, locator.getPort());
+    gfsh.connectAndVerify(locator);
+
+    server.invoke(() -> createConnection());
+
     CommandResultAssert commandResultAssert = gfsh
-        .executeAndAssertThat(
-            DESCRIBE_CONNECTION + " --name=" + CONNECTION_NAME + " --member=server-1")
-        .statusIsSuccess();
+        .executeAndAssertThat(DESCRIBE_CONNECTION + " --name=" + CONNECTION_NAME).statusIsSuccess();
 
     commandResultAssert.statusIsSuccess();
     commandResultAssert.containsKeyValuePair("name", CONNECTION_NAME);
     commandResultAssert.containsKeyValuePair("url", "myUrl");
     commandResultAssert.containsKeyValuePair("user", "username");
     commandResultAssert.containsKeyValuePair("password", "\\*\\*\\*\\*\\*\\*\\*\\*");
-    commandResultAssert.containsOutput("key1");
-    commandResultAssert.containsOutput("value1");
-    commandResultAssert.containsOutput("key2");
-    commandResultAssert.containsOutput("value2");
+  }
+
+  private void createConnection() throws ConnectionConfigExistsException {
+    InternalCache cache = ClusterStartupRule.getCache();
+    JdbcConnectorService service = cache.getService(JdbcConnectorService.class);
+    service.createConnectionConfig(new ConnectorService.Connection(CONNECTION_NAME, "myUrl",
+        "username", "password ", (String) null));
+    assertThat(service.getConnectionConfig(CONNECTION_NAME)).isNotNull();
   }
 }
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeConnectionCommandTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeConnectionCommandTest.java
index e922d71..a014917 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeConnectionCommandTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeConnectionCommandTest.java
@@ -39,7 +39,7 @@ import org.apache.geode.test.junit.rules.GfshParserRule;
 
 @Category(UnitTest.class)
 public class DescribeConnectionCommandTest {
-  public static final String COMMAND = "describe jdbc-connection --name=name ";
+  public static final String COMMAND = "describe jdbc-connection --name=name";
   private DescribeConnectionCommand command;
   private ClusterConfigurationService ccService;
 
@@ -47,10 +47,9 @@ public class DescribeConnectionCommandTest {
   public static GfshParserRule gfsh = new GfshParserRule();
 
   @Before
-  public void setUp() throws Exception {
+  public void setUp() {
     command = spy(DescribeConnectionCommand.class);
     ccService = mock(InternalClusterConfigurationService.class);
-    doReturn(ccService).when(command).getConfigurationService();
   }
 
   @Test
@@ -60,20 +59,16 @@ public class DescribeConnectionCommandTest {
   }
 
   @Test
-  public void whenCCServiceIsNotAvailable() {
-    doReturn(null).when(command).getConfigurationService();
-    gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess()
-        .containsOutput("cluster configuration service is not running");
-  }
-
-  @Test
   public void whenCCServiceIsRunningAndNoConnectorServiceFound() {
+    doReturn(ccService).when(command).getConfigurationService();
     gfsh.executeAndAssertThat(command, COMMAND).statusIsError()
         .containsOutput("connection named 'name' not found");
   }
 
   @Test
   public void whenCCServiceIsRunningAndNoConnectionFound() {
+    doReturn(ccService).when(command).getConfigurationService();
+
     ConnectorService connectorService = mock(ConnectorService.class);
     when(ccService.getCustomCacheElement(any(), any(), any())).thenReturn(connectorService);
     gfsh.executeAndAssertThat(command, COMMAND).statusIsError()
@@ -81,7 +76,9 @@ public class DescribeConnectionCommandTest {
   }
 
   @Test
-  public void successfulResult() {
+  public void whenCCIsAvailable() {
+    doReturn(ccService).when(command).getConfigurationService();
+
     // connection found in CC
     ConnectorService.Connection connection = new ConnectorService.Connection("name", "url1",
         "user1", "password1", "param1:value1,param2:value2");
@@ -99,22 +96,20 @@ public class DescribeConnectionCommandTest {
   }
 
   @Test
-  public void whenCCIsNotAvailableAndMemberIsNotSpecified() {
+  public void whenCCIsNotAvailableAndNoMemberExists() {
     doReturn(null).when(command).getConfigurationService();
-    gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess()
-        .containsOutput("Use --member option to describe connections");
-  }
+    doReturn(Collections.emptySet()).when(command).findMembers(null, null);
 
-  @Test
-  public void whenNonExistingMemberIsSpecified() {
     doReturn(null).when(command).getMember(any());
-    gfsh.executeAndAssertThat(command, COMMAND + " --member=member1").statusIsError()
-        .containsOutput("No Members Found");
+    gfsh.executeAndAssertThat(command, COMMAND).statusIsError()
+        .containsOutput("connection named 'name' not found");
   }
 
   @Test
-  public void whenExistingMemberIsSpecified() {
-    doReturn(mock(DistributedMember.class)).when(command).getMember(any());
+  public void whenCCIsNotAvailableAndMemberExists() {
+    doReturn(null).when(command).getConfigurationService();
+    doReturn(Collections.singleton(mock(DistributedMember.class))).when(command).findMembers(null,
+        null);
 
     ConnectorService.Connection connection =
         new ConnectorService.Connection("name", "url1", "user1", "password1", "p1:v1,p2:v2");
@@ -122,9 +117,23 @@ public class DescribeConnectionCommandTest {
     doReturn(rc).when(command).executeFunction(any(), any(), any(DistributedMember.class));
     when(rc.getResult()).thenReturn(Collections.singletonList(connection));
 
-    gfsh.executeAndAssertThat(command, COMMAND + " --member=member1").statusIsSuccess()
-        .containsOutput("name", "name").containsOutput("url", "url1")
-        .containsOutput("user", "user1").containsOutput("password", "********")
-        .containsOutput("p1", "v1").containsOutput("p2", "v2");
+    gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess().containsOutput("name", "name")
+        .containsOutput("url", "url1").containsOutput("user", "user1")
+        .containsOutput("password", "********").containsOutput("p1", "v1")
+        .containsOutput("p2", "v2");
+  }
+
+  @Test
+  public void whenCCIsNotAvailableAndNoConnectionFoundOnMember() {
+    doReturn(null).when(command).getConfigurationService();
+    doReturn(Collections.singleton(mock(DistributedMember.class))).when(command).findMembers(null,
+        null);
+
+    ResultCollector rc = mock(ResultCollector.class);
+    doReturn(rc).when(command).executeFunction(any(), any(), any(DistributedMember.class));
+    when(rc.getResult()).thenReturn(Collections.emptyList());
+
+    gfsh.executeAndAssertThat(command, COMMAND).statusIsError()
+        .containsOutput("connection named 'name' not found");
   }
 }
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingCommandDUnitTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingCommandDUnitTest.java
index 7234164..e56d5cb 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingCommandDUnitTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingCommandDUnitTest.java
@@ -23,13 +23,20 @@ import static org.apache.geode.connectors.jdbc.internal.cli.CreateMappingCommand
 import static org.apache.geode.connectors.jdbc.internal.cli.CreateMappingCommand.CREATE_MAPPING__VALUE_CONTAINS_PRIMARY_KEY;
 import static org.apache.geode.connectors.jdbc.internal.cli.DescribeMappingCommand.DESCRIBE_MAPPING;
 import static org.apache.geode.connectors.jdbc.internal.cli.DescribeMappingCommand.DESCRIBE_MAPPING__REGION_NAME;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.Serializable;
+import java.util.Properties;
 
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
+import org.apache.geode.connectors.jdbc.internal.JdbcConnectorService;
+import org.apache.geode.connectors.jdbc.internal.RegionMappingExistsException;
+import org.apache.geode.connectors.jdbc.internal.configuration.ConnectorService;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.internal.cache.InternalCache;
 import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
 import org.apache.geode.test.dunit.rules.ClusterStartupRule;
 import org.apache.geode.test.dunit.rules.MemberVM;
@@ -39,23 +46,23 @@ import org.apache.geode.test.junit.rules.GfshCommandRule;
 import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
 
 @Category(DistributedTest.class)
-public class DescribeMappingCommandDUnitTest {
+public class DescribeMappingCommandDUnitTest implements Serializable {
 
   private static final String REGION_NAME = "testRegion";
 
-  @ClassRule
-  public static GfshCommandRule gfsh = new GfshCommandRule();
+  @Rule
+  public transient GfshCommandRule gfsh = new GfshCommandRule();
 
-  @ClassRule
-  public static ClusterStartupRule startupRule = new ClusterStartupRule();
+  @Rule
+  public transient ClusterStartupRule startupRule = new ClusterStartupRule();
 
   @Rule
   public SerializableTestName testName = new SerializableTestName();
 
-  private static MemberVM locator, server;
+  private MemberVM locator, server;
 
-  @BeforeClass
-  public static void before() throws Exception {
+  @Test
+  public void describesExistingMapping() throws Exception {
     locator = startupRule.startLocatorVM(0);
     server = startupRule.startServerVM(1, locator.getPort());
 
@@ -70,12 +77,9 @@ public class DescribeMappingCommandDUnitTest {
     csb.addOption(CREATE_MAPPING__FIELD_MAPPING, "field1:column1,field2:column2");
 
     gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess();
-  }
 
-  @Test
-  public void describesExistingMapping() {
-    CommandStringBuilder csb = new CommandStringBuilder(DESCRIBE_MAPPING)
-        .addOption(DESCRIBE_MAPPING__REGION_NAME, REGION_NAME);
+    csb = new CommandStringBuilder(DESCRIBE_MAPPING).addOption(DESCRIBE_MAPPING__REGION_NAME,
+        REGION_NAME);
 
     CommandResultAssert commandResultAssert = gfsh.executeAndAssertThat(csb.toString());
 
@@ -92,7 +96,11 @@ public class DescribeMappingCommandDUnitTest {
   }
 
   @Test
-  public void reportsNoMappingFound() {
+  public void reportsNoMappingFound() throws Exception {
+    locator = startupRule.startLocatorVM(0);
+    server = startupRule.startServerVM(1, locator.getPort());
+    gfsh.connectAndVerify(locator);
+
     CommandStringBuilder csb = new CommandStringBuilder(DESCRIBE_MAPPING)
         .addOption(DESCRIBE_MAPPING__REGION_NAME, "nonExisting");
 
@@ -103,19 +111,31 @@ public class DescribeMappingCommandDUnitTest {
   }
 
   @Test
-  public void reportConfigurationFoundOnMember() {
-    CommandResultAssert commandResultAssert = gfsh
-        .executeAndAssertThat(DESCRIBE_MAPPING + " --region=" + REGION_NAME + " --member=server-1")
-        .statusIsSuccess();
+  public void reportConfigurationFoundOnMember() throws Exception {
+    Properties properties = new Properties();
+    properties.put(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "false");
+
+    locator = startupRule.startLocatorVM(0, properties);
+    server = startupRule.startServerVM(1, locator.getPort());
+    gfsh.connectAndVerify(locator);
+
+    server.invoke(() -> createRegionMapping());
+
+    CommandResultAssert commandResultAssert =
+        gfsh.executeAndAssertThat(DESCRIBE_MAPPING + " --region=" + REGION_NAME).statusIsSuccess();
 
     commandResultAssert.containsKeyValuePair(CREATE_MAPPING__REGION_NAME, REGION_NAME);
     commandResultAssert.containsKeyValuePair(CREATE_MAPPING__CONNECTION_NAME, "connection");
     commandResultAssert.containsKeyValuePair(CREATE_MAPPING__TABLE_NAME, "testTable");
     commandResultAssert.containsKeyValuePair(CREATE_MAPPING__PDX_CLASS_NAME, "myPdxClass");
     commandResultAssert.containsKeyValuePair(CREATE_MAPPING__VALUE_CONTAINS_PRIMARY_KEY, "true");
-    commandResultAssert.containsOutput("field1");
-    commandResultAssert.containsOutput("field2");
-    commandResultAssert.containsOutput("column1");
-    commandResultAssert.containsOutput("column2");
+  }
+
+  private void createRegionMapping() throws RegionMappingExistsException {
+    InternalCache cache = ClusterStartupRule.getCache();
+    JdbcConnectorService service = cache.getService(JdbcConnectorService.class);
+    service.createRegionMapping(new ConnectorService.RegionMapping(REGION_NAME, "myPdxClass",
+        "testTable", "connection", true));
+    assertThat(service.getMappingForRegion(REGION_NAME)).isNotNull();
   }
 }
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingCommandTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingCommandTest.java
index 25559b8..18b68a8 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingCommandTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingCommandTest.java
@@ -51,7 +51,6 @@ public class DescribeMappingCommandTest {
   public void setUp() {
     command = spy(DescribeMappingCommand.class);
     ccService = mock(InternalClusterConfigurationService.class);
-    doReturn(ccService).when(command).getConfigurationService();
   }
 
   @Test
@@ -61,20 +60,16 @@ public class DescribeMappingCommandTest {
   }
 
   @Test
-  public void whenCCServiceIsNotAvailable() {
-    doReturn(null).when(command).getConfigurationService();
-    gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess()
-        .containsOutput("cluster configuration service is not running");
-  }
-
-  @Test
   public void whenCCServiceIsRunningAndNoConnectorServiceFound() {
+    doReturn(ccService).when(command).getConfigurationService();
     gfsh.executeAndAssertThat(command, COMMAND).statusIsError()
         .containsOutput("mapping for region 'region' not found");
   }
 
   @Test
   public void whenCCServiceIsRunningAndNoConnectionFound() {
+    doReturn(ccService).when(command).getConfigurationService();
+
     ConnectorService connectorService = mock(ConnectorService.class);
     when(ccService.getCustomCacheElement(any(), any(), any())).thenReturn(connectorService);
     gfsh.executeAndAssertThat(command, COMMAND).statusIsError()
@@ -82,7 +77,9 @@ public class DescribeMappingCommandTest {
   }
 
   @Test
-  public void successfulResult() {
+  public void whenCCIsAvailable() {
+    doReturn(ccService).when(command).getConfigurationService();
+
     // mapping found in CC
     ConnectorService.RegionMapping mapping =
         new ConnectorService.RegionMapping("region", "class1", "table1", "name1", true);
@@ -105,22 +102,19 @@ public class DescribeMappingCommandTest {
   }
 
   @Test
-  public void whenCCIsNotAvailableAndMemberIsNotSpecified() {
+  public void whenCCIsNotAvailableAndNoMemberExists() {
     doReturn(null).when(command).getConfigurationService();
-    gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess()
-        .containsOutput("Use --member option to describe mappings");
-  }
+    doReturn(Collections.emptySet()).when(command).findMembers(null, null);
 
-  @Test
-  public void whenNonExistingMemberIsSpecified() {
-    doReturn(null).when(command).getMember(any());
-    gfsh.executeAndAssertThat(command, COMMAND + " --member=member1").statusIsError()
-        .containsOutput("No Members Found");
+    gfsh.executeAndAssertThat(command, COMMAND).statusIsError()
+        .containsOutput("mapping for region 'region' not found");
   }
 
   @Test
-  public void whenExistingMemberIsSpecified() {
-    doReturn(mock(DistributedMember.class)).when(command).getMember(any());
+  public void whenCCIsNotAvailableAndMemberExists() {
+    doReturn(null).when(command).getConfigurationService();
+    doReturn(Collections.singleton(mock(DistributedMember.class))).when(command).findMembers(null,
+        null);
 
     ConnectorService.RegionMapping mapping =
         new ConnectorService.RegionMapping("region", "class1", "table1", "name1", true);
@@ -133,10 +127,24 @@ public class DescribeMappingCommandTest {
     doReturn(rc).when(command).executeFunction(any(), any(), any(DistributedMember.class));
     when(rc.getResult()).thenReturn(Collections.singletonList(mapping));
 
-    gfsh.executeAndAssertThat(command, COMMAND + " --member=member1").statusIsSuccess()
-        .containsOutput("region", "region").containsOutput("connection", "name1")
-        .containsOutput("table", "table1").containsOutput("pdx-class-name", "class1")
+    gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess().containsOutput("region", "region")
+        .containsOutput("connection", "name1").containsOutput("table", "table1")
+        .containsOutput("pdx-class-name", "class1")
         .containsOutput("value-contains-primary-key", "true").containsOutput("field1", "value1")
         .containsOutput("field2", "value2");
   }
+
+  @Test
+  public void whenCCIsNotAvailableAndNoMappingFoundOnMember() {
+    doReturn(null).when(command).getConfigurationService();
+    doReturn(Collections.singleton(mock(DistributedMember.class))).when(command).findMembers(null,
+        null);
+
+    ResultCollector rc = mock(ResultCollector.class);
+    doReturn(rc).when(command).executeFunction(any(), any(), any(DistributedMember.class));
+    when(rc.getResult()).thenReturn(Collections.emptyList());
+
+    gfsh.executeAndAssertThat(command, COMMAND).statusIsError()
+        .containsOutput("mapping for region 'region' not found");
+  }
 }
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionCommandDUnitTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionCommandDUnitTest.java
index faf97c2..640ed25 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionCommandDUnitTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionCommandDUnitTest.java
@@ -16,14 +16,20 @@ package org.apache.geode.connectors.jdbc.internal.cli;
 
 import static org.apache.geode.connectors.jdbc.internal.cli.ListConnectionCommand.LIST_JDBC_CONNECTION;
 import static org.apache.geode.connectors.jdbc.internal.cli.ListConnectionCommand.LIST_OF_CONNECTIONS;
+import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.Serializable;
+import java.util.Properties;
 
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
+import org.apache.geode.connectors.jdbc.internal.ConnectionConfigExistsException;
+import org.apache.geode.connectors.jdbc.internal.JdbcConnectorService;
+import org.apache.geode.connectors.jdbc.internal.configuration.ConnectorService;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.internal.cache.InternalCache;
 import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
 import org.apache.geode.test.dunit.rules.ClusterStartupRule;
 import org.apache.geode.test.dunit.rules.MemberVM;
@@ -39,7 +45,7 @@ public class ListConnectionCommandDUnitTest implements Serializable {
   public transient GfshCommandRule gfsh = new GfshCommandRule();
 
   @Rule
-  public ClusterStartupRule startupRule = new ClusterStartupRule();
+  public transient ClusterStartupRule startupRule = new ClusterStartupRule();
 
   @Rule
   public SerializableTestName testName = new SerializableTestName();
@@ -47,20 +53,14 @@ public class ListConnectionCommandDUnitTest implements Serializable {
   private MemberVM locator;
   private MemberVM server;
 
-  private String connectionName;
-
-  @Before
-  public void before() throws Exception {
-    connectionName = "name";
+  private String connectionName = "name";
 
+  @Test
+  public void listsConnectionFromClusterConfiguration() throws Exception {
     locator = startupRule.startLocatorVM(0);
     server = startupRule.startServerVM(1, locator.getPort());
-
     gfsh.connectAndVerify(locator);
-  }
 
-  @Test
-  public void listsOneConnection() {
     String conn1 =
         "create jdbc-connection --name=name --url=url --user=user --password=pass --params=param1:value1,param2:value2";
     gfsh.executeAndAssertThat(conn1).statusIsSuccess();
@@ -74,40 +74,17 @@ public class ListConnectionCommandDUnitTest implements Serializable {
   }
 
   @Test
-  public void listsMultipleConnections() {
-    String conn1 =
-        "create jdbc-connection --name=name-1 --url=url --user=user --password=pass --params=param1:value1,param2:value2";
-    gfsh.executeAndAssertThat(conn1).statusIsSuccess();
-    String conn2 =
-        "create jdbc-connection --name=name-2 --url=url --user=user --password=pass --params=param1:value1,param2:value2";
-    gfsh.executeAndAssertThat(conn2).statusIsSuccess();
-    String conn3 =
-        "create jdbc-connection --name=name-3 --url=url --user=user --password=pass --params=param1:value1,param2:value2";
-    gfsh.executeAndAssertThat(conn3).statusIsSuccess();
+  public void listsConnectionsFromMember() throws Exception {
+    Properties properties = new Properties();
+    properties.put(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "false");
 
-    CommandStringBuilder csb = new CommandStringBuilder(LIST_JDBC_CONNECTION);
-    CommandResultAssert commandResultAssert = gfsh.executeAndAssertThat(csb.toString());
-
-    commandResultAssert.statusIsSuccess();
-    commandResultAssert.tableHasRowCount(LIST_OF_CONNECTIONS, 3);
-    commandResultAssert.tableHasColumnOnlyWithValues(LIST_OF_CONNECTIONS, connectionName + "-1",
-        connectionName + "-2", connectionName + "-3");
-  }
+    locator = startupRule.startLocatorVM(0, properties);
+    server = startupRule.startServerVM(1, locator.getPort());
+    gfsh.connectAndVerify(locator);
 
-  @Test
-  public void listsConnectionsFromMember() {
-    String conn1 =
-        "create jdbc-connection --name=name-1 --url=url --user=user --password=pass --params=param1:value1,param2:value2";
-    gfsh.executeAndAssertThat(conn1).statusIsSuccess();
-    String conn2 =
-        "create jdbc-connection --name=name-2 --url=url --user=user --password=pass --params=param1:value1,param2:value2";
-    gfsh.executeAndAssertThat(conn2).statusIsSuccess();
-    String conn3 =
-        "create jdbc-connection --name=name-3 --url=url --user=user --password=pass --params=param1:value1,param2:value2";
-    gfsh.executeAndAssertThat(conn3).statusIsSuccess();
+    server.invoke(() -> createNConnections(3));
 
-    CommandResultAssert commandResultAssert =
-        gfsh.executeAndAssertThat(LIST_JDBC_CONNECTION + " --member=server-1").statusIsSuccess();
+    CommandResultAssert commandResultAssert = gfsh.executeAndAssertThat(LIST_JDBC_CONNECTION);
 
     commandResultAssert.statusIsSuccess();
     commandResultAssert.tableHasRowCount(LIST_OF_CONNECTIONS, 3);
@@ -116,12 +93,26 @@ public class ListConnectionCommandDUnitTest implements Serializable {
   }
 
   @Test
-  public void reportsNoConnectionsFound() {
+  public void reportsNoConnectionsFound() throws Exception {
+    locator = startupRule.startLocatorVM(0);
+    server = startupRule.startServerVM(1, locator.getPort());
+    gfsh.connectAndVerify(locator);
+
     CommandStringBuilder csb = new CommandStringBuilder(LIST_JDBC_CONNECTION);
 
     CommandResultAssert commandResultAssert = gfsh.executeAndAssertThat(csb.toString());
-
     commandResultAssert.statusIsSuccess();
     commandResultAssert.containsOutput("No connections found");
   }
+
+  private void createNConnections(int N) throws ConnectionConfigExistsException {
+    InternalCache cache = ClusterStartupRule.getCache();
+    JdbcConnectorService service = cache.getService(JdbcConnectorService.class);
+    for (int i = 1; i <= N; i++) {
+      String name = connectionName + "-" + i;
+      service.createConnectionConfig(
+          new ConnectorService.Connection(name, null, null, null, (String) null));
+      assertThat(service.getConnectionConfig(name)).isNotNull();
+    }
+  }
 }
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionCommandTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionCommandTest.java
index d69f22d..4018ec8 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionCommandTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionCommandTest.java
@@ -51,24 +51,19 @@ public class ListConnectionCommandTest {
   public void setUp() {
     command = spy(ListConnectionCommand.class);
     ccService = mock(InternalClusterConfigurationService.class);
-    doReturn(ccService).when(command).getConfigurationService();
-  }
-
-  @Test
-  public void whenCCServiceIsNotAvailable() {
-    doReturn(null).when(command).getConfigurationService();
-    gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess()
-        .containsOutput("cluster configuration service is not running");
   }
 
   @Test
   public void whenCCServiceIsRunningAndNoConnectorServiceFound() {
+    doReturn(ccService).when(command).getConfigurationService();
     gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess()
         .containsOutput("No connections found");
   }
 
   @Test
   public void whenCCServiceIsRunningAndNoConnectionFound() {
+    doReturn(ccService).when(command).getConfigurationService();
+
     ConnectorService connectorService = mock(ConnectorService.class);
     when(ccService.getCustomCacheElement(any(), any(), any())).thenReturn(connectorService);
     gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess()
@@ -76,7 +71,9 @@ public class ListConnectionCommandTest {
   }
 
   @Test
-  public void successfulResult() {
+  public void whenCCIsAvailable() {
+    doReturn(ccService).when(command).getConfigurationService();
+
     // connections found in CC
     ConnectorService.Connection connection1 = new ConnectorService.Connection("name1", "url1",
         "user1", "password1", "param1:value1,param2:value2");
@@ -97,22 +94,19 @@ public class ListConnectionCommandTest {
   }
 
   @Test
-  public void whenCCIsNotAvailableAndMemberIsNotSpecified() {
+  public void whenCCIsNotAvailableAndNoMemberExists() {
     doReturn(null).when(command).getConfigurationService();
-    gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess()
-        .containsOutput("Use --member option to describe connections");
-  }
+    doReturn(Collections.emptySet()).when(command).findMembers(null, null);
 
-  @Test
-  public void whenNonExistingMemberIsSpecified() {
-    doReturn(null).when(command).getMember(any());
-    gfsh.executeAndAssertThat(command, COMMAND + " --member=member1").statusIsError()
-        .containsOutput("No Members Found");
+    gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess()
+        .containsOutput("No connections found");
   }
 
   @Test
-  public void whenExistingMemberIsSpecified() {
-    doReturn(mock(DistributedMember.class)).when(command).getMember(any());
+  public void whenCCIsNotAvailableAndMemberExists() {
+    doReturn(null).when(command).getConfigurationService();
+    doReturn(Collections.singleton(mock(DistributedMember.class))).when(command).findMembers(null,
+        null);
 
     ConnectorService.Connection connection1 =
         new ConnectorService.Connection("name1", "url1", "user1", "password1", "p1:v1,p2:v2");
@@ -129,4 +123,18 @@ public class ListConnectionCommandTest {
     gfsh.executeAndAssertThat(command, COMMAND + " --member=member1").statusIsSuccess()
         .containsOutput("name1", "name2", "name3");
   }
+
+  @Test
+  public void whenCCIsNotAvailableAndNoConnectionFoundOnMember() {
+    doReturn(null).when(command).getConfigurationService();
+    doReturn(Collections.singleton(mock(DistributedMember.class))).when(command).findMembers(null,
+        null);
+
+    ResultCollector rc = mock(ResultCollector.class);
+    doReturn(rc).when(command).executeFunction(any(), any(), any(DistributedMember.class));
+    when(rc.getResult()).thenReturn(Collections.emptyList());
+
+    gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess()
+        .containsOutput("No connections found");
+  }
 }
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListMappingCommandDUnitTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListMappingCommandDUnitTest.java
index 3aa1be1..bdaeed6 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListMappingCommandDUnitTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListMappingCommandDUnitTest.java
@@ -16,14 +16,20 @@ package org.apache.geode.connectors.jdbc.internal.cli;
 
 import static org.apache.geode.connectors.jdbc.internal.cli.ListMappingCommand.LIST_MAPPING;
 import static org.apache.geode.connectors.jdbc.internal.cli.ListMappingCommand.LIST_OF_MAPPINGS;
+import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.Serializable;
+import java.util.Properties;
 
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
+import org.apache.geode.connectors.jdbc.internal.JdbcConnectorService;
+import org.apache.geode.connectors.jdbc.internal.RegionMappingExistsException;
+import org.apache.geode.connectors.jdbc.internal.configuration.ConnectorService;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.internal.cache.InternalCache;
 import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
 import org.apache.geode.test.dunit.rules.ClusterStartupRule;
 import org.apache.geode.test.dunit.rules.MemberVM;
@@ -39,7 +45,7 @@ public class ListMappingCommandDUnitTest implements Serializable {
   public transient GfshCommandRule gfsh = new GfshCommandRule();
 
   @Rule
-  public ClusterStartupRule startupRule = new ClusterStartupRule();
+  public transient ClusterStartupRule startupRule = new ClusterStartupRule();
 
   @Rule
   public SerializableTestName testName = new SerializableTestName();
@@ -47,20 +53,14 @@ public class ListMappingCommandDUnitTest implements Serializable {
   private MemberVM locator;
   private MemberVM server;
 
-  private String regionName;
-
-  @Before
-  public void before() throws Exception {
-    regionName = "testRegion";
+  private String regionName = "testRegion";
 
+  @Test
+  public void listsRegionMappingFromClusterConfiguration() throws Exception {
     locator = startupRule.startLocatorVM(0);
     server = startupRule.startServerVM(1, locator.getPort());
-
     gfsh.connectAndVerify(locator);
-  }
 
-  @Test
-  public void listsOneRegionMapping() {
     String mapping = "create jdbc-mapping --region=testRegion --connection=connection "
         + "--table=myTable --pdx-class-name=myPdxClass --value-contains-primary-key=true "
         + "--field-mapping=field1:column1,field2:column2";
@@ -75,46 +75,18 @@ public class ListMappingCommandDUnitTest implements Serializable {
   }
 
   @Test
-  public void listsMultipleRegionMappings() {
-    String mapping1 = "create jdbc-mapping --region=testRegion-1 --connection=connection "
-        + "--table=myTable --pdx-class-name=myPdxClass --value-contains-primary-key=true "
-        + "--field-mapping=field1:column1,field2:column2";
-    gfsh.executeAndAssertThat(mapping1).statusIsSuccess();
-    String mapping2 = "create jdbc-mapping --region=testRegion-2 --connection=connection "
-        + "--table=myTable --pdx-class-name=myPdxClass --value-contains-primary-key=true "
-        + "--field-mapping=field1:column1,field2:column2";
-    gfsh.executeAndAssertThat(mapping2).statusIsSuccess();
-    String mapping3 = "create jdbc-mapping --region=testRegion-3 --connection=connection "
-        + "--table=myTable --pdx-class-name=myPdxClass --value-contains-primary-key=true "
-        + "--field-mapping=field1:column1,field2:column2";
-    gfsh.executeAndAssertThat(mapping3).statusIsSuccess();
-
-    CommandStringBuilder csb = new CommandStringBuilder(LIST_MAPPING);
-    CommandResultAssert commandResultAssert = gfsh.executeAndAssertThat(csb.toString());
+  public void listsRegionMappingsFromMember() throws Exception {
+    Properties properties = new Properties();
+    properties.put(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "false");
 
-    commandResultAssert.statusIsSuccess();
-    commandResultAssert.tableHasRowCount(LIST_OF_MAPPINGS, 3);
-    commandResultAssert.tableHasColumnOnlyWithValues(LIST_OF_MAPPINGS, regionName + "-1",
-        regionName + "-2", regionName + "-3");
-  }
+    locator = startupRule.startLocatorVM(0, properties);
+    server = startupRule.startServerVM(1, locator.getPort());
+    gfsh.connectAndVerify(locator);
 
-  @Test
-  public void listsMultipleRegionMappingsFromMember() {
-    String mapping1 = "create jdbc-mapping --region=testRegion-1 --connection=connection "
-        + "--table=myTable --pdx-class-name=myPdxClass --value-contains-primary-key=true "
-        + "--field-mapping=field1:column1,field2:column2";
-    gfsh.executeAndAssertThat(mapping1).statusIsSuccess();
-    String mapping2 = "create jdbc-mapping --region=testRegion-2 --connection=connection "
-        + "--table=myTable --pdx-class-name=myPdxClass --value-contains-primary-key=true "
-        + "--field-mapping=field1:column1,field2:column2";
-    gfsh.executeAndAssertThat(mapping2).statusIsSuccess();
-    String mapping3 = "create jdbc-mapping --region=testRegion-3 --connection=connection "
-        + "--table=myTable --pdx-class-name=myPdxClass --value-contains-primary-key=true "
-        + "--field-mapping=field1:column1,field2:column2";
-    gfsh.executeAndAssertThat(mapping3).statusIsSuccess();
+    server.invoke(() -> createNRegionMappings(3));
 
     CommandResultAssert commandResultAssert =
-        gfsh.executeAndAssertThat(LIST_MAPPING + " --member=server-1").statusIsSuccess();
+        gfsh.executeAndAssertThat(LIST_MAPPING).statusIsSuccess();
 
     commandResultAssert.statusIsSuccess();
     commandResultAssert.tableHasRowCount(LIST_OF_MAPPINGS, 3);
@@ -123,12 +95,26 @@ public class ListMappingCommandDUnitTest implements Serializable {
   }
 
   @Test
-  public void reportsNoRegionMappingsFound() {
+  public void reportsNoRegionMappingsFound() throws Exception {
+    locator = startupRule.startLocatorVM(0);
+    server = startupRule.startServerVM(1, locator.getPort());
+    gfsh.connectAndVerify(locator);
+
     CommandStringBuilder csb = new CommandStringBuilder(LIST_MAPPING);
 
     CommandResultAssert commandResultAssert = gfsh.executeAndAssertThat(csb.toString());
-
     commandResultAssert.statusIsSuccess();
     commandResultAssert.containsOutput("No mappings found");
   }
+
+  private void createNRegionMappings(int N) throws RegionMappingExistsException {
+    InternalCache cache = ClusterStartupRule.getCache();
+    JdbcConnectorService service = cache.getService(JdbcConnectorService.class);
+    for (int i = 1; i <= N; i++) {
+      String name = regionName + "-" + i;
+      service.createRegionMapping(
+          new ConnectorService.RegionMapping(name, "x.y.MyPdxClass", "table", "connection", true));
+      assertThat(service.getMappingForRegion(name)).isNotNull();
+    }
+  }
 }
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListMappingCommandTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListMappingCommandTest.java
index 640d186..c31e2f3 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListMappingCommandTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListMappingCommandTest.java
@@ -51,24 +51,19 @@ public class ListMappingCommandTest {
   public void setUp() {
     command = spy(ListMappingCommand.class);
     ccService = mock(InternalClusterConfigurationService.class);
-    doReturn(ccService).when(command).getConfigurationService();
-  }
-
-  @Test
-  public void whenCCServiceIsNotAvailable() {
-    doReturn(null).when(command).getConfigurationService();
-    gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess()
-        .containsOutput("cluster configuration service is not running");
   }
 
   @Test
   public void whenCCServiceIsRunningAndNoConnectorServiceFound() {
+    doReturn(ccService).when(command).getConfigurationService();
     gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess()
         .containsOutput("No mappings found");
   }
 
   @Test
   public void whenCCServiceIsRunningAndNoConnectionFound() {
+    doReturn(ccService).when(command).getConfigurationService();
+
     ConnectorService connectorService = mock(ConnectorService.class);
     when(ccService.getCustomCacheElement(any(), any(), any())).thenReturn(connectorService);
     gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess()
@@ -76,7 +71,9 @@ public class ListMappingCommandTest {
   }
 
   @Test
-  public void successfulResult() {
+  public void whenCCIsAvailable() {
+    doReturn(ccService).when(command).getConfigurationService();
+
     // mappings found in CC
     ConnectorService.RegionMapping mapping1 =
         new ConnectorService.RegionMapping("region1", "class1", "table1", "name1", true);
@@ -98,22 +95,19 @@ public class ListMappingCommandTest {
   }
 
   @Test
-  public void whenCCIsNotAvailableAndMemberIsNotSpecified() {
+  public void whenCCIsNotAvailableAndNoMemberExists() {
     doReturn(null).when(command).getConfigurationService();
-    gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess()
-        .containsOutput("Use --member option to describe mappings");
-  }
+    doReturn(Collections.emptySet()).when(command).findMembers(null, null);
 
-  @Test
-  public void whenNonExistingMemberIsSpecified() {
-    doReturn(null).when(command).getMember(any());
-    gfsh.executeAndAssertThat(command, COMMAND + " --member=member1").statusIsError()
-        .containsOutput("No Members Found");
+    gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess()
+        .containsOutput("No mappings found");
   }
 
   @Test
   public void whenExistingMemberIsSpecified() {
-    doReturn(mock(DistributedMember.class)).when(command).getMember(any());
+    doReturn(null).when(command).getConfigurationService();
+    doReturn(Collections.singleton(mock(DistributedMember.class))).when(command).findMembers(null,
+        null);
 
     ConnectorService.RegionMapping mapping1 =
         new ConnectorService.RegionMapping("region1", "class1", "table1", "name1", true);
@@ -134,8 +128,22 @@ public class ListMappingCommandTest {
     when(rc.getResult())
         .thenReturn(Collections.singletonList(Stream.of(mapping1, mapping2).collect(toSet())));
 
-    gfsh.executeAndAssertThat(command, COMMAND + " --member=member1").statusIsSuccess()
-        .containsOutput("region1", "region2");
+    gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess().containsOutput("region1",
+        "region2");
   }
 
+
+  @Test
+  public void whenCCIsNotAvailableAndNoConnectionFoundOnMember() {
+    doReturn(null).when(command).getConfigurationService();
+    doReturn(Collections.singleton(mock(DistributedMember.class))).when(command).findMembers(null,
+        null);
+
+    ResultCollector rc = mock(ResultCollector.class);
+    doReturn(rc).when(command).executeFunction(any(), any(), any(DistributedMember.class));
+    when(rc.getResult()).thenReturn(Collections.emptyList());
+
+    gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess()
+        .containsOutput("No mappings found");
+  }
 }

-- 
To stop receiving notification emails like this one, please contact
sai_boorlagadda@apache.org.