You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2017/05/31 20:50:56 UTC

[11/47] geode git commit: GEODE-2975: Change the location of the lucene xsd

GEODE-2975: Change the location of the lucene xsd

The lucene xsd was not in the right location on disk, which resulted in
a failure to validate lucene elements in the xml file.

Adding tests and validation for cases where lucene elements show up in the
wrong place, which we were unable to catch with the xsd validation.

This closes #538


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

Branch: refs/heads/feature/GEODE-2632-18
Commit: b89d2fb867b7f2b3aa157574bea52f53c2ae3934
Parents: 76ff506
Author: Dan Smith <up...@apache.org>
Authored: Thu May 25 13:05:23 2017 -0700
Committer: Dan Smith <up...@apache.org>
Committed: Wed May 31 10:19:36 2017 -0700

----------------------------------------------------------------------
 .../lucene/internal/xml/LuceneXmlParser.java    |  8 +++
 .../geode.apache.org/lucene/lucene-1.0.xsd      | 58 --------------------
 .../schema/lucene/lucene-1.0.xsd                | 58 ++++++++++++++++++++
 ...uceneIndexXmlParserIntegrationJUnitTest.java | 25 +++++++++
 ...neElementShouldThrowParseException.cache.xml | 39 +++++++++++++
 ...lLocationShouldThrowParseException.cache.xml | 40 ++++++++++++++
 ...nvalidXmlShouldThrowParseException.cache.xml | 39 +++++++++++++
 7 files changed, 209 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/b89d2fb8/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/xml/LuceneXmlParser.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/xml/LuceneXmlParser.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/xml/LuceneXmlParser.java
index 5eae743..07a3c2a 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/xml/LuceneXmlParser.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/xml/LuceneXmlParser.java
@@ -56,6 +56,11 @@ public class LuceneXmlParser extends AbstractXmlParser {
     if (stack.peek() instanceof StringBuffer) {
       stack.pop();
     }
+
+    if (!(stack.peek() instanceof LuceneIndexCreation)) {
+      throw new CacheXmlException(
+          "lucene <field> elements must occur within lucene <index> elements");
+    }
     LuceneIndexCreation creation = (LuceneIndexCreation) stack.peek();
     String name = atts.getValue(NAME);
     String className = atts.getValue(ANALYZER);
@@ -68,6 +73,9 @@ public class LuceneXmlParser extends AbstractXmlParser {
   }
 
   private void startIndex(Attributes atts) {
+    if (!(stack.peek() instanceof RegionCreation)) {
+      throw new CacheXmlException("lucene <index> elements must occur within <region> elements");
+    }
     final RegionCreation region = (RegionCreation) stack.peek();
     String name = atts.getValue(NAME);
     LuceneIndexCreation indexCreation = new LuceneIndexCreation();

http://git-wip-us.apache.org/repos/asf/geode/blob/b89d2fb8/geode-lucene/src/main/resources/META-INF/schemas/geode.apache.org/lucene/lucene-1.0.xsd
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/resources/META-INF/schemas/geode.apache.org/lucene/lucene-1.0.xsd b/geode-lucene/src/main/resources/META-INF/schemas/geode.apache.org/lucene/lucene-1.0.xsd
deleted file mode 100644
index ec82c2f..0000000
--- a/geode-lucene/src/main/resources/META-INF/schemas/geode.apache.org/lucene/lucene-1.0.xsd
+++ /dev/null
@@ -1,58 +0,0 @@
-<?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.
--->
-<xsd:schema
-    targetNamespace="http://geode.apache.org/schema/lucene"
-    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-    elementFormDefault="qualified"
-    attributeFormDefault="unqualified"
-    version="1.0">
-  
-  <xsd:import
-      namespace="http://geode.apache.org/schema/cache"
-      schemaLocation="http://geode.apache.org/schema/cache/cache-1.0.xsd"/>
-  
-  <xsd:annotation>
-    <xsd:documentation><![CDATA[
-XML schema for Lucene indexes in Geode.
-
-  <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">
-    
-    ]]></xsd:documentation>
-  </xsd:annotation>
-  <xsd:element name="index">
-    <xsd:complexType>
-    	<xsd:sequence>
-    	  <xsd:element name="field" maxOccurs="unbounded">
-			<xsd:complexType>
-				<xsd:attribute name="name" type="xsd:string" />
-				<xsd:attribute name="analyzer" type="xsd:string" />
-			</xsd:complexType>
-    	  </xsd:element>
-    	</xsd:sequence>
-    	<xsd:attribute name="name" type="xsd:string"/>
-    </xsd:complexType>
-  </xsd:element>
-</xsd:schema>

http://git-wip-us.apache.org/repos/asf/geode/blob/b89d2fb8/geode-lucene/src/main/resources/META-INF/schemas/geode.apache.org/schema/lucene/lucene-1.0.xsd
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/resources/META-INF/schemas/geode.apache.org/schema/lucene/lucene-1.0.xsd b/geode-lucene/src/main/resources/META-INF/schemas/geode.apache.org/schema/lucene/lucene-1.0.xsd
new file mode 100644
index 0000000..ec82c2f
--- /dev/null
+++ b/geode-lucene/src/main/resources/META-INF/schemas/geode.apache.org/schema/lucene/lucene-1.0.xsd
@@ -0,0 +1,58 @@
+<?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.
+-->
+<xsd:schema
+    targetNamespace="http://geode.apache.org/schema/lucene"
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+    elementFormDefault="qualified"
+    attributeFormDefault="unqualified"
+    version="1.0">
+  
+  <xsd:import
+      namespace="http://geode.apache.org/schema/cache"
+      schemaLocation="http://geode.apache.org/schema/cache/cache-1.0.xsd"/>
+  
+  <xsd:annotation>
+    <xsd:documentation><![CDATA[
+XML schema for Lucene indexes in Geode.
+
+  <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">
+    
+    ]]></xsd:documentation>
+  </xsd:annotation>
+  <xsd:element name="index">
+    <xsd:complexType>
+    	<xsd:sequence>
+    	  <xsd:element name="field" maxOccurs="unbounded">
+			<xsd:complexType>
+				<xsd:attribute name="name" type="xsd:string" />
+				<xsd:attribute name="analyzer" type="xsd:string" />
+			</xsd:complexType>
+    	  </xsd:element>
+    	</xsd:sequence>
+    	<xsd:attribute name="name" type="xsd:string"/>
+    </xsd:complexType>
+  </xsd:element>
+</xsd:schema>

http://git-wip-us.apache.org/repos/asf/geode/blob/b89d2fb8/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlParserIntegrationJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlParserIntegrationJUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlParserIntegrationJUnitTest.java
index 5fecf2e..fef0684 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlParserIntegrationJUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlParserIntegrationJUnitTest.java
@@ -17,6 +17,7 @@ package org.apache.geode.cache.lucene.internal.xml;
 
 import org.apache.geode.cache.Cache;
 import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.cache.CacheXmlException;
 import org.apache.geode.cache.lucene.LuceneIndex;
 import org.apache.geode.cache.lucene.LuceneService;
 import org.apache.geode.cache.lucene.LuceneServiceProvider;
@@ -73,6 +74,30 @@ public class LuceneIndexXmlParserIntegrationJUnitTest {
     validateExpectedIndexes(region, expectedIndexes);
   }
 
+  /**
+   * Test that we parse the index fields correctly
+   */
+  @Test(expected = CacheXmlException.class)
+  public void invalidXmlShouldThrowParseException() throws FileNotFoundException {
+    RegionCreation region = createRegionCreation("region");
+  }
+
+  /**
+   * Test that we parse the index fields correctly
+   */
+  @Test(expected = CacheXmlException.class)
+  public void invalidLuceneElementShouldThrowParseException() throws FileNotFoundException {
+    RegionCreation region = createRegionCreation("region");
+  }
+
+  /**
+   * Test that we parse the index fields correctly
+   */
+  @Test(expected = CacheXmlException.class)
+  public void invalidXmlLocationShouldThrowParseException() throws FileNotFoundException {
+    RegionCreation region = createRegionCreation("region");
+  }
+
   @Test
   public void parseIndexWithAnalyzers() throws FileNotFoundException {
     RegionCreation region = createRegionCreation("region");

http://git-wip-us.apache.org/repos/asf/geode/blob/b89d2fb8/geode-lucene/src/test/resources/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlParserIntegrationJUnitTest.invalidLuceneElementShouldThrowParseException.cache.xml
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/resources/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlParserIntegrationJUnitTest.invalidLuceneElementShouldThrowParseException.cache.xml b/geode-lucene/src/test/resources/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlParserIntegrationJUnitTest.invalidLuceneElementShouldThrowParseException.cache.xml
new file mode 100644
index 0000000..3ce66c1
--- /dev/null
+++ b/geode-lucene/src/test/resources/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlParserIntegrationJUnitTest.invalidLuceneElementShouldThrowParseException.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">
+    	<lucene:index name="index1">
+    	  <lucene:field name="a"/>
+    	</lucene:index>
+
+		<lucene:indexxx name="index2">
+			<lucene:field name="a"/>
+			<lucene:field name="b"/>
+		</lucene:indexxx>
+    </region>
+</cache>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/geode/blob/b89d2fb8/geode-lucene/src/test/resources/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlParserIntegrationJUnitTest.invalidXmlLocationShouldThrowParseException.cache.xml
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/resources/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlParserIntegrationJUnitTest.invalidXmlLocationShouldThrowParseException.cache.xml b/geode-lucene/src/test/resources/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlParserIntegrationJUnitTest.invalidXmlLocationShouldThrowParseException.cache.xml
new file mode 100644
index 0000000..b267535
--- /dev/null
+++ b/geode-lucene/src/test/resources/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlParserIntegrationJUnitTest.invalidXmlLocationShouldThrowParseException.cache.xml
@@ -0,0 +1,40 @@
+<?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">
+    	<lucene:index name="index1">
+    	  <lucene:field name="a"/>
+    	</lucene:index>
+
+    </region>
+
+	<lucene:index name="index2">
+		<lucene:field name="a"/>
+		<lucene:field name="b"/>
+	</lucene:index>
+</cache>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/geode/blob/b89d2fb8/geode-lucene/src/test/resources/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlParserIntegrationJUnitTest.invalidXmlShouldThrowParseException.cache.xml
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/resources/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlParserIntegrationJUnitTest.invalidXmlShouldThrowParseException.cache.xml b/geode-lucene/src/test/resources/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlParserIntegrationJUnitTest.invalidXmlShouldThrowParseException.cache.xml
new file mode 100644
index 0000000..5d5dca7
--- /dev/null
+++ b/geode-lucene/src/test/resources/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlParserIntegrationJUnitTest.invalidXmlShouldThrowParseException.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">
+    	<lucene:index name="index1">
+    	  <lucene:field name="a"/>
+    	</lucene:index>
+
+		<lucene:index namexx="index2">
+			<lucene:field name="a"/>
+			<lucene:field name="b"/>
+		</lucene:index>
+    </region>
+</cache>
\ No newline at end of file