geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject [geode] branch develop updated: GEODE-5047: list lucene index result modified (#1799)
Date Thu, 03 May 2018 22:10:22 GMT
This is an automated email from the ASF dual-hosted git repository.

nnag pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 8f0b97a  GEODE-5047: list lucene index result modified (#1799)
8f0b97a is described below

commit 8f0b97a48396d5d1ae23aa28696d2d4786160d4b
Author: Nabarun Nag <nabarunnag@users.noreply.github.com>
AuthorDate: Thu May 3 15:10:13 2018 -0700

    GEODE-5047: list lucene index result modified (#1799)
    
             * list lucene index gfsh command will now display on of three states
    	* NOT_INITIALIZED if the index is present in only in defined map
    	* INITIALIZED if the index is present in the index map
    	* INDEXING_IN_PROGRESS if the index creation is in progress.
---
 .../org/apache/geode/cache/lucene/LuceneIndex.java |  9 ++++
 .../internal/LuceneIndexForPartitionedRegion.java  | 14 +++++
 .../cache/lucene/internal/LuceneRawIndex.java      |  5 ++
 .../lucene/internal/cli/LuceneIndexCommands.java   |  6 ++-
 .../lucene/internal/cli/LuceneIndexDetails.java    | 31 ++++++++---
 .../lucene/internal/cli/LuceneIndexStatus.java     | 20 +++++++
 .../cli/functions/LuceneListIndexFunction.java     | 17 ++++--
 .../lucene/internal/xml/LuceneIndexCreation.java   |  6 +--
 .../internal/xml/LuceneIndexXmlGenerator.java      |  5 +-
 .../sanctioned-geode-lucene-serializables.txt      |  3 +-
 .../internal/cli/LuceneIndexCommandsDUnitTest.java |  4 +-
 .../internal/cli/LuceneIndexCommandsJUnitTest.java | 36 +++++++------
 ...neIndexCommandsWithReindexAllowedDUnitTest.java | 30 +++++++++++
 .../LuceneListIndexFunctionJUnitTest.java          | 61 ++++++++++++++++------
 .../LuceneClusterConfigurationDUnitTest.java       |  4 +-
 .../xml/LuceneIndexXmlGeneratorJUnitTest.java      |  5 +-
 16 files changed, 194 insertions(+), 62 deletions(-)

diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/LuceneIndex.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/LuceneIndex.java
index 3b48919..7779a92 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/LuceneIndex.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/LuceneIndex.java
@@ -20,6 +20,7 @@ import java.util.Map;
 import org.apache.lucene.analysis.Analyzer;
 
 
+
 /**
  * <p>
  * LuceneIndex represents the Lucene index created over the data stored in Apache Geode regions.
The
@@ -83,4 +84,12 @@ public interface LuceneIndex {
    */
   LuceneSerializer getLuceneSerializer();
 
+  /**
+   * Returns a boolean value to indicate if reindexing is in progress.
+   *
+   * @Return a boolean value indicating indexing progress
+   */
+
+  boolean isIndexingInProgress();
+
 }
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
index 99b9a89..778b8fd 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
@@ -41,6 +41,7 @@ import org.apache.geode.distributed.internal.DistributionManager;
 import org.apache.geode.distributed.internal.ReplyException;
 import org.apache.geode.distributed.internal.ReplyProcessor21;
 import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.internal.cache.BucketRegion;
 import org.apache.geode.internal.cache.InternalCache;
 import org.apache.geode.internal.cache.PartitionedRegion;
 
@@ -70,6 +71,19 @@ public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
     return partitionedRepositoryManager;
   }
 
+  public boolean isIndexingInProgress() {
+    PartitionedRegion userRegion = (PartitionedRegion) cache.getRegion(this.getRegionPath());
+    Set<Integer> fileRegionPrimaryBucketIds =
+        this.getFileAndChunkRegion().getDataStore().getAllLocalPrimaryBucketIds();
+    for (Integer bucketId : fileRegionPrimaryBucketIds) {
+      BucketRegion userBucket = userRegion.getDataStore().getLocalBucketById(bucketId);
+      if (!userBucket.isEmpty() && !this.isIndexAvailable(bucketId)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
   protected void createLuceneListenersAndFileChunkRegions(
       PartitionedRepositoryManager partitionedRepositoryManager) {
     partitionedRepositoryManager.setUserRegionForRepositoryManager((PartitionedRegion) dataRegion);
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneRawIndex.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneRawIndex.java
index 1416cab..2e23235 100755
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneRawIndex.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneRawIndex.java
@@ -55,4 +55,9 @@ public class LuceneRawIndex extends LuceneIndexImpl {
   public boolean isIndexAvailable(int id) {
     return true;
   }
+
+  @Override
+  public boolean isIndexingInProgress() {
+    return false;
+  }
 }
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 0e99d9d..43b7d2c 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
@@ -123,10 +123,12 @@ public class LuceneIndexCommands extends InternalGfshCommand {
         indexData.accumulate("Indexed Fields", indexDetails.getSearchableFieldNamesString());
         indexData.accumulate("Field Analyzer", indexDetails.getFieldAnalyzersString());
         indexData.accumulate("Serializer", indexDetails.getSerializerString());
-        indexData.accumulate("Status", indexDetails.getInitialized() ? "Initialized" : "Defined");
+        indexData.accumulate("Status", indexDetails.getStatus().toString());
 
         if (stats) {
-          if (!indexDetails.getInitialized()) {
+          LuceneIndexStatus luceneIndexStatus = indexDetails.getStatus();
+          if (luceneIndexStatus == LuceneIndexStatus.NOT_INITIALIZED
+              || luceneIndexStatus == LuceneIndexStatus.INDEXING_IN_PROGRESS) {
             indexData.accumulate("Query Executions", "NA");
             indexData.accumulate("Updates", "NA");
             indexData.accumulate("Commits", "NA");
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexDetails.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexDetails.java
index a837064..20c7a94 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexDetails.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexDetails.java
@@ -35,31 +35,46 @@ public class LuceneIndexDetails extends LuceneFunctionSerializable
   private final String[] searchableFieldNames;
   private Map<String, String> fieldAnalyzers = null;
   private final Map<String, Integer> indexStats;
-  private boolean initialized;
+  private LuceneIndexStatus status;
   private String serializer;
 
   public LuceneIndexDetails(final String indexName, final String regionPath,
       final String[] searchableFieldNames, final Map<String, Analyzer> fieldAnalyzers,
-      LuceneIndexStats indexStats, boolean initialized, final String serverName,
+      LuceneIndexStats indexStats, LuceneIndexStatus status, final String serverName,
       LuceneSerializer serializer) {
     super(indexName, regionPath);
     this.serverName = serverName;
     this.searchableFieldNames = searchableFieldNames;
     this.fieldAnalyzers = getFieldAnalyzerStrings(fieldAnalyzers);
     this.indexStats = getIndexStatsMap(indexStats);
-    this.initialized = initialized;
+    this.status = status;
     this.serializer = serializer != null ? serializer.getClass().getSimpleName()
         : HeterogeneousLuceneSerializer.class.getSimpleName();
   }
 
   public LuceneIndexDetails(LuceneIndexImpl index, final String serverName) {
     this(index.getName(), index.getRegionPath(), index.getFieldNames(), index.getFieldAnalyzers(),
-        index.getIndexStats(), true, serverName, index.getLuceneSerializer());
+        index.getIndexStats(), LuceneIndexStatus.INITIALIZED, serverName,
+        index.getLuceneSerializer());
+  }
+
+  public LuceneIndexDetails(LuceneIndexImpl index, final String serverName,
+      final LuceneIndexStatus status) {
+    this(index.getName(), index.getRegionPath(), index.getFieldNames(), index.getFieldAnalyzers(),
+        index.getIndexStats(), status, serverName, index.getLuceneSerializer());
   }
 
   public LuceneIndexDetails(LuceneIndexCreationProfile indexProfile, final String serverName)
{
     this(indexProfile.getIndexName(), indexProfile.getRegionPath(), indexProfile.getFieldNames(),
-        null, null, false, serverName, null);
+        null, null, LuceneIndexStatus.NOT_INITIALIZED, serverName, null);
+    this.fieldAnalyzers = getFieldAnalyzerStringsFromProfile(indexProfile.getFieldAnalyzers());
+    this.serializer = indexProfile.getSerializerClass();
+  }
+
+  public LuceneIndexDetails(LuceneIndexCreationProfile indexProfile, final String serverName,
+      final LuceneIndexStatus status) {
+    this(indexProfile.getIndexName(), indexProfile.getRegionPath(), indexProfile.getFieldNames(),
+        null, null, status, serverName, null);
     this.fieldAnalyzers = getFieldAnalyzerStringsFromProfile(indexProfile.getFieldAnalyzers());
     this.serializer = indexProfile.getSerializerClass();
   }
@@ -137,14 +152,14 @@ public class LuceneIndexDetails extends LuceneFunctionSerializable
     buffer.append(",\tIndexed Fields = " + getSearchableFieldNamesString());
     buffer.append(",\tField Analyzer = " + getFieldAnalyzersString());
     buffer.append(",\tSerializer = " + getSerializerString());
-    buffer.append(",\tStatus =\n\t" + getInitialized());
+    buffer.append(",\tStatus =\n\t" + getStatus());
     buffer.append(",\tIndex Statistics =\n\t" + getIndexStatsString());
     buffer.append("\n}\n");
     return buffer.toString();
   }
 
-  public boolean getInitialized() {
-    return initialized;
+  public LuceneIndexStatus getStatus() {
+    return status;
   }
 
   private static <T extends Comparable<T>> int compare(final T obj1, final T
obj2) {
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexStatus.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexStatus.java
new file mode 100644
index 0000000..81ebf9a
--- /dev/null
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexStatus.java
@@ -0,0 +1,20 @@
+/*
+ * 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.cli;
+
+public enum LuceneIndexStatus {
+  NOT_INITIALIZED, INITIALIZED, INDEXING_IN_PROGRESS
+
+}
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneListIndexFunction.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneListIndexFunction.java
index a4d7193..90421cd 100755
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneListIndexFunction.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneListIndexFunction.java
@@ -27,6 +27,7 @@ import org.apache.geode.cache.lucene.internal.LuceneIndexCreationProfile;
 import org.apache.geode.cache.lucene.internal.LuceneIndexImpl;
 import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
 import org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails;
+import org.apache.geode.cache.lucene.internal.cli.LuceneIndexStatus;
 import org.apache.geode.internal.InternalEntity;
 import org.apache.geode.internal.cache.execute.InternalFunction;
 
@@ -56,12 +57,18 @@ public class LuceneListIndexFunction implements InternalFunction {
     final Cache cache = context.getCache();
     final String serverName = cache.getDistributedSystem().getDistributedMember().getName();
     LuceneServiceImpl service = (LuceneServiceImpl) LuceneServiceProvider.get(cache);
-    for (LuceneIndex index : service.getAllIndexes()) {
-      indexDetailsSet.add(new LuceneIndexDetails((LuceneIndexImpl) index, serverName));
-    }
-
     for (LuceneIndexCreationProfile profile : service.getAllDefinedIndexes()) {
-      indexDetailsSet.add(new LuceneIndexDetails(profile, serverName));
+      indexDetailsSet
+          .add(new LuceneIndexDetails(profile, serverName, LuceneIndexStatus.NOT_INITIALIZED));
+    }
+    for (LuceneIndex index : service.getAllIndexes()) {
+      LuceneIndexStatus initialized;
+      if (index.isIndexingInProgress()) {
+        initialized = LuceneIndexStatus.INDEXING_IN_PROGRESS;
+      } else {
+        initialized = LuceneIndexStatus.INITIALIZED;
+      }
+      indexDetailsSet.add(new LuceneIndexDetails((LuceneIndexImpl) index, serverName, initialized));
     }
     context.getResultSender().lastResult(indexDetailsSet);
   }
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexCreation.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexCreation.java
index d781c05..eeff69d 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexCreation.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexCreation.java
@@ -28,7 +28,6 @@ import org.apache.lucene.analysis.standard.StandardAnalyzer;
 
 import org.apache.geode.cache.Cache;
 import org.apache.geode.cache.Region;
-import org.apache.geode.cache.lucene.LuceneIndex;
 import org.apache.geode.cache.lucene.LuceneIndexExistsException;
 import org.apache.geode.cache.lucene.LuceneSerializer;
 import org.apache.geode.cache.lucene.LuceneServiceProvider;
@@ -39,7 +38,7 @@ import org.apache.geode.internal.cache.xmlcache.XmlGenerator;
 import org.apache.geode.internal.i18n.LocalizedStrings;
 import org.apache.geode.internal.logging.LogService;
 
-public class LuceneIndexCreation implements LuceneIndex, Extension<Region<?, ?>>
{
+public class LuceneIndexCreation implements Extension<Region<?, ?>> {
   private Region region;
   private String name;
   private Set<String> fieldNames = new LinkedHashSet<String>();
@@ -61,7 +60,6 @@ public class LuceneIndexCreation implements LuceneIndex, Extension<Region<?,
?>>
     this.fieldAnalyzers = fieldAnalyzers;
   }
 
-  @Override
   public Map<String, Analyzer> getFieldAnalyzers() {
     if (this.fieldAnalyzers == null) {
       this.fieldAnalyzers = new HashMap<>();
@@ -77,12 +75,10 @@ public class LuceneIndexCreation implements LuceneIndex, Extension<Region<?,
?>>
     return fieldNames.toArray(new String[fieldNames.size()]);
   }
 
-  @Override
   public String getRegionPath() {
     return region.getFullPath();
   }
 
-  @Override
   public LuceneSerializer getLuceneSerializer() {
     return this.luceneSerializer;
   }
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGenerator.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGenerator.java
index f6689d9..6dcca04 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGenerator.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGenerator.java
@@ -29,7 +29,6 @@ import org.xml.sax.SAXException;
 import org.xml.sax.helpers.AttributesImpl;
 
 import org.apache.geode.cache.Region;
-import org.apache.geode.cache.lucene.LuceneIndex;
 import org.apache.geode.cache.lucene.LuceneSerializer;
 import org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator;
 import org.apache.geode.internal.cache.xmlcache.XmlGenerator;
@@ -38,9 +37,9 @@ import org.apache.geode.internal.cache.xmlcache.XmlGeneratorUtils;
 public class LuceneIndexXmlGenerator implements XmlGenerator<Region<?, ?>> {
   private static final AttributesImpl EMPTY = new AttributesImpl();
 
-  private final LuceneIndex index;
+  private final LuceneIndexCreation index;
 
-  public LuceneIndexXmlGenerator(LuceneIndex index) {
+  public LuceneIndexXmlGenerator(LuceneIndexCreation index) {
     this.index = index;
   }
 
diff --git a/geode-lucene/src/main/resources/org/apache/geode/internal/sanctioned-geode-lucene-serializables.txt
b/geode-lucene/src/main/resources/org/apache/geode/internal/sanctioned-geode-lucene-serializables.txt
index 3a9117a..2ef12c2 100755
--- a/geode-lucene/src/main/resources/org/apache/geode/internal/sanctioned-geode-lucene-serializables.txt
+++ b/geode-lucene/src/main/resources/org/apache/geode/internal/sanctioned-geode-lucene-serializables.txt
@@ -2,9 +2,10 @@ org/apache/geode/cache/lucene/LuceneIndexDestroyedException,false,indexName:java
 org/apache/geode/cache/lucene/LuceneIndexExistsException,false,indexName:java/lang/String,regionPath:java/lang/String
 org/apache/geode/cache/lucene/LuceneIndexNotFoundException,false,indexName:java/lang/String,regionPath:java/lang/String
 org/apache/geode/cache/lucene/LuceneQueryException,false
+org/apache/geode/cache/lucene/internal/cli/LuceneIndexStatus,false
 org/apache/geode/cache/lucene/internal/cli/LuceneDestroyIndexInfo,false,definedDestroyOnly:boolean
 org/apache/geode/cache/lucene/internal/cli/LuceneFunctionSerializable,false,indexName:java/lang/String,regionPath:java/lang/String
-org/apache/geode/cache/lucene/internal/cli/LuceneIndexDetails,true,1,fieldAnalyzers:java/util/Map,indexStats:java/util/Map,initialized:boolean,searchableFieldNames:java/lang/String[],serializer:java/lang/String,serverName:java/lang/String
+org/apache/geode/cache/lucene/internal/cli/LuceneIndexDetails,true,1,fieldAnalyzers:java/util/Map,indexStats:java/util/Map,searchableFieldNames:java/lang/String[],serializer:java/lang/String,serverName:java/lang/String,status:org/apache/geode/cache/lucene/internal/cli/LuceneIndexStatus
 org/apache/geode/cache/lucene/internal/cli/LuceneIndexInfo,true,1,fieldAnalyzers:java/lang/String[],searchableFieldNames:java/lang/String[],serializer:java/lang/String
 org/apache/geode/cache/lucene/internal/cli/LuceneQueryInfo,true,1,defaultField:java/lang/String,keysOnly:boolean,limit:int,queryString:java/lang/String
 org/apache/geode/cache/lucene/internal/cli/LuceneSearchResults,false,exceptionFlag:boolean,exceptionMessage:java/lang/String,key:java/lang/String,score:float,value:java/lang/String
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
index 96b2884..bded765 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
@@ -130,7 +130,7 @@ public class LuceneIndexCommandsDUnitTest implements Serializable {
     csb.addOption(LuceneCliStrings.LUCENE_LIST_INDEX__STATS, "true");
 
     gfsh.executeAndAssertThat(csb.toString())
-        .tableHasColumnWithExactValuesInAnyOrder("Status", "Defined")
+        .tableHasColumnWithExactValuesInAnyOrder("Status", "NOT_INITIALIZED")
         .tableHasColumnWithExactValuesInAnyOrder("Index Name", INDEX_NAME);
   }
 
@@ -149,7 +149,7 @@ public class LuceneIndexCommandsDUnitTest implements Serializable {
 
     gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess()
         .tableHasColumnWithExactValuesInAnyOrder("Index Name", INDEX_NAME)
-        .tableHasColumnWithExactValuesInAnyOrder("Status", "Initialized")
+        .tableHasColumnWithExactValuesInAnyOrder("Status", "INITIALIZED")
         .tableHasColumnWithExactValuesInAnyOrder("Region Path", "/region")
         .tableHasColumnWithExactValuesInAnyOrder("Query Executions", "1")
         .tableHasColumnWithExactValuesInAnyOrder("Documents", "2");
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsJUnitTest.java
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsJUnitTest.java
index 5bb5b93..9f6bdc0 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsJUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsJUnitTest.java
@@ -113,11 +113,12 @@ public class LuceneIndexCommandsJUnitTest {
     fieldAnalyzers.put("field3", null);
     LuceneSerializer serializer = new HeterogeneousLuceneSerializer();
     final LuceneIndexDetails indexDetails1 = createIndexDetails("memberFive", "/Employees",
-        searchableFields, fieldAnalyzers, true, serverName, serializer);
-    final LuceneIndexDetails indexDetails2 = createIndexDetails("memberSix", "/Employees",
-        searchableFields, fieldAnalyzers, false, serverName, serializer);
+        searchableFields, fieldAnalyzers, LuceneIndexStatus.INITIALIZED, serverName, serializer);
+    final LuceneIndexDetails indexDetails2 =
+        createIndexDetails("memberSix", "/Employees", searchableFields, fieldAnalyzers,
+            LuceneIndexStatus.NOT_INITIALIZED, serverName, serializer);
     final LuceneIndexDetails indexDetails3 = createIndexDetails("memberTen", "/Employees",
-        searchableFields, fieldAnalyzers, true, serverName, serializer);
+        searchableFields, fieldAnalyzers, LuceneIndexStatus.INITIALIZED, serverName, serializer);
 
     final List<Set<LuceneIndexDetails>> results = new ArrayList<>();
 
@@ -142,7 +143,7 @@ public class LuceneIndexCommandsJUnitTest {
             "{field1=StandardAnalyzer, field2=KeywordAnalyzer}",
             "{field1=StandardAnalyzer, field2=KeywordAnalyzer}"),
         data.retrieveAllValues("Field Analyzer"));
-    assertEquals(Arrays.asList("Initialized", "Defined", "Initialized"),
+    assertEquals(Arrays.asList("INITIALIZED", "NOT_INITIALIZED", "INITIALIZED"),
         data.retrieveAllValues("Status"));
   }
 
@@ -161,12 +162,15 @@ public class LuceneIndexCommandsJUnitTest {
     fieldAnalyzers.put("field2", new KeywordAnalyzer());
     fieldAnalyzers.put("field3", null);
     LuceneSerializer serializer = new HeterogeneousLuceneSerializer();
-    final LuceneIndexDetails indexDetails1 = createIndexDetails("memberFive", "/Employees",
-        searchableFields, fieldAnalyzers, mockIndexStats1, true, serverName, serializer);
-    final LuceneIndexDetails indexDetails2 = createIndexDetails("memberSix", "/Employees",
-        searchableFields, fieldAnalyzers, mockIndexStats2, true, serverName, serializer);
-    final LuceneIndexDetails indexDetails3 = createIndexDetails("memberTen", "/Employees",
-        searchableFields, fieldAnalyzers, mockIndexStats3, true, serverName, serializer);
+    final LuceneIndexDetails indexDetails1 =
+        createIndexDetails("memberFive", "/Employees", searchableFields, fieldAnalyzers,
+            mockIndexStats1, LuceneIndexStatus.INITIALIZED, serverName, serializer);
+    final LuceneIndexDetails indexDetails2 =
+        createIndexDetails("memberSix", "/Employees", searchableFields, fieldAnalyzers,
+            mockIndexStats2, LuceneIndexStatus.INITIALIZED, serverName, serializer);
+    final LuceneIndexDetails indexDetails3 =
+        createIndexDetails("memberTen", "/Employees", searchableFields, fieldAnalyzers,
+            mockIndexStats3, LuceneIndexStatus.INITIALIZED, serverName, serializer);
 
     final List<Set<LuceneIndexDetails>> results = new ArrayList<>();
 
@@ -248,7 +252,7 @@ public class LuceneIndexCommandsJUnitTest {
     final List<LuceneIndexDetails> indexDetails = new ArrayList<>();
     LuceneSerializer serializer = new HeterogeneousLuceneSerializer();
     indexDetails.add(createIndexDetails("memberFive", "/Employees", searchableFields,
-        fieldAnalyzers, mockIndexStats, true, serverName, serializer));
+        fieldAnalyzers, mockIndexStats, LuceneIndexStatus.INITIALIZED, serverName, serializer));
 
     doReturn(mockResultCollector).when(commands).executeFunctionOnRegion(
         isA(LuceneDescribeIndexFunction.class), any(LuceneIndexInfo.class), eq(true));
@@ -263,7 +267,7 @@ public class LuceneIndexCommandsJUnitTest {
         data.retrieveAllValues("Indexed Fields"));
     assertEquals(Collections.singletonList("{field1=StandardAnalyzer, field2=KeywordAnalyzer}"),
         data.retrieveAllValues("Field Analyzer"));
-    assertEquals(Collections.singletonList("Initialized"), data.retrieveAllValues("Status"));
+    assertEquals(Collections.singletonList("INITIALIZED"), data.retrieveAllValues("Status"));
     assertEquals(Collections.singletonList("1"), data.retrieveAllValues("Query Executions"));
     assertEquals(Collections.singletonList("10"), data.retrieveAllValues("Commits"));
     assertEquals(Collections.singletonList("5"), data.retrieveAllValues("Updates"));
@@ -629,15 +633,15 @@ public class LuceneIndexCommandsJUnitTest {
 
   private LuceneIndexDetails createIndexDetails(final String indexName, final String regionPath,
       final String[] searchableFields, final Map<String, Analyzer> fieldAnalyzers,
-      LuceneIndexStats indexStats, boolean status, final String serverName,
+      LuceneIndexStats indexStats, LuceneIndexStatus status, final String serverName,
       LuceneSerializer serializer) {
     return new LuceneIndexDetails(indexName, regionPath, searchableFields, fieldAnalyzers,
         indexStats, status, serverName, serializer);
   }
 
   private LuceneIndexDetails createIndexDetails(final String indexName, final String regionPath,
-      final String[] searchableFields, final Map<String, Analyzer> fieldAnalyzers,
boolean status,
-      final String serverName, LuceneSerializer serializer) {
+      final String[] searchableFields, final Map<String, Analyzer> fieldAnalyzers,
+      LuceneIndexStatus status, final String serverName, LuceneSerializer serializer) {
     return new LuceneIndexDetails(indexName, regionPath, searchableFields, fieldAnalyzers,
null,
         status, serverName, serializer);
   }
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsWithReindexAllowedDUnitTest.java
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsWithReindexAllowedDUnitTest.java
index bc53531..e2a29a1 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsWithReindexAllowedDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsWithReindexAllowedDUnitTest.java
@@ -30,6 +30,7 @@ import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.experimental.categories.Category;
 
 import org.apache.geode.cache.lucene.LuceneIndex;
 import org.apache.geode.cache.lucene.LuceneService;
@@ -37,7 +38,11 @@ import org.apache.geode.cache.lucene.LuceneServiceProvider;
 import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
 import org.apache.geode.cache.lucene.internal.repository.serializer.PrimitiveSerializer;
 import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
+import org.apache.geode.test.dunit.AsyncInvocation;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.categories.LuceneTest;
 
+@Category({DistributedTest.class, LuceneTest.class})
 public class LuceneIndexCommandsWithReindexAllowedDUnitTest extends LuceneIndexCommandsDUnitTest
{
 
   @After
@@ -51,6 +56,31 @@ public class LuceneIndexCommandsWithReindexAllowedDUnitTest extends LuceneIndexC
   }
 
   @Test
+  public void whenLuceneReindexingInProgressThenListIndexCommandMustExecuteSuccessfully()
{
+
+    CommandStringBuilder csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX);
+    csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, INDEX_NAME);
+    csb.addOption(LuceneCliStrings.LUCENE__REGION_PATH, REGION_NAME);
+    csb.addOption(LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD, "__REGION_VALUE_FIELD");
+
+    serverVM.invoke(() -> createRegion());
+    AsyncInvocation ai = serverVM.invokeAsync(() -> {
+      int count = 0;
+      while (true) {
+        getCache().getRegion(REGION_NAME).put(count, "hello world" + count);
+      }
+    });
+
+    gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess()
+        .containsOutput("Successfully created lucene index");
+    csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_LIST_INDEX);
+    csb.addOption(LuceneCliStrings.LUCENE_LIST_INDEX__STATS, "true");
+    gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess();
+    ai.cancel(true);
+
+  }
+
+  @Test
   public void whenLuceneReindexAllowedCreateIndexShouldCreateANewIndex() {
     CommandStringBuilder csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX);
     csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, INDEX_NAME);
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneListIndexFunctionJUnitTest.java
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneListIndexFunctionJUnitTest.java
index e9f356c..c691e46 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneListIndexFunctionJUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneListIndexFunctionJUnitTest.java
@@ -14,11 +14,14 @@
  */
 package org.apache.geode.cache.lucene.internal.cli.functions;
 
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
@@ -34,10 +37,14 @@ import org.apache.geode.cache.execute.FunctionContext;
 import org.apache.geode.cache.execute.ResultSender;
 import org.apache.geode.cache.lucene.LuceneIndex;
 import org.apache.geode.cache.lucene.internal.InternalLuceneService;
-import org.apache.geode.cache.lucene.internal.LuceneIndexImpl;
+import org.apache.geode.cache.lucene.internal.LuceneIndexForPartitionedRegion;
 import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
 import org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails;
+import org.apache.geode.cache.lucene.internal.cli.LuceneIndexStatus;
+import org.apache.geode.internal.cache.BucketRegion;
 import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.internal.cache.PartitionedRegion;
+import org.apache.geode.internal.cache.PartitionedRegionDataStore;
 import org.apache.geode.test.fake.Fakes;
 import org.apache.geode.test.junit.categories.LuceneTest;
 import org.apache.geode.test.junit.categories.UnitTest;
@@ -46,11 +53,12 @@ import org.apache.geode.test.junit.categories.UnitTest;
 
 public class LuceneListIndexFunctionJUnitTest {
 
+
   @Test
   @SuppressWarnings("unchecked")
-  public void testExecute() throws Throwable {
+  public void executeListLuceneIndexWhenReindexingInProgress() {
     GemFireCacheImpl cache = Fakes.cache();
-    final String serverName = "mockServer";
+    final String serverName = "mockedServer";
     LuceneServiceImpl service = mock(LuceneServiceImpl.class);
     when(cache.getService(InternalLuceneService.class)).thenReturn(service);
 
@@ -59,18 +67,37 @@ public class LuceneListIndexFunctionJUnitTest {
     when(context.getResultSender()).thenReturn(resultSender);
     when(context.getCache()).thenReturn(cache);
 
-    LuceneIndexImpl index1 = getMockLuceneIndex("index1");
-    LuceneIndexImpl index2 = getMockLuceneIndex("index2");
+    LuceneIndexForPartitionedRegion index1 = getMockLuceneIndex("index1");
 
-    TreeSet expectedResult = new TreeSet();
-    expectedResult.add(new LuceneIndexDetails(index1, serverName));
-    expectedResult.add(new LuceneIndexDetails(index2, serverName));
+    PartitionedRegion userRegion = mock(PartitionedRegion.class);
+    when(cache.getRegion(index1.getRegionPath())).thenReturn(userRegion);
+
+    PartitionedRegionDataStore userRegionDataStore = mock(PartitionedRegionDataStore.class);
+    when(userRegion.getDataStore()).thenReturn(userRegionDataStore);
+
+    BucketRegion userBucket = mock(BucketRegion.class);
+    when(userRegionDataStore.getLocalBucketById(1)).thenReturn(userBucket);
+
+    when(userBucket.isEmpty()).thenReturn(false);
 
     ArrayList<LuceneIndex> allIndexes = new ArrayList();
     allIndexes.add(index1);
-    allIndexes.add(index2);
     when(service.getAllIndexes()).thenReturn(allIndexes);
 
+    PartitionedRegion mockFileRegion = mock(PartitionedRegion.class);
+    when(index1.getFileAndChunkRegion()).thenReturn(mockFileRegion);
+
+    PartitionedRegionDataStore mockPartitionedRegionDataStore =
+        mock(PartitionedRegionDataStore.class);
+    when(mockFileRegion.getDataStore()).thenReturn(mockPartitionedRegionDataStore);
+
+    Set<Integer> bucketSet = new HashSet<>();
+    bucketSet.add(1);
+
+    when(mockPartitionedRegionDataStore.getAllLocalPrimaryBucketIds()).thenReturn(bucketSet);
+
+    when(index1.isIndexAvailable(1)).thenReturn(false);
+
     LuceneListIndexFunction function = new LuceneListIndexFunction();
     function.execute(context);
 
@@ -78,17 +105,21 @@ public class LuceneListIndexFunctionJUnitTest {
     verify(resultSender).lastResult(resultCaptor.capture());
     Set<String> result = resultCaptor.getValue();
 
-    assertEquals(2, result.size());
+    TreeSet expectedResult = new TreeSet();
+    expectedResult
+        .add(new LuceneIndexDetails(index1, serverName, LuceneIndexStatus.INDEXING_IN_PROGRESS));
+
+    assertEquals(1, result.size());
     assertEquals(expectedResult, result);
+
   }
 
-  private LuceneIndexImpl getMockLuceneIndex(final String indexName) {
+  private LuceneIndexForPartitionedRegion getMockLuceneIndex(final String indexName) {
+    LuceneIndexForPartitionedRegion index = mock(LuceneIndexForPartitionedRegion.class);
     String[] searchableFields = {"field1", "field2"};
     Map<String, Analyzer> fieldAnalyzers = new HashMap<>();
     fieldAnalyzers.put("field1", new StandardAnalyzer());
     fieldAnalyzers.put("field2", new KeywordAnalyzer());
-
-    LuceneIndexImpl index = mock(LuceneIndexImpl.class);
     when(index.getName()).thenReturn(indexName);
     when(index.getRegionPath()).thenReturn("/region");
     when(index.getFieldNames()).thenReturn(searchableFields);
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 7000138..6ad15b7 100644
--- 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
@@ -240,8 +240,8 @@ public class LuceneClusterConfigurationDUnitTest {
     // Verify all members have indexes
     csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_LIST_INDEX);
     gfshConnector.executeAndAssertThat(csb.toString()).statusIsSuccess()
-        .tableHasColumnWithExactValuesInExactOrder("Status", "Initialized", "Initialized",
-            "Initialized");
+        .tableHasColumnWithExactValuesInExactOrder("Status", "INITIALIZED", "INITIALIZED",
+            "INITIALIZED");
   }
 
   MemberVM createServer(Properties properties, int index) throws Exception {
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorJUnitTest.java
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorJUnitTest.java
index e981c1f..f3a0cbe 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorJUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorJUnitTest.java
@@ -28,7 +28,6 @@ import org.mockito.ArgumentCaptor;
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
 
-import org.apache.geode.cache.lucene.LuceneIndex;
 import org.apache.geode.cache.lucene.LuceneSerializer;
 import org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator;
 import org.apache.geode.internal.cache.xmlcache.Declarable2;
@@ -43,7 +42,7 @@ public class LuceneIndexXmlGeneratorJUnitTest {
    */
   @Test
   public void generateWithFields() throws Exception {
-    LuceneIndex index = mock(LuceneIndex.class);
+    LuceneIndexCreation index = mock(LuceneIndexCreation.class);
     when(index.getName()).thenReturn("index");
     String[] fields = new String[] {"field1", "field2"};
     when(index.getFieldNames()).thenReturn(fields);
@@ -79,7 +78,7 @@ public class LuceneIndexXmlGeneratorJUnitTest {
    */
   @Test
   public void generateWithSerializer() throws Exception {
-    LuceneIndex index = mock(LuceneIndex.class);
+    LuceneIndexCreation index = mock(LuceneIndexCreation.class);
     LuceneSerializer mySerializer =
         mock(LuceneSerializer.class, withSettings().extraInterfaces(Declarable2.class));
     Properties props = new Properties();

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

Mime
View raw message