You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by nn...@apache.org on 2016/06/30 22:55:43 UTC
incubator-geode git commit: GEODE-1339: Added test to validate
getAllIndexes and getIndex functions for Lucene.
Repository: incubator-geode
Updated Branches:
refs/heads/develop ec5578a22 -> 369d4320d
GEODE-1339: Added test to validate getAllIndexes and getIndex functions for Lucene.
* Added test to validate that a list of the indexes is returned if they are present in the system
* validated that an empty list is returned when there are no indexes in the system.
* getIndex function call with index name and region name as parameter will return the index object
* Null is returned when unmatched index names / region names are used or there are no indexes in the system.
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/369d4320
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/369d4320
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/369d4320
Branch: refs/heads/develop
Commit: 369d4320d18b0c6afdb40a36970316e64e3d7e62
Parents: ec5578a
Author: nabarun <nn...@pivotal.io>
Authored: Mon Jun 27 15:12:28 2016 -0700
Committer: nabarun <nn...@pivotal.io>
Committed: Thu Jun 30 15:54:45 2016 -0700
----------------------------------------------------------------------
.../lucene/LuceneIndexCreationDUnitTest.java | 114 ++++++++++++++++++-
...nDUnitTest.verifyXMLEmptyIndexList.cache.xml | 33 ++++++
...nitTest.verifyXMLMultipleIndexList.cache.xml | 39 +++++++
3 files changed, 184 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/369d4320/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationDUnitTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationDUnitTest.java
index f51c848..cec8d0e 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationDUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationDUnitTest.java
@@ -33,13 +33,13 @@ import org.junit.runner.RunWith;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import static com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities.*;
import static junitparams.JUnitParamsRunner.$;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
@Category(DistributedTest.class)
@RunWith(JUnitParamsRunner.class)
@@ -51,6 +51,65 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
getCache().createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
}
+
+ @Test
+ @Parameters({"1", "2" , "10"})
+ public void verifyThatIndexObjectsAreListedWhenPresentInTheSystem(int numberOfIndexes){
+ SerializableRunnableIF createIndex = getMultipleIndexes(numberOfIndexes);
+ dataStore1.invoke(() -> initDataStore(createIndex));
+ dataStore1.invoke(() -> verifyIndexList(numberOfIndexes));
+
+ dataStore2.invoke(() -> initDataStore(createIndex));
+ dataStore2.invoke(() -> verifyIndexList(numberOfIndexes));
+ }
+
+ @Test
+ @Parameters({"1", "2" , "10"})
+ public void verifyThatIndexObjectIsRetrievedWhenPresentInTheSystem(int numberOfIndexes){
+ SerializableRunnableIF createIndex = getMultipleIndexes(numberOfIndexes);
+ dataStore1.invoke(() -> initDataStore(createIndex));
+ dataStore1.invoke(() -> verifyIndexes(numberOfIndexes));
+
+ dataStore2.invoke(() -> initDataStore(createIndex));
+ dataStore2.invoke(() -> verifyIndexes(numberOfIndexes));
+ }
+
+ @Test
+ public void verifyThatEmptyListIsOutputWhenThereAreNoIndexesInTheSystem(){
+ dataStore1.invoke(() -> verifyIndexList(0));
+ dataStore2.invoke(() -> verifyIndexList(0));
+ }
+
+ @Test
+ public void verifyNullIsReturnedWhenGetIndexIsCalledAndNoIndexesArePresent(){
+ dataStore1.invoke(() -> {
+ LuceneService luceneService = LuceneServiceProvider.get(getCache());
+ assertNull(luceneService.getIndex(INDEX_NAME,REGION_NAME));
+ });
+
+ dataStore2.invoke(() -> {
+ LuceneService luceneService = LuceneServiceProvider.get(getCache());
+ assertNull(luceneService.getIndex(INDEX_NAME,REGION_NAME));
+ });
+ }
+
+ @Test
+ public void verifyNullIsReturnedWhenGetIndexIsCalledWithNoMatchingIndex(){
+ SerializableRunnableIF createIndex = get2FieldsIndexes();
+ dataStore1.invoke(() -> createIndex);
+ dataStore2.invoke(() -> createIndex);
+ dataStore1.invoke(() -> {
+ LuceneService luceneService = LuceneServiceProvider.get(getCache());
+ assertNull(luceneService.getIndex(INDEX_NAME+"_A",REGION_NAME));
+ });
+
+ dataStore2.invoke(() -> {
+ LuceneService luceneService = LuceneServiceProvider.get(getCache());
+ assertNull(luceneService.getIndex(INDEX_NAME+"_A",REGION_NAME));
+ });
+ }
+
+
@Test
public void verifyDifferentFieldsFails() {
SerializableRunnableIF createIndex1 = getFieldsIndexWithOneField();
@@ -167,6 +226,35 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
dataStore2.invoke(() -> initCache(getXmlFileForTest(cacheXmlFileBaseName + ".2"), exceptionMessage));
}
+ @Test
+ public void verifyXMLMultipleIndexList() {
+ dataStore1.invoke(() -> initCache(getXmlFileForTest("verifyXMLMultipleIndexList")));
+ dataStore2.invoke(() -> initCache(getXmlFileForTest("verifyXMLMultipleIndexList")));
+
+ dataStore1.invoke(() -> verifyIndexList(2));
+ dataStore2.invoke(() -> verifyIndexList(2));
+ }
+
+ @Test
+ public void verifyXMLMultipleIndexes() {
+ dataStore1.invoke(() -> initCache(getXmlFileForTest("verifyXMLMultipleIndexList")));
+ dataStore2.invoke(() -> initCache(getXmlFileForTest("verifyXMLMultipleIndexList")));
+
+ dataStore1.invoke(() -> verifyIndexes(2));
+ dataStore2.invoke(() -> verifyIndexes(2));
+ }
+
+ @Test
+ public void verifyXMLEmptyIndexList() {
+ dataStore1.invoke(() -> initCache(getXmlFileForTest("verifyXMLEmptyIndexList")));
+ dataStore2.invoke(() -> initCache(getXmlFileForTest("verifyXMLEmptyIndexList")));
+
+ dataStore1.invoke(() -> verifyIndexList(0));
+ dataStore2.invoke(() -> verifyIndexList(0));
+ }
+
+
+
private final Object[] getXmlAndExceptionMessages() {
return $(
new Object[] { "verifyDifferentFieldsFails", CANNOT_CREATE_LUCENE_INDEX_DIFFERENT_FIELDS },
@@ -231,6 +319,28 @@ public class LuceneIndexCreationDUnitTest extends LuceneDUnitTest {
};
}
+ private SerializableRunnableIF getMultipleIndexes(final int numberOfIndexes) {
+ return () -> {
+ LuceneService luceneService = LuceneServiceProvider.get(getCache());
+ for(int count = 1 ; count <= numberOfIndexes; count++){
+ luceneService.createIndex(INDEX_NAME+"_"+count, REGION_NAME, "field"+count);
+ }
+ };
+ }
+
+ private void verifyIndexList(final int expectedSize) {
+ LuceneService luceneService = LuceneServiceProvider.get(getCache());
+ Collection<LuceneIndex> indexList = luceneService.getAllIndexes();
+ assertEquals(indexList.size() , expectedSize);
+ }
+
+ private void verifyIndexes(final int numberOfIndexes) {
+ LuceneService luceneService = LuceneServiceProvider.get(getCache());
+ for(int count = 1; count <= numberOfIndexes; count++){
+ assertEquals(luceneService.getIndex(INDEX_NAME+"_"+count, REGION_NAME).getName(), INDEX_NAME+"_"+count);
+ }
+ }
+
private SerializableRunnableIF getAnalyzersIndexWithNullField1() {
return () -> {
LuceneService luceneService = LuceneServiceProvider.get(getCache());
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/369d4320/geode-lucene/src/test/resources/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationDUnitTest.verifyXMLEmptyIndexList.cache.xml
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/resources/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationDUnitTest.verifyXMLEmptyIndexList.cache.xml b/geode-lucene/src/test/resources/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationDUnitTest.verifyXMLEmptyIndexList.cache.xml
new file mode 100755
index 0000000..925625e
--- /dev/null
+++ b/geode-lucene/src/test/resources/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationDUnitTest.verifyXMLEmptyIndexList.cache.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<cache
+ xmlns="http://geode.apache.org/schema/cache"
+ xmlns:lucene="http://geode.apache.org/schema/lucene"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://geode.apache.org/schema/cache
+ http://geode.apache.org/schema/cache/cache-1.0.xsd
+ http://geode.apache.org/schema/lucene
+ http://geode.apache.org/schema/lucene/lucene-1.0.xsd"
+ version="1.0">
+
+ <region name="region" refid="PARTITION_REDUNDANT">
+ </region>
+
+</cache>
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/369d4320/geode-lucene/src/test/resources/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationDUnitTest.verifyXMLMultipleIndexList.cache.xml
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/resources/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationDUnitTest.verifyXMLMultipleIndexList.cache.xml b/geode-lucene/src/test/resources/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationDUnitTest.verifyXMLMultipleIndexList.cache.xml
new file mode 100755
index 0000000..ab4c211
--- /dev/null
+++ b/geode-lucene/src/test/resources/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationDUnitTest.verifyXMLMultipleIndexList.cache.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<cache
+ xmlns="http://geode.apache.org/schema/cache"
+ xmlns:lucene="http://geode.apache.org/schema/lucene"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://geode.apache.org/schema/cache
+ http://geode.apache.org/schema/cache/cache-1.0.xsd
+ http://geode.apache.org/schema/lucene
+ http://geode.apache.org/schema/lucene/lucene-1.0.xsd"
+ version="1.0">
+
+ <region name="region" refid="PARTITION_REDUNDANT">
+ <lucene:index name="index_1">
+ <lucene:field name="field1" analyzer="org.apache.lucene.analysis.standard.StandardAnalyzer"/>
+ </lucene:index>
+ <lucene:index name="index_2">
+ <lucene:field name="field2" analyzer="org.apache.lucene.analysis.standard.StandardAnalyzer"/>
+ </lucene:index>
+ </region>
+
+</cache>