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

mkevo 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 9f2ba7b9d6 GEODE-7875:  fix create index gfsh command on partitioned 
region (#7629)
9f2ba7b9d6 is described below

commit 9f2ba7b9d6976adcf28383c566c9f80af67219e3
Author: Mario Kevo <48509719+mk...@users.noreply.github.com>
AuthorDate: Thu Jun 9 11:14:13 2022 +0200

    GEODE-7875:  fix create index gfsh command on partitioned region (#7629)
    
    * GEODE-7875:  fix create index gfsh command on partitioned region
---
 .../commands/IndexCommandsIntegrationTestBase.java |  6 ++--
 .../cli/commands/CreateIndexCommandDUnitTest.java  | 37 +++++++++++++++++++---
 .../internal/cli/commands/CreateIndexCommand.java  |  5 ++-
 .../cli/functions/CreateIndexFunction.java         |  6 ++--
 4 files changed, 42 insertions(+), 12 deletions(-)

diff --git 
a/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommandsIntegrationTestBase.java
 
b/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommandsIntegrationTestBase.java
index 1359dc4189..d9f2a472fd 100644
--- 
a/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommandsIntegrationTestBase.java
+++ 
b/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommandsIntegrationTestBase.java
@@ -136,7 +136,9 @@ public class IndexCommandsIntegrationTestBase {
     csb.addOption(CliStrings.CREATE_INDEX__REGION, SEPARATOR + regionName);
     csb.addOption(CliStrings.CREATE_INDEX__TYPE, "hash");
 
-    gfsh.executeAndAssertThat(csb.toString()).statusIsError();
+    gfsh.executeAndAssertThat(csb.toString())
+        .statusIsSuccess()
+        .containsOutput("Index \"indexA\" already exists.  Create failed due 
to duplicate name.");
   }
 
   @Test
@@ -170,7 +172,7 @@ public class IndexCommandsIntegrationTestBase {
     createSimpleIndexA();
     gfsh.executeAndAssertThat(
         "create index --name=indexA --expression=key --region=" + SEPARATOR + 
"regionA")
-        .statusIsError()
+        .statusIsSuccess()
         .containsOutput("Index \"indexA\" already exists.  Create failed due 
to duplicate name");
   }
 
diff --git 
a/geode-gfsh/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/CreateIndexCommandDUnitTest.java
 
b/geode-gfsh/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/CreateIndexCommandDUnitTest.java
index 75c8db4e41..1790cb36bd 100644
--- 
a/geode-gfsh/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/CreateIndexCommandDUnitTest.java
+++ 
b/geode-gfsh/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/CreateIndexCommandDUnitTest.java
@@ -48,13 +48,14 @@ public class CreateIndexCommandDUnitTest {
   @ClassRule
   public static GfshCommandRule gfsh = new GfshCommandRule();
 
-  private static MemberVM locator, server1, server2;
+  private static MemberVM locator;
+  private static MemberVM server1;
 
   @BeforeClass
   public static void beforeClass() throws Exception {
     locator = cluster.startLocatorVM(0);
     server1 = cluster.startServerVM(1, locator.getPort());
-    server2 = cluster.startServerVM(2, "group2", locator.getPort());
+    cluster.startServerVM(2, "group2", locator.getPort());
     gfsh.connectAndVerify(locator);
 
     // create a region on server-2 in group 2
@@ -71,7 +72,7 @@ public class CreateIndexCommandDUnitTest {
   }
 
   @Test
-  public void createIndexOnSubRegion() throws Exception {
+  public void createIndexOnSubRegion() {
     gfsh.executeAndAssertThat(
         "create region --name=regionB" + SEPARATOR + "child --group=group2 
--type=REPLICATE")
         .statusIsSuccess();
@@ -107,7 +108,7 @@ public class CreateIndexCommandDUnitTest {
   @Test
   // index can't be created on region name with ".".
   // GEODE-7523
-  public void createIndexOnRegionNameWithDot() throws Exception {
+  public void createIndexOnRegionNameWithDot() {
     gfsh.executeAndAssertThat("create region --name=A.B --type=REPLICATE")
         .statusIsSuccess();
     gfsh.executeAndAssertThat("create index --name=indexWithDot --region=A.B 
--expression=id")
@@ -124,7 +125,7 @@ public class CreateIndexCommandDUnitTest {
   }
 
   @Test
-  public void regionNotExistInThatMember() throws Exception {
+  public void regionNotExistInThatMember() {
     gfsh.executeAndAssertThat(
         "create index --name=myIndex --expression=id --region=" + SEPARATOR
             + "regionB --member=server-1")
@@ -210,4 +211,30 @@ public class CreateIndexCommandDUnitTest {
     commandAssert.hasInfoSection().hasOutput()
         .contains("Region regionB does not exist in some of the groups.");
   }
+
+  @Test
+  public void indexCreationOnPartitionedRegionUpdateClusterConfig() {
+    int serversNum = 8;
+    int initialIndex = 1;
+
+    for (int index = 2; index < serversNum; index++) {
+      cluster.startServerVM(initialIndex + index, locator.getPort());
+    }
+
+    gfsh.executeAndAssertThat("create region --name=regionC --type=PARTITION")
+        .statusIsSuccess();
+
+    gfsh.executeAndAssertThat(
+        "create index --name=index1 --expression=id --region=regionC")
+        .statusIsSuccess()
+        .hasTableSection()
+        .hasRowSize(8);
+
+    gfsh.executeAndAssertThat("export cluster-configuration")
+        .statusIsSuccess()
+        .hasInfoSection()
+        .hasOutput()
+        .contains(
+            "index name=\"index1\" expression=\"id\" from-clause=\"/regionC\" 
key-index=\"false\" type=\"range\"");
+  }
 }
diff --git 
a/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/CreateIndexCommand.java
 
b/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/CreateIndexCommand.java
index d1f4f1892a..be126d9a73 100644
--- 
a/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/CreateIndexCommand.java
+++ 
b/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/CreateIndexCommand.java
@@ -96,9 +96,8 @@ public class CreateIndexCommand extends GfshCommand {
             .createError("Region " + regionName + " does not exist in some of 
the groups.");
       }
       if (groups == null) {
-        // the calculatedGroups will have "cluster" value to indicate the 
"cluster" level, in thise
-        // case
-        // we want the groups to an empty array
+        // the calculatedGroups will have "cluster" value to indicate the 
"cluster" level,
+        // in this case we want the groups to an empty array
         groups = calculatedGroups.stream().filter(s -> 
!AbstractConfiguration.CLUSTER.equals(s))
             .toArray(String[]::new);
       }
diff --git 
a/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/functions/CreateIndexFunction.java
 
b/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/functions/CreateIndexFunction.java
index d232b6e676..261447ab03 100644
--- 
a/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/functions/CreateIndexFunction.java
+++ 
b/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/functions/CreateIndexFunction.java
@@ -66,11 +66,13 @@ public class CreateIndexFunction implements 
InternalFunction<RegionConfig.Index>
     } catch (IndexExistsException e) {
       String message =
           CliStrings.format(CliStrings.CREATE_INDEX__INDEX__EXISTS, 
indexInfo.getName());
-      context.getResultSender().lastResult(new CliFunctionResult(memberId, 
false, message));
+      context.getResultSender().lastResult(
+          new CliFunctionResult(memberId, 
CliFunctionResult.StatusState.IGNORABLE, message));
     } catch (IndexNameConflictException e) {
       String message =
           CliStrings.format(CliStrings.CREATE_INDEX__NAME__CONFLICT, 
indexInfo.getName());
-      context.getResultSender().lastResult(new CliFunctionResult(memberId, 
false, message));
+      context.getResultSender().lastResult(
+          new CliFunctionResult(memberId, 
CliFunctionResult.StatusState.IGNORABLE, message));
     } catch (RegionNotFoundException e) {
       String message = 
CliStrings.format(CliStrings.CREATE_INDEX__INVALID__REGIONPATH,
           indexInfo.getFromClause());

Reply via email to