You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kh...@apache.org on 2017/03/17 20:11:20 UTC
[45/49] geode git commit: GEODE-2639: Added DUnit tests for
expiration on Lucene
GEODE-2639: Added DUnit tests for expiration on Lucene
* Tests added to validate the effect of the expiration of Lucene Index entries.
* Once the entries expire, the lucene index entries must be updated.
This closes #422
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/5be70038
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/5be70038
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/5be70038
Branch: refs/heads/feature/GEODE-2420
Commit: 5be700386bd5f1483868f0a821c58d9642743699
Parents: 16bf532
Author: nabarun <nn...@pivotal.io>
Authored: Fri Mar 10 11:00:09 2017 -0800
Committer: Ken Howe <kh...@pivotal.io>
Committed: Fri Mar 17 13:09:45 2017 -0700
----------------------------------------------------------------------
.../geode/cache/lucene/ExpirationDUnitTest.java | 89 ++++++++++++++++++++
.../geode/cache/lucene/LuceneDUnitTest.java | 34 ++++++--
2 files changed, 116 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/5be70038/geode-lucene/src/test/java/org/apache/geode/cache/lucene/ExpirationDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/ExpirationDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/ExpirationDUnitTest.java
new file mode 100644
index 0000000..92c7370
--- /dev/null
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/ExpirationDUnitTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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 org.apache.geode.cache.lucene;
+
+import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.INDEX_NAME;
+import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.REGION_NAME;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.test.dunit.SerializableRunnableIF;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.awaitility.Awaitility;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
+import junitparams.JUnitParamsRunner;
+import junitparams.Parameters;
+
+@Category(DistributedTest.class)
+@RunWith(JUnitParamsRunner.class)
+public class ExpirationDUnitTest extends LuceneQueriesAccessorBase {
+
+ protected final static int EXTRA_WAIT_TIME_SEC = 15;
+
+ protected RegionTestableType[] getPartitionRegionsWithExpirationSet() {
+ return new RegionTestableType[] {RegionTestableType.PARTITION_WITH_EXPIRATION_DESTROY,
+ RegionTestableType.PARTITION_REDUNDANT_WITH_EXPIRATION_DESTROY,
+ RegionTestableType.PARTITION_REDUNDANT_PERSISTENT_WITH_EXPIRATION_DESTROY};
+ }
+
+ @Test
+ @Parameters(method = "getPartitionRegionsWithExpirationSet")
+ public void regionWithExpirationSetMustAlsoRemoveLuceneIndexEntries(
+ RegionTestableType regionTestType) {
+ SerializableRunnableIF createIndex = () -> {
+ LuceneService luceneService = LuceneServiceProvider.get(getCache());
+ luceneService.createIndexFactory().setFields("text").create(INDEX_NAME, REGION_NAME);
+ };
+
+ dataStore1.invoke(() -> initDataStore(createIndex, regionTestType));
+ dataStore2.invoke(() -> initDataStore(createIndex, regionTestType));
+ accessor.invoke(() -> initDataStore(createIndex, regionTestType));
+
+ accessor.invoke(() -> {
+ Cache cache = getCache();
+ Region region = cache.getRegion(REGION_NAME);
+ IntStream.range(0, NUM_BUCKETS).forEach(i -> region.put(i, new TestObject("hello world")));
+ });
+
+ assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
+
+ accessor.invoke(() -> Awaitility.await()
+ .atMost(EXPIRATION_TIMEOUT_SEC + EXTRA_WAIT_TIME_SEC, TimeUnit.SECONDS).until(() -> {
+ LuceneService luceneService = LuceneServiceProvider.get(getCache());
+ LuceneQuery<Integer, TestObject> luceneQuery = luceneService.createLuceneQueryFactory()
+ .setResultLimit(100).create(INDEX_NAME, REGION_NAME, "world", "text");
+
+ Collection luceneResultList = null;
+ try {
+ luceneResultList = luceneQuery.findKeys();
+ } catch (LuceneQueryException e) {
+ e.printStackTrace();
+ fail();
+ }
+ assertEquals(0, luceneResultList.size());
+ }));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/5be70038/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneDUnitTest.java
index fa3c470..b80f5de 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneDUnitTest.java
@@ -17,6 +17,8 @@ package org.apache.geode.cache.lucene;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.EvictionAction;
import org.apache.geode.cache.EvictionAttributes;
+import org.apache.geode.cache.ExpirationAction;
+import org.apache.geode.cache.ExpirationAttributes;
import org.apache.geode.cache.PartitionAttributes;
import org.apache.geode.cache.PartitionAttributesFactory;
import org.apache.geode.cache.Region;
@@ -37,6 +39,7 @@ public abstract class LuceneDUnitTest extends JUnit4CacheTestCase {
protected static int NUM_BUCKETS = 10;
protected static int MAX_ENTRIES_FOR_EVICTION = 20;
+ protected static int EXPIRATION_TIMEOUT_SEC = 5;
@Override
public void postSetUp() throws Exception {
@@ -98,12 +101,16 @@ public abstract class LuceneDUnitTest extends JUnit4CacheTestCase {
EvictionAction.LOCAL_DESTROY)),
PARTITION_PERSISTENT_EVICTION_LOCAL_DESTROY(RegionShortcut.PARTITION_PROXY,
RegionShortcut.PARTITION_PERSISTENT, EvictionAttributes
- .createLRUEntryAttributes(MAX_ENTRIES_FOR_EVICTION, EvictionAction.LOCAL_DESTROY))
-
-
- ;
-
-
+ .createLRUEntryAttributes(MAX_ENTRIES_FOR_EVICTION, EvictionAction.LOCAL_DESTROY)),
+ PARTITION_REDUNDANT_WITH_EXPIRATION_DESTROY(RegionShortcut.PARTITION_PROXY_REDUNDANT,
+ RegionShortcut.PARTITION_REDUNDANT, EXPIRATION_TIMEOUT_SEC, ExpirationAction.DESTROY),
+ PARTITION_WITH_EXPIRATION_DESTROY(RegionShortcut.PARTITION_PROXY, RegionShortcut.PARTITION,
+ EXPIRATION_TIMEOUT_SEC, ExpirationAction.DESTROY),
+ PARTITION_REDUNDANT_PERSISTENT_WITH_EXPIRATION_DESTROY(RegionShortcut.PARTITION_PROXY_REDUNDANT,
+ RegionShortcut.PARTITION_REDUNDANT_PERSISTENT, EXPIRATION_TIMEOUT_SEC,
+ ExpirationAction.DESTROY);
+
+ ExpirationAttributes expirationAttributes = null;
EvictionAttributes evictionAttributes = null;
private RegionShortcut serverRegionShortcut;
private RegionShortcut clientRegionShortcut;
@@ -117,6 +124,15 @@ public abstract class LuceneDUnitTest extends JUnit4CacheTestCase {
this.clientRegionShortcut = clientRegionShortcut;
this.serverRegionShortcut = serverRegionShortcut;
this.evictionAttributes = evictionAttributes;
+ this.expirationAttributes = null;
+ }
+
+ RegionTestableType(RegionShortcut clientRegionShortcut, RegionShortcut serverRegionShortcut,
+ int timeout, ExpirationAction expirationAction) {
+ this.clientRegionShortcut = clientRegionShortcut;
+ this.serverRegionShortcut = serverRegionShortcut;
+ this.evictionAttributes = null;
+ this.expirationAttributes = new ExpirationAttributes(timeout, expirationAction);
}
public Region createDataStore(Cache cache, String regionName) {
@@ -128,7 +144,11 @@ public abstract class LuceneDUnitTest extends JUnit4CacheTestCase {
return null;
}
}
- if (evictionAttributes == null) {
+ if (expirationAttributes != null) {
+ return cache.createRegionFactory(serverRegionShortcut)
+ .setEntryTimeToLive(expirationAttributes)
+ .setPartitionAttributes(getPartitionAttributes(false)).create(regionName);
+ } else if (evictionAttributes == null) {
return cache.createRegionFactory(serverRegionShortcut)
.setPartitionAttributes(getPartitionAttributes(false)).create(regionName);
} else {