geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ash...@apache.org
Subject [2/2] incubator-geode git commit: GEODE-11: Use QueryProvider in LuceneFunction
Date Fri, 18 Sep 2015 23:38:17 GMT
GEODE-11: Use QueryProvider in LuceneFunction

LuceneFunction needs query object for execution. If the argement is missing,
fail the function execution

https://reviews.apache.org/r/38513/


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

Branch: refs/heads/feature/GEODE-11
Commit: ac7c9286df261c4176b90f30c7e50ecb7f35ee94
Parents: ce1c6b2
Author: Ashvin Agrawal <ashvin@apache.org>
Authored: Fri Sep 18 16:16:32 2015 -0700
Committer: Ashvin Agrawal <ashvin@apache.org>
Committed: Fri Sep 18 16:37:37 2015 -0700

----------------------------------------------------------------------
 gemfire-lucene/build.gradle                     |   1 +
 .../internal/distributed/LuceneFunction.java    |  44 ++-
 .../distributed/LuceneFunctionContext.java      |  53 ++--
 .../distributed/LuceneFunctionJUnitTest.java    | 277 ++++++++++---------
 .../TopEntriesFunctionCollectorJUnitTest.java   |   6 +-
 5 files changed, 222 insertions(+), 159 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac7c9286/gemfire-lucene/build.gradle
----------------------------------------------------------------------
diff --git a/gemfire-lucene/build.gradle b/gemfire-lucene/build.gradle
index 53d4730..3303a69 100644
--- a/gemfire-lucene/build.gradle
+++ b/gemfire-lucene/build.gradle
@@ -10,6 +10,7 @@ dependencies {
     //Lucene test framework.
     testCompile 'org.apache.lucene:lucene-test-framework:5.3.0'
     testCompile 'org.apache.lucene:lucene-codecs:5.3.0'
+    testCompile project(path: ':gemfire-core', configuration: 'testOutput', transitive: false)
     //Dependency ot lucene-test-framework. Can we turn on transitive depencies for
     //the test framework somehow? We've disabled them globally in the parent
     //build.gadle.

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac7c9286/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunction.java
----------------------------------------------------------------------
diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunction.java
b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunction.java
index 25b7454..ca28154 100644
--- a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunction.java
+++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunction.java
@@ -5,6 +5,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 
 import org.apache.logging.log4j.Logger;
+import org.apache.lucene.search.Query;
 
 import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.execute.FunctionAdapter;
@@ -12,9 +13,11 @@ import com.gemstone.gemfire.cache.execute.FunctionContext;
 import com.gemstone.gemfire.cache.execute.RegionFunctionContext;
 import com.gemstone.gemfire.cache.execute.ResultSender;
 import com.gemstone.gemfire.cache.lucene.LuceneQueryFactory;
+import com.gemstone.gemfire.cache.lucene.LuceneQueryProvider;
 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.cache.query.QueryException;
 import com.gemstone.gemfire.internal.cache.BucketNotFoundException;
 import com.gemstone.gemfire.internal.logging.LogService;
 
@@ -29,7 +32,7 @@ public class LuceneFunction extends FunctionAdapter {
 
   private static final Logger logger = LogService.getLogger();
 
-  private RepositoryManager repoManager;
+  private static RepositoryManager repoManager;
 
   @Override
   public void execute(FunctionContext context) {
@@ -37,11 +40,30 @@ public class LuceneFunction extends FunctionAdapter {
     ResultSender<TopEntriesCollector> resultSender = ctx.getResultSender();
 
     Region region = ctx.getDataSet();
-    if (logger.isDebugEnabled()) {
-      logger.debug("Executing lucene query on region:" + region.getFullPath());
+
+    LuceneFunctionContext<IndexResultCollector> searchContext = (LuceneFunctionContext)
ctx.getArguments();
+    if (searchContext == null) {
+      resultSender.sendException(new IllegalArgumentException("Missing search context"));
+      return;
+    }
+
+    LuceneQueryProvider queryProvider = searchContext.getQueryProvider();
+    if (queryProvider == null) {
+      resultSender.sendException(new IllegalArgumentException("Missing query provider"));
+      return;
+    }
+
+    Query query = null;
+    try {
+      query = queryProvider.getQuery();
+    } catch (QueryException e) {
+      resultSender.sendException(e);
+      return;
     }
 
-    LuceneFunctionContext searchContext = (LuceneFunctionContext) ctx.getArguments();
+    if (logger.isDebugEnabled()) {
+      logger.debug("Executing lucene query: {}, on region {}", query, region.getFullPath());
+    }
 
     CollectorManager manager = (searchContext == null) ? null : searchContext.getCollectorManager();
     if (manager == null) {
@@ -51,11 +73,11 @@ public class LuceneFunction extends FunctionAdapter {
 
     Collection<IndexResultCollector> results = new ArrayList<>();
     try {
-      Collection<IndexRepository> repositories = repoManager.getRepositories(region,
ctx);
+      Collection<IndexRepository> repositories = getIndexRepositories(ctx, region);
       for (IndexRepository repo : repositories) {
         IndexResultCollector collector = manager.newCollector(repo.toString());
         logger.debug("Executing search on repo: " + repo.toString());
-        repo.query(null, 0, collector);
+        repo.query(query, 0, collector);
         results.add(collector);
       }
     } catch (IOException e) {
@@ -79,8 +101,14 @@ public class LuceneFunction extends FunctionAdapter {
     }
   }
 
-  void setRepositoryManager(RepositoryManager manager) {
-    this.repoManager = manager;
+  private Collection<IndexRepository> getIndexRepositories(RegionFunctionContext ctx,
Region region) throws BucketNotFoundException {
+    synchronized (LuceneFunction.class) {
+      return repoManager.getRepositories(region, ctx);
+    }
+  }
+
+  static synchronized void setRepositoryManager(RepositoryManager manager) {
+    repoManager = manager;
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac7c9286/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionContext.java
----------------------------------------------------------------------
diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionContext.java
b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionContext.java
index b3a613f..ad0fdfb 100644
--- a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionContext.java
+++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionContext.java
@@ -4,46 +4,35 @@ import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
 
+import com.gemstone.gemfire.DataSerializable;
 import com.gemstone.gemfire.cache.lucene.LuceneQueryFactory;
+import com.gemstone.gemfire.cache.lucene.LuceneQueryProvider;
 import com.gemstone.gemfire.cache.lucene.internal.repository.IndexRepository;
 import com.gemstone.gemfire.cache.lucene.internal.repository.IndexResultCollector;
-import com.gemstone.gemfire.internal.Version;
-import com.gemstone.gemfire.internal.VersionedDataSerializable;
 
 /**
  * Contains function arguments for text / lucene search
  */
-public class LuceneFunctionContext<C extends IndexResultCollector> implements VersionedDataSerializable
{
+public class LuceneFunctionContext<C extends IndexResultCollector> implements DataSerializable
{
   private static final long serialVersionUID = 1L;
+
   private final CollectorManager<C> manager;
   private final int limit;
 
-  public LuceneFunctionContext(CollectorManager<C> manager) {
-    this.manager = manager;
-    this.limit = LuceneQueryFactory.DEFAULT_LIMIT;
-  }
-  
-  public LuceneFunctionContext(int limit) {
-    this.limit = limit;
-    this.manager = null;
-  }
-
-  @Override
-  public void toData(DataOutput out) throws IOException {
-    // TODO Auto-generated method stub
+  final LuceneQueryProvider queryProvider;
 
+  public LuceneFunctionContext(LuceneQueryProvider provider) {
+    this(provider, null);
   }
 
-  @Override
-  public void fromData(DataInput in) throws IOException, ClassNotFoundException {
-    // TODO Auto-generated method stub
-
+  public LuceneFunctionContext(LuceneQueryProvider provider, CollectorManager<C> manager)
{
+    this(provider, manager, LuceneQueryFactory.DEFAULT_LIMIT);
   }
 
-  @Override
-  public Version[] getSerializationVersions() {
-    // TODO Auto-generated method stub
-    return null;
+  public LuceneFunctionContext(LuceneQueryProvider provider, CollectorManager<C> manager,
int limit) {
+    this.queryProvider = provider;
+    this.manager = manager;
+    this.limit = limit;
   }
 
   /**
@@ -62,4 +51,20 @@ public class LuceneFunctionContext<C extends IndexResultCollector>
implements Ve
   public CollectorManager<C> getCollectorManager() {
     return this.manager;
   }
+
+  @Override
+  public void toData(DataOutput out) throws IOException {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
+  public void fromData(DataInput in) throws IOException, ClassNotFoundException {
+    // TODO Auto-generated method stub
+
+  }
+
+  public LuceneQueryProvider getQueryProvider() {
+    return queryProvider;
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac7c9286/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 ec7cd3d..24f8ad0 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
@@ -19,14 +19,18 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
+import org.mockito.Mockito;
 
 import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.execute.RegionFunctionContext;
 import com.gemstone.gemfire.cache.execute.ResultSender;
 import com.gemstone.gemfire.cache.lucene.LuceneQueryFactory;
+import com.gemstone.gemfire.cache.lucene.LuceneQueryProvider;
+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.cache.query.QueryException;
 import com.gemstone.gemfire.internal.cache.BucketNotFoundException;
 import com.gemstone.gemfire.test.junit.categories.UnitTest;
 
@@ -40,25 +44,37 @@ public class LuceneFunctionJUnitTest {
   final EntryScore r2_1 = new EntryScore("key-2-1", .45f);
   final EntryScore r2_2 = new EntryScore("key-2-2", .35f);
 
+  RegionFunctionContext mockContext;
+  ResultSender<TopEntriesCollector> mockResultSender;
+  Region<Object, Object> mockRegion;
+
+  RepositoryManager mockRepoManager;
+  IndexRepository mockRepository1;
+  IndexRepository mockRepository2;
+  IndexResultCollector mockCollector;
+
+  ArrayList<IndexRepository> repos;
+  LuceneFunctionContext searchArgs;
+  LuceneQueryProvider queryProvider;
+  Query query;
+
   @Test
   public void testRepoQueryAndMerge() throws Exception {
     final AtomicReference<TopEntriesCollector> result = new AtomicReference<>();
-
-    final QueryMocks m = new QueryMocks();
     mocker.checking(new Expectations() {
       {
-        oneOf(m.mockContext).getDataSet();
-        will(returnValue(m.mockRegion));
-        oneOf(m.mockContext).getArguments();
-        will(returnValue(null));
+        oneOf(mockContext).getDataSet();
+        will(returnValue(mockRegion));
+        oneOf(mockContext).getArguments();
+        will(returnValue(searchArgs));
 
-        oneOf(m.mockRepoManager).getRepositories(m.mockRegion, m.mockContext);
-        will(returnValue(m.repos));
+        oneOf(mockRepoManager).getRepositories(mockRegion, mockContext);
+        will(returnValue(repos));
 
-        oneOf(m.mockContext).getResultSender();
-        will(returnValue(m.mockResultSender));
+        oneOf(mockContext).getResultSender();
+        will(returnValue(mockResultSender));
 
-        oneOf(m.mockRepository1).query(with(aNull(Query.class)), with(equal(0)), with(any(IndexResultCollector.class)));
+        oneOf(mockRepository1).query(with(query), with(equal(0)), with(any(IndexResultCollector.class)));
         will(new CustomAction("streamSearchResults") {
           @Override
           public Object invoke(Invocation invocation) throws Throwable {
@@ -70,7 +86,7 @@ public class LuceneFunctionJUnitTest {
           }
         });
 
-        oneOf(m.mockRepository2).query(with(aNull(Query.class)), with(equal(0)), with(any(IndexResultCollector.class)));
+        oneOf(mockRepository2).query(with(query), with(equal(0)), with(any(IndexResultCollector.class)));
         will(new CustomAction("streamSearchResults") {
           @Override
           public Object invoke(Invocation invocation) throws Throwable {
@@ -81,7 +97,7 @@ public class LuceneFunctionJUnitTest {
           }
         });
 
-        oneOf(m.mockResultSender).lastResult(with(any(TopEntriesCollector.class)));
+        oneOf(mockResultSender).lastResult(with(any(TopEntriesCollector.class)));
         will(new CustomAction("collectResult") {
           @Override
           public Object invoke(Invocation invocation) throws Throwable {
@@ -93,9 +109,9 @@ public class LuceneFunctionJUnitTest {
     });
 
     LuceneFunction function = new LuceneFunction();
-    function.setRepositoryManager(m.mockRepoManager);
+    function.setRepositoryManager(mockRepoManager);
 
-    function.execute(m.mockContext);
+    function.execute(mockContext);
     List<EntryScore> hits = result.get().getEntries().getHits();
     assertEquals(5, hits.size());
     TopEntriesJUnitTest.verifyResultOrder(result.get().getEntries().getHits(), r1_1, r2_1,
r1_2, r2_2, r1_3);
@@ -105,26 +121,22 @@ public class LuceneFunctionJUnitTest {
   public void testResultLimitClause() throws Exception {
     final AtomicReference<TopEntriesCollector> result = new AtomicReference<>();
 
-    final QueryMocks m = new QueryMocks();
+    searchArgs = new LuceneFunctionContext<IndexResultCollector>(queryProvider, null,
3);
+
     mocker.checking(new Expectations() {
       {
-        oneOf(m.mockContext).getDataSet();
-        will(returnValue(m.mockRegion));
-        oneOf(m.mockContext).getArguments();
-        will(returnValue(m.mockSearchContext));
-
-        oneOf(m.mockContext).getResultSender();
-        will(returnValue(m.mockResultSender));
+        oneOf(mockContext).getDataSet();
+        will(returnValue(mockRegion));
+        oneOf(mockContext).getArguments();
+        will(returnValue(searchArgs));
 
-        oneOf(m.mockSearchContext).getLimit();
-        will(returnValue(3));
-        oneOf(m.mockSearchContext).getCollectorManager();
-        will(returnValue(null));
+        oneOf(mockContext).getResultSender();
+        will(returnValue(mockResultSender));
 
-        oneOf(m.mockRepoManager).getRepositories(m.mockRegion, m.mockContext);
-        will(returnValue(m.repos));
+        oneOf(mockRepoManager).getRepositories(mockRegion, mockContext);
+        will(returnValue(repos));
 
-        oneOf(m.mockRepository1).query(with(aNull(Query.class)), with(equal(0)), with(any(IndexResultCollector.class)));
+        oneOf(mockRepository1).query(with(query), with(equal(0)), with(any(IndexResultCollector.class)));
         will(new CustomAction("streamSearchResults") {
           @Override
           public Object invoke(Invocation invocation) throws Throwable {
@@ -136,7 +148,7 @@ public class LuceneFunctionJUnitTest {
           }
         });
 
-        oneOf(m.mockRepository2).query(with(aNull(Query.class)), with(equal(0)), with(any(IndexResultCollector.class)));
+        oneOf(mockRepository2).query(with(query), with(equal(0)), with(any(IndexResultCollector.class)));
         will(new CustomAction("streamSearchResults") {
           @Override
           public Object invoke(Invocation invocation) throws Throwable {
@@ -147,7 +159,7 @@ public class LuceneFunctionJUnitTest {
           }
         });
 
-        oneOf(m.mockResultSender).lastResult(with(any(TopEntriesCollector.class)));
+        oneOf(mockResultSender).lastResult(with(any(TopEntriesCollector.class)));
         will(new CustomAction("collectResult") {
           @Override
           public Object invoke(Invocation invocation) throws Throwable {
@@ -159,9 +171,9 @@ public class LuceneFunctionJUnitTest {
     });
 
     LuceneFunction function = new LuceneFunction();
-    function.setRepositoryManager(m.mockRepoManager);
+    function.setRepositoryManager(mockRepoManager);
 
-    function.execute(m.mockContext);
+    function.execute(mockContext);
     List<EntryScore> hits = result.get().getEntries().getHits();
     assertEquals(3, hits.size());
     TopEntriesJUnitTest.verifyResultOrder(result.get().getEntries().getHits(), r1_1, r2_1,
r1_2);
@@ -169,41 +181,37 @@ public class LuceneFunctionJUnitTest {
 
   @Test
   public void injectCustomCollectorManager() throws Exception {
-    final QueryMocks m = new QueryMocks();
-
+    final CollectorManager mockManager = mocker.mock(CollectorManager.class);
+    searchArgs = new LuceneFunctionContext<IndexResultCollector>(queryProvider, mockManager);
     mocker.checking(new Expectations() {
       {
-        oneOf(m.mockContext).getDataSet();
-        will(returnValue(m.mockRegion));
-        oneOf(m.mockContext).getArguments();
-        will(returnValue(m.mockSearchContext));
-
-        oneOf(m.mockContext).getResultSender();
-        will(returnValue(m.mockResultSender));
-
-        oneOf(m.mockSearchContext).getCollectorManager();
-        will(returnValue(m.mockManager));
-
-        oneOf(m.mockRepoManager).getRepositories(m.mockRegion, m.mockContext);
-        m.repos.remove(0);
-        will(returnValue(m.repos));
-
-        oneOf(m.mockManager).newCollector("repo2");
-        will(returnValue(m.mockCollector));
-        oneOf(m.mockManager).reduce(with(any(Collection.class)));
+        oneOf(mockContext).getDataSet();
+        will(returnValue(mockRegion));
+        oneOf(mockContext).getArguments();
+        will(returnValue(searchArgs));
+        oneOf(mockContext).getResultSender();
+        will(returnValue(mockResultSender));
+
+        oneOf(mockRepoManager).getRepositories(mockRegion, mockContext);
+        repos.remove(0);
+        will(returnValue(repos));
+
+        oneOf(mockManager).newCollector("repo2");
+        will(returnValue(mockCollector));
+        oneOf(mockManager).reduce(with(any(Collection.class)));
         will(new CustomAction("reduce") {
           @Override
           public Object invoke(Invocation invocation) throws Throwable {
             Collection<IndexResultCollector> collectors = (Collection<IndexResultCollector>)
invocation.getParameter(0);
             assertEquals(1, collectors.size());
-            assertEquals(m.mockCollector, collectors.iterator().next());
+            assertEquals(mockCollector, collectors.iterator().next());
             return new TopEntriesCollector(null);
           }
         });
 
-        oneOf(m.mockCollector).collect("key-2-1", .45f);
+        oneOf(mockCollector).collect("key-2-1", .45f);
 
-        oneOf(m.mockRepository2).query(with(aNull(Query.class)), with(equal(0)), with(any(IndexResultCollector.class)));
+        oneOf(mockRepository2).query(with(query), with(equal(0)), with(any(IndexResultCollector.class)));
         will(new CustomAction("streamSearchResults") {
           @Override
           public Object invoke(Invocation invocation) throws Throwable {
@@ -213,128 +221,132 @@ public class LuceneFunctionJUnitTest {
           }
         });
 
-        oneOf(m.mockResultSender).lastResult(with(any(TopEntriesCollector.class)));
+        oneOf(mockResultSender).lastResult(with(any(TopEntriesCollector.class)));
       }
     });
 
     LuceneFunction function = new LuceneFunction();
-    function.setRepositoryManager(m.mockRepoManager);
+    function.setRepositoryManager(mockRepoManager);
 
-    function.execute(m.mockContext);
+    function.execute(mockContext);
   }
 
   @Test
   public void testIndexRepoQueryFails() throws Exception {
-    final QueryMocks m = new QueryMocks();
     mocker.checking(new Expectations() {
       {
-        oneOf(m.mockContext).getDataSet();
-        will(returnValue(m.mockRegion));
-        oneOf(m.mockContext).getArguments();
-        will(returnValue(null));
+        oneOf(mockContext).getDataSet();
+        will(returnValue(mockRegion));
+        oneOf(mockContext).getArguments();
+        will(returnValue(searchArgs));
 
-        oneOf(m.mockRepoManager).getRepositories(m.mockRegion, m.mockContext);
-        will(returnValue(m.repos));
+        oneOf(mockRepoManager).getRepositories(mockRegion, mockContext);
+        will(returnValue(repos));
 
-        oneOf(m.mockContext).getResultSender();
-        will(returnValue(m.mockResultSender));
-        oneOf(m.mockResultSender).sendException(with(any(IOException.class)));
+        oneOf(mockContext).getResultSender();
+        will(returnValue(mockResultSender));
+        oneOf(mockResultSender).sendException(with(any(IOException.class)));
 
-        oneOf(m.mockRepository1).query(with(aNull(Query.class)), with(equal(0)), with(any(IndexResultCollector.class)));
+        oneOf(mockRepository1).query(with(query), with(equal(0)), with(any(IndexResultCollector.class)));
         will(throwException(new IOException()));
       }
     });
 
     LuceneFunction function = new LuceneFunction();
-    function.setRepositoryManager(m.mockRepoManager);
+    function.setRepositoryManager(mockRepoManager);
 
-    function.execute(m.mockContext);
+    function.execute(mockContext);
   }
 
   @Test
   public void testBucketNotFound() throws Exception {
-    final QueryMocks m = new QueryMocks();
     mocker.checking(new Expectations() {
       {
-        oneOf(m.mockContext).getDataSet();
-        will(returnValue(m.mockRegion));
-        oneOf(m.mockContext).getArguments();
-        will(returnValue(null));
+        oneOf(mockContext).getDataSet();
+        will(returnValue(mockRegion));
+        oneOf(mockContext).getArguments();
+        will(returnValue(searchArgs));
 
-        oneOf(m.mockRepoManager).getRepositories(m.mockRegion, m.mockContext);
+        oneOf(mockRepoManager).getRepositories(mockRegion, mockContext);
         will(throwException(new BucketNotFoundException("")));
 
-        oneOf(m.mockContext).getResultSender();
-        will(returnValue(m.mockResultSender));
-        oneOf(m.mockResultSender).sendException(with(any(BucketNotFoundException.class)));
+        oneOf(mockContext).getResultSender();
+        will(returnValue(mockResultSender));
+        oneOf(mockResultSender).sendException(with(any(BucketNotFoundException.class)));
       }
     });
 
     LuceneFunction function = new LuceneFunction();
-    function.setRepositoryManager(m.mockRepoManager);
+    function.setRepositoryManager(mockRepoManager);
 
-    function.execute(m.mockContext);
+    function.execute(mockContext);
   }
 
   @Test
   public void testReduceError() throws Exception {
-    final QueryMocks m = new QueryMocks();
+    final CollectorManager mockManager = mocker.mock(CollectorManager.class);
+    searchArgs = new LuceneFunctionContext<IndexResultCollector>(queryProvider, mockManager);
     mocker.checking(new Expectations() {
       {
-        oneOf(m.mockContext).getDataSet();
-        will(returnValue(m.mockRegion));
-        oneOf(m.mockContext).getResultSender();
-        will(returnValue(m.mockResultSender));
-
-        oneOf(m.mockContext).getArguments();
-        will(returnValue(m.mockSearchContext));
-        oneOf(m.mockSearchContext).getCollectorManager();
-        will(returnValue(m.mockManager));
-        oneOf(m.mockManager).newCollector("repo1");
-        will(returnValue(m.mockCollector));
-        oneOf(m.mockManager).reduce(with(any(Collection.class)));
+        oneOf(mockContext).getDataSet();
+        will(returnValue(mockRegion));
+        oneOf(mockContext).getResultSender();
+        will(returnValue(mockResultSender));
+        oneOf(mockContext).getArguments();
+        will(returnValue(searchArgs));
+
+        oneOf(mockManager).newCollector("repo1");
+        will(returnValue(mockCollector));
+        oneOf(mockManager).reduce(with(any(Collection.class)));
         will(throwException(new IOException()));
 
-        oneOf(m.mockRepoManager).getRepositories(m.mockRegion, m.mockContext);
-        m.repos.remove(1);
-        will(returnValue(m.repos));
+        oneOf(mockRepoManager).getRepositories(mockRegion, mockContext);
+        repos.remove(1);
+        will(returnValue(repos));
 
-        oneOf(m.mockRepository1).query(null, 0, m.mockCollector);
-        oneOf(m.mockResultSender).sendException(with(any(IOException.class)));
+        oneOf(mockRepository1).query(query, 0, mockCollector);
+        oneOf(mockResultSender).sendException(with(any(IOException.class)));
       }
     });
 
     LuceneFunction function = new LuceneFunction();
-    function.setRepositoryManager(m.mockRepoManager);
+    function.setRepositoryManager(mockRepoManager);
 
-    function.execute(m.mockContext);
+    function.execute(mockContext);
   }
 
   @Test
+  public void queryProviderErrorIsHandled() throws Exception {
+    queryProvider = mocker.mock(LuceneQueryProvider.class);
+    searchArgs = new LuceneFunctionContext<IndexResultCollector>(queryProvider, null);
+    mocker.checking(new Expectations() {
+      {
+        oneOf(mockContext).getDataSet();
+        will(returnValue(mockRegion));
+        oneOf(mockContext).getResultSender();
+        will(returnValue(mockResultSender));
+        oneOf(mockContext).getArguments();
+        will(returnValue(searchArgs));
+        
+        oneOf(queryProvider).getQuery();
+        will(throwException(new QueryException()));
+        
+        oneOf(mockResultSender).sendException(with(any(QueryException.class)));
+      }
+    });
+    
+    LuceneFunction function = new LuceneFunction();
+    function.setRepositoryManager(mockRepoManager);
+    
+    function.execute(mockContext);
+  }
+  
+  @Test
   public void testQueryFunctionId() {
     String id = new LuceneFunction().getId();
     assertEquals(LuceneFunction.class.getName(), id);
   }
 
-  class QueryMocks {
-    RegionFunctionContext mockContext = mocker.mock(RegionFunctionContext.class);
-    ResultSender<TopEntriesCollector> mockResultSender = mocker.mock(ResultSender.class);
-    Region<Object, Object> mockRegion = mocker.mock(Region.class);
-
-    RepositoryManager mockRepoManager = mocker.mock(RepositoryManager.class);
-    ArrayList<IndexRepository> repos = new ArrayList<IndexRepository>();
-    IndexRepository mockRepository1 = mocker.mock(IndexRepository.class, "repo1");
-    IndexRepository mockRepository2 = mocker.mock(IndexRepository.class, "repo2");
-    LuceneFunctionContext mockSearchContext = mocker.mock(LuceneFunctionContext.class);
-    CollectorManager mockManager = mocker.mock(CollectorManager.class);
-    IndexResultCollector mockCollector = mocker.mock(IndexResultCollector.class);
-
-    QueryMocks() {
-      repos.add(mockRepository1);
-      repos.add(mockRepository2);
-    }
-  }
-
   @Test
   public void testLuceneFunctionArgsDefaults() {
     LuceneFunctionContext context = new LuceneFunctionContext(null);
@@ -342,13 +354,30 @@ public class LuceneFunctionJUnitTest {
   }
 
   @Before
-  public void setupMock() {
+  public void createMocksAndCommonObjects() throws Exception {
     mocker = new Mockery() {
       {
         setImposteriser(ClassImposteriser.INSTANCE);
         setThreadingPolicy(new Synchroniser());
       }
     };
+
+    mockContext = mocker.mock(RegionFunctionContext.class);
+    mockResultSender = mocker.mock(ResultSender.class);
+    mockRegion = mocker.mock(Region.class);
+
+    mockRepoManager = mocker.mock(RepositoryManager.class);
+    mockRepository1 = mocker.mock(IndexRepository.class, "repo1");
+    mockRepository2 = mocker.mock(IndexRepository.class, "repo2");
+    mockCollector = mocker.mock(IndexResultCollector.class);
+
+    repos = new ArrayList<IndexRepository>();
+    repos.add(mockRepository1);
+    repos.add(mockRepository2);
+
+    queryProvider = new StringQueryProvider("gemfire:lucene");
+    query = queryProvider.getQuery();
+    searchArgs = new LuceneFunctionContext<IndexResultCollector>(queryProvider);
   }
 
   @After

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ac7c9286/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java
b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java
index 6e02e4e..be7e5fb 100644
--- a/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java
+++ b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java
@@ -184,7 +184,7 @@ public class TopEntriesFunctionCollectorJUnitTest {
 
   @Test
   public void mergeShardAndLimitResults() throws Exception {
-    LuceneFunctionContext<TopEntriesCollector> context = new LuceneFunctionContext<>(3);
+    LuceneFunctionContext<TopEntriesCollector> context = new LuceneFunctionContext<>(null,
null, 3);
     
     TopEntriesFunctionCollector collector = new TopEntriesFunctionCollector(context);
     collector.addResult(null, result1);
@@ -226,7 +226,7 @@ public class TopEntriesFunctionCollectorJUnitTest {
           }
         }));
 
-    LuceneFunctionContext<TopEntriesCollector> context = new LuceneFunctionContext<>(mockManager);
+    LuceneFunctionContext<TopEntriesCollector> context = new LuceneFunctionContext<>(null,
mockManager);
     TopEntriesFunctionCollector collector = new TopEntriesFunctionCollector(context);
     collector.addResult(null, result1);
     collector.addResult(null, result2);
@@ -255,7 +255,7 @@ public class TopEntriesFunctionCollectorJUnitTest {
     TopEntriesCollectorManager mockManager = mock(TopEntriesCollectorManager.class);
     Mockito.doThrow(new IOException()).when(mockManager).reduce(any(Collection.class));
 
-    LuceneFunctionContext<TopEntriesCollector> context = new LuceneFunctionContext<>(mockManager);
+    LuceneFunctionContext<TopEntriesCollector> context = new LuceneFunctionContext<>(null,
mockManager);
     TopEntriesFunctionCollector collector = new TopEntriesFunctionCollector(context);
     collector.endResults();
     collector.getResult();


Mime
View raw message