[ 
https://issues.apache.org/jira/browse/GEODE-4227?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16327892#comment-16327892
 ] 

ASF GitHub Bot commented on GEODE-4227:
---------------------------------------

jhuynh1 closed pull request #1257: GEODE-4227 : Cluster config updated during 
Lucene Reindex
URL: https://github.com/apache/geode/pull/1257
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommands.java
 
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommands.java
index 926b2d0e92..505328033e 100755
--- 
a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommands.java
+++ 
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommands.java
@@ -170,8 +170,6 @@ public Result createIndex(@CliOption(key = 
LuceneCliStrings.LUCENE__INDEX_NAME,
       throws CommandResultException {
 
     Result result;
-    XmlEntity xmlEntity = null;
-
     // Every lucene index potentially writes to disk.
     getSecurityService().authorize(Resource.CLUSTER, Operation.MANAGE, 
LucenePermission.TARGET);
 
@@ -185,23 +183,25 @@ public Result createIndex(@CliOption(key = 
LuceneCliStrings.LUCENE__INDEX_NAME,
     final ResultCollector<?, ?> rc =
         this.executeFunctionOnAllMembers(createIndexFunction, indexInfo);
     final List<CliFunctionResult> funcResults = (List<CliFunctionResult>) 
rc.getResult();
-
+    final XmlEntity xmlEntity = 
funcResults.stream().filter(CliFunctionResult::isSuccessful)
+        
.map(CliFunctionResult::getXmlEntity).filter(Objects::nonNull).findFirst().orElse(null);
     final TabularResultData tabularResult = 
ResultBuilder.createTabularResultData();
     for (final CliFunctionResult cliFunctionResult : funcResults) {
       tabularResult.accumulate("Member", 
cliFunctionResult.getMemberIdOrName());
 
       if (cliFunctionResult.isSuccessful()) {
         tabularResult.accumulate("Status", "Successfully created lucene 
index");
-        // if (xmlEntity == null) {
-        // xmlEntity = cliFunctionResult.getXmlEntity();
-        // }
       } else {
         tabularResult.accumulate("Status", "Failed: " + 
cliFunctionResult.getMessage());
       }
     }
 
     result = ResultBuilder.buildResult(tabularResult);
-
+    if (xmlEntity != null) {
+      persistClusterConfiguration(result, () -> {
+        getSharedConfiguration().addXmlEntity(xmlEntity, null);
+      });
+    }
     return result;
   }
 
diff --git 
a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java
 
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java
index df8bf303d3..dcfd193aec 100644
--- 
a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java
+++ 
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java
@@ -36,8 +36,10 @@
 import org.apache.geode.cache.lucene.internal.cli.LuceneCliStrings;
 import org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails;
 import org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo;
+import org.apache.geode.cache.lucene.internal.xml.LuceneXmlConstants;
 import org.apache.geode.cache.lucene.internal.security.LucenePermission;
 import org.apache.geode.internal.InternalEntity;
+import org.apache.geode.internal.cache.xmlcache.CacheXml;
 import org.apache.geode.management.internal.cli.CliUtil;
 import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
@@ -72,10 +74,13 @@ public void execute(final FunctionContext context) {
     try {
       final LuceneIndexInfo indexInfo = (LuceneIndexInfo) 
context.getArguments();
       final Cache cache = context.getCache();
+      final String indexName = indexInfo.getIndexName();
+      final String regionPath = indexInfo.getRegionPath();
+
       memberId = cache.getDistributedSystem().getDistributedMember().getId();
       LuceneService service = LuceneServiceProvider.get(cache);
 
-      INDEX_NAME.validateName(indexInfo.getIndexName());
+      INDEX_NAME.validateName(indexName);
 
       String[] fields = indexInfo.getSearchableFieldNames();
       String[] analyzerName = indexInfo.getFieldAnalyzers();
@@ -100,15 +105,17 @@ public void execute(final FunctionContext context) {
         indexFactory.setLuceneSerializer(toSerializer(serializerName));
       }
 
-      REGION_PATH.validateName(indexInfo.getRegionPath());
+      XmlEntity xmlEntity = null;
+      REGION_PATH.validateName(regionPath);
       if (LuceneServiceImpl.LUCENE_REINDEX) {
-        indexFactory.create(indexInfo.getIndexName(), 
indexInfo.getRegionPath(), true);
+        indexFactory.create(indexName, regionPath, true);
+        if (cache.getRegion(regionPath) != null) {
+          xmlEntity = getXmlEntity(indexName, regionPath);
+        }
       } else {
-        indexFactory.create(indexInfo.getIndexName(), 
indexInfo.getRegionPath(), false);
+        indexFactory.create(indexName, regionPath, false);
       }
 
-      // TODO - update cluster configuration by returning a valid XmlEntity
-      XmlEntity xmlEntity = null;
       context.getResultSender().lastResult(new CliFunctionResult(memberId, 
xmlEntity));
     } catch (Exception e) {
       String exceptionMessage = 
CliStrings.format(CliStrings.EXCEPTION_CLASS_AND_MESSAGE,
@@ -117,6 +124,11 @@ public void execute(final FunctionContext context) {
     }
   }
 
+  protected XmlEntity getXmlEntity(String indexName, String regionPath) {
+    String regionName = StringUtils.stripStart(regionPath, "/");
+    return new XmlEntity(CacheXml.REGION, "name", regionName);
+  }
+  
   @Override
   public Collection<ResourcePermission> getRequiredPermissions(String 
regionName) {
     return Collections.singleton(
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java
index 46cae2676f..a36528b16a 100755
--- 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java
@@ -22,6 +22,7 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.Map;
 import java.util.Properties;
@@ -69,15 +70,13 @@ public void before() throws Exception {
 
   @Test
   public void indexGetsCreatedUsingClusterConfiguration() throws Exception {
-    ls.startServerVM(1, locator.getPort());
+    createServer(1);
 
     // Connect Gfsh to locator.
     gfshConnector.connectAndVerify(locator);
 
     // Create lucene index.
-    createLuceneIndexUsingGfsh();
-
-    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+    createLuceneIndexAndDataRegion();
 
     // Start vm2. This should have lucene index created using cluster
     // configuration.
@@ -90,22 +89,27 @@ public void indexGetsCreatedUsingClusterConfiguration() 
throws Exception {
     });
   }
 
+  void createLuceneIndexAndDataRegion() throws Exception {
+    createLuceneIndexUsingGfsh();
+    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+  }
+
+  MemberVM createServer(int index) throws IOException {
+    return ls.startServerVM(index, locator.getPort());
+  }
+
 
   @Test
   public void indexWithAnalyzerGetsCreatedUsingClusterConfiguration() throws 
Exception {
-    ls.startServerVM(1, locator.getPort());
-
+    createServer(1);
     // Connect Gfsh to locator.
     gfshConnector.connectAndVerify(locator);
 
-    // Create lucene index.
-    createLuceneIndexWithAnalyzerUsingGfsh();
-
-    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+    createLuceneIndexWithAnalyzerAndDataRegion();
 
     // Start vm2. This should have lucene index created using cluster
     // configuration.
-    MemberVM vm2 = ls.startServerVM(2, locator.getPort());
+    MemberVM vm2 = createServer(2);
     vm2.invoke(() -> {
       LuceneService luceneService = 
LuceneServiceProvider.get(ClusterStartupRule.getCache());
       final LuceneIndex index = luceneService.getIndex(INDEX_NAME, 
REGION_NAME);
@@ -121,17 +125,21 @@ public void 
indexWithAnalyzerGetsCreatedUsingClusterConfiguration() throws Excep
     });
   }
 
+  void createLuceneIndexWithAnalyzerAndDataRegion() throws Exception {
+    // Create lucene index.
+    createLuceneIndexWithAnalyzerUsingGfsh();
+    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+  }
+
   @Test
   public void indexWithSerializerGetsCreatedUsingClusterConfiguration() throws 
Exception {
-    ls.startServerVM(1, locator.getPort());
+    createServer(1);
 
     // Connect Gfsh to locator.
     gfshConnector.connectAndVerify(locator);
 
     // Create lucene index.
-    createLuceneIndexWithSerializerUsingGfsh(false);
-
-    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+    createLuceneIndexWithSerializerAndDataRegion();
 
     // Start vm2. This should have lucene index created using cluster
     // configuration.
@@ -147,9 +155,15 @@ public void 
indexWithSerializerGetsCreatedUsingClusterConfiguration() throws Exc
     });
   }
 
+  void createLuceneIndexWithSerializerAndDataRegion() throws Exception {
+    createLuceneIndexWithSerializerUsingGfsh();
+
+    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+  }
+
   @Test
   public void verifyClusterConfigurationAfterDestroyIndex() throws Exception {
-    ls.startServerVM(1, locator.getPort());
+    createServer(1);
 
     // Connect Gfsh to locator.
     gfshConnector.connectAndVerify(locator);
@@ -157,6 +171,9 @@ public void verifyClusterConfigurationAfterDestroyIndex() 
throws Exception {
     // Create and add indexes
     createAndAddIndexes();
 
+    // Verify cluster configuration contains the indexes
+    locator.invoke(verifyClusterConfiguration(true));
+
     // Destroy one index
     destroyLuceneIndexUsingGfsh(INDEX_NAME + "0");
 
@@ -169,7 +186,7 @@ public void verifyClusterConfigurationAfterDestroyIndex() 
throws Exception {
 
   @Test
   public void verifyClusterConfigurationAfterDestroyIndexes() throws Exception 
{
-    ls.startServerVM(1, locator.getPort());
+    createServer(1);
 
     // Connect Gfsh to locator.
     gfshConnector.connectAndVerify(locator);
@@ -177,6 +194,9 @@ public void verifyClusterConfigurationAfterDestroyIndexes() 
throws Exception {
     // Create and add indexes
     createAndAddIndexes();
 
+    // Verify cluster configuration contains the indexes
+    locator.invoke(verifyClusterConfiguration(true));
+
     // Destroy all indexes
     destroyLuceneIndexUsingGfsh(null);
 
@@ -187,20 +207,19 @@ public void 
verifyClusterConfigurationAfterDestroyIndexes() throws Exception {
   @Test
   public void verifyMemberWithGroupStartsAfterAlterRegion() throws Exception {
     // Start a member with no group
-    ls.startServerVM(1, locator.getPort());
+    createServer(1);
 
     // Start a member with group
     String group = "group1";
     Properties properties = new Properties();
     properties.setProperty(GROUPS, group);
-    MemberVM vm2 = ls.startServerVM(2, properties, locator.getPort());
+    MemberVM vm2 = createServer(properties, 2);
 
     // Connect Gfsh to locator
     gfshConnector.connectAndVerify(locator);
 
     // Create index and region in no group
-    createLuceneIndexUsingGfsh();
-    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+    createLuceneIndexAndDataRegion();
 
     // Alter region in group
     CommandStringBuilder csb = new 
CommandStringBuilder(CliStrings.ALTER_REGION);
@@ -214,7 +233,7 @@ public void verifyMemberWithGroupStartsAfterAlterRegion() 
throws Exception {
         .tableHasColumnWithExactValuesInExactOrder("Status", 
expectedStatusOutput);
 
     // Start another member with group
-    ls.startServerVM(3, properties, locator.getPort());
+    createServer(properties, 3);
 
     // Verify all members have indexes
     csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_LIST_INDEX);
@@ -223,7 +242,11 @@ public void verifyMemberWithGroupStartsAfterAlterRegion() 
throws Exception {
             "Initialized");
   }
 
-  private void createAndAddIndexes() throws Exception {
+  MemberVM createServer(Properties properties, int index) throws Exception {
+    return ls.startServerVM(index, properties, locator.getPort());
+  }
+
+  void createAndAddIndexes() throws Exception {
     // Create lucene index.
     createLuceneIndexUsingGfsh(INDEX_NAME + "0");
 
@@ -233,11 +256,9 @@ private void createAndAddIndexes() throws Exception {
     // Create region
     createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
 
-    // Verify cluster configuration contains the indexes
-    locator.invoke(verifyClusterConfiguration(true));
   }
 
-  private SerializableRunnableIF verifyClusterConfiguration(boolean 
verifyIndexesExist) {
+  SerializableRunnableIF verifyClusterConfiguration(boolean 
verifyIndexesExist) {
     return () -> {
       InternalLocator internalLocator = ClusterStartupRule.getLocator();
       ClusterConfigurationService sc = 
internalLocator.getSharedConfiguration();
@@ -260,11 +281,11 @@ private SerializableRunnableIF 
verifyClusterConfiguration(boolean verifyIndexesE
   }
 
 
-  private void createLuceneIndexUsingGfsh() throws Exception {
+  void createLuceneIndexUsingGfsh() throws Exception {
     createLuceneIndexUsingGfsh(INDEX_NAME);
   }
 
-  private void createLuceneIndexUsingGfsh(String indexName) throws Exception {
+  void createLuceneIndexUsingGfsh(String indexName) throws Exception {
     // Execute Gfsh command to create lucene index.
     CommandStringBuilder csb = new 
CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX);
     csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, indexName);
@@ -273,7 +294,7 @@ private void createLuceneIndexUsingGfsh(String indexName) 
throws Exception {
     gfshConnector.executeAndAssertThat(csb.toString()).statusIsSuccess();
   }
 
-  private void createLuceneIndexWithAnalyzerUsingGfsh() throws Exception {
+  void createLuceneIndexWithAnalyzerUsingGfsh() throws Exception {
     // Gfsh command to create lucene index.
     CommandStringBuilder csb = new 
CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX);
     csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, INDEX_NAME);
@@ -288,7 +309,7 @@ private void createLuceneIndexWithAnalyzerUsingGfsh() 
throws Exception {
     gfshConnector.executeAndAssertThat(csb.toString()).statusIsSuccess();
   }
 
-  private void createLuceneIndexWithSerializerUsingGfsh(boolean addGroup) 
throws Exception {
+  void createLuceneIndexWithSerializerUsingGfsh() throws Exception {
     // Gfsh command to create lucene index.
     CommandStringBuilder csb = new 
CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX);
     csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, INDEX_NAME);
@@ -311,7 +332,7 @@ private void destroyLuceneIndexUsingGfsh(String indexName) 
throws Exception {
     gfshConnector.executeAndAssertThat(csb.toString()).statusIsSuccess();
   }
 
-  private void createRegionUsingGfsh(String regionName, RegionShortcut 
regionShortCut, String group)
+  void createRegionUsingGfsh(String regionName, RegionShortcut regionShortCut, 
String group)
       throws Exception {
     CommandStringBuilder csb = new 
CommandStringBuilder(CliStrings.CREATE_REGION);
     csb.addOption(CliStrings.CREATE_REGION__REGION, regionName);
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationWhereRegionCreatedBeforeReindexDUnitTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationWhereRegionCreatedBeforeReindexDUnitTest.java
new file mode 100644
index 0000000000..672e2eb893
--- /dev/null
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationWhereRegionCreatedBeforeReindexDUnitTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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.cache.lucene.internal.configuration;
+
+import static 
org.apache.geode.cache.lucene.test.LuceneTestUtilities.INDEX_NAME;
+import static 
org.apache.geode.cache.lucene.test.LuceneTestUtilities.REGION_NAME;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import org.junit.After;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.categories.DistributedTest;
+
+@Category(DistributedTest.class)
+public class LuceneClusterConfigurationWhereRegionCreatedBeforeReindexDUnitTest
+    extends LuceneClusterConfigurationDUnitTest {
+
+  MemberVM[] servers = new MemberVM[3];
+
+  @Override
+  MemberVM createServer(int index) throws IOException {
+    servers[index - 1] = super.createServer(index);
+    servers[index - 1].invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = true);
+    return servers[index - 1];
+
+  }
+
+  @After
+  public void clearLuceneReindexFlag() {
+    for (MemberVM server : servers) {
+      if (server != null) {
+        server.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = false);
+      }
+    }
+  }
+
+  @Override
+  void createLuceneIndexAndDataRegion() throws Exception {
+    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+    createLuceneIndexUsingGfsh();
+  }
+
+  @Override
+  void createLuceneIndexWithAnalyzerAndDataRegion() throws Exception {
+    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+    createLuceneIndexWithAnalyzerUsingGfsh();
+  }
+
+  @Override
+  void createAndAddIndexes() throws Exception {
+    // Create region
+    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+
+    // Create lucene index.
+    createLuceneIndexUsingGfsh(INDEX_NAME + "0");
+
+    // Create another lucene index.
+    createLuceneIndexUsingGfsh(INDEX_NAME + "1");
+
+  }
+
+  @Override
+  void createLuceneIndexWithSerializerAndDataRegion() throws Exception {
+    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+    createLuceneIndexWithSerializerUsingGfsh();
+  }
+
+  @Override
+  MemberVM createServer(Properties properties, int index) throws Exception {
+    servers[index - 1] = super.createServer(properties, index);
+    servers[index - 1].getVM().invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = 
true);
+    return servers[index - 1];
+  }
+}
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationWithReindexFlagEnabled.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationWithReindexFlagEnabled.java
new file mode 100644
index 0000000000..a2e25baaa5
--- /dev/null
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationWithReindexFlagEnabled.java
@@ -0,0 +1,58 @@
+/*
+ * 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.cache.lucene.internal.configuration;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import org.junit.After;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.categories.DistributedTest;
+
+
+// Delete this file when LuceneServiceImpl.LUCENE_REINDEX flag is removed.
+@Category(DistributedTest.class)
+public class LuceneClusterConfigurationWithReindexFlagEnabled
+    extends LuceneClusterConfigurationDUnitTest {
+
+  MemberVM[] servers = new MemberVM[3];
+
+  @Override
+  MemberVM createServer(int index) throws IOException {
+    servers[index - 1] = super.createServer(index);
+    servers[index - 1].invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = true);
+    return servers[index - 1];
+
+  }
+
+  @After
+  public void clearLuceneReindexFlag() {
+    for (MemberVM server : servers) {
+      if (server != null) {
+        server.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = false);
+      }
+    }
+  }
+
+  @Override
+  MemberVM createServer(Properties properties, int index) throws Exception {
+    servers[index - 1] = super.createServer(properties, index);
+    servers[index - 1].getVM().invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = 
true);
+    return servers[index - 1];
+  }
+}
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorIntegrationJUnitTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorIntegrationJUnitTest.java
index eef6ed1ad5..cd1ec067f7 100644
--- 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorIntegrationJUnitTest.java
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorIntegrationJUnitTest.java
@@ -31,7 +31,6 @@
 
 import org.apache.geode.cache.Cache;
 import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.cache.Declarable;
 import org.apache.geode.cache.RegionShortcut;
 import org.apache.geode.cache.lucene.*;
 import org.apache.geode.cache.lucene.test.LuceneDeclarable2TestSerializer;
@@ -42,13 +41,25 @@
 @Category(IntegrationTest.class)
 public class LuceneIndexXmlGeneratorIntegrationJUnitTest {
 
-  private Cache cache;
+  protected Cache cache;
 
   @After
   public void closeCache() {
     cache.close();
   }
 
+  protected void createDataRegionAndLuceneIndex(LuceneService service) {
+    service.createIndexFactory().setFields("a", "b", "c").create("index", 
"region");
+    cache.createRegionFactory(RegionShortcut.PARTITION).create("region");
+  }
+
+  protected void 
createDataRegionAndLuceneIndexWithSerializer(LuceneTestSerializer 
luceneSerializer,
+      LuceneService service) {
+    
service.createIndexFactory().setLuceneSerializer(luceneSerializer).setFields("a",
 "b", "c")
+        .create("index", "region");
+    cache.createRegionFactory(RegionShortcut.PARTITION).create("region");
+  }
+
   /**
    * Test of generating and reading cache configuration back in.
    */
@@ -56,8 +67,7 @@ public void closeCache() {
   public void generateWithFields() {
     cache = new CacheFactory().set(MCAST_PORT, "0").create();
     LuceneService service = LuceneServiceProvider.get(cache);
-    service.createIndexFactory().setFields("a", "b", "c").create("index", 
"region");
-    cache.createRegionFactory(RegionShortcut.PARTITION).create("region");
+    createDataRegionAndLuceneIndex(service);
 
 
     LuceneIndex index = generateAndParseXml(service);
@@ -92,9 +102,7 @@ private Properties generateAndParseDeclarable2Serializer(
       LuceneDeclarable2TestSerializer luceneSerializer) {
     cache = new CacheFactory().set(MCAST_PORT, "0").create();
     LuceneService service = LuceneServiceProvider.get(cache);
-    
service.createIndexFactory().setLuceneSerializer(luceneSerializer).setFields("a",
 "b", "c")
-        .create("index", "region");
-    cache.createRegionFactory(RegionShortcut.PARTITION).create("region");
+    createDataRegionAndLuceneIndexWithSerializer(luceneSerializer, service);
 
     LuceneIndex index = generateAndParseXml(service);
 
@@ -104,14 +112,11 @@ private Properties generateAndParseDeclarable2Serializer(
     return ((LuceneDeclarable2TestSerializer) testSerializer).getConfig();
   }
 
-
   @Test
   public void generateWithSerializer() {
     cache = new CacheFactory().set(MCAST_PORT, "0").create();
     LuceneService service = LuceneServiceProvider.get(cache);
-    service.createIndexFactory().setLuceneSerializer(new 
LuceneTestSerializer())
-        .setFields("a", "b", "c").create("index", "region");
-    cache.createRegionFactory(RegionShortcut.PARTITION).create("region");
+    createDataRegionAndLuceneIndexWithSerializer(new LuceneTestSerializer(), 
service);
 
     LuceneIndex index = generateAndParseXml(service);
 
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorWhereRegionCreatedBeforeReindexIntegrationJUnitTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorWhereRegionCreatedBeforeReindexIntegrationJUnitTest.java
new file mode 100644
index 0000000000..49e0a370ca
--- /dev/null
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorWhereRegionCreatedBeforeReindexIntegrationJUnitTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.cache.lucene.internal.xml;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.lucene.LuceneService;
+import org.apache.geode.cache.lucene.internal.LuceneIndexFactoryImpl;
+import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
+import org.apache.geode.cache.lucene.test.LuceneTestSerializer;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+
+@Category(IntegrationTest.class)
+public class 
LuceneIndexXmlGeneratorWhereRegionCreatedBeforeReindexIntegrationJUnitTest
+    extends LuceneIndexXmlGeneratorIntegrationJUnitTest {
+
+  @After
+  public void clearLuceneReindexFeatureFlag() {
+    LuceneServiceImpl.LUCENE_REINDEX = false;
+  }
+
+  @Before
+  public void setLuceneReindexFeatureFlag() {
+    LuceneServiceImpl.LUCENE_REINDEX = true;
+  }
+
+  protected void createDataRegionAndLuceneIndex(LuceneService service) {
+    super.cache.createRegionFactory(RegionShortcut.PARTITION).create("region");
+    ((LuceneIndexFactoryImpl) service.createIndexFactory().setFields("a", "b", 
"c")).create("index",
+        "region", true);
+
+  }
+
+  protected void 
createDataRegionAndLuceneIndexWithSerializer(LuceneTestSerializer 
luceneSerializer,
+      LuceneService service) {
+    cache.createRegionFactory(RegionShortcut.PARTITION).create("region");
+    ((LuceneIndexFactoryImpl) 
service.createIndexFactory().setLuceneSerializer(luceneSerializer)
+        .setFields("a", "b", "c")).create("index", "region", true);
+  }
+
+}
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorWithReindexFlagEnabledIntegrationJUnitTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorWithReindexFlagEnabledIntegrationJUnitTest.java
new file mode 100644
index 0000000000..6810596273
--- /dev/null
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorWithReindexFlagEnabledIntegrationJUnitTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.cache.lucene.internal.xml;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+
+@Category(IntegrationTest.class)
+public class LuceneIndexXmlGeneratorWithReindexFlagEnabledIntegrationJUnitTest
+    extends LuceneIndexXmlGeneratorIntegrationJUnitTest {
+  // Delete this test file after when the feature flag 
LuceneServiceImpl.LUCENE_REINDEX is removed
+  // from the project.
+  @After
+  public void clearLuceneReindexFeatureFlag() {
+    LuceneServiceImpl.LUCENE_REINDEX = false;
+  }
+
+  @Before
+  public void setLuceneReindexFeatureFlag() {
+    LuceneServiceImpl.LUCENE_REINDEX = true;
+  }
+
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Cache xml must be updated if lucene index was created after the region 
> -----------------------------------------------------------------------
>
>                 Key: GEODE-4227
>                 URL: https://issues.apache.org/jira/browse/GEODE-4227
>             Project: Geode
>          Issue Type: Sub-task
>          Components: lucene
>            Reporter: nabarun
>            Priority: Major
>              Labels: pull-request-available
>
> - Create region.
> - Create Lucene Index
> - Cache xml must contain the information about the newly created Lucene Index.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to