geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From upthewatersp...@apache.org
Subject [geode] 02/02: GEODE-3242: Adding lucene serializer to describe command
Date Wed, 04 Oct 2017 17:28:23 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 17820305e599b91f362be440e16b5f4726f73a39
Author: Dan Smith <upthewaterspout@apache.org>
AuthorDate: Mon Oct 2 16:17:53 2017 -0700

    GEODE-3242: Adding lucene serializer to describe command
    
    Printing the lucene index's serializer in the output of describe index.
---
 .../lucene/internal/cli/LuceneIndexCommands.java   |  1 +
 .../lucene/internal/cli/LuceneIndexDetails.java    | 19 ++++++++++---
 .../internal/cli/LuceneIndexCommandsDUnitTest.java | 24 ++++++++++++++++
 .../internal/cli/LuceneIndexCommandsJUnitTest.java | 33 ++++++++++++++--------
 4 files changed, 62 insertions(+), 15 deletions(-)

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 77c4535..9b548f6 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
@@ -139,6 +139,7 @@ public class LuceneIndexCommands implements GfshCommand {
         indexData.accumulate("Server Name", indexDetails.getServerName());
         indexData.accumulate("Indexed Fields", indexDetails.getSearchableFieldNamesString());
         indexData.accumulate("Field Analyzer", indexDetails.getFieldAnalyzersString());
+        indexData.accumulate("Serializer", indexDetails.getSerializerString());
         indexData.accumulate("Status", indexDetails.getInitialized() ? "Initialized" : "Defined");
 
         if (stats) {
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 2acc144..20e5d81 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
@@ -20,9 +20,11 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
 
+import org.apache.geode.cache.lucene.LuceneSerializer;
 import org.apache.geode.cache.lucene.internal.LuceneIndexCreationProfile;
 import org.apache.geode.cache.lucene.internal.LuceneIndexImpl;
 import org.apache.geode.cache.lucene.internal.LuceneIndexStats;
+import org.apache.geode.cache.lucene.internal.repository.serializer.HeterogeneousLuceneSerializer;
 
 import org.apache.lucene.analysis.Analyzer;
 
@@ -34,27 +36,32 @@ public class LuceneIndexDetails extends LuceneFunctionSerializable
   private Map<String, String> fieldAnalyzers = null;
   private final Map<String, Integer> indexStats;
   private boolean initialized;
+  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, boolean initialized, 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.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.getIndexStats(), true, serverName, index.getLuceneSerializer());
   }
 
   public LuceneIndexDetails(LuceneIndexCreationProfile indexProfile, final String serverName)
{
     this(indexProfile.getIndexName(), indexProfile.getRegionPath(), indexProfile.getFieldNames(),
-        null, null, false, serverName);
+        null, null, false, serverName, null);
     this.fieldAnalyzers = getFieldAnalyzerStringsFromProfile(indexProfile.getFieldAnalyzers());
+    this.serializer = indexProfile.getSerializerClass();
   }
 
   public Map<String, Integer> getIndexStats() {
@@ -114,11 +121,14 @@ public class LuceneIndexDetails extends LuceneFunctionSerializable
     return Arrays.asList(searchableFieldNames).toString();
   }
 
-
   public String getFieldAnalyzersString() {
     return fieldAnalyzers.toString();
   }
 
+  public String getSerializerString() {
+    return this.serializer;
+  }
+
   @Override
   public String toString() {
     final StringBuffer buffer = new StringBuffer();
@@ -126,6 +136,7 @@ public class LuceneIndexDetails extends LuceneFunctionSerializable
     buffer.append(",\tRegion Path = " + regionPath);
     buffer.append(",\tIndexed Fields = " + getSearchableFieldNamesString());
     buffer.append(",\tField Analyzer = " + getFieldAnalyzersString());
+    buffer.append(",\tSerializer = " + getSerializerString());
     buffer.append(",\tStatus =\n\t" + getInitialized());
     buffer.append(",\tIndex Statistics =\n\t" + getIndexStatsString());
     buffer.append("\n}\n");
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 eb491df..7cd464b 100755
--- 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
@@ -417,6 +417,30 @@ public class LuceneIndexCommandsDUnitTest extends CliCommandTestBase
{
   }
 
   @Test
+  public void describeIndexShouldShowSerializer() throws Exception {
+    final VM vm1 = Host.getHost(0).getVM(1);
+
+    vm1.invoke(() -> {
+      getCache();
+    });
+    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, "field1,field2,field3");
+    csb.addOption(LuceneCliStrings.LUCENE_CREATE_INDEX__SERIALIZER,
+        PrimitiveSerializer.class.getCanonicalName());
+
+    String resultAsString = executeCommandAndLogResult(csb);
+    vm1.invoke(() -> createRegion());
+
+    csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_DESCRIBE_INDEX);
+    csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, INDEX_NAME);
+    csb.addOption(LuceneCliStrings.LUCENE__REGION_PATH, REGION_NAME);
+    resultAsString = executeCommandAndLogResult(csb);
+    assertThat(resultAsString).contains(PrimitiveSerializer.class.getSimpleName());
+  }
+
+  @Test
   public void describeIndexShouldNotReturnResultWhenIndexNotFound() throws Exception {
     final VM vm1 = Host.getHost(0).getVM(1);
 
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 6c95e9c..bb010e7 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
@@ -51,11 +51,13 @@ import org.mockito.ArgumentCaptor;
 
 import org.apache.geode.cache.execute.Execution;
 import org.apache.geode.cache.execute.ResultCollector;
+import org.apache.geode.cache.lucene.LuceneSerializer;
 import org.apache.geode.cache.lucene.internal.LuceneIndexStats;
 import org.apache.geode.cache.lucene.internal.cli.functions.LuceneCreateIndexFunction;
 import org.apache.geode.cache.lucene.internal.cli.functions.LuceneDescribeIndexFunction;
 import org.apache.geode.cache.lucene.internal.cli.functions.LuceneDestroyIndexFunction;
 import org.apache.geode.cache.lucene.internal.cli.functions.LuceneListIndexFunction;
+import org.apache.geode.cache.lucene.internal.repository.serializer.HeterogeneousLuceneSerializer;
 import org.apache.geode.cache.lucene.internal.repository.serializer.PrimitiveSerializer;
 import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.internal.cache.InternalCache;
@@ -109,12 +111,13 @@ public class LuceneIndexCommandsJUnitTest {
     fieldAnalyzers.put("field1", new StandardAnalyzer());
     fieldAnalyzers.put("field2", new KeywordAnalyzer());
     fieldAnalyzers.put("field3", null);
+    LuceneSerializer serializer = new HeterogeneousLuceneSerializer();
     final LuceneIndexDetails indexDetails1 = createIndexDetails("memberFive", "/Employees",
-        searchableFields, fieldAnalyzers, true, serverName);
+        searchableFields, fieldAnalyzers, true, serverName, serializer);
     final LuceneIndexDetails indexDetails2 = createIndexDetails("memberSix", "/Employees",
-        searchableFields, fieldAnalyzers, false, serverName);
+        searchableFields, fieldAnalyzers, false, serverName, serializer);
     final LuceneIndexDetails indexDetails3 = createIndexDetails("memberTen", "/Employees",
-        searchableFields, fieldAnalyzers, true, serverName);
+        searchableFields, fieldAnalyzers, true, serverName, serializer);
 
     final List<Set<LuceneIndexDetails>> results = new ArrayList<>();
 
@@ -157,12 +160,13 @@ public class LuceneIndexCommandsJUnitTest {
     fieldAnalyzers.put("field1", new StandardAnalyzer());
     fieldAnalyzers.put("field2", new KeywordAnalyzer());
     fieldAnalyzers.put("field3", null);
+    LuceneSerializer serializer = new HeterogeneousLuceneSerializer();
     final LuceneIndexDetails indexDetails1 = createIndexDetails("memberFive", "/Employees",
-        searchableFields, fieldAnalyzers, mockIndexStats1, true, serverName);
+        searchableFields, fieldAnalyzers, mockIndexStats1, true, serverName, serializer);
     final LuceneIndexDetails indexDetails2 = createIndexDetails("memberSix", "/Employees",
-        searchableFields, fieldAnalyzers, mockIndexStats2, true, serverName);
+        searchableFields, fieldAnalyzers, mockIndexStats2, true, serverName, serializer);
     final LuceneIndexDetails indexDetails3 = createIndexDetails("memberTen", "/Employees",
-        searchableFields, fieldAnalyzers, mockIndexStats3, true, serverName);
+        searchableFields, fieldAnalyzers, mockIndexStats3, true, serverName, serializer);
 
     final List<Set<LuceneIndexDetails>> results = new ArrayList<>();
 
@@ -191,6 +195,11 @@ public class LuceneIndexCommandsJUnitTest {
     assertEquals(Arrays.asList("10", "20", "30"), data.retrieveAllValues("Commits"));
     assertEquals(Arrays.asList("5", "10", "15"), data.retrieveAllValues("Updates"));
     assertEquals(Arrays.asList("1", "2", "3"), data.retrieveAllValues("Documents"));
+    assertEquals(
+        Arrays.asList(HeterogeneousLuceneSerializer.class.getSimpleName(),
+            HeterogeneousLuceneSerializer.class.getSimpleName(),
+            HeterogeneousLuceneSerializer.class.getSimpleName()),
+        data.retrieveAllValues("Serializer"));
   }
 
   @Test
@@ -237,8 +246,9 @@ public class LuceneIndexCommandsJUnitTest {
     fieldAnalyzers.put("field3", null);
     final LuceneIndexStats mockIndexStats = getMockIndexStats(1, 10, 5, 1);
     final List<LuceneIndexDetails> indexDetails = new ArrayList<>();
+    LuceneSerializer serializer = new HeterogeneousLuceneSerializer();
     indexDetails.add(createIndexDetails("memberFive", "/Employees", searchableFields,
-        fieldAnalyzers, mockIndexStats, true, serverName));
+        fieldAnalyzers, mockIndexStats, true, serverName, serializer));
 
     doReturn(mockResultCollector).when(commands).executeFunctionOnRegion(
         isA(LuceneDescribeIndexFunction.class), any(LuceneIndexInfo.class), eq(true));
@@ -619,16 +629,17 @@ 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, boolean status, final String serverName,
+      LuceneSerializer serializer) {
     return new LuceneIndexDetails(indexName, regionPath, searchableFields, fieldAnalyzers,
-        indexStats, status, serverName);
+        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) {
+      final String serverName, LuceneSerializer serializer) {
     return new LuceneIndexDetails(indexName, regionPath, searchableFields, fieldAnalyzers,
null,
-        status, serverName);
+        status, serverName, serializer);
   }
 
   private LuceneSearchResults createQueryResults(final String key, final String value,

-- 
To stop receiving notification emails like this one, please contact
"commits@geode.apache.org" <commits@geode.apache.org>.

Mime
View raw message