You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by as...@apache.org on 2015/11/11 22:24:11 UTC

[39/50] [abbrv] incubator-geode git commit: GEODE-11: Add dunits for various partition regions

GEODE-11: Add dunits for various partition regions


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

Branch: refs/heads/develop
Commit: 28a0eb81740076278d9471872ced68c1f01183d7
Parents: 1f597bb
Author: Ashvin Agrawal <as...@apache.org>
Authored: Fri Oct 16 15:45:06 2015 -0700
Committer: Ashvin Agrawal <as...@apache.org>
Committed: Fri Oct 16 15:49:06 2015 -0700

----------------------------------------------------------------------
 .../LuceneFunctionReadPathDUnitTest.java        | 170 ++++++++++++-------
 1 file changed, 104 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/28a0eb81/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionReadPathDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionReadPathDUnitTest.java b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionReadPathDUnitTest.java
index 0bf1842..b3460b7 100644
--- a/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionReadPathDUnitTest.java
+++ b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionReadPathDUnitTest.java
@@ -1,6 +1,5 @@
 package com.gemstone.gemfire.cache.lucene.internal.distributed;
 
-import java.io.IOException;
 import java.io.Serializable;
 import java.util.HashMap;
 import java.util.List;
@@ -11,6 +10,8 @@ import org.junit.Assert;
 import org.junit.experimental.categories.Category;
 
 import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.EvictionAction;
+import com.gemstone.gemfire.cache.EvictionAlgorithm;
 import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.RegionFactory;
 import com.gemstone.gemfire.cache.RegionShortcut;
@@ -21,10 +22,10 @@ import com.gemstone.gemfire.cache.lucene.LuceneQueryResults;
 import com.gemstone.gemfire.cache.lucene.LuceneResultStruct;
 import com.gemstone.gemfire.cache.lucene.LuceneService;
 import com.gemstone.gemfire.cache.lucene.LuceneServiceProvider;
-import com.gemstone.gemfire.cache.lucene.internal.InternalLuceneIndex;
 import com.gemstone.gemfire.cache.lucene.internal.LuceneServiceImpl;
 import com.gemstone.gemfire.cache30.CacheTestCase;
-import com.gemstone.gemfire.internal.cache.BucketNotFoundException;
+import com.gemstone.gemfire.internal.cache.EvictionAttributesImpl;
+import com.gemstone.gemfire.internal.cache.PartitionedRegion;
 import com.gemstone.gemfire.test.junit.categories.DistributedTest;
 
 import dunit.Host;
@@ -34,7 +35,6 @@ import dunit.VM;
 @Category(DistributedTest.class)
 public class LuceneFunctionReadPathDUnitTest extends CacheTestCase {
   private static final String INDEX_NAME = "index";
-  private static final String REGION_NAME = "indexedRegion";
 
   private static final long serialVersionUID = 1L;
 
@@ -54,101 +54,140 @@ public class LuceneFunctionReadPathDUnitTest extends CacheTestCase {
   }
 
   public void testEnd2EndFunctionExecution() {
-    SerializableCallable createPartitionRegion = new SerializableCallable("createRegion") {
+    e2eTextSearchForRegionType(RegionShortcut.PARTITION);
+    e2eTextSearchForRegionType(RegionShortcut.PARTITION_PERSISTENT);
+    e2eTextSearchForRegionType(RegionShortcut.PARTITION_OVERFLOW);
+    e2eTextSearchForRegionType(RegionShortcut.PARTITION_PERSISTENT_OVERFLOW);
+  }
+
+  private void e2eTextSearchForRegionType(RegionShortcut type) {
+    final String regionName = type.toString();
+    createPartitionRegionAndIndex(server1, regionName, type);
+    putDataInRegion(server1, regionName);
+    createPartitionRegionAndIndex(server2, regionName, type);
+    // Make sure we can search from both members
+    executeTextSearch(server1, regionName);
+    executeTextSearch(server2, regionName);
+
+    rebalanceRegion(server1);
+    // Make sure the search still works
+    executeTextSearch(server1, regionName);
+    executeTextSearch(server2, regionName);
+    destroyRegion(server2, regionName);
+  }
+
+  private void rebalanceRegion(VM vm) {
+    // Do a rebalance
+    vm.invoke(new SerializableCallable<Object>() {
+      private static final long serialVersionUID = 1L;
+
+      @Override
+      public Object call() throws CancellationException, InterruptedException {
+        RebalanceOperation op = getCache().getResourceManager().createRebalanceFactory().start();
+        RebalanceResults results = op.getResults();
+        assertTrue(1 < results.getTotalBucketTransfersCompleted());
+        return null;
+      }
+    });
+  }
+
+  private void executeTextSearch(VM vm, final String regionName) {
+    SerializableCallable<Object> executeSearch = new SerializableCallable<Object>("executeSearch") {
       private static final long serialVersionUID = 1L;
 
       public Object call() throws Exception {
-        final Cache cache = getCache();
+        Cache cache = getCache();
         assertNotNull(cache);
+        Region<Object, Object> region = cache.getRegion(regionName);
+        Assert.assertNotNull(region);
+
         LuceneService service = LuceneServiceProvider.get(cache);
-        service.createIndex(INDEX_NAME, REGION_NAME, "text");
-        RegionFactory<Object, Object> regionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
-        Region<Object, Object> region = regionFactory.
-            create(REGION_NAME);
+        LuceneQuery<Integer, TestObject> query;
+        query = service.createLuceneQueryFactory().create(INDEX_NAME, regionName, "text:world");
+        LuceneQueryResults<Integer, TestObject> results = query.search();
+        assertEquals(3, results.size());
+        List<LuceneResultStruct<Integer, TestObject>> page = results.getNextPage();
+
+        Map<Integer, TestObject> data = new HashMap<Integer, TestObject>();
+        for (LuceneResultStruct<Integer, TestObject> row : page) {
+          data.put(row.getKey(), row.getValue());
+        }
+
+        assertEquals(data, region);
         return null;
       }
     };
-        
-    server1.invoke(createPartitionRegion);
-    
 
-    SerializableCallable createSomeData = new SerializableCallable("createRegion") {
+    vm.invoke(executeSearch);
+  }
+
+  private void putDataInRegion(VM vm, final String regionName) {
+    SerializableCallable<Object> createSomeData = new SerializableCallable<Object>("putDataInRegion") {
       private static final long serialVersionUID = 1L;
 
       public Object call() throws Exception {
         final Cache cache = getCache();
-        Region<Object, Object> region = cache.getRegion(REGION_NAME);
-        
-        putInRegion(region, 1, new TestObject("hello world"));
-        putInRegion(region, 113, new TestObject("hi world"));
-        putInRegion(region, 2, new TestObject("goodbye world"));
-        
+        Region<Object, Object> region = cache.getRegion(regionName);
+        assertNotNull(region);
+        region.put(1, new TestObject("hello world"));
+        region.put(113, new TestObject("hi world"));
+        region.put(2, new TestObject("goodbye world"));
+
         return null;
       }
     };
 
-    server1.invoke(createSomeData);
-    server2.invoke(createPartitionRegion);
+    vm.invoke(createSomeData);
+  }
 
-    SerializableCallable executeSearch = new SerializableCallable("executeSearch") {
+  private void createPartitionRegionAndIndex(VM vm, final String regionName, final RegionShortcut type) {
+    SerializableCallable<Object> createPartitionRegion = new SerializableCallable<Object>("createRegionAndIndex") {
       private static final long serialVersionUID = 1L;
 
       public Object call() throws Exception {
-        Cache cache = getCache();
+        final Cache cache = getCache();
         assertNotNull(cache);
-        Region<Object, Object> region = cache.getRegion(REGION_NAME);
-        Assert.assertNotNull(region);
-
         LuceneService service = LuceneServiceProvider.get(cache);
-        LuceneQuery<Integer, TestObject> query = service.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME, "text:world");
-        LuceneQueryResults<Integer, TestObject> results = query.search();
-        assertEquals(3, results.size());
-        List<LuceneResultStruct<Integer, TestObject>> page = results.getNextPage();
-        
-        Map<Integer, TestObject> data = new HashMap<Integer, TestObject>();
-        for(LuceneResultStruct<Integer, TestObject> row : page) {
-          data.put(row.getKey(), row.getValue());
+        service.createIndex(INDEX_NAME, regionName, "text");
+        RegionFactory<Object, Object> regionFactory = cache.createRegionFactory(type);
+        if (regionName.contains("OVERFLOW")) {
+          System.out.println("yello");
+          EvictionAttributesImpl evicAttr = new EvictionAttributesImpl().setAction(EvictionAction.OVERFLOW_TO_DISK);
+          evicAttr.setAlgorithm(EvictionAlgorithm.LRU_ENTRY).setMaximum(1);
+          regionFactory.setEvictionAttributes(evicAttr);
         }
-        
-        assertEquals(data, region);
-        
+        regionFactory.create(regionName);
         return null;
       }
     };
+    vm.invoke(createPartitionRegion);
+  }
 
-    //Make sure we can search from both members
-    server1.invoke(executeSearch);
-    server2.invoke(executeSearch);
+  private void destroyRegion(VM vm, final String regionName) {
+    SerializableCallable<Object> createPartitionRegion = new SerializableCallable<Object>("destroyRegion") {
+      private static final long serialVersionUID = 1L;
 
-    //Do a rebalance
-    server1.invoke(new SerializableCallable() {
-      @Override
-      public Object call() throws CancellationException, InterruptedException {
-        RebalanceOperation op = getCache().getResourceManager().createRebalanceFactory().start();
-        RebalanceResults results = op.getResults();
-        assertTrue(1 < results.getTotalBucketTransfersCompleted());
+      public Object call() throws Exception {
+        final Cache cache = getCache();
+        assertNotNull(cache);
+        String aeqId = LuceneServiceImpl.getUniqueIndexName(INDEX_NAME, regionName);
+        PartitionedRegion chunkRegion = (PartitionedRegion) cache.getRegion(aeqId + ".chunks");
+        assertNotNull(chunkRegion);
+        chunkRegion.destroyRegion();
+        PartitionedRegion fileRegion = (PartitionedRegion) cache.getRegion(aeqId + ".files");
+        assertNotNull(fileRegion);
+        fileRegion.destroyRegion();
+        Region<Object, Object> region = cache.getRegion(regionName);
+        assertNotNull(region);
+        region.destroyRegion();
         return null;
       }
-    });
-    
-    //Make sure the search still works
-    server1.invoke(executeSearch);
-    server2.invoke(executeSearch);
-  }
-  
-  private static void putInRegion(Region<Object, Object> region, Object key, Object value) throws BucketNotFoundException, IOException {
-    region.put(key, value);
-    
-    //TODO - the async event queue hasn't been hooked up, so we'll fake out
-    //writing the entry to the repository.
-//    LuceneService service = LuceneServiceProvider.get(region.getCache());
-//    InternalLuceneIndex index = (InternalLuceneIndex) service.getIndex(INDEX_NAME, REGION_NAME);
-//    IndexRepository repository1 = index.getRepositoryManager().getRepository(region, 1, null);
-//    repository1.create(key, value);
-//    repository1.commit();
+    };
+    vm.invoke(createPartitionRegion);
   }
 
   private static class TestObject implements Serializable {
+    private static final long serialVersionUID = 1L;
     private String text;
 
     public TestObject(String text) {
@@ -180,5 +219,4 @@ public class LuceneFunctionReadPathDUnitTest extends CacheTestCase {
       return true;
     }
   }
-
 }