You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ds...@apache.org on 2018/11/15 23:28:34 UTC

[geode] branch feature/GEODE-6025 updated: added dunit test

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

dschneider pushed a commit to branch feature/GEODE-6025
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/feature/GEODE-6025 by this push:
     new a464cc2  added dunit test
a464cc2 is described below

commit a464cc2869ebb4552d1f916c0b0f8250087e328f
Author: Darrel Schneider <ds...@pivotal.io>
AuthorDate: Thu Nov 15 15:28:12 2018 -0800

    added dunit test
---
 .../cli/DescribeDataSourceCommandDUnitTest.java    | 114 +++++++++++++++++++++
 .../internal/cli/DescribeDataSourceCommand.java    |   5 +-
 .../cli/DescribeDataSourceCommandTest.java         |   2 +-
 3 files changed, 118 insertions(+), 3 deletions(-)

diff --git a/geode-connectors/src/distributedTest/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeDataSourceCommandDUnitTest.java b/geode-connectors/src/distributedTest/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeDataSourceCommandDUnitTest.java
new file mode 100644
index 0000000..dc51f64
--- /dev/null
+++ b/geode-connectors/src/distributedTest/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeDataSourceCommandDUnitTest.java
@@ -0,0 +1,114 @@
+/*
+ * 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.connectors.jdbc.internal.cli;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Properties;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.management.internal.cli.result.model.InfoResultModel;
+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.rules.GfshCommandRule;
+
+public class DescribeDataSourceCommandDUnitTest {
+
+  private MemberVM locator, server;
+
+  @Rule
+  public ClusterStartupRule cluster = new ClusterStartupRule();
+
+  @Rule
+  public GfshCommandRule gfsh = new GfshCommandRule();
+
+  @Before
+  public void before() throws Exception {
+    locator = cluster.startLocatorVM(0);
+    server = cluster.startServerVM(1, new Properties(), locator.getPort());
+
+    gfsh.connectAndVerify(locator);
+  }
+
+  @Test
+  public void describeDataSourceForSimpleDataSource() {
+    gfsh.executeAndAssertThat(
+        "create data-source --name=simple --url=\"jdbc:derby:newDB;create=true\" --username=joe --password=myPassword")
+        .statusIsSuccess().tableHasColumnOnlyWithValues("Member", "server-1");
+
+    CommandResultAssert result = gfsh.executeAndAssertThat("describe data-source --name=simple");
+
+    result.statusIsSuccess()
+        .tableHasRowWithValues("Property", "Value", "name", "simple")
+        .tableHasRowWithValues("Property", "Value", "pooled", "false")
+        .tableHasRowWithValues("Property", "Value", "username", "joe")
+        .tableHasRowWithValues("Property", "Value", "url", "jdbc:derby:newDB;create=true");
+    assertThat(result.getResultModel().toString()).doesNotContain("myPassword");
+  }
+
+  @Test
+  public void describeDataSourceUsedByRegionsListsTheRegionsInOutput() {
+    gfsh.executeAndAssertThat(
+        "create data-source --name=simple --url=\"jdbc:derby:newDB;create=true\"")
+        .statusIsSuccess().tableHasColumnOnlyWithValues("Member", "server-1");
+    gfsh.executeAndAssertThat("create region --name=region1 --type=REPLICATE").statusIsSuccess();
+    gfsh.executeAndAssertThat("create region --name=region2 --type=PARTITION").statusIsSuccess();
+    gfsh.executeAndAssertThat(
+        "create jdbc-mapping --region=region1 --data-source=simple --pdx-name=myPdx");
+    gfsh.executeAndAssertThat(
+        "create jdbc-mapping --region=region2 --data-source=simple --pdx-name=myPdx");
+
+    CommandResultAssert result = gfsh.executeAndAssertThat("describe data-source --name=simple");
+
+    result.statusIsSuccess()
+        .tableHasRowWithValues("Property", "Value", "name", "simple")
+        .tableHasRowWithValues("Property", "Value", "pooled", "false")
+        .tableHasRowWithValues("Property", "Value", "url", "jdbc:derby:newDB;create=true");
+    InfoResultModel infoSection = result.getResultModel()
+        .getInfoSection(DescribeDataSourceCommand.REGIONS_USING_DATA_SOURCE_SECTION);
+    assertThat(new HashSet<>(infoSection.getContent()))
+        .isEqualTo(new HashSet<>(Arrays.asList("region1", "region2")));
+  }
+
+  @Test
+  public void describeDataSourceForPooledDataSource() {
+    gfsh.executeAndAssertThat(
+        "create data-source --name=pooled --pooled --url=\"jdbc:derby:newDB;create=true\" --pooled-data-source-factory-class=org.apache.geode.internal.jta.CacheJTAPooledDataSourceFactory --pool-properties={'name':'prop1','value':'value1'},{'name':'pool.prop2','value':'value2'}")
+        .statusIsSuccess().tableHasColumnOnlyWithValues("Member", "server-1");
+
+    gfsh.executeAndAssertThat("describe data-source --name=pooled").statusIsSuccess()
+        .tableHasRowWithValues("Property", "Value", "name", "pooled")
+        .tableHasRowWithValues("Property", "Value", "pooled", "true")
+        .tableHasRowWithValues("Property", "Value", "username", "")
+        .tableHasRowWithValues("Property", "Value", "url", "jdbc:derby:newDB;create=true")
+        .tableHasRowWithValues("Property", "Value", "pooled-data-source-factory-class",
+            "org.apache.geode.internal.jta.CacheJTAPooledDataSourceFactory")
+        .tableHasRowWithValues("Property", "Value", "prop1", "value1")
+        .tableHasRowWithValues("Property", "Value", "pool.prop2", "value2");
+  }
+
+  @Test
+  public void describeDataSourceDoesNotExist() {
+    gfsh.executeAndAssertThat("describe data-source --name=unknown").statusIsError()
+        .containsOutput("Data source: unknown not found");
+  }
+}
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeDataSourceCommand.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeDataSourceCommand.java
index ecc29e9..611fe74 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeDataSourceCommand.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeDataSourceCommand.java
@@ -40,7 +40,7 @@ import org.apache.geode.security.ResourcePermission;
 @Experimental
 public class DescribeDataSourceCommand extends InternalGfshCommand {
   static final String DESCRIBE_DATA_SOURCE = "describe data-source";
-  private static final String DESCRIBE_DATA_SOURCE__HELP =
+  private static final String DESCRIBE_DATA_SOURCE__HELP = EXPERIMENTAL +
       "Describe the configuration of the given data source.";
 
   static final String DATA_SOURCE_PROPERTIES_SECTION = "data-source-properties";
@@ -54,6 +54,7 @@ public class DescribeDataSourceCommand extends InternalGfshCommand {
       help = "Name of the data source to describe") String dataSourceName) {
 
     ResultModel resultModel = new ResultModel();
+    resultModel.setHeader(EXPERIMENTAL);
     TabularResultModel tabularData = resultModel.addTable(DATA_SOURCE_PROPERTIES_SECTION);
 
     InternalConfigurationPersistenceService ccService = getConfigurationPersistenceService();
@@ -62,7 +63,7 @@ public class DescribeDataSourceCommand extends InternalGfshCommand {
     }
     CacheConfig cacheConfig = ccService.getCacheConfig(null);
     if (cacheConfig == null) {
-      return ResultModel.createError("Cluster configuration is not available.");
+      return ResultModel.createError(String.format("Data source: %s not found", dataSourceName));
     }
 
     List<JndiBindingsType.JndiBinding> jndiBindings = cacheConfig.getJndiBindings();
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeDataSourceCommandTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeDataSourceCommandTest.java
index b85e47c..abba7a2 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeDataSourceCommandTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeDataSourceCommandTest.java
@@ -107,7 +107,7 @@ public class DescribeDataSourceCommandTest {
     ResultModel result = command.describeDataSource(DATA_SOURCE_NAME);
 
     assertThat(result.getStatus()).isEqualTo(Status.ERROR);
-    assertThat(result.toString()).contains("Cluster configuration is not available.");
+    assertThat(result.toString()).contains("Data source: " + DATA_SOURCE_NAME + " not found");
   }
 
   @Test