geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [03/19] incubator-geode git commit: GEODE-11: Adding tests of fixed partitions and persistent lucene indexes
Date Wed, 18 May 2016 17:04:43 GMT
GEODE-11: Adding tests of fixed partitions and persistent lucene indexes

In addition to the tests, I fixed some code to properly propagate the
disk synchronous flag to the index.


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

Branch: refs/heads/feature/GEODE-1392
Commit: 3490f37a01d75b92ca36bbe2aaae1e31a763021b
Parents: 67d5e8d
Author: Dan Smith <upthewaterspout@apache.org>
Authored: Thu May 12 15:36:38 2016 -0700
Committer: Kirk Lund <klund@apache.org>
Committed: Wed May 18 10:04:22 2016 -0700

----------------------------------------------------------------------
 .../com/gemstone/gemfire/test/fake/Fakes.java   |  19 +++
 .../gemfire/test/junit/rules/DiskDirRule.java   |  54 ++++++++
 .../test/junit/rules/DiskDirRuleTest.java       |  49 +++++++
 .../LuceneIndexForPartitionedRegion.java        |  28 ++--
 .../lucene/internal/LuceneQueryFactoryImpl.java |   3 +
 .../internal/PartitionedRepositoryManager.java  |   1 +
 .../LuceneIndexCreationIntegrationTest.java     | 131 +++++++++++++++++--
 .../cache/lucene/LuceneIntegrationTest.java     |  14 +-
 .../LuceneIndexForPartitionedRegionTest.java    |  58 ++++----
 .../LuceneQueryFactoryImplJUnitTest.java        |  21 ++-
 10 files changed, 312 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3490f37a/geode-core/src/test/java/com/gemstone/gemfire/test/fake/Fakes.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/fake/Fakes.java b/geode-core/src/test/java/com/gemstone/gemfire/test/fake/Fakes.java
index 99644b7..2a1fd8e 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/fake/Fakes.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/fake/Fakes.java
@@ -23,6 +23,10 @@ import java.net.UnknownHostException;
 import org.junit.Assert;
 
 import com.gemstone.gemfire.CancelCriterion;
+import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.DataPolicy;
+import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.RegionAttributes;
 import com.gemstone.gemfire.distributed.internal.DSClock;
 import com.gemstone.gemfire.distributed.internal.DistributionConfig;
 import com.gemstone.gemfire.distributed.internal.DistributionManager;
@@ -96,6 +100,21 @@ public class Fakes {
     return cache().getDistributedSystem();
   }
 
+  /**
+   * A fake region, which contains a fake cache and some other
+   * fake attributes
+   */
+  public static Region region(String name, Cache cache) {
+    Region region = mock(Region.class);
+    RegionAttributes attributes = mock(RegionAttributes.class);
+    DataPolicy policy = mock(DataPolicy.class);
+    when(region.getAttributes()).thenReturn(attributes);
+    when(attributes.getDataPolicy()).thenReturn(policy);
+    when(region.getCache()).thenReturn(cache);
+    when(region.getRegionService()).thenReturn(cache);
+    return region;
+  }
+
   private Fakes() {
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3490f37a/geode-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/DiskDirRule.java
----------------------------------------------------------------------
diff --git a/geode-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/DiskDirRule.java
b/geode-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/DiskDirRule.java
new file mode 100644
index 0000000..184619f
--- /dev/null
+++ b/geode-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/DiskDirRule.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.test.junit.rules;
+
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+
+import org.junit.rules.ExternalResource;
+
+public class DiskDirRule extends ExternalResource {
+  private File diskDir;
+
+  @Override protected void before() throws Throwable {
+    diskDir = new File(".", "DiskDirRule-" + System.nanoTime());
+  }
+
+  @Override protected void after() {
+    try {
+      Files.walk(diskDir.toPath()).forEach((path) -> {
+        try {
+          Files.delete(path);
+        }
+        catch (IOException e) {
+          //Ignore
+        }
+      });
+    } catch(IOException e) {
+      throw new RuntimeException("Could not delete disk dir: " + diskDir, e);
+    }
+    diskDir.delete();
+  }
+
+  public File get() {
+    diskDir.mkdirs();
+    return diskDir;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3490f37a/geode-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/DiskDirRuleTest.java
----------------------------------------------------------------------
diff --git a/geode-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/DiskDirRuleTest.java
b/geode-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/DiskDirRuleTest.java
new file mode 100644
index 0000000..8c322a4
--- /dev/null
+++ b/geode-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/DiskDirRuleTest.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.test.junit.rules;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.Arrays;
+
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(UnitTest.class)
+public class DiskDirRuleTest {
+  @Test
+  public void shouldDeleteDirInAfter() throws Throwable {
+    DiskDirRule diskDirRule = new DiskDirRule();
+    diskDirRule.before();
+    final File dir = diskDirRule.get();
+    assertTrue(dir.exists());
+    final File file1 = new File(dir, "file1");
+    final File subdir = new File(dir, "subdir");
+    final File file2 = new File(dir, "file2");
+    subdir.mkdir();
+    Files.write(file1.toPath(), Arrays.asList("abc"));
+    Files.write(file2.toPath(), Arrays.asList("stuff"));
+    diskDirRule.after();
+    assertFalse(dir.exists());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3490f37a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
index dd9d384..d22ca4a 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
@@ -29,7 +29,6 @@ import com.gemstone.gemfire.cache.RegionAttributes;
 import com.gemstone.gemfire.cache.RegionShortcut;
 import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue;
 import com.gemstone.gemfire.cache.asyncqueue.internal.AsyncEventQueueFactoryImpl;
-import com.gemstone.gemfire.cache.asyncqueue.internal.AsyncEventQueueImpl;
 import com.gemstone.gemfire.cache.lucene.internal.filesystem.ChunkKey;
 import com.gemstone.gemfire.cache.lucene.internal.filesystem.File;
 import com.gemstone.gemfire.cache.lucene.internal.repository.serializer.HeterogeneousLuceneSerializer;
@@ -88,46 +87,37 @@ public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
       repositoryManager = new PartitionedRepositoryManager(dataRegion, (PartitionedRegion)fileRegion,
(PartitionedRegion)chunkRegion, mapper, analyzer);
       
       // create AEQ, AEQ listener and specify the listener to repositoryManager
-      if (withPersistence) {
-        createAEQWithPersistence();
-      }
-      else {
-        createAEQ();
-      }
+      createAEQ(dataRegion);
 
       addExtension(dataRegion);
       hasInitialized = true;
     }
   }
 
-  private AsyncEventQueueFactoryImpl createAEQFactory() {
+  private AsyncEventQueueFactoryImpl createAEQFactory(final Region dataRegion) {
     AsyncEventQueueFactoryImpl factory = (AsyncEventQueueFactoryImpl) cache.createAsyncEventQueueFactory();
     factory.setParallel(true); // parallel AEQ for PR
     factory.setMaximumQueueMemory(1000);
     factory.setDispatcherThreads(1);
     factory.setIsMetaQueue(true);
+    if(dataRegion.getAttributes().getDataPolicy().withPersistence()) {
+      factory.setPersistent(true);
+    }
+    factory.setDiskSynchronous(dataRegion.getAttributes().isDiskSynchronous());
     return factory;
   }
 
-  AsyncEventQueue createAEQWithPersistence() {
-    AsyncEventQueueFactoryImpl factory = createAEQFactory();
-    factory.setPersistent(true);
-    return createAEQ(factory);
-  }
-
-  AsyncEventQueue createAEQ() {
-    return createAEQ(createAEQFactory());
+  AsyncEventQueue createAEQ(Region dataRegion) {
+    return createAEQ(createAEQFactory(dataRegion));
   }
 
   private AsyncEventQueue createAEQ(AsyncEventQueueFactoryImpl factory) {
     LuceneEventListener listener = new LuceneEventListener(repositoryManager);
     String aeqId = LuceneServiceImpl.getUniqueIndexName(getName(), regionPath);
-    AsyncEventQueueImpl aeq = (AsyncEventQueueImpl)cache.getAsyncEventQueue(aeqId);
     AsyncEventQueue indexQueue = factory.create(aeqId, listener);
     return indexQueue;
   }
 
-
   boolean fileRegionExists(String fileRegionName) {
     return cache.<String, File> getRegion(fileRegionName) != null;
   }
@@ -156,7 +146,7 @@ public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
     return LuceneServiceImpl.getUniqueIndexName(indexName, regionPath) + ".chunks";
   }
 
-  private PartitionAttributesFactory configureLuceneRegionAttributesFactory(PartitionAttributesFactory
attributesFactory, PartitionAttributes dataRegionAttributes) {
+  private PartitionAttributesFactory configureLuceneRegionAttributesFactory(PartitionAttributesFactory
attributesFactory, PartitionAttributes<?,?> dataRegionAttributes) {
     attributesFactory.setTotalNumBuckets(dataRegionAttributes.getTotalNumBuckets());
     attributesFactory.setRedundantCopies(dataRegionAttributes.getRedundantCopies());
     return attributesFactory;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3490f37a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImpl.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImpl.java
b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImpl.java
index c6087ea..385b226 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImpl.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImpl.java
@@ -54,6 +54,9 @@ public class LuceneQueryFactoryImpl implements LuceneQueryFactory {
   
   public <K, V> LuceneQuery<K, V> create(String indexName, String regionName,
LuceneQueryProvider provider) {
     Region<K, V> region = cache.getRegion(regionName);
+    if(region == null) {
+      throw new IllegalArgumentException("Region not found: " + regionName);
+    }
     LuceneQueryImpl<K, V> luceneQuery = new LuceneQueryImpl<K, V>(indexName,
region, provider, projectionFields, limit, pageSize);
     return luceneQuery;
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3490f37a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/PartitionedRepositoryManager.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/PartitionedRepositoryManager.java
b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/PartitionedRepositoryManager.java
index 07050e2..57b8862 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/PartitionedRepositoryManager.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/PartitionedRepositoryManager.java
@@ -27,6 +27,7 @@ import java.util.Set;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.IndexWriterConfig.OpenMode;
 
 import com.gemstone.gemfire.InternalGemFireError;
 import com.gemstone.gemfire.cache.Region;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3490f37a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationIntegrationTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationIntegrationTest.java
index 2d16e32..6429143 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationIntegrationTest.java
@@ -29,23 +29,26 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Consumer;
-import java.util.function.Function;
 
 import com.gemstone.gemfire.cache.EvictionAttributes;
 import com.gemstone.gemfire.cache.ExpirationAttributes;
+import com.gemstone.gemfire.cache.FixedPartitionAttributes;
+import com.gemstone.gemfire.cache.PartitionAttributesFactory;
 import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.RegionShortcut;
-import com.gemstone.gemfire.cache.lucene.LuceneIndex;
-import com.gemstone.gemfire.cache.lucene.LuceneIntegrationTest;
-import com.gemstone.gemfire.cache.lucene.LuceneServiceProvider;
+import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue;
+import com.gemstone.gemfire.cache.asyncqueue.internal.AsyncEventQueueImpl;
 import com.gemstone.gemfire.cache.lucene.internal.LuceneIndexForPartitionedRegion;
+import com.gemstone.gemfire.cache.lucene.internal.LuceneServiceImpl;
 import com.gemstone.gemfire.internal.cache.BucketNotFoundException;
 import com.gemstone.gemfire.internal.cache.LocalRegion;
+import com.gemstone.gemfire.internal.cache.PartitionedRegion;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
 import com.jayway.awaitility.Awaitility;
 
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.core.KeywordTokenizer;
+import org.apache.lucene.queryparser.classic.ParseException;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
@@ -122,6 +125,18 @@ public class LuceneIndexCreationIntegrationTest extends LuceneIntegrationTest
{
   }
 
   @Test
+  public void shouldNotUseOffHeapForInternalRegionsWhenUserRegionHasOffHeap() {
+    createIndex("text");
+    cache.createRegionFactory(RegionShortcut.PARTITION)
+      .setOffHeap(true)
+      .create(REGION_NAME);
+
+    verifyInternalRegions(region -> {
+      assertEquals(false, region.getOffHeap());
+    });
+  }
+
+  @Test
   public void shouldNotUseOverflowForInternalRegionsWhenUserRegionHasOverflow() {
     createIndex("text");
     cache.createRegionFactory(RegionShortcut.PARTITION_OVERFLOW).create(REGION_NAME);
@@ -131,18 +146,112 @@ public class LuceneIndexCreationIntegrationTest extends LuceneIntegrationTest
{
   }
 
   @Test
-  public void shouldCreateInternalRegionsForIndex() {
+  public void shouldUseDiskSynchronousWhenUserRegionHasDiskSynchronous() {
+    createIndex("text");
+    cache.createRegionFactory(RegionShortcut.PARTITION_PERSISTENT)
+      .setDiskSynchronous(true)
+      .create(REGION_NAME);
+    verifyInternalRegions(region -> {
+      assertTrue(region.getDataPolicy().withPersistence());
+      assertTrue(region.isDiskSynchronous());
+    });
+    AsyncEventQueue queue = getIndexQueue();
+    assertEquals(true, queue.isDiskSynchronous());
+    assertEquals(true, queue.isPersistent());
+  }
+
+  @Test
+  public void shouldUseDiskSyncFalseOnQueueWhenUserRegionHasDiskSynchronousFalse() {
     createIndex("text");
+    cache.createRegionFactory(RegionShortcut.PARTITION_PERSISTENT)
+      .setDiskSynchronous(false)
+      .create(REGION_NAME);
+    verifyInternalRegions(region -> {
+      assertTrue(region.getDataPolicy().withPersistence());
+      assertTrue(region.isDiskSynchronous());
+    });
+    AsyncEventQueue queue = getIndexQueue();
+    assertEquals(false, queue.isDiskSynchronous());
+    assertEquals(true, queue.isPersistent());
+  }
+
+  @Test
+  public void shouldRecoverPersistentIndexWhenDataStillInQueue() throws ParseException, InterruptedException
{
+    createIndex("field1", "field2");
+    Region dataRegion = cache.createRegionFactory(RegionShortcut.PARTITION_PERSISTENT)
+      .create(REGION_NAME);
+    //Pause the sender so that the entry stays in the queue
+    final AsyncEventQueueImpl queue = (AsyncEventQueueImpl) getIndexQueue();
+    queue.getSender().pause();
+
+    dataRegion.put("A", new TestObject());
+    cache.close();
+    createCache();
+    createIndex("field1", "field2");
+    dataRegion = cache.createRegionFactory(RegionShortcut.PARTITION_PERSISTENT)
+      .create(REGION_NAME);
+    LuceneQuery<Object, Object> query = luceneService.createLuceneQueryFactory()
+      .create(INDEX_NAME, REGION_NAME,
+        "field1:world");
+    Awaitility.await().atMost(60, TimeUnit.SECONDS).until(() -> {
+      assertEquals(1, query.search().size());
+    });
+  }
+
+  @Test
+  public void shouldRecoverPersistentIndexWhenDataIsWrittenToIndex() throws ParseException,
InterruptedException {
+    createIndex("field1", "field2");
+    Region dataRegion = cache.createRegionFactory(RegionShortcut.PARTITION_PERSISTENT)
+      .create(REGION_NAME);
+    dataRegion.put("A", new TestObject());
+    final AsyncEventQueueImpl queue = (AsyncEventQueueImpl) getIndexQueue();
+
+    //Wait until the queue has drained
+    Awaitility.await().atMost(60, TimeUnit.SECONDS).until(() -> assertEquals(0, queue.size()));
+    cache.close();
+    createCache();
+    createIndex("text");
+    dataRegion = cache.createRegionFactory(RegionShortcut.PARTITION_PERSISTENT)
+      .create(REGION_NAME);
+    LuceneQuery<Object, Object> query = luceneService.createLuceneQueryFactory()
+      .create(INDEX_NAME, REGION_NAME,
+      "field1:world");
+    assertEquals(1, query.search().size());
+  }
+
+  @Test
+  public void shouldCreateInternalRegionsForIndex() {
+    createIndex("field1", "field2");
 
     // Create partitioned region
     createRegion();
 
     verifyInternalRegions(region -> {
       region.isInternalRegion();
+      assertNotNull(region.getAttributes().getPartitionAttributes().getColocatedWith());
       cache.rootRegions().contains(region);
     });
   }
 
+  @Test
+  public void shouldUseFixedPartitionsForInternalRegions() {
+    createIndex("text");
+
+    PartitionAttributesFactory partitionAttributesFactory = new PartitionAttributesFactory<>();
+    final FixedPartitionAttributes fixedAttributes = FixedPartitionAttributes.createFixedPartition("A",
true, 1);
+    partitionAttributesFactory.addFixedPartitionAttributes(fixedAttributes);
+    cache.createRegionFactory(RegionShortcut.PARTITION)
+      .setPartitionAttributes(partitionAttributesFactory.create())
+      .create(REGION_NAME);
+
+    verifyInternalRegions(region -> {
+      //Fixed partitioned regions don't allow you to specify the partitions on the colocated
region
+      assertNull(region.getAttributes().getPartitionAttributes().getFixedPartitionAttributes());
+      assertTrue(((PartitionedRegion) region).isFixedPartitionedRegion());
+    });
+  }
+
+
   private void verifyInternalRegions(Consumer<LocalRegion> verify) {
     // Get index
     LuceneIndexForPartitionedRegion index = (LuceneIndexForPartitionedRegion) luceneService.getIndex(INDEX_NAME,
REGION_NAME);
@@ -152,21 +261,25 @@ public class LuceneIndexCreationIntegrationTest extends LuceneIntegrationTest
{
     LocalRegion fileRegion = (LocalRegion) cache.getRegion(index.createFileRegionName());
     verify.accept(chunkRegion);
     verify.accept(fileRegion);
+  }
 
+  private AsyncEventQueue getIndexQueue() {
+    String aeqId = LuceneServiceImpl.getUniqueIndexName(INDEX_NAME, REGION_NAME);
+    return cache.getAsyncEventQueue(aeqId);
   }
 
   private Region createRegion() {
     return this.cache.createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
   }
 
-  private void createIndex(String fieldName) {
-    LuceneServiceProvider.get(this.cache).createIndex(INDEX_NAME, REGION_NAME, fieldName);
+  private void createIndex(String ... fieldNames) {
+    LuceneServiceProvider.get(this.cache).createIndex(INDEX_NAME, REGION_NAME, fieldNames);
   }
 
   private static class TestObject implements Serializable {
 
-    String field1 = "a b c d";
-    String field2 = "f g h";
+    String field1 = "hello world";
+    String field2 = "this is a field";
   }
 
   private static class RecordingAnalyzer extends Analyzer {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3490f37a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIntegrationTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIntegrationTest.java
index 8c6f59e..67775d2 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIntegrationTest.java
@@ -19,10 +19,15 @@
 
 package com.gemstone.gemfire.cache.lucene;
 
+import java.io.File;
+
 import com.gemstone.gemfire.cache.Cache;
 import com.gemstone.gemfire.cache.CacheFactory;
 import com.gemstone.gemfire.cache.lucene.LuceneService;
 import com.gemstone.gemfire.cache.lucene.LuceneServiceProvider;
+import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
+import com.gemstone.gemfire.internal.offheap.MemoryAllocatorImpl;
+import com.gemstone.gemfire.test.junit.rules.DiskDirRule;
 
 import org.junit.After;
 import org.junit.Before;
@@ -33,15 +38,15 @@ public class LuceneIntegrationTest {
 
   protected Cache cache;
   protected LuceneService luceneService;
-
   @Rule
-  public TestName name = new TestName();
+  public DiskDirRule diskDirRule = new DiskDirRule();
 
   @After
   public void tearDown() {
     if(this.cache != null) {
       this.cache.close();
     }
+    MemoryAllocatorImpl.freeOffHeapMemory();
   }
 
   @Before
@@ -49,7 +54,12 @@ public class LuceneIntegrationTest {
     CacheFactory cf = new CacheFactory();
     cf.set("mcast-port", "0");
     cf.set("locators", "");
+    cf.set("off-heap-memory-size", "100m");
     this.cache = cf.create();
+    cache.createDiskStoreFactory()
+      .setDiskDirs(new File[] {diskDirRule.get()})
+      .setMaxOplogSize(1)
+      .create(GemFireCacheImpl.getDefaultDiskStoreName());
     luceneService = LuceneServiceProvider.get(this.cache);
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3490f37a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegionTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegionTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegionTest.java
index 984b221..e35de5e 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegionTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegionTest.java
@@ -32,6 +32,7 @@ import com.gemstone.gemfire.cache.DataPolicy;
 import com.gemstone.gemfire.cache.ExpirationAttributes;
 import com.gemstone.gemfire.cache.MembershipAttributes;
 import com.gemstone.gemfire.cache.PartitionAttributes;
+import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.RegionAttributes;
 import com.gemstone.gemfire.cache.RegionShortcut;
 import com.gemstone.gemfire.cache.asyncqueue.internal.AsyncEventQueueFactoryImpl;
@@ -120,12 +121,16 @@ public class LuceneIndexForPartitionedRegionTest {
     String name = "indexName";
     String regionPath = "regionName";
     Cache cache = Fakes.cache();
+    final Region region =Fakes.region(regionPath, cache);
+    RegionAttributes attributes  = region.getAttributes();
+    when(attributes.getDataPolicy()).thenReturn(DataPolicy.PERSISTENT_PARTITION);
     AsyncEventQueueFactoryImpl aeqFactory = mock(AsyncEventQueueFactoryImpl.class);
     when(cache.createAsyncEventQueueFactory()).thenReturn(aeqFactory);
 
     LuceneIndexForPartitionedRegion index = new LuceneIndexForPartitionedRegion(name, regionPath,
cache);
-    index.createAEQWithPersistence();
+    index.createAEQ(region);
 
+    verify(aeqFactory).setPersistent(eq(true));
     verify(aeqFactory).create(any(), any());
   }
 
@@ -134,21 +139,23 @@ public class LuceneIndexForPartitionedRegionTest {
     String name = "indexName";
     String regionPath = "regionName";
     Cache cache = Fakes.cache();
+    final Region region =Fakes.region(regionPath, cache);
     AsyncEventQueueFactoryImpl aeqFactory = mock(AsyncEventQueueFactoryImpl.class);
     when(cache.createAsyncEventQueueFactory()).thenReturn(aeqFactory);
 
     LuceneIndexForPartitionedRegion index = new LuceneIndexForPartitionedRegion(name, regionPath,
cache);
-    index.createAEQ();
+    index.createAEQ(region);
 
+    verify(aeqFactory, never()).setPersistent(eq(true));
     verify(aeqFactory).create(any(), any());
   }
 
-  private void initializeScenario(final boolean withPersistence, final String regionPath,
final Cache cache) {
+  private Region initializeScenario(final boolean withPersistence, final String regionPath,
final Cache cache) {
     int defaultLocalMemory = 100;
-    initializeScenario(withPersistence, regionPath, cache, defaultLocalMemory);
+    return initializeScenario(withPersistence, regionPath, cache, defaultLocalMemory);
   }
 
-  private void initializeScenario(final boolean withPersistence, final String regionPath,
final Cache cache, int localMaxMemory) {
+  private Region initializeScenario(final boolean withPersistence, final String regionPath,
final Cache cache, int localMaxMemory) {
     PartitionedRegion region = mock(PartitionedRegion.class);
     RegionAttributes regionAttributes = mock(RegionAttributes.class);
     PartitionAttributes partitionAttributes = mock(PartitionAttributes.class);
@@ -162,6 +169,8 @@ public class LuceneIndexForPartitionedRegionTest {
     when(partitionAttributes.getTotalNumBuckets()).thenReturn(113);
     when(dataPolicy.withPersistence()).thenReturn(withPersistence);
     when(region.getExtensionPoint()).thenReturn(extensionPoint);
+
+    return region;
   }
 
   private PartitionAttributes initializeAttributes(final Cache cache) {
@@ -192,41 +201,22 @@ public class LuceneIndexForPartitionedRegionTest {
   }
 
   @Test
-  public void initializeWithPersistenceShouldCreateAEQWithPersistence() {
-    boolean withPersistence = true;
-    String name = "indexName";
-    String regionPath = "regionName";
-    Cache cache = Fakes.cache();
-    initializeScenario(withPersistence, regionPath, cache);
-
-    LuceneIndexForPartitionedRegion index = new LuceneIndexForPartitionedRegion(name, regionPath,
cache);
-    index.setSearchableFields(new String[]{"field"});
-    LuceneIndexForPartitionedRegion spy = spy(index);
-    doReturn(null).when(spy).createFileRegion(any(), any(), any());
-    doReturn(null).when(spy).createChunkRegion(any(), any(), any(), any());
-    doReturn(null).when(spy).createAEQWithPersistence();
-    spy.initialize();
-
-    verify(spy).createAEQWithPersistence();
-  }
-
-  @Test
   public void initializeWithoutPersistenceShouldCreateAEQ() {
     boolean withPersistence = false;
     String name = "indexName";
     String regionPath = "regionName";
     Cache cache = Fakes.cache();
-    initializeScenario(withPersistence, regionPath, cache);
+    Region region = initializeScenario(withPersistence, regionPath, cache);
 
     LuceneIndexForPartitionedRegion index = new LuceneIndexForPartitionedRegion(name, regionPath,
cache);
     index.setSearchableFields(new String[]{"field"});
     LuceneIndexForPartitionedRegion spy = spy(index);
     doReturn(null).when(spy).createFileRegion(any(), any(), any());
     doReturn(null).when(spy).createChunkRegion(any(), any(), any(), any());
-    doReturn(null).when(spy).createAEQ();
+    doReturn(null).when(spy).createAEQ(eq(region));
     spy.initialize();
 
-    verify(spy).createAEQ();
+    verify(spy).createAEQ(eq(region));
   }
 
   @Test
@@ -235,14 +225,14 @@ public class LuceneIndexForPartitionedRegionTest {
     String name = "indexName";
     String regionPath = "regionName";
     Cache cache = Fakes.cache();
-    initializeScenario(withPersistence, regionPath, cache);
+    Region region = initializeScenario(withPersistence, regionPath, cache);
 
     LuceneIndexForPartitionedRegion index = new LuceneIndexForPartitionedRegion(name, regionPath,
cache);
     index.setSearchableFields(new String[]{"field"});
     LuceneIndexForPartitionedRegion spy = spy(index);
     doReturn(null).when(spy).createFileRegion(any(), any(), any());
     doReturn(null).when(spy).createChunkRegion(any(), any(), any(), any());
-    doReturn(null).when(spy).createAEQ();
+    doReturn(null).when(spy).createAEQ(eq(region));
     spy.initialize();
 
     verify(spy).createChunkRegion(eq(RegionShortcut.PARTITION), eq(index.createFileRegionName()),
any(), eq(index.createChunkRegionName()));
@@ -254,14 +244,14 @@ public class LuceneIndexForPartitionedRegionTest {
     String name = "indexName";
     String regionPath = "regionName";
     Cache cache = Fakes.cache();
-    initializeScenario(withPersistence, regionPath, cache);
+    Region region = initializeScenario(withPersistence, regionPath, cache);
 
     LuceneIndexForPartitionedRegion index = new LuceneIndexForPartitionedRegion(name, regionPath,
cache);
     index.setSearchableFields(new String[]{"field"});
     LuceneIndexForPartitionedRegion spy = spy(index);
     doReturn(null).when(spy).createFileRegion(any(), any(), any());
     doReturn(null).when(spy).createChunkRegion(any(), any(), any(), any());
-    doReturn(null).when(spy).createAEQ();
+    doReturn(null).when(spy).createAEQ(eq(region));
     spy.initialize();
 
     verify(spy).createFileRegion(eq(RegionShortcut.PARTITION), eq(index.createFileRegionName()),
any());
@@ -309,7 +299,7 @@ public class LuceneIndexForPartitionedRegionTest {
     LuceneIndexForPartitionedRegion spy = spy(index);
     doReturn(null).when(spy).createFileRegion(any(), any(), any());
     doReturn(null).when(spy).createChunkRegion(any(), any(), any(), any());
-    doReturn(null).when(spy).createAEQWithPersistence();
+    doReturn(null).when(spy).createAEQ(any());
     spy.initialize();
 
     verify(spy).createChunkRegion(eq(RegionShortcut.PARTITION_PERSISTENT), eq(index.createFileRegionName()),
any(), eq(index.createChunkRegionName()));
@@ -328,7 +318,7 @@ public class LuceneIndexForPartitionedRegionTest {
     LuceneIndexForPartitionedRegion spy = spy(index);
     doReturn(null).when(spy).createFileRegion(any(), any(), any());
     doReturn(null).when(spy).createChunkRegion(any(), any(), any(), any());
-    doReturn(null).when(spy).createAEQWithPersistence();
+    doReturn(null).when(spy).createAEQ(any());
     spy.initialize();
 
     verify(spy).createFileRegion(eq(RegionShortcut.PARTITION_PERSISTENT), eq(index.createFileRegionName()),
any());
@@ -347,7 +337,7 @@ public class LuceneIndexForPartitionedRegionTest {
     LuceneIndexForPartitionedRegion spy = spy(index);
     doReturn(null).when(spy).createFileRegion(any(), any(), any());
     doReturn(null).when(spy).createChunkRegion(any(), any(), any(), any());
-    doReturn(null).when(spy).createAEQWithPersistence();
+    doReturn(null).when(spy).createAEQ(any());
     spy.initialize();
     spy.initialize();
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3490f37a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImplJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImplJUnitTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImplJUnitTest.java
index 0614e62..975b92f 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImplJUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImplJUnitTest.java
@@ -19,21 +19,30 @@
 package com.gemstone.gemfire.cache.lucene.internal;
 
 import static org.junit.Assert.*;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.*;
 
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
 import org.mockito.Mockito;
 
 import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.lucene.LuceneQuery;
 import com.gemstone.gemfire.test.junit.categories.UnitTest;
 
 @Category(UnitTest.class)
 public class LuceneQueryFactoryImplJUnitTest {
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
 
   @Test
-  public void test() {
-    Cache cache = Mockito.mock(Cache.class);
+  public void shouldCreateQueryWithCorrectAttributes() {
+    Cache cache = mock(Cache.class);
+    Region region = mock(Region.class);
+    when(cache.getRegion(any())).thenReturn(region);
     LuceneQueryFactoryImpl f = new LuceneQueryFactoryImpl(cache);
     f.setPageSize(5);
     f.setResultLimit(25);
@@ -47,4 +56,12 @@ public class LuceneQueryFactoryImplJUnitTest {
     Mockito.verify(cache).getRegion(Mockito.eq("region"));
   }
 
+  @Test
+  public void shouldThrowIllegalArgumentWhenRegionIsMissing() {
+    Cache cache = mock(Cache.class);
+    LuceneQueryFactoryImpl f = new LuceneQueryFactoryImpl(cache);
+    thrown.expect(IllegalArgumentException.class);
+    LuceneQuery<Object, Object> query = f.create("index", "region", new StringQueryProvider("test"));
+  }
+
 }


Mime
View raw message