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

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

commit ad93a2e1fec604f9acc9ab8fd3dbca119835615c
Author: Lynn Hughes-Godfrey <lhughesgodf...@pivotal.io>
AuthorDate: Thu Jan 18 16:03:47 2018 -0800

    GEODE-3928: createIndex on existing region creates lucene indexes for 
existing data
---
 .../lucene/internal/IndexRepositoryFactory.java    |  71 +++++++++++-
 .../cache/lucene/internal/LuceneServiceImpl.java   |  66 ++++++++++-
 .../lucene/internal/filesystem/FileSystem.java     |   5 +-
 .../apache/geode/cache/lucene/LuceneDUnitTest.java |   8 ++
 .../lucene/LuceneIndexCreationIntegrationTest.java |  12 +-
 .../LuceneIndexMaintenanceIntegrationTest.java     |  10 +-
 .../cache/lucene/LuceneQueriesAccessorBase.java    |  10 ++
 .../geode/cache/lucene/LuceneQueriesDUnitTest.java | 102 ++++++-----------
 .../cache/lucene/LuceneQueriesIntegrationTest.java |  67 +++++------
 .../LuceneQueriesReindexClientDUnitTest.java       |  90 +++++++++++++++
 .../lucene/LuceneQueriesReindexDUnitTest.java      | 127 +++++++++++++++++++++
 ...hRegionCreatedBeforeReindexClientDUnitTest.java |  74 ++++++++++++
 ...iesWithRegionCreatedBeforeReindexDUnitTest.java |  95 +++++++++++++++
 ...hRegionCreatedBeforeReindexIntegrationTest.java |  95 +++++++++++++++
 ...eriesWithReindexFlagEnabledClientDUnitTest.java |  53 +++++++++
 ...ceneQueriesWithReindexFlagEnabledDUnitTest.java |  74 ++++++++++++
 ...eriesWithReindexFlagEnabledIntegrationTest.java |  80 +++++++++++++
 .../lucene/RebalanceWithRedundancyDUnitTest.java   |   7 +-
 .../PartitionedRepositoryManagerJUnitTest.java     |  22 ++++
 .../management/LuceneManagementDUnitTest.java      |   6 +-
 20 files changed, 948 insertions(+), 126 deletions(-)

diff --git 
a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/IndexRepositoryFactory.java
 
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/IndexRepositoryFactory.java
index b825940..99ef788 100644
--- 
a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/IndexRepositoryFactory.java
+++ 
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/IndexRepositoryFactory.java
@@ -15,19 +15,31 @@
 package org.apache.geode.cache.lucene.internal;
 
 import java.io.IOException;
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.logging.log4j.Logger;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.IndexWriterConfig;
 
+import org.apache.geode.cache.CacheClosedException;
+import org.apache.geode.cache.EntryDestroyedException;
+import org.apache.geode.cache.Region;
 import org.apache.geode.cache.lucene.LuceneSerializer;
 import org.apache.geode.cache.lucene.internal.directory.RegionDirectory;
 import org.apache.geode.cache.lucene.internal.partition.BucketTargetingMap;
 import org.apache.geode.cache.lucene.internal.repository.IndexRepository;
 import org.apache.geode.cache.lucene.internal.repository.IndexRepositoryImpl;
+import org.apache.geode.cache.query.internal.DefaultQuery;
 import org.apache.geode.distributed.DistributedLockService;
+import org.apache.geode.distributed.LockServiceDestroyedException;
 import org.apache.geode.internal.cache.BucketRegion;
+import org.apache.geode.internal.cache.ColocationHelper;
+import org.apache.geode.internal.cache.EntrySnapshot;
+import org.apache.geode.internal.cache.PartitionRegionConfig;
 import org.apache.geode.internal.cache.PartitionedRegion;
 import org.apache.geode.internal.cache.PartitionedRegionHelper;
 import org.apache.geode.internal.logging.LogService;
@@ -36,6 +48,7 @@ public class IndexRepositoryFactory {
 
   private static final Logger logger = LogService.getLogger();
   public static final String FILE_REGION_LOCK_FOR_BUCKET_ID = 
"FileRegionLockForBucketId:";
+  public static final String APACHE_GEODE_INDEX_COMPLETE = 
"APACHE_GEODE_INDEX_COMPLETE";
 
   public IndexRepositoryFactory() {}
 
@@ -45,6 +58,14 @@ public class IndexRepositoryFactory {
     LuceneIndexForPartitionedRegion indexForPR = 
(LuceneIndexForPartitionedRegion) index;
     final PartitionedRegion fileRegion = indexForPR.getFileAndChunkRegion();
 
+    // We need to ensure that all members have created the fileAndChunk region 
before continuing
+    Region prRoot = PartitionedRegionHelper.getPRRoot(fileRegion.getCache());
+    PartitionRegionConfig prConfig =
+        (PartitionRegionConfig) prRoot.get(fileRegion.getRegionIdentifier());
+    while (!prConfig.isColocationComplete()) {
+      prConfig = (PartitionRegionConfig) 
prRoot.get(fileRegion.getRegionIdentifier());
+    }
+
     BucketRegion fileAndChunkBucket = getMatchingBucket(fileRegion, bucketId);
     BucketRegion dataBucket = getMatchingBucket(userRegion, bucketId);
     boolean success = false;
@@ -77,25 +98,69 @@ public class IndexRepositoryFactory {
     }
 
     final IndexRepository repo;
+    DefaultQuery.setPdxReadSerialized(true);
     try {
-      RegionDirectory dir = new 
RegionDirectory(getBucketTargetingMap(fileAndChunkBucket, bucketId),
-          indexForPR.getFileSystemStats());
+      // bucketTargetingMap handles partition resolver (via bucketId as 
callbackArg)
+      Map bucketTargetingMap = getBucketTargetingMap(fileAndChunkBucket, 
bucketId);
+      RegionDirectory dir =
+          new RegionDirectory(bucketTargetingMap, 
indexForPR.getFileSystemStats());
       IndexWriterConfig config = new 
IndexWriterConfig(indexForPR.getAnalyzer());
       IndexWriter writer = new IndexWriter(dir, config);
       repo = new IndexRepositoryImpl(fileAndChunkBucket, writer, serializer,
           indexForPR.getIndexStats(), dataBucket, lockService, lockName, 
indexForPR);
-      success = true;
+      success = false;
+      // fileRegion ops (get/put) need bucketId as a callbackArg for 
PartitionResolver
+      if (null != fileRegion.get(APACHE_GEODE_INDEX_COMPLETE, bucketId)) {
+        success = true;
+        return repo;
+      } else {
+        Set<IndexRepository> affectedRepos = new HashSet<IndexRepository>();
+
+        Iterator keysIterator = dataBucket.keySet().iterator();
+        while (keysIterator.hasNext()) {
+          Object key = keysIterator.next();
+          Object value = getValue(userRegion.getEntry(key));
+          if (value != null) {
+            repo.update(key, value);
+          } else {
+            repo.delete(key);
+          }
+          affectedRepos.add(repo);
+        }
+
+        for (IndexRepository affectedRepo : affectedRepos) {
+          affectedRepo.commit();
+        }
+        // fileRegion ops (get/put) need bucketId as a callbackArg for 
PartitionResolver
+        fileRegion.put(APACHE_GEODE_INDEX_COMPLETE, 
APACHE_GEODE_INDEX_COMPLETE, bucketId);
+        success = true;
+      }
       return repo;
     } catch (IOException e) {
       logger.info("Exception thrown while constructing Lucene Index for 
bucket:" + bucketId
           + " for file region:" + fileAndChunkBucket.getFullPath());
       throw e;
+    } catch (CacheClosedException e) {
+      logger.info("CacheClosedException thrown while constructing Lucene Index 
for bucket:"
+          + bucketId + " for file region:" + fileAndChunkBucket.getFullPath());
+      throw e;
     } finally {
       if (!success) {
         lockService.unlock(lockName);
+        DefaultQuery.setPdxReadSerialized(false);
       }
     }
+  }
 
+  private Object getValue(Region.Entry entry) {
+    final EntrySnapshot es = (EntrySnapshot) entry;
+    Object value;
+    try {
+      value = es == null ? null : es.getRawValue(true);
+    } catch (EntryDestroyedException e) {
+      value = null;
+    }
+    return value;
   }
 
   private Map getBucketTargetingMap(BucketRegion region, int bucketId) {
diff --git 
a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
 
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
index e7813af..3894e32 100644
--- 
a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
+++ 
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
@@ -15,10 +15,15 @@
 
 package org.apache.geode.cache.lucene.internal;
 
+import static 
org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl.ASYNC_EVENT_QUEUE_PREFIX;
+
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -31,12 +36,18 @@ import org.apache.logging.log4j.Logger;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.miscellaneous.PerFieldAnalyzerWrapper;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.store.AlreadyClosedException;
 
+import org.apache.geode.InternalGemFireError;
+import org.apache.geode.cache.AttributesMutator;
 import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheClosedException;
+import org.apache.geode.cache.EntryDestroyedException;
 import org.apache.geode.cache.EvictionAlgorithm;
 import org.apache.geode.cache.EvictionAttributes;
 import org.apache.geode.cache.Region;
 import org.apache.geode.cache.RegionAttributes;
+import org.apache.geode.cache.RegionDestroyedException;
 import org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl;
 import org.apache.geode.cache.execute.Execution;
 import org.apache.geode.cache.execute.FunctionService;
@@ -58,15 +69,23 @@ import 
org.apache.geode.cache.lucene.internal.filesystem.ChunkKey;
 import org.apache.geode.cache.lucene.internal.filesystem.File;
 import org.apache.geode.cache.lucene.internal.management.LuceneServiceMBean;
 import 
org.apache.geode.cache.lucene.internal.management.ManagementIndexListener;
+import org.apache.geode.cache.lucene.internal.repository.IndexRepository;
 import org.apache.geode.cache.lucene.internal.results.LuceneGetPageFunction;
 import org.apache.geode.cache.lucene.internal.results.PageResults;
 import org.apache.geode.cache.lucene.internal.xml.LuceneServiceXmlGenerator;
+import org.apache.geode.cache.query.internal.DefaultQuery;
 import org.apache.geode.distributed.internal.DistributionConfig;
 import org.apache.geode.internal.DSFIDFactory;
 import org.apache.geode.internal.DataSerializableFixedID;
+import org.apache.geode.internal.cache.AbstractRegion;
+import org.apache.geode.internal.cache.BucketNotFoundException;
+import org.apache.geode.internal.cache.BucketRegion;
 import org.apache.geode.internal.cache.CacheService;
+import org.apache.geode.internal.cache.EntrySnapshot;
 import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.LocalDataSet;
 import org.apache.geode.internal.cache.PartitionedRegion;
+import org.apache.geode.internal.cache.PrimaryBucketException;
 import org.apache.geode.internal.cache.RegionListener;
 import org.apache.geode.internal.cache.extension.Extensible;
 import org.apache.geode.internal.cache.xmlcache.XmlGenerator;
@@ -228,14 +247,15 @@ public class LuceneServiceImpl implements 
InternalLuceneService {
       regionPath = "/" + regionPath;
     }
 
+    // We must always register the index (this is where 
IndexAlreadyExistsException is detected)
     registerDefinedIndex(indexName, regionPath, new 
LuceneIndexCreationProfile(indexName,
         regionPath, fields, analyzer, fieldAnalyzers, serializer));
 
+    // If the region does not yet exist, install LuceneRegionListener and 
return
     PartitionedRegion region = (PartitionedRegion) cache.getRegion(regionPath);
-
-    LuceneRegionListener regionListener = new LuceneRegionListener(this, 
cache, indexName,
-        regionPath, fields, analyzer, fieldAnalyzers, serializer);
     if (region == null) {
+      LuceneRegionListener regionListener = new LuceneRegionListener(this, 
cache, indexName,
+          regionPath, fields, analyzer, fieldAnalyzers, serializer);
       cache.addRegionListener(regionListener);
       return;
     }
@@ -245,10 +265,9 @@ public class LuceneServiceImpl implements 
InternalLuceneService {
       throw new IllegalStateException("The lucene index must be created before 
region");
     }
 
-
+    // do work normally handled by LuceneRegionListener (if region already 
exists)
     createIndexOnExistingRegion(region, indexName, regionPath, fields, 
analyzer, fieldAnalyzers,
         serializer);
-
   }
 
   private void createIndexOnExistingRegion(PartitionedRegion region, String 
indexName,
@@ -266,6 +285,43 @@ public class LuceneServiceImpl implements 
InternalLuceneService {
         region.getAttributes(), analyzer, fieldAnalyzers, aeqId, serializer, 
fields);
 
     afterDataRegionCreated(luceneIndex);
+
+    createLuceneIndexOnDataRegion(region, luceneIndex);
+  }
+
+  protected boolean createLuceneIndexOnDataRegion(final PartitionedRegion 
userRegion,
+      final LuceneIndexImpl luceneIndex) {
+    try {
+      AbstractPartitionedRepositoryManager repositoryManager =
+          (AbstractPartitionedRepositoryManager) 
luceneIndex.getRepositoryManager();
+      if (userRegion.getDataStore() == null) {
+        return true;
+      }
+      Set<Integer> primaryBucketIds = 
userRegion.getDataStore().getAllLocalPrimaryBucketIds();
+      Iterator primaryBucketIterator = primaryBucketIds.iterator();
+      while (primaryBucketIterator.hasNext()) {
+        int primaryBucketId = (Integer) primaryBucketIterator.next();
+        try {
+          BucketRegion userBucket = 
userRegion.getDataStore().getLocalBucketById(primaryBucketId);
+          if (!userBucket.isEmpty()) {
+            repositoryManager.getRepository(primaryBucketId);
+          }
+        } catch (BucketNotFoundException | PrimaryBucketException e) {
+          logger.debug("Bucket ID : " + primaryBucketId
+              + " not found while saving to lucene index: " + e.getMessage(), 
e);
+        }
+      }
+      return true;
+    } catch (RegionDestroyedException e) {
+      logger.debug("Bucket not found while saving to lucene index: " + 
e.getMessage(), e);
+      return false;
+    } catch (CacheClosedException e) {
+      logger.debug("Unable to save to lucene index, cache has been closed", e);
+      return false;
+    } catch (AlreadyClosedException e) {
+      logger.debug("Unable to commit, the lucene index is already closed", e);
+      return false;
+    }
   }
 
   static void validateRegionAttributes(RegionAttributes attrs) {
diff --git 
a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/filesystem/FileSystem.java
 
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/filesystem/FileSystem.java
index fd8d620..25e0706 100644
--- 
a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/filesystem/FileSystem.java
+++ 
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/filesystem/FileSystem.java
@@ -23,6 +23,7 @@ import java.util.stream.Collectors;
 
 import org.apache.logging.log4j.Logger;
 
+import org.apache.geode.cache.lucene.internal.IndexRepositoryFactory;
 import org.apache.geode.internal.logging.LogService;
 
 /**
@@ -60,7 +61,9 @@ public class FileSystem {
 
   public Collection<String> listFileNames() {
     return (Collection<String>) fileAndChunkRegion.keySet().stream()
-        .filter(entry -> (entry instanceof 
String)).collect(Collectors.toList());
+        .filter(entry -> ((entry instanceof String) && !((String) entry)
+            
.equalsIgnoreCase(IndexRepositoryFactory.APACHE_GEODE_INDEX_COMPLETE)))
+        .collect(Collectors.toList());
   }
 
   public File createFile(final String name) throws IOException {
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneDUnitTest.java 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneDUnitTest.java
index c3f5dc2..44962f8 100644
--- 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneDUnitTest.java
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneDUnitTest.java
@@ -61,6 +61,14 @@ public abstract class LuceneDUnitTest extends 
JUnit4CacheTestCase {
     regionTestType.createAccessor(getCache(), REGION_NAME);
   }
 
+  protected void initDataStore(RegionTestableType regionTestType) throws 
Exception {
+    regionTestType.createDataStore(getCache(), REGION_NAME);
+  }
+
+  protected void initAccessor(RegionTestableType regionTestType) throws 
Exception {
+    regionTestType.createAccessor(getCache(), REGION_NAME);
+  }
+
   protected RegionTestableType[] getListOfRegionTestTypes() {
     return new RegionTestableType[] {RegionTestableType.PARTITION,
         RegionTestableType.PARTITION_REDUNDANT, 
RegionTestableType.PARTITION_OVERFLOW_TO_DISK,
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationIntegrationTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationIntegrationTest.java
index 8d88875..e62acf5 100644
--- 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationIntegrationTest.java
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationIntegrationTest.java
@@ -25,8 +25,10 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Consumer;
 import java.util.stream.Collectors;
@@ -94,8 +96,8 @@ public class LuceneIndexCreationIntegrationTest extends 
LuceneIntegrationTest {
     region.put("key1", new TestObject());
     verifyIndexFinishFlushing(cache, INDEX_NAME, REGION_NAME);
     assertEquals(analyzers, index.getFieldAnalyzers());
-    assertEquals(Arrays.asList("field1"), field1Analyzer.analyzedfields);
-    assertEquals(Arrays.asList("field2"), field2Analyzer.analyzedfields);
+    assertEquals(new HashSet(Arrays.asList("field1")), 
field1Analyzer.analyzedfields);
+    assertEquals(new HashSet(Arrays.asList("field2")), 
field2Analyzer.analyzedfields);
   }
 
   @Test
@@ -171,8 +173,8 @@ public class LuceneIndexCreationIntegrationTest extends 
LuceneIntegrationTest {
       region.put("key1", new TestObject());
       verifyIndexFinishFlushing(cache, INDEX_NAME, REGION_NAME);
       assertEquals(analyzers, index.getFieldAnalyzers());
-      assertEquals(Arrays.asList("field1"), field1Analyzer.analyzedfields);
-      assertEquals(Arrays.asList("field2"), field2Analyzer.analyzedfields);
+      assertEquals(new HashSet(Arrays.asList("field1")), 
field1Analyzer.analyzedfields);
+      assertEquals(new HashSet(Arrays.asList("field2")), 
field2Analyzer.analyzedfields);
     } finally {
       LuceneServiceImpl.luceneIndexFactory = new LuceneIndexImplFactory();
     }
@@ -316,7 +318,7 @@ public class LuceneIndexCreationIntegrationTest extends 
LuceneIntegrationTest {
 
   private static class RecordingAnalyzer extends Analyzer {
 
-    private List<String> analyzedfields = new ArrayList<String>();
+    private Set<String> analyzedfields = new HashSet<String>();
 
     @Override
     protected TokenStreamComponents createComponents(final String fieldName) {
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
index 854bca7..9fe6f4e 100644
--- 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
@@ -15,6 +15,8 @@
 package org.apache.geode.cache.lucene;
 
 import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.*;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
 import static org.junit.Assert.*;
 
 import java.io.Serializable;
@@ -153,8 +155,8 @@ public class LuceneIndexMaintenanceIntegrationTest extends 
LuceneIntegrationTest
     assertEquals(2, results.size());
     LuceneIndexForPartitionedRegion indexForPR = 
(LuceneIndexForPartitionedRegion) index;
     LuceneIndexStats indexStats = indexForPR.getIndexStats();
-    assertEquals(1, indexStats.getFailedEntries());
-    assertEquals(4, indexStats.getUpdates());
+    assertEquals(2, indexStats.getFailedEntries());
+    assertEquals(8, indexStats.getUpdates());
   }
 
   @Test
@@ -177,7 +179,7 @@ public class LuceneIndexMaintenanceIntegrationTest extends 
LuceneIntegrationTest
     assertEquals(5, results.size());
     LuceneIndexForPartitionedRegion indexForPR = 
(LuceneIndexForPartitionedRegion) index;
     LuceneIndexStats indexStats = indexForPR.getIndexStats();
-    assertEquals(10, indexStats.getUpdates());
+    assertThat("indexStats.getUpdates()", indexStats.getUpdates(), 
greaterThanOrEqualTo(10));
   }
 
   @Test
@@ -269,7 +271,7 @@ public class LuceneIndexMaintenanceIntegrationTest extends 
LuceneIntegrationTest
     LuceneTestUtilities.resumeSender(cache);
     assertTrue(luceneService.waitUntilFlushed(INDEX_NAME, REGION_NAME, 
WAIT_FOR_FLUSH_TIME,
         TimeUnit.MILLISECONDS));
-    assertEquals(4, index.getIndexStats().getCommits());
+    assertEquals(8, index.getIndexStats().getCommits());
   }
 
   @Test
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesAccessorBase.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesAccessorBase.java
index ecb5d7c..2116a82 100644
--- 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesAccessorBase.java
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesAccessorBase.java
@@ -62,6 +62,16 @@ public class LuceneQueriesAccessorBase extends 
LuceneDUnitTest {
     accessor = Host.getHost(0).getVM(3);
   }
 
+  protected void putDataInRegion(VM vm) {
+    vm.invoke(() -> {
+      final Cache cache = getCache();
+      Region<Object, Object> region = cache.getRegion(REGION_NAME);
+      region.put(1, new TestObject("hello world"));
+      region.put(113, new TestObject("hi world"));
+      region.put(2, new TestObject("goodbye world"));
+    });
+  }
+
   protected boolean waitForFlushBeforeExecuteTextSearch(VM vm, int ms) {
     return vm.invoke(() -> {
       Cache cache = getCache();
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesDUnitTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesDUnitTest.java
index 08e0e05..f29e89d 100644
--- 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesDUnitTest.java
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesDUnitTest.java
@@ -28,10 +28,17 @@ import org.junit.experimental.categories.Category;
 import org.junit.runner.RunWith;
 
 import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.PartitionAttributes;
+import org.apache.geode.cache.PartitionAttributesFactory;
 import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.lucene.internal.LuceneIndexFactoryImpl;
 import org.apache.geode.cache.lucene.internal.LuceneQueryImpl;
+import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
 import org.apache.geode.cache.lucene.test.LuceneTestUtilities;
 import org.apache.geode.distributed.ConfigurationProperties;
+import org.apache.geode.test.dunit.AsyncInvocation;
+import org.apache.geode.test.dunit.SerializableRunnable;
 import org.apache.geode.test.dunit.SerializableRunnableIF;
 import org.apache.geode.test.dunit.VM;
 import org.apache.geode.test.junit.categories.DistributedTest;
@@ -47,17 +54,26 @@ public class LuceneQueriesDUnitTest extends 
LuceneQueriesAccessorBase {
 
   private static final long serialVersionUID = 1L;
 
-  @Test
-  @Parameters(method = "getListOfRegionTestTypes")
-  public void 
transactionWithLuceneQueriesShouldThrowException(RegionTestableType 
regionTestType) {
-    SerializableRunnableIF createIndex = () -> {
+  protected SerializableRunnable createIndex = new 
SerializableRunnable("createIndex") {
+    public void run() {
       LuceneService luceneService = LuceneServiceProvider.get(getCache());
-      luceneService.createIndexFactory().addField("text").create(INDEX_NAME, 
REGION_NAME);
-    };
+      ((LuceneIndexFactoryImpl) 
luceneService.createIndexFactory()).addField("text")
+          .create(INDEX_NAME, REGION_NAME, LuceneServiceImpl.LUCENE_REINDEX);
+    }
+  };
+
+  protected void createRegionAndIndexForAllDataStores(RegionTestableType 
regionTestType,
+      SerializableRunnableIF createIndex) throws Exception {
     dataStore1.invoke(() -> initDataStore(createIndex, regionTestType));
     dataStore2.invoke(() -> initDataStore(createIndex, regionTestType));
     accessor.invoke(() -> initAccessor(createIndex, regionTestType));
+  }
 
+  @Test
+  @Parameters(method = "getListOfRegionTestTypes")
+  public void 
transactionWithLuceneQueriesShouldThrowException(RegionTestableType 
regionTestType)
+      throws Exception {
+    createRegionAndIndexForAllDataStores(regionTestType, createIndex);
     putDataInRegion(accessor);
     assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
     assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore1, 60000));
@@ -86,15 +102,8 @@ public class LuceneQueriesDUnitTest extends 
LuceneQueriesAccessorBase {
   @Test
   @Parameters(method = "getListOfRegionTestTypes")
   public void returnCorrectResultsFromStringQueryWithDefaultAnalyzer(
-      RegionTestableType regionTestType) {
-    SerializableRunnableIF createIndex = () -> {
-      LuceneService luceneService = LuceneServiceProvider.get(getCache());
-      luceneService.createIndexFactory().addField("text").create(INDEX_NAME, 
REGION_NAME);
-    };
-    dataStore1.invoke(() -> initDataStore(createIndex, regionTestType));
-    dataStore2.invoke(() -> initDataStore(createIndex, regionTestType));
-    accessor.invoke(() -> initAccessor(createIndex, regionTestType));
-
+      RegionTestableType regionTestType) throws Exception {
+    createRegionAndIndexForAllDataStores(regionTestType, createIndex);
     putDataInRegion(accessor);
     assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
     assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore1, 60000));
@@ -103,15 +112,9 @@ public class LuceneQueriesDUnitTest extends 
LuceneQueriesAccessorBase {
 
   @Test
   @Parameters(method = "getListOfRegionTestTypes")
-  public void defaultFieldShouldPropogateCorrectlyThroughFunction(
-      RegionTestableType regionTestType) {
-    SerializableRunnableIF createIndex = () -> {
-      LuceneService luceneService = LuceneServiceProvider.get(getCache());
-      luceneService.createIndexFactory().addField("text").create(INDEX_NAME, 
REGION_NAME);
-    };
-    dataStore1.invoke(() -> initDataStore(createIndex, regionTestType));
-    dataStore2.invoke(() -> initDataStore(createIndex, regionTestType));
-    accessor.invoke(() -> initAccessor(createIndex, regionTestType));
+  public void 
defaultFieldShouldPropogateCorrectlyThroughFunction(RegionTestableType 
regionTestType)
+      throws Exception {
+    createRegionAndIndexForAllDataStores(regionTestType, createIndex);
     putDataInRegion(accessor);
     assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
     assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore1, 60000));
@@ -121,14 +124,9 @@ public class LuceneQueriesDUnitTest extends 
LuceneQueriesAccessorBase {
 
   @Test
   @Parameters(method = "getListOfRegionTestTypes")
-  public void canQueryWithCustomLuceneQueryObject(RegionTestableType 
regionTestType) {
-    SerializableRunnableIF createIndex = () -> {
-      LuceneService luceneService = LuceneServiceProvider.get(getCache());
-      luceneService.createIndexFactory().addField("text").create(INDEX_NAME, 
REGION_NAME);
-    };
-    dataStore1.invoke(() -> initDataStore(createIndex, regionTestType));
-    dataStore2.invoke(() -> initDataStore(createIndex, regionTestType));
-    accessor.invoke(() -> initAccessor(createIndex, regionTestType));
+  public void canQueryWithCustomLuceneQueryObject(RegionTestableType 
regionTestType)
+      throws Exception {
+    createRegionAndIndexForAllDataStores(regionTestType, createIndex);
     putDataInRegion(accessor);
     assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
     assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore1, 60000));
@@ -149,14 +147,8 @@ public class LuceneQueriesDUnitTest extends 
LuceneQueriesAccessorBase {
   @Test
   @Parameters(method = "getListOfRegionTestTypes")
   public void verifyWaitForFlushedFunctionOnAccessor(RegionTestableType 
regionTestType)
-      throws InterruptedException {
-    SerializableRunnableIF createIndex = () -> {
-      LuceneService luceneService = LuceneServiceProvider.get(getCache());
-      luceneService.createIndexFactory().addField("text").create(INDEX_NAME, 
REGION_NAME);
-    };
-    dataStore1.invoke(() -> initDataStore(createIndex, regionTestType));
-    dataStore2.invoke(() -> initDataStore(createIndex, regionTestType));
-    accessor.invoke(() -> initAccessor(createIndex, regionTestType));
+      throws InterruptedException, Exception {
+    createRegionAndIndexForAllDataStores(regionTestType, createIndex);
     dataStore1.invoke(() -> LuceneTestUtilities.pauseSender(getCache()));
     dataStore2.invoke(() -> LuceneTestUtilities.pauseSender(getCache()));
     putDataInRegion(accessor);
@@ -170,14 +162,8 @@ public class LuceneQueriesDUnitTest extends 
LuceneQueriesAccessorBase {
 
   @Test
   @Parameters(method = "getListOfRegionTestTypes")
-  public void verifyWildcardQueriesSucceed(RegionTestableType regionTestType) {
-    SerializableRunnableIF createIndex = () -> {
-      LuceneService luceneService = LuceneServiceProvider.get(getCache());
-      luceneService.createIndexFactory().addField("text").create(INDEX_NAME, 
REGION_NAME);
-    };
-    dataStore1.invoke(() -> initDataStore(createIndex, regionTestType));
-    dataStore2.invoke(() -> initDataStore(createIndex, regionTestType));
-    accessor.invoke(() -> initAccessor(createIndex, regionTestType));
+  public void verifyWildcardQueriesSucceed(RegionTestableType regionTestType) 
throws Exception {
+    createRegionAndIndexForAllDataStores(regionTestType, createIndex);
     putDataInRegion(accessor);
     assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
     assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore1, 60000));
@@ -189,14 +175,8 @@ public class LuceneQueriesDUnitTest extends 
LuceneQueriesAccessorBase {
 
   @Test
   @Parameters(method = "getListOfRegionTestTypes")
-  public void verifySpaceQueriesFail(RegionTestableType regionTestType) {
-    SerializableRunnableIF createIndex = () -> {
-      LuceneService luceneService = LuceneServiceProvider.get(getCache());
-      luceneService.createIndexFactory().addField("text").create(INDEX_NAME, 
REGION_NAME);
-    };
-    dataStore1.invoke(() -> initDataStore(createIndex, regionTestType));
-    dataStore2.invoke(() -> initDataStore(createIndex, regionTestType));
-    accessor.invoke(() -> initAccessor(createIndex, regionTestType));
+  public void verifySpaceQueriesFail(RegionTestableType regionTestType) throws 
Exception {
+    createRegionAndIndexForAllDataStores(regionTestType, createIndex);
     putDataInRegion(accessor);
     assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
     assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore1, 60000));
@@ -205,16 +185,6 @@ public class LuceneQueriesDUnitTest extends 
LuceneQueriesAccessorBase {
     executeTextSearchWithExpectedException(accessor, " ", "XXX", 
LuceneQueryException.class);
   }
 
-  protected void putDataInRegion(VM vm) {
-    vm.invoke(() -> {
-      final Cache cache = getCache();
-      Region<Object, Object> region = cache.getRegion(REGION_NAME);
-      region.put(1, new TestObject("hello world"));
-      region.put(113, new TestObject("hi world"));
-      region.put(2, new TestObject("goodbye world"));
-    });
-  }
-
   @Override
   public Properties getDistributedSystemProperties() {
     Properties result = super.getDistributedSystemProperties();
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesIntegrationTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesIntegrationTest.java
index de5ad76..9dc683c 100644
--- 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesIntegrationTest.java
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesIntegrationTest.java
@@ -52,6 +52,8 @@ import org.apache.geode.cache.CacheLoaderException;
 import org.apache.geode.cache.LoaderHelper;
 import org.apache.geode.cache.Region;
 import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.lucene.internal.LuceneIndexFactoryImpl;
+import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
 import org.apache.geode.cache.lucene.test.TestObject;
 import org.apache.geode.pdx.JSONFormatter;
 import org.apache.geode.pdx.PdxInstance;
@@ -64,18 +66,30 @@ import 
org.apache.geode.test.junit.categories.IntegrationTest;
 public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest {
   @Rule
   public ExpectedException thrown = ExpectedException.none();
-  private static final String INDEX_NAME = "index";
+  protected static final String INDEX_NAME = "index";
   public static final String REGION_NAME = "index";
-  private Region region;
+  protected Region region;
+
+  protected Region createRegionAndIndex(Map<String, Analyzer> fields) {
+    ((LuceneIndexFactoryImpl) 
luceneService.createIndexFactory().setFields(fields))
+        .create(INDEX_NAME, REGION_NAME, LuceneServiceImpl.LUCENE_REINDEX);
+    region = 
cache.createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
+    return region;
+  }
+
+  protected Region createRegionAndIndex(RegionShortcut regionShortcut, 
String... fields) {
+    ((LuceneIndexFactoryImpl) 
luceneService.createIndexFactory().setFields(fields))
+        .create(INDEX_NAME, REGION_NAME, LuceneServiceImpl.LUCENE_REINDEX);
+    region = cache.createRegionFactory(regionShortcut).create(REGION_NAME);
+    return region;
+  }
 
   @Test()
   public void shouldNotTokenizeWordsWithKeywordAnalyzer() throws Exception {
     Map<String, Analyzer> fields = new HashMap<String, Analyzer>();
     fields.put("field1", new StandardAnalyzer());
     fields.put("field2", new KeywordAnalyzer());
-    luceneService.createIndexFactory().setFields(fields).create(INDEX_NAME, 
REGION_NAME);
-    Region region = 
cache.createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
-    final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
+    region = createRegionAndIndex(fields);
 
     // Put two values with some of the same tokens
     String value1 = "one three";
@@ -131,9 +145,7 @@ public class LuceneQueriesIntegrationTest extends 
LuceneIntegrationTest {
   public void shouldQueryUsingIntRangeQueryProvider() throws Exception {
     // Note: range query on numeric field has some limitations. But 
IntRangeQueryProvider
     // provided basic functionality
-    
luceneService.createIndexFactory().setFields(LuceneService.REGION_VALUE_FIELD)
-        .create(INDEX_NAME, REGION_NAME);
-    Region region = 
cache.createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
+    region = createRegionAndIndex(RegionShortcut.PARTITION, 
LuceneService.REGION_VALUE_FIELD);
     final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
 
     region.put("primitiveInt0", 122);
@@ -151,9 +163,7 @@ public class LuceneQueriesIntegrationTest extends 
LuceneIntegrationTest {
     Map<String, Analyzer> fields = new HashMap<String, Analyzer>();
     fields.put("field1", new StandardAnalyzer());
     fields.put("field2", new DoubleMetaphoneAnalyzer());
-    luceneService.createIndexFactory().setFields(fields).create(INDEX_NAME, 
REGION_NAME);
-    Region region = 
cache.createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
-    final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
+    region = createRegionAndIndex(fields);
 
     // Put two values with some of the same tokens
     String value1 = "Stefan";
@@ -187,9 +197,7 @@ public class LuceneQueriesIntegrationTest extends 
LuceneIntegrationTest {
   public void queryParserCannotQueryByRange() throws Exception {
     // Note: range query on numeric field has some limitations. But 
IntRangeQueryProvider
     // provided basic functionality
-    
luceneService.createIndexFactory().setFields(LuceneService.REGION_VALUE_FIELD)
-        .create(INDEX_NAME, REGION_NAME);
-    Region region = 
cache.createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
+    region = createRegionAndIndex(RegionShortcut.PARTITION, 
LuceneService.REGION_VALUE_FIELD);
     final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
 
     region.put("primitiveInt0", 122);
@@ -243,9 +251,7 @@ public class LuceneQueriesIntegrationTest extends 
LuceneIntegrationTest {
 
   private LuceneQuery<Object, Object> addValuesAndCreateQuery(int pagesize)
       throws InterruptedException {
-    luceneService.createIndexFactory().setFields("field1", 
"field2").create(INDEX_NAME,
-        REGION_NAME);
-    region = 
cache.createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
+    region = createRegionAndIndex(RegionShortcut.PARTITION, "field1", 
"field2");
     final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
 
     // Put two values with some of the same tokens
@@ -272,9 +278,7 @@ public class LuceneQueriesIntegrationTest extends 
LuceneIntegrationTest {
     // Note: fields has to contain "field1", otherwise, field1 will not be 
tokenized
     fields.put("field1", null);
     fields.put("field2", new MyCharacterAnalyzer());
-    luceneService.createIndexFactory().setFields(fields).create(INDEX_NAME, 
REGION_NAME);
-    Region region = 
cache.createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
-    final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
+    region = createRegionAndIndex(fields);
 
     // Put two values with some of the same tokens
     String value1 = "one three";
@@ -297,9 +301,7 @@ public class LuceneQueriesIntegrationTest extends 
LuceneIntegrationTest {
     Map<String, Analyzer> fields = new HashMap<String, Analyzer>();
     fields.put("field1", null);
     fields.put("field2", null);
-    luceneService.createIndexFactory().setFields(fields).create(INDEX_NAME, 
REGION_NAME);
-    Region region = 
cache.createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
-    final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
+    region = createRegionAndIndex(fields);
 
     // Put two values with some of the same tokens
     String value1 = "one three";
@@ -315,9 +317,7 @@ public class LuceneQueriesIntegrationTest extends 
LuceneIntegrationTest {
     fields.put("name", null);
     fields.put("lastName", null);
     fields.put("address", null);
-    luceneService.createIndexFactory().setFields(fields).create(INDEX_NAME, 
REGION_NAME);
-    Region region = 
cache.createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
-    final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
+    region = createRegionAndIndex(fields);
 
     // Put two values with some of the same tokens
     PdxInstance pdx1 = insertAJson(region, "jsondoc1");
@@ -337,9 +337,7 @@ public class LuceneQueriesIntegrationTest extends 
LuceneIntegrationTest {
     fields.put("name", null);
     fields.put("lastName", null);
     fields.put("address", null);
-    luceneService.createIndexFactory().setFields(fields).create(INDEX_NAME, 
REGION_NAME);
-    Region region = 
cache.createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
-    final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
+    region = createRegionAndIndex(fields);
 
     // This is to send IllegalStateException from WaitUntilFlushedFunction
     String nonCreatedIndex = "index2";
@@ -358,9 +356,7 @@ public class LuceneQueriesIntegrationTest extends 
LuceneIntegrationTest {
 
   @Test()
   public void shouldAllowQueryOnRegionWithStringValue() throws Exception {
-    
luceneService.createIndexFactory().setFields(LuceneService.REGION_VALUE_FIELD)
-        .create(INDEX_NAME, REGION_NAME);
-    Region region = 
cache.createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
+    region = createRegionAndIndex(RegionShortcut.PARTITION, 
LuceneService.REGION_VALUE_FIELD);
     final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
 
     region.put("A", "one three");
@@ -372,8 +368,7 @@ public class LuceneQueriesIntegrationTest extends 
LuceneIntegrationTest {
   @Test()
   public void throwFunctionExceptionWhenGivenBadQuery() throws Exception {
     LuceneService luceneService = LuceneServiceProvider.get(cache);
-    luceneService.createIndexFactory().setFields("text").create(INDEX_NAME, 
REGION_NAME);
-    Region region = 
cache.createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
+    region = createRegionAndIndex(RegionShortcut.PARTITION, "text");
 
     // Create a query that throws an exception
     final LuceneQuery<Object, Object> query =
@@ -529,9 +524,7 @@ public class LuceneQueriesIntegrationTest extends 
LuceneIntegrationTest {
     Map<String, Analyzer> fields = new HashMap<String, Analyzer>();
     fields.put("field1", new DoubleMetaphoneAnalyzer());
     fields.put("field2", null);
-    luceneService.createIndexFactory().setFields(fields).create(INDEX_NAME, 
REGION_NAME);
-    Region region = 
cache.createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
-    final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
+    region = createRegionAndIndex(fields);
 
     region.put("A", new TestObject("Stefan", "soundex"));
     region.put("B", new TestObject("Steph", "soundex"));
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesReindexClientDUnitTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesReindexClientDUnitTest.java
new file mode 100644
index 0000000..60f6dc7
--- /dev/null
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesReindexClientDUnitTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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;
+
+import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.*;
+import static org.junit.Assert.*;
+
+import java.util.Properties;
+
+import junitparams.JUnitParamsRunner;
+import junitparams.Parameters;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.TermQuery;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.PartitionAttributes;
+import org.apache.geode.cache.PartitionAttributesFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.client.ClientCacheFactory;
+import org.apache.geode.cache.client.ClientRegionShortcut;
+import org.apache.geode.cache.lucene.internal.LuceneIndexFactoryImpl;
+import org.apache.geode.cache.lucene.internal.LuceneQueryImpl;
+import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
+import org.apache.geode.cache.lucene.test.LuceneTestUtilities;
+import org.apache.geode.cache.server.CacheServer;
+import org.apache.geode.distributed.ConfigurationProperties;
+import org.apache.geode.test.dunit.AsyncInvocation;
+import org.apache.geode.test.dunit.SerializableCallableIF;
+import org.apache.geode.test.dunit.SerializableRunnableIF;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.junit.categories.DistributedTest;
+
+/**
+ * This test class is intended to contain basic integration tests of the 
lucene query class that
+ * should be executed against a number of different regions types and 
topologies.
+ *
+ */
+@Category(DistributedTest.class)
+@RunWith(JUnitParamsRunner.class)
+public class LuceneQueriesReindexClientDUnitTest extends 
LuceneQueriesReindexDUnitTest {
+
+  private static final long serialVersionUID = 1L;
+
+  @Override
+  public void postSetUp() throws Exception {
+    super.postSetUp();
+    SerializableCallableIF<Integer> launchServer = () -> {
+      final Cache cache = getCache();
+      final CacheServer server = cache.addCacheServer();
+      server.setPort(0);
+      server.start();
+      return server.getPort();
+    };
+    final int port1 = dataStore1.invoke(launchServer);
+    final int port2 = dataStore2.invoke(launchServer);
+
+    accessor.invoke(() -> {
+      ClientCacheFactory clientCacheFactory = new ClientCacheFactory();
+      clientCacheFactory.addPoolServer("localhost", port1);
+      clientCacheFactory.addPoolServer("localhost", port2);
+      ClientCache clientCache = getClientCache(clientCacheFactory);
+      
clientCache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(REGION_NAME);
+    });
+  }
+
+  protected void initAccessor(SerializableRunnableIF createIndex, 
RegionTestableType regionTestType)
+      throws Exception {}
+
+  protected RegionTestableType[] getListOfRegionTestTypes() {
+    return new RegionTestableType[] {RegionTestableType.PARTITION_WITH_CLIENT};
+  }
+
+}
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesReindexDUnitTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesReindexDUnitTest.java
new file mode 100644
index 0000000..68da7f9
--- /dev/null
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesReindexDUnitTest.java
@@ -0,0 +1,127 @@
+/*
+ * 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;
+
+import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.*;
+import static org.junit.Assert.*;
+
+import junitparams.JUnitParamsRunner;
+import junitparams.Parameters;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import org.apache.geode.cache.lucene.internal.LuceneIndexFactoryImpl;
+import org.apache.geode.test.dunit.AsyncInvocation;
+import org.apache.geode.test.dunit.SerializableRunnableIF;
+import org.apache.geode.test.junit.categories.DistributedTest;
+
+/**
+ * This test class is intended to contain basic integration tests of the 
lucene query class that
+ * should be executed against a number of different regions types and 
topologies.
+ *
+ */
+@Category(DistributedTest.class)
+@RunWith(JUnitParamsRunner.class)
+public class LuceneQueriesReindexDUnitTest extends LuceneQueriesAccessorBase {
+
+  private static final long serialVersionUID = 1L;
+
+  private void destroyIndex() {
+    LuceneService luceneService = LuceneServiceProvider.get(getCache());
+    luceneService.destroyIndex(INDEX_NAME, REGION_NAME);
+  }
+
+  private void recreateIndex() {
+    LuceneService luceneService = LuceneServiceProvider.get(getCache());
+    LuceneIndexFactoryImpl indexFactory =
+        (LuceneIndexFactoryImpl) 
luceneService.createIndexFactory().addField("text");
+    indexFactory.create(INDEX_NAME, REGION_NAME, true);
+  };
+
+  @Test
+  @Parameters(method = "getListOfRegionTestTypes")
+  public void dropAndRecreateIndex(RegionTestableType regionTestType) throws 
Exception {
+    SerializableRunnableIF createIndex = () -> {
+      LuceneService luceneService = LuceneServiceProvider.get(getCache());
+      luceneService.createIndexFactory().addField("text").create(INDEX_NAME, 
REGION_NAME);
+    };
+    dataStore1.invoke(() -> initDataStore(createIndex, regionTestType));
+    dataStore2.invoke(() -> initDataStore(createIndex, regionTestType));
+    accessor.invoke(() -> initAccessor(createIndex, regionTestType));
+
+    putDataInRegion(accessor);
+    assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
+    assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore1, 60000));
+    executeTextSearch(accessor);
+
+    dataStore1.invoke(() -> destroyIndex());
+
+    // re-index stored data
+    AsyncInvocation ai1 = dataStore1.invokeAsync(() -> {
+      recreateIndex();
+    });
+
+    AsyncInvocation ai2 = dataStore2.invokeAsync(() -> {
+      recreateIndex();
+    });
+
+    ai1.join();
+    ai2.join();
+
+    ai1.checkException();
+    ai2.checkException();
+
+    executeTextSearch(accessor);
+  }
+
+  @Test
+  @Parameters(method = "getListOfRegionTestTypes")
+  public void reindexThenQuery(RegionTestableType regionTestType) throws 
Exception {
+    SerializableRunnableIF createIndex = () -> {
+      LuceneService luceneService = LuceneServiceProvider.get(getCache());
+      LuceneIndexFactoryImpl indexFactory =
+          (LuceneIndexFactoryImpl) 
luceneService.createIndexFactory().addField("text");
+      indexFactory.create(INDEX_NAME, REGION_NAME, true);
+    };
+
+    // Create dataRegion prior to index
+    dataStore1.invoke(() -> initDataStore(regionTestType));
+    dataStore2.invoke(() -> initDataStore(regionTestType));
+    accessor.invoke(() -> initAccessor(regionTestType));
+
+    // populate region
+    putDataInRegion(accessor);
+
+    // re-index stored data
+    AsyncInvocation ai1 = dataStore1.invokeAsync(() -> {
+      recreateIndex();
+    });
+
+    // re-index stored data
+    AsyncInvocation ai2 = dataStore2.invokeAsync(() -> {
+      recreateIndex();
+    });
+
+    ai1.join();
+    ai2.join();
+
+    ai1.checkException();
+    ai2.checkException();
+
+    executeTextSearch(accessor);
+  }
+
+}
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesWithRegionCreatedBeforeReindexClientDUnitTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesWithRegionCreatedBeforeReindexClientDUnitTest.java
new file mode 100755
index 0000000..e0d99e3
--- /dev/null
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesWithRegionCreatedBeforeReindexClientDUnitTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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;
+
+import static 
org.apache.geode.cache.lucene.test.LuceneTestUtilities.REGION_NAME;
+
+import junitparams.JUnitParamsRunner;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.client.ClientCacheFactory;
+import org.apache.geode.cache.client.ClientRegionShortcut;
+import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
+import org.apache.geode.cache.server.CacheServer;
+import org.apache.geode.test.dunit.AsyncInvocation;
+import org.apache.geode.test.dunit.SerializableCallableIF;
+import org.apache.geode.test.dunit.SerializableRunnableIF;
+import org.apache.geode.test.junit.categories.DistributedTest;
+
+@Category(DistributedTest.class)
+@RunWith(JUnitParamsRunner.class)
+public class LuceneQueriesWithRegionCreatedBeforeReindexClientDUnitTest
+    extends LuceneQueriesClientDUnitTest {
+
+  @Before
+  public void setLuceneReindexFlag() {
+    dataStore1.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = true);
+    dataStore2.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = true);
+  }
+
+  @After
+  public void clearLuceneReindexFlag() {
+    dataStore1.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = false);
+    dataStore2.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = false);
+  }
+
+  @Override
+  protected void createRegionAndIndexForAllDataStores(RegionTestableType 
regionTestType,
+      SerializableRunnableIF createIndex) throws Exception {
+
+    // Create dataRegion prior to index
+    dataStore1.invoke(() -> initDataStore(regionTestType));
+    dataStore2.invoke(() -> initDataStore(regionTestType));
+    accessor.invoke(() -> initAccessor(regionTestType));
+
+    // re-index stored data
+    AsyncInvocation ai1 = dataStore1.invokeAsync(createIndex);
+
+    // re-index stored data
+    AsyncInvocation ai2 = dataStore2.invokeAsync(createIndex);
+
+    ai1.join();
+    ai2.join();
+
+    ai1.checkException();
+    ai2.checkException();
+  }
+}
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesWithRegionCreatedBeforeReindexDUnitTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesWithRegionCreatedBeforeReindexDUnitTest.java
new file mode 100644
index 0000000..7b216d3
--- /dev/null
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesWithRegionCreatedBeforeReindexDUnitTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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;
+
+import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.*;
+import static org.junit.Assert.*;
+
+import java.util.Properties;
+
+import junitparams.JUnitParamsRunner;
+import junitparams.Parameters;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.TermQuery;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.PartitionAttributes;
+import org.apache.geode.cache.PartitionAttributesFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.lucene.internal.LuceneIndexFactoryImpl;
+import org.apache.geode.cache.lucene.internal.LuceneQueryImpl;
+import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
+import org.apache.geode.cache.lucene.test.LuceneTestUtilities;
+import org.apache.geode.distributed.ConfigurationProperties;
+import org.apache.geode.test.dunit.AsyncInvocation;
+import org.apache.geode.test.dunit.SerializableRunnableIF;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.junit.categories.DistributedTest;
+
+/**
+ * This test class is intended to contain basic integration tests of the 
lucene query class that
+ * should be executed against a number of different regions types and 
topologies.
+ *
+ */
+@Category(DistributedTest.class)
+@RunWith(JUnitParamsRunner.class)
+public class LuceneQueriesWithRegionCreatedBeforeReindexDUnitTest extends 
LuceneQueriesDUnitTest {
+
+  private static final long serialVersionUID = 1L;
+
+  @Before
+  public void setLuceneReindexFlag() {
+    dataStore1.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = true);
+    dataStore2.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = true);
+    accessor.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = true);
+  }
+
+  @After
+  public void clearLuceneReindexFlag() {
+    dataStore1.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = false);
+    dataStore2.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = false);
+    accessor.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = false);
+  }
+
+  @Override
+  protected void createRegionAndIndexForAllDataStores(RegionTestableType 
regionTestType,
+      SerializableRunnableIF createIndex) throws Exception {
+
+    // Create dataRegion prior to index
+    dataStore1.invoke(() -> initDataStore(regionTestType));
+    dataStore2.invoke(() -> initDataStore(regionTestType));
+    accessor.invoke(() -> initAccessor(regionTestType));
+
+    // re-index stored data
+    AsyncInvocation ai1 = dataStore1.invokeAsync(createIndex);
+    AsyncInvocation ai2 = dataStore2.invokeAsync(createIndex);
+    AsyncInvocation ai3 = accessor.invokeAsync(createIndex);
+
+    ai1.join();
+    ai2.join();
+    ai3.join();
+
+    ai1.checkException();
+    ai2.checkException();
+    ai3.checkException();
+  }
+
+}
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesWithRegionCreatedBeforeReindexIntegrationTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesWithRegionCreatedBeforeReindexIntegrationTest.java
new file mode 100644
index 0000000..4e581a9
--- /dev/null
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesWithRegionCreatedBeforeReindexIntegrationTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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;
+
+import static 
org.apache.geode.cache.lucene.test.LuceneTestUtilities.DEFAULT_FIELD;
+import static 
org.apache.geode.cache.lucene.test.LuceneTestUtilities.IntRangeQueryProvider;
+import static 
org.apache.geode.cache.lucene.test.LuceneTestUtilities.verifyQueryKeyAndValues;
+import static 
org.apache.geode.cache.lucene.test.LuceneTestUtilities.verifyQueryKeys;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.Tokenizer;
+import org.apache.lucene.analysis.core.KeywordAnalyzer;
+import org.apache.lucene.analysis.core.LowerCaseFilter;
+import org.apache.lucene.analysis.phonetic.DoubleMetaphoneFilter;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.analysis.standard.StandardTokenizer;
+import org.apache.lucene.analysis.util.CharTokenizer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
+
+import org.apache.geode.cache.CacheLoader;
+import org.apache.geode.cache.CacheLoaderException;
+import org.apache.geode.cache.LoaderHelper;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.lucene.internal.LuceneIndexFactoryImpl;
+import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
+import org.apache.geode.cache.lucene.test.TestObject;
+import org.apache.geode.pdx.JSONFormatter;
+import org.apache.geode.pdx.PdxInstance;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+
+/**
+ * This class contains tests of lucene queries that can fit
+ */
+@Category(IntegrationTest.class)
+public class LuceneQueriesWithRegionCreatedBeforeReindexIntegrationTest
+    extends LuceneQueriesIntegrationTest {
+
+  @Before
+  public void setLuceneReindexFlag() {
+    LuceneServiceImpl.LUCENE_REINDEX = true;
+  }
+
+  @After
+  public void clearLuceneReindexFlag() {
+    LuceneServiceImpl.LUCENE_REINDEX = false;
+  }
+
+  protected Region createRegionAndIndex(Map<String, Analyzer> fields) {
+    region = 
cache.createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
+    ((LuceneIndexFactoryImpl) 
luceneService.createIndexFactory().setFields(fields))
+        .create(INDEX_NAME, REGION_NAME, LuceneServiceImpl.LUCENE_REINDEX);
+    return region;
+  }
+
+  protected Region createRegionAndIndex(RegionShortcut regionShortcut, 
String... fields) {
+    region = cache.createRegionFactory(regionShortcut).create(REGION_NAME);
+    ((LuceneIndexFactoryImpl) 
luceneService.createIndexFactory().setFields(fields))
+        .create(INDEX_NAME, REGION_NAME, LuceneServiceImpl.LUCENE_REINDEX);
+    return region;
+  }
+
+}
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesWithReindexFlagEnabledClientDUnitTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesWithReindexFlagEnabledClientDUnitTest.java
new file mode 100755
index 0000000..4517cd9
--- /dev/null
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesWithReindexFlagEnabledClientDUnitTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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;
+
+import static 
org.apache.geode.cache.lucene.test.LuceneTestUtilities.REGION_NAME;
+
+import junitparams.JUnitParamsRunner;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.client.ClientCacheFactory;
+import org.apache.geode.cache.client.ClientRegionShortcut;
+import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
+import org.apache.geode.cache.server.CacheServer;
+import org.apache.geode.test.dunit.SerializableCallableIF;
+import org.apache.geode.test.dunit.SerializableRunnableIF;
+import org.apache.geode.test.junit.categories.DistributedTest;
+
+@Category(DistributedTest.class)
+@RunWith(JUnitParamsRunner.class)
+public class LuceneQueriesWithReindexFlagEnabledClientDUnitTest
+    extends LuceneQueriesClientDUnitTest {
+
+  private static final long serialVersionUID = 1L;
+
+  @Before
+  public void setLuceneReindexFlag() {
+    dataStore1.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = true);
+    dataStore2.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = true);
+  }
+
+  @After
+  public void clearLuceneReindexFlag() {
+    dataStore1.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = false);
+    dataStore2.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = false);
+  }
+}
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesWithReindexFlagEnabledDUnitTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesWithReindexFlagEnabledDUnitTest.java
new file mode 100644
index 0000000..0232e08
--- /dev/null
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesWithReindexFlagEnabledDUnitTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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;
+
+import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.*;
+import static org.junit.Assert.*;
+
+import java.util.Properties;
+
+import junitparams.JUnitParamsRunner;
+import junitparams.Parameters;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.TermQuery;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.PartitionAttributes;
+import org.apache.geode.cache.PartitionAttributesFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.lucene.internal.LuceneIndexFactoryImpl;
+import org.apache.geode.cache.lucene.internal.LuceneQueryImpl;
+import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
+import org.apache.geode.cache.lucene.test.LuceneTestUtilities;
+import org.apache.geode.distributed.ConfigurationProperties;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.test.dunit.AsyncInvocation;
+import org.apache.geode.test.dunit.SerializableRunnableIF;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.categories.DistributedTest;
+
+/**
+ * This test class is intended to contain basic integration tests of the 
lucene query class that
+ * should be executed against a number of different regions types and 
topologies.
+ *
+ */
+@Category(DistributedTest.class)
+@RunWith(JUnitParamsRunner.class)
+public class LuceneQueriesWithReindexFlagEnabledDUnitTest extends 
LuceneQueriesDUnitTest {
+
+  private static final long serialVersionUID = 1L;
+
+  @Before
+  public void setLuceneReindexFlag() {
+    dataStore1.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = true);
+    dataStore2.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = true);
+    accessor.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = true);
+  }
+
+  @After
+  public void clearLuceneReindexFlag() {
+    dataStore1.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = false);
+    dataStore2.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = false);
+    accessor.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = false);
+  }
+
+}
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesWithReindexFlagEnabledIntegrationTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesWithReindexFlagEnabledIntegrationTest.java
new file mode 100644
index 0000000..5716283
--- /dev/null
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesWithReindexFlagEnabledIntegrationTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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;
+
+import static 
org.apache.geode.cache.lucene.test.LuceneTestUtilities.DEFAULT_FIELD;
+import static 
org.apache.geode.cache.lucene.test.LuceneTestUtilities.IntRangeQueryProvider;
+import static 
org.apache.geode.cache.lucene.test.LuceneTestUtilities.verifyQueryKeyAndValues;
+import static 
org.apache.geode.cache.lucene.test.LuceneTestUtilities.verifyQueryKeys;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.Tokenizer;
+import org.apache.lucene.analysis.core.KeywordAnalyzer;
+import org.apache.lucene.analysis.core.LowerCaseFilter;
+import org.apache.lucene.analysis.phonetic.DoubleMetaphoneFilter;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.analysis.standard.StandardTokenizer;
+import org.apache.lucene.analysis.util.CharTokenizer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
+
+import org.apache.geode.cache.CacheLoader;
+import org.apache.geode.cache.CacheLoaderException;
+import org.apache.geode.cache.LoaderHelper;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
+import org.apache.geode.cache.lucene.test.TestObject;
+import org.apache.geode.pdx.JSONFormatter;
+import org.apache.geode.pdx.PdxInstance;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+
+/**
+ * This class contains tests of lucene queries that can fit
+ */
+@Category(IntegrationTest.class)
+public class LuceneQueriesWithReindexFlagEnabledIntegrationTest
+    extends LuceneQueriesIntegrationTest {
+
+  @Before
+  public void setLuceneReindexFlag() {
+    LuceneServiceImpl.LUCENE_REINDEX = true;
+  }
+
+  @After
+  public void clearLuceneReindexFlag() {
+    LuceneServiceImpl.LUCENE_REINDEX = false;
+  }
+
+}
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/RebalanceWithRedundancyDUnitTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/RebalanceWithRedundancyDUnitTest.java
index 720dcc4..7481780 100644
--- 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/RebalanceWithRedundancyDUnitTest.java
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/RebalanceWithRedundancyDUnitTest.java
@@ -177,15 +177,16 @@ public class RebalanceWithRedundancyDUnitTest extends 
LuceneQueriesAccessorBase
     dataStore1.invoke(() -> initDataStore(createIndex, regionTestType));
     dataStore2.invoke(() -> initDataStore(createIndex, regionTestType));
     accessor.invoke(() -> initAccessor(createIndex, regionTestType));
+
     dataStore1.invoke(() -> LuceneTestUtilities.pauseSender(getCache()));
     dataStore2.invoke(() -> LuceneTestUtilities.pauseSender(getCache()));
     accessor.invoke(() -> LuceneTestUtilities.pauseSender(getCache()));
 
     putEntryInEachBucket();
 
-    dataStore1.invoke(() -> LuceneTestUtilities.resumeSender(getCache()));
-    dataStore2.invoke(() -> LuceneTestUtilities.resumeSender(getCache()));
-    accessor.invoke(() -> LuceneTestUtilities.resumeSender(getCache()));
+    dataStore1.invoke(() -> LuceneTestUtilities.resumeSender(basicGetCache()));
+    dataStore2.invoke(() -> LuceneTestUtilities.resumeSender(basicGetCache()));
+    accessor.invoke(() -> LuceneTestUtilities.resumeSender(basicGetCache()));
 
     assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore2, 60000));
 
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/PartitionedRepositoryManagerJUnitTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/PartitionedRepositoryManagerJUnitTest.java
index df7deca..894a193 100644
--- 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/PartitionedRepositoryManagerJUnitTest.java
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/PartitionedRepositoryManagerJUnitTest.java
@@ -34,9 +34,14 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
 import org.mockito.Mockito;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
 
 import org.apache.geode.cache.lucene.LuceneSerializer;
 import org.apache.geode.cache.lucene.internal.directory.RegionDirectory;
@@ -45,11 +50,14 @@ import 
org.apache.geode.cache.lucene.internal.partition.BucketTargetingMap;
 import org.apache.geode.cache.lucene.internal.repository.IndexRepository;
 import org.apache.geode.cache.lucene.internal.repository.IndexRepositoryImpl;
 import 
org.apache.geode.cache.lucene.internal.repository.serializer.HeterogeneousLuceneSerializer;
+import org.apache.geode.cache.partition.PartitionRegionHelper;
 import org.apache.geode.distributed.internal.locks.DLockService;
 import org.apache.geode.internal.cache.BucketAdvisor;
 import org.apache.geode.internal.cache.BucketNotFoundException;
 import org.apache.geode.internal.cache.BucketRegion;
 import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.internal.cache.LocalRegion;
+import org.apache.geode.internal.cache.PartitionRegionConfig;
 import org.apache.geode.internal.cache.PartitionedRegion;
 import org.apache.geode.internal.cache.PartitionedRegion.RetryTimeKeeper;
 import org.apache.geode.internal.cache.PartitionedRegionDataStore;
@@ -59,6 +67,9 @@ import org.apache.geode.test.fake.Fakes;
 import org.apache.geode.test.junit.categories.UnitTest;
 
 @Category(UnitTest.class)
+@RunWith(PowerMockRunner.class)
+@PowerMockIgnore("*.UnitTest")
+@PrepareForTest({PartitionedRegionHelper.class})
 public class PartitionedRepositoryManagerJUnitTest {
 
   protected PartitionedRegion userRegion;
@@ -66,6 +77,9 @@ public class PartitionedRepositoryManagerJUnitTest {
   protected LuceneSerializer serializer;
   protected PartitionedRegionDataStore userDataStore;
   protected PartitionedRegionDataStore fileDataStore;
+  protected PartitionedRegionHelper prHelper;
+  protected PartitionRegionConfig prConfig;
+  protected LocalRegion prRoot;
 
   protected Map<Integer, BucketRegion> fileAndChunkBuckets = new 
HashMap<Integer, BucketRegion>();
   protected Map<Integer, BucketRegion> dataBuckets = new HashMap<Integer, 
BucketRegion>();
@@ -101,6 +115,8 @@ public class PartitionedRepositoryManagerJUnitTest {
     when(fileAndChunkRegion.getDataStore()).thenReturn(fileDataStore);
     when(fileAndChunkRegion.getTotalNumberOfBuckets()).thenReturn(113);
     when(fileAndChunkRegion.getFullPath()).thenReturn("FileRegion");
+    when(fileAndChunkRegion.getCache()).thenReturn(cache);
+    when(fileAndChunkRegion.getRegionIdentifier()).thenReturn("rid");
     indexStats = Mockito.mock(LuceneIndexStats.class);
     fileSystemStats = Mockito.mock(FileSystemStats.class);
     indexForPR = Mockito.mock(LuceneIndexForPartitionedRegion.class);
@@ -112,6 +128,12 @@ public class PartitionedRepositoryManagerJUnitTest {
     when(indexForPR.getAnalyzer()).thenReturn(new StandardAnalyzer());
     when(indexForPR.getCache()).thenReturn(cache);
     when(indexForPR.getRegionPath()).thenReturn("/testRegion");
+    prRoot = Mockito.mock(LocalRegion.class);
+    prConfig = Mockito.mock(PartitionRegionConfig.class);
+    when(prConfig.isColocationComplete()).thenReturn(true);
+    when(prRoot.get("rid")).thenReturn(prConfig);
+    PowerMockito.mockStatic(PartitionedRegionHelper.class);
+    
PowerMockito.when(PartitionedRegionHelper.getPRRoot(cache)).thenReturn(prRoot);
     repoManager = new PartitionedRepositoryManager(indexForPR, serializer);
     repoManager.setUserRegionForRepositoryManager();
     repoManager.allowRepositoryComputation();
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/management/LuceneManagementDUnitTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/management/LuceneManagementDUnitTest.java
index adb05fb..5193d59 100644
--- 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/management/LuceneManagementDUnitTest.java
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/management/LuceneManagementDUnitTest.java
@@ -15,6 +15,8 @@
 package org.apache.geode.cache.lucene.internal.management;
 
 import static 
org.apache.geode.cache.lucene.test.LuceneTestUtilities.INDEX_NAME;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
@@ -253,8 +255,8 @@ public class LuceneManagementDUnitTest extends 
ManagementTestBase {
     }
 
     // Verify index metrics counts
-    assertEquals(expectedPuts, totalCommits);
-    assertEquals(expectedPuts, totalUpdates);
+    assertThat("totalCommits", totalCommits, 
greaterThanOrEqualTo(expectedPuts));
+    assertThat("totalUpdates", totalUpdates, 
greaterThanOrEqualTo(expectedPuts));
     assertEquals(expectedPuts, totalDocuments);
     assertEquals(expectedQueries, totalQueries);
     assertEquals(expectedHits, totalHits);

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

Reply via email to