geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ash...@apache.org
Subject [2/4] incubator-geode git commit: GEODE-11: Register LuceneQueryFunction on members
Date Fri, 11 Sep 2015 21:56:38 GMT
GEODE-11: Register LuceneQueryFunction on members

LuceneQueryFunction will be registered by LuceneQueryService. If the service is
running, the member is capable of executing search function.

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


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

Branch: refs/heads/feature/GEODE-11
Commit: 54bc45eb524b9ffd8fcf04071bfbf6e3f3beb6a8
Parents: 0460dbb
Author: Ashvin Agrawal <ashvin@apache.org>
Authored: Thu Sep 10 13:54:38 2015 -0700
Committer: Ashvin Agrawal <ashvin@apache.org>
Committed: Fri Sep 11 14:54:51 2015 -0700

----------------------------------------------------------------------
 .../lucene/internal/LuceneServiceImpl.java      | 26 +++++------
 .../distributed/LuceneQueryFunction.java        |  1 -
 .../internal/LuceneServiceImplJUnitTest.java    | 46 ++++++++++++++++++++
 3 files changed, 59 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/54bc45eb/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImpl.java
----------------------------------------------------------------------
diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImpl.java
b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImpl.java
index 864de33..bcc2c07 100644
--- a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImpl.java
+++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImpl.java
@@ -7,10 +7,11 @@ import java.util.Map;
 import org.apache.lucene.analysis.Analyzer;
 
 import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.cache.GemFireCache;
+import com.gemstone.gemfire.cache.execute.FunctionService;
 import com.gemstone.gemfire.cache.lucene.LuceneIndex;
 import com.gemstone.gemfire.cache.lucene.LuceneQueryFactory;
 import com.gemstone.gemfire.cache.lucene.LuceneService;
+import com.gemstone.gemfire.cache.lucene.internal.distributed.LuceneQueryFunction;
 import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
 import com.gemstone.gemfire.internal.cache.extension.Extensible;
 import com.gemstone.gemfire.internal.cache.extension.Extension;
@@ -18,7 +19,7 @@ import com.gemstone.gemfire.internal.cache.xmlcache.XmlGenerator;
 import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
 
 /**
- * Implementation of LuceneService to create lucene index and query. 
+ * Implementation of LuceneService to create lucene index and query.
  * 
  * @author Xiaojian Zhou
  * 
@@ -27,7 +28,7 @@ import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
 public class LuceneServiceImpl implements LuceneService, Extension<Cache> {
   private final Cache cache;
 
-  private final HashMap<String, LuceneIndex>  indexMap;
+  private final HashMap<String, LuceneIndex> indexMap;
 
   public LuceneServiceImpl(final Cache cache) {
     if (cache == null) {
@@ -38,16 +39,17 @@ public class LuceneServiceImpl implements LuceneService, Extension<Cache>
{
 
     this.cache = gfc;
 
-    
+    FunctionService.registerFunction(new LuceneQueryFunction());
+
     // Initialize the Map which maintains indexes
     this.indexMap = new HashMap<String, LuceneIndex>();
   }
-  
+
   public String getUniqueIndexName(String indexName, String regionName) {
-    String name = indexName+"#"+regionName.replace('/', '_');
+    String name = indexName + "#" + regionName.replace('/', '_');
     return name;
   }
-  
+
   @Override
   public LuceneIndex createIndex(String indexName, String regionName, String... fields) {
     // TODO Auto-generated method stub
@@ -65,15 +67,14 @@ public class LuceneServiceImpl implements LuceneService, Extension<Cache>
{
   }
 
   @Override
-  public LuceneIndex createIndex(String indexName, String regionName, 
-      Map<String, Analyzer> analyzerPerField) {
+  public LuceneIndex createIndex(String indexName, String regionName, Map<String, Analyzer>
analyzerPerField) {
     // TODO Auto-generated method stub
     return null;
   }
 
   @Override
   public void destroyIndex(LuceneIndex index) {
-    LuceneIndexImpl indexImpl = (LuceneIndexImpl)index;
+    LuceneIndexImpl indexImpl = (LuceneIndexImpl) index;
     indexMap.remove(getUniqueIndexName(index.getName(), index.getRegionName()));
     indexImpl.close();
   }
@@ -90,10 +91,9 @@ public class LuceneServiceImpl implements LuceneService, Extension<Cache>
{
   }
 
   @Override
-  public void onCreate(Extensible<Cache> source,
-      Extensible<Cache> target) {
+  public void onCreate(Extensible<Cache> source, Extensible<Cache> target) {
     // TODO Auto-generated method stub
-    
+
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/54bc45eb/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneQueryFunction.java
----------------------------------------------------------------------
diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneQueryFunction.java
b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneQueryFunction.java
index 27a42ad..369ceb8 100644
--- a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneQueryFunction.java
+++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneQueryFunction.java
@@ -3,7 +3,6 @@ package com.gemstone.gemfire.cache.lucene.internal.distributed;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Set;
 
 import org.apache.logging.log4j.Logger;
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/54bc45eb/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
new file mode 100644
index 0000000..6ee13a7
--- /dev/null
+++ b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImplJUnitTest.java
@@ -0,0 +1,46 @@
+package com.gemstone.gemfire.cache.lucene.internal;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.junit.After;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.CacheFactory;
+import com.gemstone.gemfire.cache.execute.Function;
+import com.gemstone.gemfire.cache.execute.FunctionService;
+import com.gemstone.gemfire.cache.lucene.internal.distributed.LuceneQueryFunction;
+import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class LuceneServiceImplJUnitTest {
+  Cache cache;
+
+  // lucene service will register query execution function on initialization
+  @Test
+  public void shouldRegisterQueryFunction() {
+    Function function = FunctionService.getFunction(LuceneQueryFunction.ID);
+    assertNull(function);
+
+    cache = createBasicCache();
+    new LuceneServiceImpl(cache);
+
+    function = FunctionService.getFunction(LuceneQueryFunction.ID);
+    assertNotNull(function);
+  }
+
+  private GemFireCacheImpl createBasicCache() {
+    return (GemFireCacheImpl) new CacheFactory().set("mcast-port", "0").create();
+  }
+
+  @After
+  public void destroyCache() {
+    if (cache != null && !cache.isClosed()) {
+      cache.close();
+      cache = null;
+    }
+  }
+}


Mime
View raw message