geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinmeil...@apache.org
Subject [06/50] [abbrv] incubator-geode git commit: GEODE-1190: LuceneServiceProvider.get now accepts GemFireCache as a parameter.
Date Thu, 21 Apr 2016 17:16:41 GMT
GEODE-1190: LuceneServiceProvider.get now accepts GemFireCache as a parameter.

* Modified the LuceneServiceProvider.get function signature to use GemFireCache as a parameter.
* Wrote a small test case to check that LuceneServiceProvider.get does not return null when
ClientCache is passed as a parameter.

This closes #129


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

Branch: refs/heads/feature/GEODE-17-2
Commit: 58caa328a6eabc2a33cbb8b834340a2272e1f1aa
Parents: bcaf0c6
Author: nabarun <nnag@pivotal.io>
Authored: Wed Apr 13 18:13:37 2016 -0700
Committer: Jason Huynh <huynhja@gmail.com>
Committed: Mon Apr 18 15:37:02 2016 -0700

----------------------------------------------------------------------
 .../cache/lucene/LuceneServiceProvider.java     |  9 ++-
 .../internal/LuceneServiceImplJUnitTest.java    | 68 +++++++++++++-------
 2 files changed, 47 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/58caa328/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneServiceProvider.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneServiceProvider.java
b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneServiceProvider.java
index bbd2b83..f83dffa 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneServiceProvider.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneServiceProvider.java
@@ -20,7 +20,7 @@
 package com.gemstone.gemfire.cache.lucene;
 
 import com.gemstone.gemfire.annotations.Experimental;
-import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.GemFireCache;
 import com.gemstone.gemfire.cache.lucene.internal.InternalLuceneService;
 import com.gemstone.gemfire.internal.cache.InternalCache;
 
@@ -31,16 +31,15 @@ import com.gemstone.gemfire.internal.cache.InternalCache;
  */
 @Experimental
 public class LuceneServiceProvider {
-  
   /**
    * Retrieve or create the lucene service for this cache
    */
-  public static LuceneService get(Cache cache) {
+  public static LuceneService get(GemFireCache cache) {
     InternalCache internalCache = (InternalCache) cache;
     return internalCache.getService(InternalLuceneService.class);
   }
-  
+
   private LuceneServiceProvider() {
-    
+
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/58caa328/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImplJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImplJUnitTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImplJUnitTest.java
index d0e9865..a85e617 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImplJUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImplJUnitTest.java
@@ -19,11 +19,7 @@
 
 package com.gemstone.gemfire.cache.lucene.internal;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
 
 import java.io.IOException;
 import java.util.Collections;
@@ -46,10 +42,14 @@ import org.junit.rules.ExpectedException;
 
 import com.gemstone.gemfire.cache.Cache;
 import com.gemstone.gemfire.cache.CacheFactory;
+import com.gemstone.gemfire.cache.GemFireCache;
 import com.gemstone.gemfire.cache.RegionShortcut;
 import com.gemstone.gemfire.cache.asyncqueue.internal.AsyncEventQueueImpl;
+import com.gemstone.gemfire.cache.client.ClientCache;
+import com.gemstone.gemfire.cache.client.ClientCacheFactory;
 import com.gemstone.gemfire.cache.execute.Function;
 import com.gemstone.gemfire.cache.execute.FunctionService;
+import com.gemstone.gemfire.cache.lucene.LuceneIndex;
 import com.gemstone.gemfire.cache.lucene.LuceneService;
 import com.gemstone.gemfire.cache.lucene.LuceneServiceProvider;
 import com.gemstone.gemfire.cache.lucene.internal.distributed.LuceneFunction;
@@ -64,6 +64,7 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest;
 @Category(UnitTest.class)
 public class LuceneServiceImplJUnitTest {
   Cache cache;
+  ClientCache clientCache;
   private LuceneIndexImpl repo;
   private HeterogenousLuceneSerializer mapper;
   private StandardAnalyzer analyzer = new StandardAnalyzer();
@@ -74,6 +75,13 @@ public class LuceneServiceImplJUnitTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
+  @Test
+  public void luceneServiceProviderGetShouldAcceptClientCacheAsAParameter(){
+    clientCache = getClientCache();
+    LuceneService luceneService = LuceneServiceProvider.get(clientCache);
+    assertNotNull(luceneService);
+  }
+
   // lucene service will register query execution function on initialization
   @Test
   public void shouldRegisterQueryFunction() {
@@ -89,43 +97,52 @@ public class LuceneServiceImplJUnitTest {
 
   @After
   public void destroyCache() {
-    if (cache != null && !cache.isClosed()) {
+    if (null != cache && !cache.isClosed()) {
       cache.close();
       cache = null;
     }
+    if (null != clientCache  && !clientCache.isClosed()) {
+      clientCache.close();
+      clientCache = null;
+    }
   }
-  
-  private Cache getCache() {
-    try {
-       cache = CacheFactory.getAnyInstance();
-    } catch (Exception e) {
-      //ignore
+
+  private ClientCache getClientCache() {
+    if (null == clientCache) {
+      clientCache = new ClientCacheFactory().set("mcast-port", "0").create();
+    }
+    else{
+      return clientCache;
     }
+    return clientCache;
+  }
+
+  private Cache getCache() {
     if (null == cache) {
       cache = new CacheFactory().set("mcast-port", "0").create();
     }
     return cache;
   }
-  
+
   private LuceneService getService() {
-    if (cache == null) {
+    if (null == cache) {
       getCache();
     }
-    if (service == null) {
+    if (null == service) {
       service = (LuceneServiceImpl)LuceneServiceProvider.get(cache);
     }
     return service;
   }
-  
+
   private LocalRegion createPR(String regionName, boolean isSubRegion) {
     if (isSubRegion) {
       LocalRegion root = (LocalRegion)cache.createRegionFactory(RegionShortcut.PARTITION).create("root");
       LocalRegion region = (LocalRegion)cache.createRegionFactory(RegionShortcut.PARTITION_PERSISTENT).
-          createSubregion(root, regionName);
+        createSubregion(root, regionName);
       return region;
     } else {
       LocalRegion region = (LocalRegion)cache.createRegionFactory(RegionShortcut.PARTITION_PERSISTENT).
-          create(regionName);
+        create(regionName);
       return region;
     }
   }
@@ -134,11 +151,11 @@ public class LuceneServiceImplJUnitTest {
     if (isSubRegion) {
       LocalRegion root = (LocalRegion)cache.createRegionFactory(RegionShortcut.REPLICATE).create("root");
       LocalRegion region = (LocalRegion)cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT).
-          createSubregion(root, regionName);
+        createSubregion(root, regionName);
       return region;
     } else {
       LocalRegion region = (LocalRegion)cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT).
-          create(regionName);
+        create(regionName);
       return region;
     }
   }
@@ -146,6 +163,7 @@ public class LuceneServiceImplJUnitTest {
   @Test(expected = IllegalStateException.class)
   public void cannotCreateLuceneIndexAfterRegionHasBeenCreated() throws IOException, ParseException
{
     getService();
+
     LocalRegion userRegion = createPR("PR1", false);
     service.createIndex("index1", "PR1", "field1", "field2", "field3");
   }
@@ -166,18 +184,18 @@ public class LuceneServiceImplJUnitTest {
     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";
     PartitionedRegion filePR = (PartitionedRegion)cache.getRegion(fileRegionName);
     PartitionedRegion chunkPR = (PartitionedRegion)cache.getRegion(chunkRegionName);
     assertTrue(filePR != null);
     assertTrue(chunkPR != null);
-    
+
     String aeqId = LuceneServiceImpl.getUniqueIndexName(index1.getName(), index1.getRegionPath());
     AsyncEventQueueImpl aeq = (AsyncEventQueueImpl)cache.getAsyncEventQueue(aeqId);
     assertTrue(aeq != null);
-    
+
     //Make sure our queue doesn't show up in the list of async event queues 
     assertEquals(Collections.emptySet(), cache.getAsyncEventQueues());
   }
@@ -207,7 +225,7 @@ public class LuceneServiceImplJUnitTest {
     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);
@@ -215,7 +233,7 @@ public class LuceneServiceImplJUnitTest {
     assertTrue(filePR != null);
     assertTrue(chunkPR != null);
   }
-  
+
   @Test
   public void cannotCreateLuceneIndexForReplicateRegion() throws IOException, ParseException
{
     expectedException.expect(UnsupportedOperationException.class);


Mime
View raw message