You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ja...@apache.org on 2016/04/13 22:40:55 UTC

incubator-geode git commit: GEODE-1220: Minor refactoring of LuceneServiceImplJUnitTest and LuceneIndexRecoveryHAJUnitTest

Repository: incubator-geode
Updated Branches:
  refs/heads/develop 6c7a0d2a2 -> 7d5f39aee


GEODE-1220: Minor refactoring of LuceneServiceImplJUnitTest and LuceneIndexRecoveryHAJUnitTest

Removed sleep with awaitility until async queue size is 0
Removed unnecessary/dead code
Renamed tests to be slightly more descriptive


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

Branch: refs/heads/develop
Commit: 7d5f39aeebeb345600e8608d77a2d42720871907
Parents: 6c7a0d2
Author: Jason Huynh <hu...@gmail.com>
Authored: Tue Apr 12 15:11:18 2016 -0700
Committer: Jason Huynh <hu...@gmail.com>
Committed: Wed Apr 13 13:39:25 2016 -0700

----------------------------------------------------------------------
 .../LuceneIndexRecoveryHAJUnitTest.java         | 20 ++++++---
 .../internal/LuceneServiceImplJUnitTest.java    | 44 ++++++++++----------
 2 files changed, 36 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7d5f39ae/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexRecoveryHAJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexRecoveryHAJUnitTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexRecoveryHAJUnitTest.java
index 405c986..9ab6e81 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexRecoveryHAJUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexRecoveryHAJUnitTest.java
@@ -19,9 +19,10 @@
 
 package com.gemstone.gemfire.cache.lucene.internal;
 
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.*;
 
 import java.io.IOException;
+import java.util.Set;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.lucene.analysis.Analyzer;
@@ -41,6 +42,7 @@ import com.gemstone.gemfire.cache.PartitionAttributesFactory;
 import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.RegionFactory;
 import com.gemstone.gemfire.cache.RegionShortcut;
+import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue;
 import com.gemstone.gemfire.cache.lucene.LuceneQuery;
 import com.gemstone.gemfire.cache.lucene.LuceneQueryResults;
 import com.gemstone.gemfire.cache.lucene.LuceneService;
@@ -54,6 +56,7 @@ import com.gemstone.gemfire.internal.cache.EvictionAttributesImpl;
 import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
 import com.gemstone.gemfire.internal.cache.PartitionedRegion;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+import com.jayway.awaitility.Awaitility;
 
 @Category(IntegrationTest.class)
 public class LuceneIndexRecoveryHAJUnitTest {
@@ -120,6 +123,8 @@ public class LuceneIndexRecoveryHAJUnitTest {
 
   @Test
   public void recoverPersistentIndex() throws Exception {
+    String aeqId = LuceneServiceImpl.getUniqueIndexName(INDEX, REGION);
+
     LuceneService service = LuceneServiceProvider.get(cache);
     service.createIndex(INDEX, REGION, Type1.fields);
 
@@ -133,8 +138,7 @@ public class LuceneIndexRecoveryHAJUnitTest {
     value = new Type1("lucene world", 1, 2L, 3.0, 4.0f);
     userRegion.put("value3", value);
 
-    // TODO flush queue
-    TimeUnit.MILLISECONDS.sleep(500);
+    waitUntilQueueEmpty(aeqId);
 
     LuceneQuery<Integer, Type1> query = service.createLuceneQueryFactory().create(INDEX, REGION, "s:world");
     LuceneQueryResults<Integer, Type1> results = query.search();
@@ -153,7 +157,6 @@ public class LuceneIndexRecoveryHAJUnitTest {
     results = query.search();
     Assert.assertEquals(3, results.size());
 
-    String aeqId = LuceneServiceImpl.getUniqueIndexName(INDEX, REGION);
     PartitionedRegion chunkRegion = (PartitionedRegion) cache.getRegion(aeqId + ".chunks");
     assertNotNull(chunkRegion);
     chunkRegion.destroyRegion();
@@ -185,8 +188,7 @@ public class LuceneIndexRecoveryHAJUnitTest {
     value = new Type1("lucene world", 1, 2L, 3.0, 4.0f);
     userRegion.put("value3", value);
 
-    // TODO flush queue
-    TimeUnit.MILLISECONDS.sleep(500);
+    waitUntilQueueEmpty(aeqId);
 
     PartitionedRegion fileRegion = (PartitionedRegion) cache.getRegion(aeqId + ".files");
     assertNotNull(fileRegion);
@@ -198,4 +200,10 @@ public class LuceneIndexRecoveryHAJUnitTest {
     LuceneQueryResults<Integer, Type1> results = query.search();
     Assert.assertEquals(3, results.size());
   }
+
+  private void waitUntilQueueEmpty(final String aeqId) {
+    // TODO flush queue
+    AsyncEventQueue queue = cache.getAsyncEventQueue(aeqId);
+    Awaitility.waitAtMost(1000, TimeUnit.MILLISECONDS).until(() -> assertEquals(0, queue.size()));
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7d5f39ae/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 3a6f38c..d0e9865 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
@@ -39,8 +39,10 @@ import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.queryparser.classic.ParseException;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
 
 import com.gemstone.gemfire.cache.Cache;
 import com.gemstone.gemfire.cache.CacheFactory;
@@ -48,6 +50,7 @@ import com.gemstone.gemfire.cache.RegionShortcut;
 import com.gemstone.gemfire.cache.asyncqueue.internal.AsyncEventQueueImpl;
 import com.gemstone.gemfire.cache.execute.Function;
 import com.gemstone.gemfire.cache.execute.FunctionService;
+import com.gemstone.gemfire.cache.lucene.LuceneService;
 import com.gemstone.gemfire.cache.lucene.LuceneServiceProvider;
 import com.gemstone.gemfire.cache.lucene.internal.distributed.LuceneFunction;
 import com.gemstone.gemfire.cache.lucene.internal.repository.RepositoryManager;
@@ -67,23 +70,22 @@ public class LuceneServiceImplJUnitTest {
   private IndexWriter writer;
   LuceneServiceImpl service = null;
   private static final Logger logger = LogService.getLogger();
-  
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
   // lucene service will register query execution function on initialization
   @Test
   public void shouldRegisterQueryFunction() {
     Function function = FunctionService.getFunction(LuceneFunction.ID);
     assertNull(function);
 
-    cache = createBasicCache();
+    cache = getCache();
     new LuceneServiceImpl().init(cache);
 
     function = FunctionService.getFunction(LuceneFunction.ID);
     assertNotNull(function);
   }
-  
-  private GemFireCacheImpl createBasicCache() {
-    return (GemFireCacheImpl) new CacheFactory().set("mcast-port", "0").create();
-  }
 
   @After
   public void destroyCache() {
@@ -93,34 +95,35 @@ public class LuceneServiceImplJUnitTest {
     }
   }
   
-  private void getCache() {
+  private Cache getCache() {
     try {
        cache = CacheFactory.getAnyInstance();
     } catch (Exception e) {
       //ignore
     }
     if (null == cache) {
-      cache = createBasicCache();
+      cache = new CacheFactory().set("mcast-port", "0").create();
     }
+    return cache;
   }
   
-  private void getService() {
+  private LuceneService getService() {
     if (cache == null) {
       getCache();
     }
     if (service == null) {
       service = (LuceneServiceImpl)LuceneServiceProvider.get(cache);
     }
+    return service;
   }
   
   private LocalRegion createPR(String regionName, boolean isSubRegion) {
     if (isSubRegion) {
-      LocalRegion root = (LocalRegion)cache.createRegionFactory(RegionShortcut.REPLICATE).create("root");
+      LocalRegion root = (LocalRegion)cache.createRegionFactory(RegionShortcut.PARTITION).create("root");
       LocalRegion region = (LocalRegion)cache.createRegionFactory(RegionShortcut.PARTITION_PERSISTENT).
           createSubregion(root, regionName);
       return region;
     } else {
-      LocalRegion root = (LocalRegion)cache.createRegionFactory(RegionShortcut.REPLICATE).create("root");
       LocalRegion region = (LocalRegion)cache.createRegionFactory(RegionShortcut.PARTITION_PERSISTENT).
           create(regionName);
       return region;
@@ -134,25 +137,21 @@ public class LuceneServiceImplJUnitTest {
           createSubregion(root, regionName);
       return region;
     } else {
-      LocalRegion root = (LocalRegion)cache.createRegionFactory(RegionShortcut.REPLICATE).create("root");
       LocalRegion region = (LocalRegion)cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT).
           create(regionName);
       return region;
     }
   }
-  
-  /**Test that we don't allow the user
-   * to create the region first.
-   */
+
   @Test(expected = IllegalStateException.class)
-  public void createRegionFirst() throws IOException, ParseException {
+  public void cannotCreateLuceneIndexAfterRegionHasBeenCreated() throws IOException, ParseException {
     getService();
     LocalRegion userRegion = createPR("PR1", false);
     service.createIndex("index1", "PR1", "field1", "field2", "field3");
   }
 
   @Test
-  public void testCreateIndexForPR() throws IOException, ParseException {
+  public void canCreateLuceneIndexForPR() throws IOException, ParseException {
     getService();
     service.createIndex("index1", "PR1", "field1", "field2", "field3");
     LocalRegion userRegion = createPR("PR1", false);
@@ -184,7 +183,7 @@ public class LuceneServiceImplJUnitTest {
   }
 
   @Test
-  public void testCreateIndexForPRWithAnalyzer() throws IOException, ParseException {
+  public void canCreateLuceneIndexForPRWithAnalyzer() throws IOException, ParseException {
     getService();
     StandardAnalyzer sa = new StandardAnalyzer();
     KeywordAnalyzer ka = new KeywordAnalyzer();
@@ -217,12 +216,13 @@ public class LuceneServiceImplJUnitTest {
     assertTrue(chunkPR != null);
   }
   
-  @Test (expected=UnsupportedOperationException.class)
-  public void testCreateIndexForRR() throws IOException, ParseException {
+  @Test
+  public void cannotCreateLuceneIndexForReplicateRegion() throws IOException, ParseException {
+    expectedException.expect(UnsupportedOperationException.class);
+    expectedException.expectMessage("Lucene indexes on replicated regions are not supported");
     getService();
     service.createIndex("index1", "RR1", "field1", "field2", "field3");
     createRR("RR1", false);
-    fail("Expect UnsupportedOperationException");
   }
 
 }