You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by up...@apache.org on 2016/05/11 23:42:32 UTC

incubator-geode git commit: GEODE-1381: Integration test of lucene index with analyzers

Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-1381 [created] dda37ad93


GEODE-1381: Integration test of lucene index with analyzers

Adding a test of lucene index with analyzers. There is still more work
to ensure that the correct analyzers were actually passed on to the
index writer.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/dda37ad9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/dda37ad9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/dda37ad9

Branch: refs/heads/feature/GEODE-1381
Commit: dda37ad933570663df76b7df28e61e6d844bb813
Parents: c92e5da
Author: Dan Smith <up...@apache.org>
Authored: Wed May 11 16:40:56 2016 -0700
Committer: Dan Smith <up...@apache.org>
Committed: Wed May 11 16:40:56 2016 -0700

----------------------------------------------------------------------
 .../gemfire/cache/lucene/LuceneService.java     |  4 +-
 .../lucene/LuceneQueriesIntegrationTest.java    | 17 +----
 .../LuceneIndexCreationIntegrationTest.java     | 70 +++++++++++++++-----
 .../lucene/internal/LuceneIntegrationTest.java  | 10 ++-
 4 files changed, 64 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/dda37ad9/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneService.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneService.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneService.java
index a42ab72..462aa7e 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneService.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneService.java
@@ -80,10 +80,8 @@ public interface LuceneService {
    * @param indexName index name
    * @param regionPath region name
    * @param analyzerPerField analyzer per field map
-   * @deprecated TODO This feature is not yet implemented
    */
-  @Deprecated
-  public void createIndex(String indexName, String regionPath,  
+  public void createIndex(String indexName, String regionPath,
       Map<String, Analyzer> analyzerPerField);
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/dda37ad9/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
index 9009e3d..32f6a8c 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
@@ -25,6 +25,7 @@ import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.RegionShortcut;
 import com.gemstone.gemfire.cache.execute.Function;
 import com.gemstone.gemfire.cache.execute.FunctionException;
+import com.gemstone.gemfire.cache.lucene.internal.LuceneIntegrationTest;
 import com.gemstone.gemfire.cache.query.QueryException;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
 
@@ -39,25 +40,11 @@ import org.junit.rules.ExpectedException;
  * This class contains tests of lucene queries that can fit
  */
 @Category(IntegrationTest.class)
-public class LuceneQueriesIntegrationTest {
+public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest {
   @Rule
   public ExpectedException thrown = ExpectedException.none();
   private static final String INDEX_NAME = "index";
   protected static final String REGION_NAME = "index";
-  Cache cache;
-
-  @Before
-  public void createCache() {
-    cache = new CacheFactory()
-      .set("mcast-port", "0")
-      .set("locators", "")
-      .set("log-level", "warning").create();
-  }
-
-  @After
-  public void closeCache() {
-    cache.close();
-  }
 
   @Test()
   public void throwFunctionExceptionWhenGivenBadQuery() {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/dda37ad9/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexCreationIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexCreationIntegrationTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexCreationIntegrationTest.java
index e04d1c7..6f6f03a 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexCreationIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexCreationIntegrationTest.java
@@ -21,40 +21,68 @@ package com.gemstone.gemfire.cache.lucene.internal;
 
 import static org.junit.Assert.*;
 
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
 import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.RegionShortcut;
+import com.gemstone.gemfire.cache.lucene.CreateCache;
+import com.gemstone.gemfire.cache.lucene.LuceneService;
 import com.gemstone.gemfire.cache.lucene.LuceneServiceProvider;
+import com.gemstone.gemfire.cache.lucene.internal.repository.IndexRepository;
+import com.gemstone.gemfire.cache.lucene.internal.repository.IndexRepositoryImpl;
+import com.gemstone.gemfire.cache.lucene.internal.repository.RepositoryManager;
+import com.gemstone.gemfire.internal.cache.BucketNotFoundException;
 import com.gemstone.gemfire.internal.cache.LocalRegion;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.core.KeywordAnalyzer;
+import org.apache.lucene.analysis.miscellaneous.PerFieldAnalyzerWrapper;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
 
 @Category(IntegrationTest.class)
 public class LuceneIndexCreationIntegrationTest extends LuceneIntegrationTest {
+  public static final String INDEX_NAME = "index";
+  public static final String REGION_NAME = "region";
 
   @Test
-  public void verifyLuceneRegionInternal() {
-    // Create cache
-    createCache();
+  public void shouldCreateIndexWriterWithAnalyzersWhenSettingPerFieldAnalyzers() throws BucketNotFoundException {
+    Map<String, Analyzer> analyzers = new HashMap<>();
+    analyzers.put("field1", new KeywordAnalyzer());
+    analyzers.put("field2", new StandardAnalyzer());
+    luceneService.createIndex(INDEX_NAME, REGION_NAME, analyzers);
+    Region region = createRegion();
+    region.put("key1", new TestObject());
 
-    // Create index
-    String indexName = "index";
-    String regionName = this.name.getMethodName();
-    createIndex(indexName, regionName, "text");
+    LuceneIndexForPartitionedRegion index = (LuceneIndexForPartitionedRegion) luceneService.getIndex(INDEX_NAME, REGION_NAME);
+
+    final RepositoryManager repoManager = index
+      .getRepositoryManager();
+    final IndexRepositoryImpl repository = (IndexRepositoryImpl) repoManager.getRepository(
+      region, "key1", null);
+    final PerFieldAnalyzerWrapper foundAnalyzer = (PerFieldAnalyzerWrapper) repository.getWriter().getAnalyzer();
+  }
+
+  @Test
+  public void verifyLuceneRegionInternal() {
+    createIndex("text");
 
     // Create partitioned region
-    createRegion(regionName);
+    createRegion();
 
     // Get index
-    LuceneIndexForPartitionedRegion index = (LuceneIndexForPartitionedRegion) LuceneServiceProvider.get(this.cache).getIndex(indexName, regionName);
-    assertNotNull(index);
+    LuceneIndexForPartitionedRegion index = (LuceneIndexForPartitionedRegion) luceneService.getIndex(INDEX_NAME, REGION_NAME);
 
     // Verify the meta regions exist and are internal
-    LocalRegion chunkRegion = (LocalRegion) this.cache.getRegion(index.createChunkRegionName());
-    assertNotNull(chunkRegion);
+    LocalRegion chunkRegion = (LocalRegion) cache.getRegion(index.createChunkRegionName());
     assertTrue(chunkRegion.isInternalRegion());
-    LocalRegion fileRegion = (LocalRegion) this.cache.getRegion(index.createFileRegionName());
-    assertNotNull(fileRegion);
+    LocalRegion fileRegion = (LocalRegion) cache.getRegion(index.createFileRegionName());
     assertTrue(fileRegion.isInternalRegion());
 
     // Verify the meta regions are not contained in the root regions
@@ -64,11 +92,17 @@ public class LuceneIndexCreationIntegrationTest extends LuceneIntegrationTest {
     }
   }
 
-  private Region createRegion(String regionName) {
-    return this.cache.createRegionFactory(RegionShortcut.PARTITION).create(regionName);
+  private Region createRegion() {
+    return this.cache.createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
   }
 
-  private void createIndex(String indexName, String regionName, String fieldName) {
-    LuceneServiceProvider.get(this.cache).createIndex(indexName, regionName, fieldName);
+  private void createIndex(String fieldName) {
+    LuceneServiceProvider.get(this.cache).createIndex(INDEX_NAME, REGION_NAME, fieldName);
+  }
+
+  private static class TestObject implements Serializable {
+
+    String field1 = "a b c d";
+    String field2 = "f g h";
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/dda37ad9/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIntegrationTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIntegrationTest.java
index 4d94042..fba8a02 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIntegrationTest.java
@@ -21,13 +21,18 @@ package com.gemstone.gemfire.cache.lucene.internal;
 
 import com.gemstone.gemfire.cache.Cache;
 import com.gemstone.gemfire.cache.CacheFactory;
+import com.gemstone.gemfire.cache.lucene.LuceneService;
+import com.gemstone.gemfire.cache.lucene.LuceneServiceProvider;
+
 import org.junit.After;
+import org.junit.Before;
 import org.junit.Rule;
 import org.junit.rules.TestName;
 
 public class LuceneIntegrationTest {
 
   protected Cache cache;
+  protected LuceneService luceneService;
 
   @Rule
   public TestName name = new TestName();
@@ -39,9 +44,12 @@ public class LuceneIntegrationTest {
     }
   }
 
-  protected void createCache() {
+  @Before
+  public void createCache() {
     CacheFactory cf = new CacheFactory();
     cf.set("mcast-port", "0");
+    cf.set("locators", "");
     this.cache = cf.create();
+    luceneService = LuceneServiceProvider.get(this.cache);
   }
 }