You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by GitBox <gi...@apache.org> on 2022/03/31 00:49:15 UTC

[GitHub] [jackrabbit-oak] nit0906 commented on a change in pull request #532: OAK-9741 Test cases for invalid index definitions

nit0906 commented on a change in pull request #532:
URL: https://github.com/apache/jackrabbit-oak/pull/532#discussion_r839076710



##########
File path: oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/invalidData/InvalidIndexDefinitionTest.java
##########
@@ -0,0 +1,259 @@
+/*
+ * 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.jackrabbit.oak.plugins.index.lucene.invalidData;
+
+import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME;
+import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NODE_TYPE;
+import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.List;
+import java.util.regex.PatternSyntaxException;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.oak.InitialContentHelper;
+import org.apache.jackrabbit.oak.Oak;
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.api.ContentRepository;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants;
+import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorProvider;
+import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProvider;
+import org.apache.jackrabbit.oak.plugins.index.nodetype.NodeTypeIndexProvider;
+import org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider;
+import org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
+import org.apache.jackrabbit.oak.query.AbstractQueryTest;
+import org.apache.jackrabbit.oak.spi.commit.Observer;
+import org.apache.jackrabbit.oak.spi.filter.PathFilter;
+import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
+import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.lucene.codecs.Codec;
+import org.junit.Test;
+
+import com.google.common.collect.Lists;
+
+public class InvalidIndexDefinitionTest extends AbstractQueryTest {
+
+    private LuceneIndexEditorProvider editorProvider;
+
+    private NodeStore nodeStore;
+    
+    @Override
+    protected ContentRepository createRepository() {
+        editorProvider = new LuceneIndexEditorProvider();
+        LuceneIndexProvider provider = new LuceneIndexProvider();
+        nodeStore = new MemoryNodeStore(InitialContentHelper.INITIAL_CONTENT);
+        return new Oak(nodeStore)
+                .with(new OpenSecurityProvider())
+                .with((QueryIndexProvider) provider)
+                .with((Observer) provider)
+                .with(editorProvider)
+                .with(new PropertyIndexEditorProvider())
+                .with(new NodeTypeIndexProvider())
+                .createContentRepository();
+    }
+    
+    @Test
+    public void allFine() throws CommitFailedException {
+        createIndexNodeAndData();
+        root.commit();
+        String query = "select [jcr:path] from [nt:base] where isdescendantnode('/tmp') and upper([test]) = 'HELLO'";
+        assertThat(explain(query), containsString("lucene:test"));
+        assertQuery(query, Lists.newArrayList("/tmp/testNode"));
+    }
+    
+    @Test(expected = IllegalArgumentException.class)
+    public void invalidCodec() throws CommitFailedException {
+        Tree def = createIndexNodeAndData();
+        // An incorrect value throws an exception, for example:
+        // java.lang.IllegalArgumentException: A SPI class of type org.apache.lucene.codecs.Codec with name 'Lucene46x' does not exist.
+        String codecValue = Codec.getDefault().getName() + "x";
+        def.setProperty(LuceneIndexConstants.CODEC_NAME, codecValue);
+        root.commit();
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void invalidCompatMode() throws CommitFailedException {
+        Tree def = createIndexNodeAndData();
+        // 3 results in IllegalArgumentException: Unknown version : 3
+        def.setProperty(LuceneIndexConstants.COMPAT_MODE, 3);
+        root.commit();
+    }
+    
+    @Test(expected = PatternSyntaxException.class)
+    public void invalidValueRegex() throws CommitFailedException {
+        Tree def = createIndexNodeAndData();
+        // An incorrect value, for example "[a-z", results in
+        // java.util.regex.PatternSyntaxException: Unclosed character class near index 3
+        def.setProperty(LuceneIndexConstants.PROP_VALUE_REGEX, "[a-z");
+        root.commit();
+    }
+    
+    @Test(expected = PatternSyntaxException.class)
+    public void invalidQueryFilterRegex() throws CommitFailedException {
+        Tree def = createIndexNodeAndData();
+        // An incorrect value, for example "[a-z", results in
+        // java.util.regex.PatternSyntaxException: Unclosed character class near index 3
+        def.setProperty(LuceneIndexConstants.PROP_QUERY_FILTER_REGEX, "[a-z");
+        root.commit();
+    }
+    
+    @Test(expected = IllegalArgumentException.class)
+    public void invalidBlobSize() throws CommitFailedException {
+        Tree def = createIndexNodeAndData();
+        // 1L + Integer.MAX_VALUE results in IllegalArgumentException: Out of range: 2147483648
+        def.setProperty("blobSize", 1L + Integer.MAX_VALUE);
+        root.commit();
+    }    
+
+    @Test
+    public void negativeBlobSize() throws CommitFailedException {
+        Tree def = createIndexNodeAndData();
+        // 1L + Integer.MAX_VALUE results in IllegalArgumentException: Out of range: 2147483648

Review comment:
       Comment can be fixed here to point out the expected behaviour when this value is set to a negative number.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org