add tests for analyzer specify LuceneSerialier for RepositoryManager
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/58f13e26 Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/58f13e26 Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/58f13e26 Branch: refs/heads/develop Commit: 58f13e2659e3f0ed8d3feac927bbadde363f1fb5 Parents: db5db7a Author: zhouxh <[email protected]> Authored: Wed Sep 23 11:49:09 2015 -0700 Committer: zhouxh <[email protected]> Committed: Wed Sep 23 12:09:31 2015 -0700 ---------------------------------------------------------------------- .../LuceneIndexForPartitionedRegion.java | 4 +- .../internal/LuceneServiceImplJUnitTest.java | 43 ++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/58f13e26/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegion.java ---------------------------------------------------------------------- diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegion.java b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegion.java index cbab401..1eff49a 100644 --- a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegion.java +++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegion.java @@ -20,6 +20,7 @@ import com.gemstone.gemfire.cache.lucene.LuceneIndex; import com.gemstone.gemfire.cache.lucene.internal.filesystem.ChunkKey; import com.gemstone.gemfire.cache.lucene.internal.filesystem.File; import com.gemstone.gemfire.cache.lucene.internal.repository.IndexRepository; +import com.gemstone.gemfire.cache.lucene.internal.repository.serializer.HeterogenousLuceneSerializer; import com.gemstone.gemfire.cache.lucene.internal.repository.serializer.LuceneSerializer; import com.gemstone.gemfire.cache.partition.PartitionRegionHelper; import com.gemstone.gemfire.internal.cache.PartitionedRegion; @@ -94,7 +95,8 @@ public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl { } // we will create RegionDirectorys on the fly when data coming - repositoryManager = new PartitionedRepositoryManager(dataRegion, (PartitionedRegion)fileRegion, (PartitionedRegion)chunkRegion, null, analyzer); + HeterogenousLuceneSerializer mapper = new HeterogenousLuceneSerializer(getFieldNames()); + repositoryManager = new PartitionedRepositoryManager(dataRegion, (PartitionedRegion)fileRegion, (PartitionedRegion)chunkRegion, mapper, analyzer); hasInitialized = true; } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/58f13e26/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImplJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImplJUnitTest.java b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImplJUnitTest.java index 65fad5d..a7ed00d 100644 --- a/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImplJUnitTest.java +++ b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImplJUnitTest.java @@ -6,8 +6,13 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import org.apache.logging.log4j.Logger; +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.apache.lucene.index.IndexWriter; import org.apache.lucene.queryparser.classic.ParseException; @@ -23,6 +28,7 @@ import com.gemstone.gemfire.cache.execute.Function; import com.gemstone.gemfire.cache.execute.FunctionService; import com.gemstone.gemfire.cache.lucene.LuceneServiceProvider; import com.gemstone.gemfire.cache.lucene.internal.distributed.LuceneFunction; +import com.gemstone.gemfire.cache.lucene.internal.repository.RepositoryManager; import com.gemstone.gemfire.cache.lucene.internal.repository.serializer.HeterogenousLuceneSerializer; import com.gemstone.gemfire.internal.cache.GemFireCacheImpl; import com.gemstone.gemfire.internal.cache.LocalRegion; @@ -124,6 +130,10 @@ public class LuceneServiceImplJUnitTest { assertEquals("PR1", index1.getRegionPath()); String[] fields1 = index1.getFieldNames(); assertEquals(3, fields1.length); + Analyzer analyzer = index1PR.getAnalyzer(); + assertTrue(analyzer instanceof StandardAnalyzer); + RepositoryManager RepositoryManager = index1PR.getRepositoryManager(); + assertTrue(RepositoryManager != null); final String fileRegionName = LuceneServiceImpl.getUniqueIndexName("index1", "PR1")+".files"; final String chunkRegionName = LuceneServiceImpl.getUniqueIndexName("index1", "PR1")+".chunks"; @@ -134,6 +144,39 @@ public class LuceneServiceImplJUnitTest { } @Test + public void testCreateIndexForPRWithAnalyzer() throws IOException, ParseException { + getService(); + createPR("PR1", false); + StandardAnalyzer sa = new StandardAnalyzer(); + KeywordAnalyzer ka = new KeywordAnalyzer(); + Map<String, Analyzer> analyzerPerField = new HashMap<String, Analyzer>(); + analyzerPerField.put("field1", ka); + analyzerPerField.put("field2", sa); + analyzerPerField.put("field3", sa); + // field2 and field3 will use StandardAnalyzer + PerFieldAnalyzerWrapper analyzer2 = new PerFieldAnalyzerWrapper(sa, analyzerPerField); + + LuceneIndexImpl index1 = (LuceneIndexImpl)service.createIndex("index1", "PR1", analyzerPerField); + assertTrue(index1 instanceof LuceneIndexForPartitionedRegion); + LuceneIndexForPartitionedRegion index1PR = (LuceneIndexForPartitionedRegion)index1; + assertEquals("index1", index1.getName()); + assertEquals("PR1", index1.getRegionPath()); + String[] fields1 = index1.getFieldNames(); + assertEquals(3, fields1.length); + Analyzer analyzer = index1PR.getAnalyzer(); + assertTrue(analyzer instanceof PerFieldAnalyzerWrapper); + RepositoryManager RepositoryManager = index1PR.getRepositoryManager(); + assertTrue(RepositoryManager != null); + + final String fileRegionName = LuceneServiceImpl.getUniqueIndexName("index1", "PR1")+".files"; + final String chunkRegionName = LuceneServiceImpl.getUniqueIndexName("index1", "PR1")+".chunks"; + PartitionedRegion filePR = (PartitionedRegion)cache.getRegion(fileRegionName); + PartitionedRegion chunkPR = (PartitionedRegion)cache.getRegion(chunkRegionName); + assertTrue(filePR != null); + assertTrue(chunkPR != null); + } + + @Test public void testCreateIndexForRR() throws IOException, ParseException { // service.createIndex("index1", "RR1", "field1", "field2", "field3");
