geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ash...@apache.org
Subject [02/50] [abbrv] incubator-geode git commit: GEODE-11: Add a basic lucene read path DUnit
Date Wed, 11 Nov 2015 21:23:34 GMT
GEODE-11: Add a basic lucene read path DUnit

* The test depends on mock for now. As other components get ready, the mocks
  could be replaced by real implementations.
* Also real queries need to be added and the results tested once the index
  searchers are available


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

Branch: refs/heads/develop
Commit: f9ef456df43645d45fb777111c664215118f744b
Parents: 18e8f41
Author: Ashvin Agrawal <ashvin@apache.org>
Authored: Tue Sep 22 11:37:50 2015 -0700
Committer: Ashvin Agrawal <ashvin@apache.org>
Committed: Tue Sep 22 14:00:10 2015 -0700

----------------------------------------------------------------------
 .../lucene/internal/StringQueryProvider.java    |   6 +-
 .../internal/StringQueryProviderJUnitTest.java  |   2 +-
 .../distributed/LuceneFunctionJUnitTest.java    |   2 +-
 .../LuceneFunctionReadPathDUnitTest.java        | 130 +++++++++++++++++++
 4 files changed, 133 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f9ef456d/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
----------------------------------------------------------------------
diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
index 7055615..78a2f99 100644
--- a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
+++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
@@ -37,11 +37,7 @@ public class StringQueryProvider implements LuceneQueryProvider, DataSerializabl
   private LuceneIndex index;
 
   public StringQueryProvider() {
-    this(null);
-  }
-
-  public StringQueryProvider(String query) {
-    this(null, query);
+    this(null, null);
   }
 
   public StringQueryProvider(LuceneIndex index, String query) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f9ef456d/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
index 1ddc91c..078ae42 100644
--- a/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
+++ b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
@@ -31,7 +31,7 @@ public class StringQueryProviderJUnitTest {
 
   @Test
   public void testQueryConstruction() throws QueryException {
-    StringQueryProvider provider = new StringQueryProvider("foo:bar");
+    StringQueryProvider provider = new StringQueryProvider(null, "foo:bar");
     Query query = provider.getQuery();
     Assert.assertNotNull(query);
     assertEquals("foo:bar", query.toString());

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f9ef456d/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionJUnitTest.java
b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionJUnitTest.java
index 1fcd663..ba5f96a 100644
--- a/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionJUnitTest.java
+++ b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionJUnitTest.java
@@ -367,7 +367,7 @@ public class LuceneFunctionJUnitTest {
     repos.add(mockRepository1);
     repos.add(mockRepository2);
 
-    queryProvider = new StringQueryProvider("gemfire:lucene");
+    queryProvider = new StringQueryProvider(null, "gemfire:lucene");
     query = queryProvider.getQuery();
     searchArgs = new LuceneFunctionContext<IndexResultCollector>(queryProvider);
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f9ef456d/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionReadPathDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionReadPathDUnitTest.java
b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionReadPathDUnitTest.java
new file mode 100644
index 0000000..55c20cc
--- /dev/null
+++ b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionReadPathDUnitTest.java
@@ -0,0 +1,130 @@
+package com.gemstone.gemfire.cache.lucene.internal.distributed;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.lucene.search.Query;
+import org.junit.Assert;
+import org.junit.experimental.categories.Category;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.RegionFactory;
+import com.gemstone.gemfire.cache.RegionShortcut;
+import com.gemstone.gemfire.cache.execute.FunctionService;
+import com.gemstone.gemfire.cache.lucene.LuceneIndex;
+import com.gemstone.gemfire.cache.lucene.LuceneQueryProvider;
+import com.gemstone.gemfire.cache.lucene.LuceneService;
+import com.gemstone.gemfire.cache.lucene.LuceneServiceProvider;
+import com.gemstone.gemfire.cache.lucene.internal.StringQueryProvider;
+import com.gemstone.gemfire.cache.lucene.internal.repository.IndexRepository;
+import com.gemstone.gemfire.cache.lucene.internal.repository.IndexResultCollector;
+import com.gemstone.gemfire.cache.lucene.internal.repository.RepositoryManager;
+import com.gemstone.gemfire.cache30.CacheTestCase;
+import com.gemstone.gemfire.internal.cache.BucketNotFoundException;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+
+import dunit.Host;
+import dunit.SerializableRunnable;
+import dunit.VM;
+
+@Category(DistributedTest.class)
+public class LuceneFunctionReadPathDUnitTest extends CacheTestCase {
+  private static final String INDEX_NAME = "index";
+  private static final String REGION_NAME = "indexedRegion";
+
+  private static final long serialVersionUID = 1L;
+
+  private VM server1;
+  private VM server2;
+
+  public LuceneFunctionReadPathDUnitTest(String name) {
+    super(name);
+  }
+
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+    Host host = Host.getHost(0);
+    server1 = host.getVM(0);
+    server2 = host.getVM(1);
+  }
+
+  public void testEnd2EndFunctionExecution() {
+    SerializableRunnable createPartitionRegion = new SerializableRunnable("createRegion")
{
+      private static final long serialVersionUID = 1L;
+
+      public void run() {
+        final Cache cache = getCache();
+        assertNotNull(cache);
+        RegionFactory<Object, Object> regionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
+        regionFactory.create(REGION_NAME);
+
+        LuceneService service = LuceneServiceProvider.get(cache);
+        service.createIndex(INDEX_NAME, REGION_NAME);
+
+        IndexRepository mockRepo = mock(IndexRepository.class);
+        Collection<IndexRepository> repos = new ArrayList<IndexRepository>();
+        repos.add(mockRepo);
+
+        RepositoryManager mockManager = mock(RepositoryManager.class);
+        // TODO avoid using repository manager mock. The manager choice depends on the region
type
+        LuceneFunction.setRepositoryManager(mockManager);
+        try {
+          Mockito.doReturn(repos).when(mockManager).getRepositories(any(Region.class));
+        } catch (BucketNotFoundException e) {
+          fail("", e);
+        }
+
+        try {
+          Mockito.doAnswer(new Answer<Object>() {
+            public Object answer(InvocationOnMock invocation) {
+              Object[] args = invocation.getArguments();
+              IndexResultCollector collector = (IndexResultCollector) args[2];
+              collector.collect(cache.getDistributedSystem().getDistributedMember().getProcessId(),
.1f);
+              return null;
+            }
+          }).when(mockRepo).query(any(Query.class), Mockito.anyInt(), any(IndexResultCollector.class));
+        } catch (IOException e) {
+          fail("", e);
+        }
+      }
+    };
+
+    server1.invoke(createPartitionRegion);
+    server2.invoke(createPartitionRegion);
+
+    SerializableRunnable executeSearch = new SerializableRunnable("executeSearch") {
+      private static final long serialVersionUID = 1L;
+
+      public void run() {
+        Cache cache = getCache();
+        assertNotNull(cache);
+        Region<Object, Object> region = cache.getRegion(REGION_NAME);
+        Assert.assertNotNull(region);
+
+        LuceneService service = LuceneServiceProvider.get(cache);
+        LuceneIndex index = service.getIndex(INDEX_NAME, REGION_NAME);
+        LuceneQueryProvider provider = new StringQueryProvider(index, "text:search");
+
+        LuceneFunctionContext<TopEntriesCollector> context = new LuceneFunctionContext<>(provider,
+            new TopEntriesCollectorManager());
+        TopEntriesFunctionCollector collector = new TopEntriesFunctionCollector();
+
+        FunctionService.onRegion(region).withArgs(context).withCollector(collector).execute(LuceneFunction.ID);
+        TopEntries entries = collector.getResult();
+        assertNotNull(entries);
+        assertEquals(2, entries.getHits().size());
+      }
+    };
+
+    server1.invoke(executeSearch);
+  }
+}


Mime
View raw message