Modified: 
jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchFacetTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchFacetTest.java?rev=1877992&r1=1877991&r2=1877992&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchFacetTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchFacetTest.java
 Thu May 21 08:56:02 2020
@@ -83,15 +83,14 @@ public class ElasticsearchFacetTest {
     private QueryManager qe;
     Repository repository;
     private Node indexNode;
-    private static String TEST_INDEX = "testIndex";
+    private static final String TEST_INDEX = "testIndex";
     private static final int NUM_LEAF_NODES = 
STATISTICAL_FACET_SAMPLE_SIZE_DEFAULT;
     private static final int NUM_LABELS = 4;
     private static final int NUM_LEAF_NODES_FOR_LARGE_DATASET = NUM_LEAF_NODES;
     private static final int NUM_LEAF_NODES_FOR_SMALL_DATASET = NUM_LEAF_NODES 
/ (2 * NUM_LABELS);
-    private Map<String, Integer> actualLabelCount = Maps.newHashMap();
-    private Map<String, Integer> actualAclLabelCount = Maps.newHashMap();
-    private Map<String, Integer> actualAclPar1LabelCount = Maps.newHashMap();
-
+    private final Map<String, Integer> actualLabelCount = Maps.newHashMap();
+    private final Map<String, Integer> actualAclLabelCount = Maps.newHashMap();
+    private final Map<String, Integer> actualAclPar1LabelCount = 
Maps.newHashMap();
 
     @Rule
     public final ElasticsearchContainer elastic =
@@ -136,38 +135,21 @@ public class ElasticsearchFacetTest {
         Jcr jcr = new Jcr(oak);
         repository = jcr.createRepository();
 
-        try {
-            session = repository.login(new SimpleCredentials("admin", 
"admin".toCharArray()), null);
-        } catch (RepositoryException e) {
-            throw e;
-        }
+        session = repository.login(new SimpleCredentials("admin", 
"admin".toCharArray()), null);
         closer.register(session::logout);
 
         // we'd always query anonymously
-        Session anonSession = null;
-        try {
-            anonSession = repository.login(new GuestCredentials(), null);
-            anonSession.refresh(true);
-            anonSession.save();
-        } catch (RepositoryException e) {
-            throw e;
-        }
+        Session anonSession = repository.login(new GuestCredentials(), null);
+        anonSession.refresh(true);
+        anonSession.save();
         closer.register(anonSession::logout);
-        try {
-            qe = anonSession.getWorkspace().getQueryManager();
-        } catch (RepositoryException e) {
-            throw e;
-        }
+        qe = anonSession.getWorkspace().getQueryManager();
     }
 
-
     private class IndexSkeleton {
         IndexDefinitionBuilder indexDefinitionBuilder;
         IndexDefinitionBuilder.IndexRule indexRule;
 
-        private IndexSkeleton() throws RepositoryException {
-        }
-
         void initialize() {
             initialize(JcrConstants.NT_BASE);
         }
@@ -185,7 +167,7 @@ public class ElasticsearchFacetTest {
     private void createIndex() throws RepositoryException {
         IndexSkeleton indexSkeleton = new IndexSkeleton();
         indexSkeleton.initialize();
-        
indexSkeleton.indexDefinitionBuilder.noAsync().evaluatePathRestrictions();
+        indexSkeleton.indexDefinitionBuilder.noAsync();
         indexSkeleton.indexRule.property("cons").propertyIndex();
         
indexSkeleton.indexRule.property("foo").propertyIndex().getBuilderTree().setProperty(FACET_PROP,
 true, Type.BOOLEAN);
         
indexSkeleton.indexRule.property("bar").propertyIndex().getBuilderTree().setProperty(FACET_PROP,
 true, Type.BOOLEAN);
@@ -248,9 +230,7 @@ public class ElasticsearchFacetTest {
     @Test
     public void secureFacets() throws Exception {
         createDataset(NUM_LEAF_NODES_FOR_LARGE_DATASET);
-        assertEventually(() -> {
-            assertEquals(actualAclLabelCount, getFacets());
-        });
+        assertEventually(() -> assertEquals(actualAclLabelCount, getFacets()));
     }
 
     @Test
@@ -260,9 +240,7 @@ public class ElasticsearchFacetTest {
         inaccessibleChild.setProperty("cons", "val");
         inaccessibleChild.setProperty("foo", "l4");
         session.save();
-        assertEventually(() -> {
-            assertEquals(actualAclLabelCount, getFacets());
-        });
+        assertEventually(() -> assertEquals(actualAclLabelCount, getFacets()));
     }
 
     @Test
@@ -272,9 +250,7 @@ public class ElasticsearchFacetTest {
         session.save();
 
         createDataset(NUM_LEAF_NODES_FOR_LARGE_DATASET);
-        assertEventually(() -> {
-            assertEquals(actualLabelCount, getFacets());
-        });
+        assertEventually(() -> assertEquals(actualLabelCount, getFacets()));
     }
 
     @Test
@@ -286,14 +262,12 @@ public class ElasticsearchFacetTest {
 
         createDataset(NUM_LEAF_NODES_FOR_LARGE_DATASET);
 
-        assertEventually(() -> {
-            assertEquals("Unexpected number of facets", 
actualAclLabelCount.size(), getFacets().size());
-        });
+        assertEventually(() -> assertEquals("Unexpected number of facets", 
actualAclLabelCount.size(), getFacets().size()));
 
         for (Map.Entry<String, Integer> facet : 
actualAclLabelCount.entrySet()) {
             String facetLabel = facet.getKey();
             assertEventually(() -> {
-                int facetCount = facetCount = getFacets().get(facetLabel);
+                int facetCount = getFacets().get(facetLabel);
                 float ratio = ((float) facetCount) / facet.getValue();
                 assertTrue("Facet count for label: " + facetLabel + " is 
outside of 10% margin of error. " +
                                 "Expected: " + facet.getValue() + "; Got: " + 
facetCount + "; Ratio: " + ratio,
@@ -311,21 +285,13 @@ public class ElasticsearchFacetTest {
 
         createDataset(NUM_LEAF_NODES_FOR_SMALL_DATASET);
 
-        assertEventually(() -> {
-            assertEquals("Unexpected number of facets", 
actualAclLabelCount.size(), getFacets().size());
-        });
+        assertEventually(() -> assertEquals("Unexpected number of facets", 
actualAclLabelCount.size(), getFacets().size()));
 
         // Since the hit count is less than sample size -> flow should have 
switched to secure facet count instead of statistical
         // and thus the count should be exactly equal
-        assertEventually(() -> {
-            assertEquals(actualAclLabelCount, getFacets());
-        });
+        assertEventually(() -> assertEquals(actualAclLabelCount, getFacets()));
     }
 
-    /*
-    Currently we are not adding path restrictions in elastic query and 
filtering paths later from results.
-    We will need path restrictions in elastic query itself to get right facet 
results.
-     */
     @Test
     public void statisticalFacets_withHitCountSameAsSampleSize() throws 
Exception {
         Node facetConfig = getOrCreateByPath(indexNode.getPath() + "/" + 
FACETS, "nt:unstructured", session);
@@ -335,17 +301,19 @@ public class ElasticsearchFacetTest {
 
         createDataset(NUM_LEAF_NODES_FOR_LARGE_DATASET);
 
-        Map<String, Integer> facets = getFacets("/parent/par1");
-        assertEquals("Unexpected number of facets", 
actualAclPar1LabelCount.size(), facets.size());
+        assertEventually(() -> {
+            Map<String, Integer> facets = getFacets("/parent/par1");
+            assertEquals("Unexpected number of facets", 
actualAclPar1LabelCount.size(), facets.size());
 
         for (Map.Entry<String, Integer> facet : 
actualAclPar1LabelCount.entrySet()) {
             String facetLabel = facet.getKey();
             int facetCount = facets.get(facetLabel);
             float ratio = ((float) facetCount) / facet.getValue();
             assertTrue("Facet count for label: " + facetLabel + " is outside 
of 10% margin of error. " +
-                            "Expected: " + facet.getValue() + "; Got: " + 
facetCount + "; Ratio: " + ratio,
-                    Math.abs(ratio - 1) < 0.1);
-        }
+                                "Expected: " + facet.getValue() + "; Got: " + 
facetCount + "; Ratio: " + ratio,
+                        Math.abs(ratio - 1) < 0.1);
+            }
+        });
     }
 
     @Test
@@ -386,9 +354,7 @@ public class ElasticsearchFacetTest {
         session.save();
         createDataset(NUM_LEAF_NODES_FOR_LARGE_DATASET);
         qe = session.getWorkspace().getQueryManager();
-        assertEventually(() -> {
-            assertEquals(actualLabelCount, getFacets());
-        });
+        assertEventually(() -> assertEquals(actualLabelCount, getFacets()));
     }
 
     @Test
@@ -438,7 +404,7 @@ public class ElasticsearchFacetTest {
             pathCons = " AND ISDESCENDANTNODE('" + path + "')";
         }
         String query = "SELECT [rep:facet(foo)], [rep:facet(bar)] FROM 
[nt:base] WHERE [cons] = 'val'" + pathCons;
-        Query q = null;
+        Query q;
         QueryResult queryResult;
         try {
             q = qe.createQuery(query, Query.JCR_SQL2);

Modified: 
jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchFullTextAsyncTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchFullTextAsyncTest.java?rev=1877992&r1=1877991&r2=1877992&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchFullTextAsyncTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchFullTextAsyncTest.java
 Thu May 21 08:56:02 2020
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.elasticsearch;
 
-
 import org.apache.jackrabbit.oak.api.Tree;
 import 
org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder;
 import org.junit.Test;

Modified: 
jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchPropertyIndexTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchPropertyIndexTest.java?rev=1877992&r1=1877991&r2=1877992&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchPropertyIndexTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchPropertyIndexTest.java
 Thu May 21 08:56:02 2020
@@ -19,8 +19,6 @@ package org.apache.jackrabbit.oak.plugin
 import org.apache.jackrabbit.oak.api.Tree;
 import 
org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder;
 import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import java.util.Arrays;
 
@@ -96,9 +94,8 @@ public class ElasticsearchPropertyIndexT
         //make index
         IndexDefinitionBuilder builder = createIndex();
         builder.includedPaths("/test")
-                .evaluatePathRestrictions()
                 .indexRule("nt:base")
-                .property("nodeName", PROPDEF_PROP_NODE_NAME).propertyIndex();
+                .property("nodeName", PROPDEF_PROP_NODE_NAME);
         setIndex("test1", builder);
         root.commit();
 

Added: 
jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/index/ElasticsearchIndexHelperTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/index/ElasticsearchIndexHelperTest.java?rev=1877992&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/index/ElasticsearchIndexHelperTest.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/index/ElasticsearchIndexHelperTest.java
 Thu May 21 08:56:02 2020
@@ -0,0 +1,73 @@
+/*
+ * 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.elasticsearch.index;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import 
org.apache.jackrabbit.oak.plugins.index.elasticsearch.ElasticsearchIndexDefinition;
+import 
org.apache.jackrabbit.oak.plugins.index.elasticsearch.util.ElasticsearchIndexDefinitionBuilder;
+import 
org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.elasticsearch.client.indices.CreateIndexRequest;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class ElasticsearchIndexHelperTest {
+
+    @Test
+    public void multiRulesWithSamePropertyNames() throws IOException {
+        IndexDefinitionBuilder builder = new 
ElasticsearchIndexDefinitionBuilder();
+        IndexDefinitionBuilder.IndexRule indexRuleA = 
builder.indexRule("typeA");
+        indexRuleA.property("foo").type("String");
+        IndexDefinitionBuilder.IndexRule indexRuleB = 
builder.indexRule("typeB");
+        indexRuleB.property("foo").type("String").analyzed();
+        NodeState nodeState = builder.build();
+
+        ElasticsearchIndexDefinition definition =
+                new ElasticsearchIndexDefinition(nodeState, nodeState, "path", 
"prefix");
+
+        CreateIndexRequest request = 
ElasticsearchIndexHelper.createIndexRequest(definition);
+
+        ObjectMapper mapper = new ObjectMapper();
+        Map<String, Object> jsonMap = 
mapper.readValue(request.mappings().streamInput(), Map.class);
+
+        Map fooMapping = (Map) ((Map) jsonMap.get("properties")).get("foo");
+        assertThat(fooMapping.get("type"), is("text"));
+        Map fooKeywordMapping = (Map) ((Map) 
fooMapping.get("fields")).get("keyword");
+        assertThat(fooKeywordMapping.get("type"), is("keyword"));
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void multiRulesWithSamePropertyNamesDifferentTypes() throws 
IOException {
+        IndexDefinitionBuilder builder = new 
ElasticsearchIndexDefinitionBuilder();
+        IndexDefinitionBuilder.IndexRule indexRuleA = 
builder.indexRule("typeA");
+        indexRuleA.property("foo").type("String");
+        IndexDefinitionBuilder.IndexRule indexRuleB = 
builder.indexRule("typeB");
+        indexRuleB.property("foo").type("Boolean");
+        NodeState nodeState = builder.build();
+
+        ElasticsearchIndexDefinition definition =
+                new ElasticsearchIndexDefinition(nodeState, nodeState, "path", 
"prefix");
+
+        ElasticsearchIndexHelper.createIndexRequest(definition);
+    }
+
+}

Propchange: 
jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/index/ElasticsearchIndexHelperTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/index/ElasticsearchIndexWriterTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/index/ElasticsearchIndexWriterTest.java?rev=1877992&r1=1877991&r2=1877992&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/index/ElasticsearchIndexWriterTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/index/ElasticsearchIndexWriterTest.java
 Thu May 21 08:56:02 2020
@@ -27,9 +27,11 @@ import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
-import java.io.IOException;
-import java.net.URLEncoder;
+import java.util.Random;
 
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.number.OrderingComparison.lessThan;
 import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
@@ -56,31 +58,31 @@ public class ElasticsearchIndexWriterTes
     }
 
     @Test
-    public void singleUpdateDocument() throws IOException {
+    public void singleUpdateDocument() {
         indexWriter.updateDocument("/foo", new ElasticsearchDocument("/foo"));
 
         ArgumentCaptor<IndexRequest> acIndexRequest = 
ArgumentCaptor.forClass(IndexRequest.class);
         verify(bulkProcessorMock).add(acIndexRequest.capture());
 
         IndexRequest request = acIndexRequest.getValue();
-        assertEquals(request.index(), "test-index");
-        assertEquals(request.id(), URLEncoder.encode("/foo", "UTF-8"));
+        assertEquals("test-index", request.index());
+        assertEquals("/foo", request.id());
     }
 
     @Test
-    public void singleDeleteDocument() throws IOException {
+    public void singleDeleteDocument() {
         indexWriter.deleteDocuments("/bar");
 
         ArgumentCaptor<DeleteRequest> acDeleteRequest = 
ArgumentCaptor.forClass(DeleteRequest.class);
         verify(bulkProcessorMock).add(acDeleteRequest.capture());
 
         DeleteRequest request = acDeleteRequest.getValue();
-        assertEquals(request.index(), "test-index");
-        assertEquals(request.id(), URLEncoder.encode("/bar", "UTF-8"));
+        assertEquals("test-index", request.index());
+        assertEquals("/bar", request.id());
     }
 
     @Test
-    public void multiRequests() throws IOException {
+    public void multiRequests() {
         indexWriter.updateDocument("/foo", new ElasticsearchDocument("/foo"));
         indexWriter.updateDocument("/bar", new ElasticsearchDocument("/bar"));
         indexWriter.deleteDocuments("/foo");
@@ -93,7 +95,29 @@ public class ElasticsearchIndexWriterTes
     }
 
     @Test
-    public void closeBulkProcessor() throws IOException {
+    public void longDocumentPath() {
+        int leftLimit = 48; // '0'
+        int rightLimit = 122; // char '~'
+        int targetStringLength = 1024;
+        final Random random = new Random(42);
+
+        String generatedPath = random.ints(leftLimit, rightLimit + 1)
+                .limit(targetStringLength)
+                .collect(StringBuilder::new, StringBuilder::appendCodePoint, 
StringBuilder::append)
+                .toString();
+
+        indexWriter.updateDocument(generatedPath, new 
ElasticsearchDocument(generatedPath));
+
+        ArgumentCaptor<IndexRequest> acIndexRequest = 
ArgumentCaptor.forClass(IndexRequest.class);
+        verify(bulkProcessorMock).add(acIndexRequest.capture());
+
+        IndexRequest request = acIndexRequest.getValue();
+        assertThat(request.id(), not(generatedPath));
+        assertThat(request.id().length(), lessThan(513));
+    }
+
+    @Test
+    public void closeBulkProcessor() {
         indexWriter.close(System.currentTimeMillis());
         verify(bulkProcessorMock).close();
     }

Modified: 
jackrabbit/oak/trunk/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/IndexDefinition.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/IndexDefinition.java?rev=1877992&r1=1877991&r2=1877992&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/IndexDefinition.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/IndexDefinition.java
 Thu May 21 08:56:02 2020
@@ -1029,6 +1029,18 @@ public class IndexDefinition implements
             return baseNodeType;
         }
 
+        /**
+         * Returns all the configured {@code PropertyDefinition}s for this 
{@code IndexRule}.
+         *
+         * In case of a pure nodetype index we just return primaryType and 
mixins.
+         *
+         * @return an {@code Iterable} of {@code PropertyDefinition}s.
+         * @see IndexDefinition#isPureNodeTypeIndex()
+         */
+        public Iterable<PropertyDefinition> getProperties() {
+            return propConfigs.values();
+        }
+
         public List<PropertyDefinition> getNullCheckEnabledProperties() {
             return nullCheckEnabledProperties;
         }


Reply via email to