You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by up...@apache.org on 2017/11/02 21:10:31 UTC

[geode] branch feature/GEODE-3930 updated (dc5d4e9 -> 2834e5a)

This is an automated email from the ASF dual-hosted git repository.

upthewaterspout pushed a change to branch feature/GEODE-3930
in repository https://gitbox.apache.org/repos/asf/geode.git.


    from dc5d4e9  Index creation after region creation works for a single member integration test
     new 6b7d30f  Added integration and DUnit tests for index creation on an existing region.
     new 2834e5a  Splotless

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../geode/internal/cache/AbstractRegion.java       |  2 +-
 .../apache/geode/internal/cache/LocalRegion.java   |  5 +-
 .../geode/internal/cache/PartitionedRegion.java    |  3 +-
 .../cache/lucene/internal/LuceneServiceImpl.java   |  8 +-
 .../cache/lucene/LuceneIndexCreationDUnitTest.java | 93 ++++++++++++++++++++++
 .../lucene/LuceneIndexCreationIntegrationTest.java | 23 +++++-
 6 files changed, 121 insertions(+), 13 deletions(-)

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].

[geode] 01/02: Added integration and DUnit tests for index creation on an existing region.

Posted by up...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

upthewaterspout pushed a commit to branch feature/GEODE-3930
in repository https://gitbox.apache.org/repos/asf/geode.git

commit 6b7d30fca9fbbdfadd33eea3e44aabc54211ffc6
Author: Dan Smith <up...@apache.org>
AuthorDate: Thu Nov 2 14:08:25 2017 -0700

    Added integration and DUnit tests for index creation on an existing
    region.
---
 .../cache/lucene/LuceneIndexCreationDUnitTest.java | 94 ++++++++++++++++++++++
 .../lucene/LuceneIndexCreationIntegrationTest.java | 17 ++++
 2 files changed, 111 insertions(+)

diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationDUnitTest.java
index 948ba14..743ccd2 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationDUnitTest.java
@@ -14,8 +14,12 @@
  */
 package org.apache.geode.cache.lucene;
 
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.lucene.internal.LuceneIndexFactoryImpl;
 import org.apache.geode.cache.lucene.internal.repository.serializer.HeterogeneousLuceneSerializer;
 import org.apache.geode.cache.lucene.test.LuceneTestUtilities;
+import org.apache.geode.cache.lucene.test.TestObject;
 import org.apache.geode.internal.i18n.LocalizedStrings;
 import org.apache.geode.test.dunit.SerializableRunnableIF;
 import org.apache.geode.test.junit.categories.DistributedTest;
@@ -25,15 +29,20 @@ import junitparams.Parameters;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.core.KeywordAnalyzer;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.hamcrest.Matchers;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
 import org.junit.runner.RunWith;
 
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
 import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.*;
 import static junitparams.JUnitParamsRunner.$;
@@ -43,6 +52,9 @@ import static org.junit.Assert.*;
 @RunWith(JUnitParamsRunner.class)
 public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
 
+  @Rule
+  public transient ExpectedException expectedException = ExpectedException.none();
+
   private Object[] parametersForMultipleIndexCreates() {
     Integer[] numIndexes = {1, 2, 10};
     RegionTestableType[] regionTestTypes = getListOfRegionTestTypes();
@@ -248,6 +260,65 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
     dataStore2.invoke(() -> initDataStore(createIndex, regionType));
   }
 
+  @Test
+  @Parameters({"PARTITION", "PARTITION_REDUNDANT"})
+  public void creatingIndexAfterRegionAndStartingUpSecondMemberSucceeds(RegionTestableType regionType) {
+    dataStore1.invoke(() -> {
+      regionType.createDataStore(getCache(), REGION_NAME);
+      createIndexAfterRegion("field1");
+    });
+
+    dataStore2.invoke(() -> {
+      createIndexAfterRegion("field1");
+      regionType.createDataStore(getCache(), REGION_NAME);
+    });
+    dataStore1.invoke(() -> {
+      putEntryAndQuery();
+    });
+  }
+
+  @Test()
+  @Parameters({"PARTITION", "PARTITION_REDUNDANT"})
+  public void creatingIndexAfterRegionAndStartingUpSecondMemberWithoutIndexFails(RegionTestableType regionType) {
+    dataStore1.invoke(() -> {
+      regionType.createDataStore(getCache(), REGION_NAME);
+      createIndexAfterRegion("field1");
+    });
+
+    expectedException.expectCause(Matchers.instanceOf(IllegalStateException.class));
+    dataStore2.invoke(() -> {
+      regionType.createDataStore(getCache(), REGION_NAME);
+      createIndexAfterRegion("field1");
+    });
+
+    dataStore1.invoke(() -> {
+      putEntryAndQuery();
+    });
+  }
+
+  @Test
+  @Parameters({"PARTITION", "PARTITION_REDUNDANT"})
+  public void creatingIndexAfterRegionInTwoMembersSucceed(RegionTestableType regionType) {
+    dataStore1.invoke(() -> {
+      regionType.createDataStore(getCache(), REGION_NAME);
+    });
+
+    dataStore2.invoke(() -> {
+      regionType.createDataStore(getCache(), REGION_NAME);
+    });
+
+    dataStore1.invoke(() -> {
+      createIndexAfterRegion("field1");
+    });
+
+    dataStore2.invoke(() -> {
+      createIndexAfterRegion("field1");
+    });
+
+    dataStore1.invoke(() -> {
+      putEntryAndQuery();
+    });
+  }
 
   @Test
   @Parameters(method = "getXmlAndExceptionMessages")
@@ -544,4 +615,27 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
   protected void verifyAsyncEventQueues(final int expectedSize) {
     assertEquals(expectedSize, getCache().getAsyncEventQueues(false).size());
   }
+
+  private void createIndexAfterRegion(String ... fields) {
+    LuceneService luceneService = LuceneServiceProvider.get(getCache());
+    LuceneIndexFactoryImpl indexFactory =
+        (LuceneIndexFactoryImpl) luceneService.createIndexFactory();
+    indexFactory.setFields(fields).create(INDEX_NAME, REGION_NAME, true);
+  }
+
+  private void putEntryAndQuery()
+      throws InterruptedException, LuceneQueryException {
+    Cache cache = getCache();
+    Region region = cache.getRegion(REGION_NAME);
+    region.put("key1", new TestObject("field1Value", "field2Value"));
+    LuceneService luceneService = LuceneServiceProvider.get(cache);
+    luceneService.waitUntilFlushed(INDEX_NAME, REGION_NAME, 1, TimeUnit.MINUTES);
+    LuceneQuery<Object, Object>
+        query =
+        luceneService.createLuceneQueryFactory()
+            .create(INDEX_NAME, REGION_NAME, "field1:field1Value", "field1");
+    assertEquals(Collections.singletonList("key1"), query.findKeys());
+  }
+
+
 }
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationIntegrationTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationIntegrationTest.java
index 8a57666..0b5bb04 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationIntegrationTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationIntegrationTest.java
@@ -208,6 +208,23 @@ public class LuceneIndexCreationIntegrationTest extends LuceneIntegrationTest {
     assertEquals(Collections.singletonList("key1"), query.findKeys());
   }
 
+
+  @Test()
+  public void creatingDuplicateLuceneIndexFails()
+      throws IOException, ParseException, InterruptedException, LuceneQueryException {
+    Region region = createRegion();
+    LuceneService luceneService = LuceneServiceProvider.get(cache);
+    final LuceneIndexFactoryImpl indexFactory =
+        (LuceneIndexFactoryImpl) luceneService.createIndexFactory();
+    indexFactory.setFields("field1", "field2").create(INDEX_NAME, REGION_NAME, true);
+
+    LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
+    assertNotNull(index);
+
+    expectedException.expect(LuceneIndexExistsException.class);
+    indexFactory.setFields("field1", "field2").create(INDEX_NAME, REGION_NAME, true);
+  }
+
   @Test
   public void cannotCreateLuceneIndexForReplicateRegion() throws IOException, ParseException {
     try {

-- 
To stop receiving notification emails like this one, please contact
"commits@geode.apache.org" <co...@geode.apache.org>.

[geode] 02/02: Splotless

Posted by up...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

upthewaterspout pushed a commit to branch feature/GEODE-3930
in repository https://gitbox.apache.org/repos/asf/geode.git

commit 2834e5a9143a6e6d443d1f36cc2eb0185eb85371
Author: Dan Smith <up...@apache.org>
AuthorDate: Thu Nov 2 14:10:05 2017 -0700

    Splotless
---
 .../org/apache/geode/internal/cache/AbstractRegion.java |  2 +-
 .../org/apache/geode/internal/cache/LocalRegion.java    |  5 +++--
 .../apache/geode/internal/cache/PartitionedRegion.java  |  3 +--
 .../geode/cache/lucene/internal/LuceneServiceImpl.java  |  8 ++++----
 .../cache/lucene/LuceneIndexCreationDUnitTest.java      | 17 ++++++++---------
 .../lucene/LuceneIndexCreationIntegrationTest.java      |  6 ++----
 6 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/AbstractRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/AbstractRegion.java
index f3971d3..43ab2f1 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/AbstractRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/AbstractRegion.java
@@ -874,7 +874,7 @@ public abstract class AbstractRegion implements Region, RegionAttributes, Attrib
 
   public void addAsyncEventQueueId(String asyncEventQueueId, boolean isInternal) {
     getAsyncEventQueueIds().add(asyncEventQueueId);
-    if(!isInternal) {
+    if (!isInternal) {
       getVisibleAsyncEventQueueIds().add(asyncEventQueueId);
     }
     setAllGatewaySenderIds();
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
index 7e703d0..abcd1df 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
@@ -541,7 +541,8 @@ public class LocalRegion extends AbstractRegion implements InternalRegion, Loade
     return this.stopper;
   }
 
-  private final CopyOnWriteHashMap<String, CacheServiceProfile> cacheServiceProfiles = new CopyOnWriteHashMap<>();
+  private final CopyOnWriteHashMap<String, CacheServiceProfile> cacheServiceProfiles =
+      new CopyOnWriteHashMap<>();
 
   private static String calcFullPath(String regionName, LocalRegion parentRegion) {
     StringBuilder buf = null;
@@ -634,7 +635,7 @@ public class LocalRegion extends AbstractRegion implements InternalRegion, Loade
     this.isUsedForParallelGatewaySenderQueue =
         internalRegionArgs.isUsedForParallelGatewaySenderQueue();
     this.serialGatewaySender = internalRegionArgs.getSerialGatewaySender();
-    if(internalRegionArgs.getCacheServiceProfiles() != null) {
+    if (internalRegionArgs.getCacheServiceProfiles() != null) {
       this.cacheServiceProfiles.putAll(internalRegionArgs.getCacheServiceProfiles());
     }
 
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java
index e3e399f..4c95e77 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java
@@ -1221,8 +1221,7 @@ public class PartitionedRegion extends LocalRegion
     addAsyncEventQueueId(asyncEventQueueId, false);
   }
 
-  public void addAsyncEventQueueId(
-      String asyncEventQueueId, boolean isInternal) {
+  public void addAsyncEventQueueId(String asyncEventQueueId, boolean isInternal) {
     super.addAsyncEventQueueId(asyncEventQueueId, isInternal);
     new UpdateAttributesProcessor(this).distribute();
     ((PartitionedRegion) this).distributeUpdatedProfileOnSenderCreation();
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
index 4d2bf31..22f498c 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
@@ -250,16 +250,16 @@ public class LuceneServiceImpl implements InternalLuceneService {
 
   }
 
-  private void createIndexOnExistingRegion(PartitionedRegion region, String indexName, String regionPath,
-      String[] fields, Analyzer analyzer, Map<String, Analyzer> fieldAnalyzers,
+  private void createIndexOnExistingRegion(PartitionedRegion region, String indexName,
+      String regionPath, String[] fields, Analyzer analyzer, Map<String, Analyzer> fieldAnalyzers,
       LuceneSerializer serializer) {
     validateRegionAttributes(region.getAttributes());
 
     String aeqId = LuceneServiceImpl.getUniqueIndexName(indexName, regionPath);
     region.addAsyncEventQueueId(aeqId, true);
 
-    region.addCacheServiceProfile(new LuceneIndexCreationProfile(indexName, regionPath,
-        fields, analyzer, fieldAnalyzers, serializer));
+    region.addCacheServiceProfile(new LuceneIndexCreationProfile(indexName, regionPath, fields,
+        analyzer, fieldAnalyzers, serializer));
 
     LuceneIndexImpl luceneIndex = beforeDataRegionCreated(indexName, regionPath,
         region.getAttributes(), analyzer, fieldAnalyzers, aeqId, serializer, fields);
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationDUnitTest.java
index 743ccd2..fd296fd 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationDUnitTest.java
@@ -262,7 +262,8 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
 
   @Test
   @Parameters({"PARTITION", "PARTITION_REDUNDANT"})
-  public void creatingIndexAfterRegionAndStartingUpSecondMemberSucceeds(RegionTestableType regionType) {
+  public void creatingIndexAfterRegionAndStartingUpSecondMemberSucceeds(
+      RegionTestableType regionType) {
     dataStore1.invoke(() -> {
       regionType.createDataStore(getCache(), REGION_NAME);
       createIndexAfterRegion("field1");
@@ -279,7 +280,8 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
 
   @Test()
   @Parameters({"PARTITION", "PARTITION_REDUNDANT"})
-  public void creatingIndexAfterRegionAndStartingUpSecondMemberWithoutIndexFails(RegionTestableType regionType) {
+  public void creatingIndexAfterRegionAndStartingUpSecondMemberWithoutIndexFails(
+      RegionTestableType regionType) {
     dataStore1.invoke(() -> {
       regionType.createDataStore(getCache(), REGION_NAME);
       createIndexAfterRegion("field1");
@@ -616,24 +618,21 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
     assertEquals(expectedSize, getCache().getAsyncEventQueues(false).size());
   }
 
-  private void createIndexAfterRegion(String ... fields) {
+  private void createIndexAfterRegion(String... fields) {
     LuceneService luceneService = LuceneServiceProvider.get(getCache());
     LuceneIndexFactoryImpl indexFactory =
         (LuceneIndexFactoryImpl) luceneService.createIndexFactory();
     indexFactory.setFields(fields).create(INDEX_NAME, REGION_NAME, true);
   }
 
-  private void putEntryAndQuery()
-      throws InterruptedException, LuceneQueryException {
+  private void putEntryAndQuery() throws InterruptedException, LuceneQueryException {
     Cache cache = getCache();
     Region region = cache.getRegion(REGION_NAME);
     region.put("key1", new TestObject("field1Value", "field2Value"));
     LuceneService luceneService = LuceneServiceProvider.get(cache);
     luceneService.waitUntilFlushed(INDEX_NAME, REGION_NAME, 1, TimeUnit.MINUTES);
-    LuceneQuery<Object, Object>
-        query =
-        luceneService.createLuceneQueryFactory()
-            .create(INDEX_NAME, REGION_NAME, "field1:field1Value", "field1");
+    LuceneQuery<Object, Object> query = luceneService.createLuceneQueryFactory().create(INDEX_NAME,
+        REGION_NAME, "field1:field1Value", "field1");
     assertEquals(Collections.singletonList("key1"), query.findKeys());
   }
 
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationIntegrationTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationIntegrationTest.java
index 0b5bb04..5f4e74b 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationIntegrationTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationIntegrationTest.java
@@ -200,10 +200,8 @@ public class LuceneIndexCreationIntegrationTest extends LuceneIntegrationTest {
 
     region.put("key1", new TestObject("hello", "world"));
     luceneService.waitUntilFlushed(INDEX_NAME, REGION_NAME, 1, TimeUnit.MINUTES);
-    LuceneQuery<Object, Object>
-        query =
-        luceneService.createLuceneQueryFactory()
-            .create(INDEX_NAME, REGION_NAME, "field1:hello", "field1");
+    LuceneQuery<Object, Object> query = luceneService.createLuceneQueryFactory().create(INDEX_NAME,
+        REGION_NAME, "field1:hello", "field1");
 
     assertEquals(Collections.singletonList("key1"), query.findKeys());
   }

-- 
To stop receiving notification emails like this one, please contact
"commits@geode.apache.org" <co...@geode.apache.org>.