Skip to content

Commit

Permalink
GEODE-2529: Rename LuceneFunction to LuceneQueryFunction
Browse files Browse the repository at this point in the history
* Included new renamed file LuceneQueryFunction.java
* Change thrown exception type to InternalFunctionInvocationTargetException instead of FunctionException
  • Loading branch information
jhuynh1 committed Feb 23, 2017
1 parent 2d72624 commit 5547c2a
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@
import org.apache.geode.cache.lucene.LuceneResultStruct;
import org.apache.geode.cache.lucene.PageableLuceneQueryResults;
import org.apache.geode.cache.lucene.internal.distributed.EntryScore;
import org.apache.geode.cache.lucene.internal.distributed.LuceneFunction;
import org.apache.geode.cache.lucene.internal.distributed.LuceneQueryFunction;
import org.apache.geode.cache.lucene.internal.distributed.LuceneFunctionContext;
import org.apache.geode.cache.lucene.internal.distributed.TopEntries;
import org.apache.geode.cache.lucene.internal.distributed.TopEntriesCollector;
import org.apache.geode.cache.lucene.internal.distributed.TopEntriesCollectorManager;
import org.apache.geode.cache.lucene.internal.distributed.TopEntriesFunctionCollector;
import org.apache.geode.internal.cache.BucketNotFoundException;
import org.apache.geode.internal.logging.LogService;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -107,23 +106,20 @@ private TopEntries<K> findTopEntries() throws LuceneQueryException {

// TODO provide a timeout to the user?
TopEntries<K> entries = null;
while (entries == null) {
try {
TopEntriesFunctionCollector collector = new TopEntriesFunctionCollector(context);
ResultCollector<TopEntriesCollector, TopEntries<K>> rc =
(ResultCollector<TopEntriesCollector, TopEntries<K>>) onRegion().withArgs(context)
.withCollector(collector).execute(LuceneFunction.ID);
entries = rc.getResult();
} catch (FunctionException e) {
if (e.getCause() instanceof BucketNotFoundException) {
entries = null;
} else if (e.getCause() instanceof LuceneQueryException) {
throw new LuceneQueryException(e);
} else {
e.printStackTrace();
throw e;
}
try {
TopEntriesFunctionCollector collector = new TopEntriesFunctionCollector(context);
ResultCollector<TopEntriesCollector, TopEntries<K>> rc =
(ResultCollector<TopEntriesCollector, TopEntries<K>>) onRegion().withArgs(context)
.withCollector(collector).execute(LuceneQueryFunction.ID);
entries = rc.getResult();
} catch (FunctionException e) {
if (e.getCause() instanceof LuceneQueryException) {
throw new LuceneQueryException(e);
} else {
e.printStackTrace();
throw e;
}

}
return entries;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.*;
import java.util.concurrent.TimeUnit;

import org.apache.geode.cache.lucene.internal.distributed.LuceneQueryFunction;
import org.apache.geode.cache.lucene.internal.management.LuceneServiceMBean;
import org.apache.geode.cache.lucene.internal.management.ManagementIndexListener;
import org.apache.geode.management.internal.beans.CacheServiceMBeanBase;
Expand All @@ -39,7 +40,6 @@
import org.apache.geode.cache.lucene.LuceneQueryFactory;
import org.apache.geode.cache.lucene.internal.directory.DumpDirectoryFiles;
import org.apache.geode.cache.lucene.internal.distributed.EntryScore;
import org.apache.geode.cache.lucene.internal.distributed.LuceneFunction;
import org.apache.geode.cache.lucene.internal.distributed.LuceneFunctionContext;
import org.apache.geode.cache.lucene.internal.distributed.TopEntries;
import org.apache.geode.cache.lucene.internal.distributed.TopEntriesCollector;
Expand All @@ -55,7 +55,6 @@
import org.apache.geode.internal.cache.CacheService;
import org.apache.geode.internal.cache.GemFireCacheImpl;
import org.apache.geode.internal.cache.InternalRegionArguments;
import org.apache.geode.internal.cache.PartitionedRegion;
import org.apache.geode.internal.cache.RegionListener;
import org.apache.geode.internal.cache.xmlcache.XmlGenerator;
import org.apache.geode.internal.i18n.LocalizedStrings;
Expand Down Expand Up @@ -89,7 +88,7 @@ public void init(final Cache cache) {

this.cache = gfc;

FunctionService.registerFunction(new LuceneFunction());
FunctionService.registerFunction(new LuceneQueryFunction());
FunctionService.registerFunction(new WaitUntilFlushedFunction());
FunctionService.registerFunction(new DumpDirectoryFiles());
registerDataSerializables();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.lucene.search.Query;

import org.apache.geode.cache.Region;
import org.apache.geode.cache.execute.FunctionAdapter;
import org.apache.geode.cache.execute.FunctionContext;
import org.apache.geode.cache.execute.FunctionException;
import org.apache.geode.cache.execute.RegionFunctionContext;
Expand All @@ -44,13 +43,14 @@
import org.apache.geode.internal.logging.LogService;

/**
* {@link LuceneFunction} coordinates text search on a member. It receives text search query from
* the coordinator and arguments like region and buckets. It invokes search on the local index and
* provides a result collector. The locally collected results are sent to the search coordinator.
* {@link LuceneQueryFunction} coordinates text search on a member. It receives text search query
* from the coordinator and arguments like region and buckets. It invokes search on the local index
* and provides a result collector. The locally collected results are sent to the search
* coordinator.
*/
public class LuceneFunction implements Function, InternalEntity {
public class LuceneQueryFunction implements Function, InternalEntity {
private static final long serialVersionUID = 1L;
public static final String ID = LuceneFunction.class.getName();
public static final String ID = LuceneQueryFunction.class.getName();

private static final Logger logger = LogService.getLogger();

Expand Down Expand Up @@ -121,7 +121,7 @@ public void execute(FunctionContext context) {
resultSender.lastResult(mergedResult);
} catch (IOException | BucketNotFoundException e) {
logger.debug("Exception during lucene query function", e);
throw new FunctionException(e);
throw new InternalFunctionInvocationTargetException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*/
/**
* Classes used for distributing lucene queries to geode nodes. Contains the lucene related
* functions like {@link org.apache.geode.cache.lucene.internal.distributed.LuceneFunction} as well
* as objects that are passed between nodes like
* functions like {@link org.apache.geode.cache.lucene.internal.distributed.LuceneQueryFunction} as
* well as objects that are passed between nodes like
* {@link org.apache.geode.cache.lucene.internal.distributed.EntryScore}
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.List;
import java.util.Map;

import org.apache.geode.cache.lucene.internal.distributed.LuceneQueryFunction;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
Expand All @@ -40,7 +41,6 @@
import org.apache.geode.cache.lucene.PageableLuceneQueryResults;
import org.apache.geode.cache.lucene.LuceneResultStruct;
import org.apache.geode.cache.lucene.internal.distributed.EntryScore;
import org.apache.geode.cache.lucene.internal.distributed.LuceneFunction;
import org.apache.geode.cache.lucene.internal.distributed.LuceneFunctionContext;
import org.apache.geode.cache.lucene.internal.distributed.TopEntries;
import org.apache.geode.cache.lucene.internal.distributed.TopEntriesCollector;
Expand Down Expand Up @@ -127,7 +127,7 @@ public void shouldInvokeLuceneFunctionWithCorrectArguments() throws Exception {
addValueToResults();
PageableLuceneQueryResults<Object, Object> results = query.findPages();

verify(execution).execute(eq(LuceneFunction.ID));
verify(execution).execute(eq(LuceneQueryFunction.ID));
ArgumentCaptor<LuceneFunctionContext> captor =
ArgumentCaptor.forClass(LuceneFunctionContext.class);
verify(execution).withArgs(captor.capture());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.geode.cache.execute.FunctionService;
import org.apache.geode.cache.lucene.LuceneService;
import org.apache.geode.cache.lucene.LuceneServiceProvider;
import org.apache.geode.cache.lucene.internal.distributed.LuceneFunction;
import org.apache.geode.cache.lucene.internal.distributed.LuceneQueryFunction;
import org.apache.geode.test.junit.categories.IntegrationTest;
import org.junit.After;
import org.junit.Rule;
Expand Down Expand Up @@ -55,13 +55,13 @@ public void luceneServiceProviderGetShouldAcceptClientCacheAsAParameter() {
// lucene service will register query execution function on initialization
@Test
public void shouldRegisterQueryFunction() {
Function function = FunctionService.getFunction(LuceneFunction.ID);
Function function = FunctionService.getFunction(LuceneQueryFunction.ID);
assertNull(function);

cache = getCache();
new LuceneServiceImpl().init(cache);

function = FunctionService.getFunction(LuceneFunction.ID);
function = FunctionService.getFunction(LuceneQueryFunction.ID);
assertNotNull(function);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.apache.geode.test.junit.categories.UnitTest;

@Category(UnitTest.class)
public class LuceneFunctionContextJUnitTest {
public class LuceneQueryFunctionContextJUnitTest {

@Test
public void testLuceneFunctionArgsDefaults() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.apache.geode.cache.lucene.internal.repository.IndexRepository;
import org.apache.geode.cache.lucene.internal.repository.IndexResultCollector;
import org.apache.geode.cache.lucene.internal.repository.RepositoryManager;
import org.apache.geode.internal.cache.BucketNotFoundException;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.cache.execute.InternalRegionFunctionContext;
import org.apache.geode.test.junit.categories.UnitTest;
Expand All @@ -52,7 +51,7 @@
import org.mockito.Mockito;

@Category(UnitTest.class)
public class LuceneFunctionJUnitTest {
public class LuceneQueryFunctionJUnitTest {

String regionPath = "/region";
String indexName = "index";
Expand Down Expand Up @@ -104,7 +103,7 @@ public void testRepoQueryAndMerge() throws Exception {
}).when(mockRepository2).query(eq(query), eq(LuceneQueryFactory.DEFAULT_LIMIT),
any(IndexResultCollector.class));

LuceneFunction function = new LuceneFunction();
LuceneQueryFunction function = new LuceneQueryFunction();

function.execute(mockContext);

Expand Down Expand Up @@ -146,7 +145,7 @@ public void testResultLimitClause() throws Exception {
}).when(mockRepository2).query(eq(query), eq(3), any(IndexResultCollector.class));


LuceneFunction function = new LuceneFunction();
LuceneQueryFunction function = new LuceneQueryFunction();

function.execute(mockContext);

Expand Down Expand Up @@ -187,7 +186,7 @@ public void injectCustomCollectorManager() throws Exception {
any(IndexResultCollector.class));


LuceneFunction function = new LuceneFunction();
LuceneQueryFunction function = new LuceneQueryFunction();

function.execute(mockContext);

Expand All @@ -204,7 +203,7 @@ public void testIndexRepoQueryFails() throws Exception {
doThrow(IOException.class).when(mockRepository1).query(eq(query),
eq(LuceneQueryFactory.DEFAULT_LIMIT), any(IndexResultCollector.class));

LuceneFunction function = new LuceneFunction();
LuceneQueryFunction function = new LuceneQueryFunction();

function.execute(mockContext);
}
Expand All @@ -217,7 +216,7 @@ public void testIndexRepoQueryFails() throws Exception {
// when(mockContext.<TopEntriesCollector>getResultSender()).thenReturn(mockResultSender);
// when(mockRepoManager.getRepositories(eq(mockContext)))
// .thenThrow(new BucketNotFoundException(""));
// LuceneFunction function = new LuceneFunction();
// LuceneQueryFunction function = new LuceneQueryFunction();
//
// function.execute(mockContext);
//
Expand All @@ -238,7 +237,7 @@ public void testReduceError() throws Exception {
when(mockManager.newCollector(eq("repo1"))).thenReturn(mockCollector);
when(mockManager.reduce(any(Collection.class))).thenThrow(IOException.class);

LuceneFunction function = new LuceneFunction();
LuceneQueryFunction function = new LuceneQueryFunction();

function.execute(mockContext);
}
Expand All @@ -251,15 +250,15 @@ public void queryProviderErrorIsHandled() throws Exception {
when(mockContext.getArguments()).thenReturn(searchArgs);
when(mockContext.<TopEntriesCollector>getResultSender()).thenReturn(mockResultSender);
when(queryProvider.getQuery(eq(mockIndex))).thenThrow(LuceneQueryException.class);
LuceneFunction function = new LuceneFunction();
LuceneQueryFunction function = new LuceneQueryFunction();

function.execute(mockContext);
}

@Test
public void testQueryFunctionId() {
String id = new LuceneFunction().getId();
assertEquals(LuceneFunction.class.getName(), id);
String id = new LuceneQueryFunction().getId();
assertEquals(LuceneQueryFunction.class.getName(), id);
}

@Before
Expand Down

0 comments on commit 5547c2a

Please sign in to comment.