You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ch...@apache.org on 2017/07/10 08:46:25 UTC

svn commit: r1801419 - in /jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index: AbstractIndexCommandTest.java IndexCommandIT.java

Author: chetanm
Date: Mon Jul 10 08:46:25 2017
New Revision: 1801419

URL: http://svn.apache.org/viewvc?rev=1801419&view=rev
Log:
OAK-6271 - Support for importing index files

Refactor testcase to enable use of base setup for other tests

Added:
    jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/AbstractIndexCommandTest.java   (with props)
Modified:
    jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IndexCommandIT.java

Added: jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/AbstractIndexCommandTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/AbstractIndexCommandTest.java?rev=1801419&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/AbstractIndexCommandTest.java (added)
+++ jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/AbstractIndexCommandTest.java Mon Jul 10 08:46:25 2017
@@ -0,0 +1,94 @@
+/*
+ * 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.index;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.jcr.Node;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
+import org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder;
+import org.junit.After;
+import org.junit.Rule;
+import org.junit.rules.TemporaryFolder;
+
+import static org.apache.jackrabbit.commons.JcrUtils.getOrCreateByPath;
+
+public class AbstractIndexCommandTest {
+    @Rule
+    public final TemporaryFolder temporaryFolder = new TemporaryFolder(new File("target"));
+    protected RepositoryFixture fixture;
+
+    @After
+    public void cleaup() throws IOException {
+        if (fixture != null) {
+            fixture.close();
+        }
+    }
+
+    protected void createTestData(boolean asyncIndex) throws IOException, RepositoryException {
+        if (fixture == null) {
+            this.fixture = new RepositoryFixture(temporaryFolder.newFolder());
+        }
+        indexIndexDefinitions();
+        createLuceneIndex(asyncIndex);
+        addTestContent();
+    }
+
+    private void indexIndexDefinitions() throws IOException, RepositoryException {
+        //By default Oak index definitions are not indexed
+        //so add them to declaringNodeTypes
+        Session session = fixture.getAdminSession();
+        Node nodeType = session.getNode("/oak:index/nodetype");
+        nodeType.setProperty(IndexConstants.DECLARING_NODE_TYPES, new String[] {"oak:QueryIndexDefinition"}, PropertyType.NAME);
+        session.save();
+        session.logout();
+    }
+
+    private void addTestContent() throws IOException, RepositoryException {
+        Session session = fixture.getAdminSession();
+        for (int i = 0; i < 100; i++) {
+            getOrCreateByPath("/testNode/a"+i,
+                    "oak:Unstructured", session).setProperty("foo", "bar");
+        }
+        session.save();
+        session.logout();
+    }
+
+    private void createLuceneIndex(boolean asyncIndex) throws IOException, RepositoryException {
+        IndexDefinitionBuilder idxBuilder = new IndexDefinitionBuilder();
+        if (!asyncIndex) {
+            idxBuilder.noAsync();
+        }
+        idxBuilder.indexRule("nt:base").property("foo").propertyIndex();
+
+        Session session = fixture.getAdminSession();
+        Node fooIndex = getOrCreateByPath("/oak:index/fooIndex",
+                "oak:QueryIndexDefinition", session);
+
+        idxBuilder.build(fooIndex);
+        session.save();
+        session.logout();
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/AbstractIndexCommandTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IndexCommandIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IndexCommandIT.java?rev=1801419&r1=1801418&r2=1801419&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IndexCommandIT.java (original)
+++ jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IndexCommandIT.java Mon Jul 10 08:46:25 2017
@@ -20,14 +20,9 @@
 package org.apache.jackrabbit.oak.index;
 
 import java.io.File;
-import java.io.IOException;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 
-import javax.jcr.Node;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
 
 import com.google.common.io.Files;
 import org.apache.jackrabbit.oak.api.PropertyState;
@@ -35,15 +30,10 @@ import org.apache.jackrabbit.oak.api.Typ
 import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
 import org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexRootDirectory;
 import org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexDir;
-import org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
-import org.junit.After;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
 
 import static java.nio.charset.Charset.defaultCharset;
-import static org.apache.jackrabbit.commons.JcrUtils.getOrCreateByPath;
 import static org.apache.jackrabbit.oak.spi.state.NodeStateUtils.getNode;
 import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.CoreMatchers.not;
@@ -52,18 +42,7 @@ import static org.junit.Assert.assertFal
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
-public class IndexCommandIT {
-
-    @Rule
-    public final TemporaryFolder temporaryFolder = new TemporaryFolder(new File("target"));
-    private RepositoryFixture fixture;
-
-    @After
-    public void cleaup() throws IOException {
-        if (fixture != null) {
-            fixture.close();
-        }
-    }
+public class IndexCommandIT extends AbstractIndexCommandTest {
 
     @Test
     public void dumpStatsAndInfo() throws Exception{
@@ -241,46 +220,4 @@ public class IndexCommandIT {
         assertEquals(1, idxDirs.size());
     }
 
-    private void createTestData(boolean asyncIndex) throws IOException, RepositoryException {
-        fixture = new RepositoryFixture(temporaryFolder.newFolder());
-        indexIndexDefinitions();
-        createLuceneIndex(asyncIndex);
-        addTestContent();
-    }
-
-    private void indexIndexDefinitions() throws IOException, RepositoryException {
-        //By default Oak index definitions are not indexed
-        //so add them to declaringNodeTypes
-        Session session = fixture.getAdminSession();
-        Node nodeType = session.getNode("/oak:index/nodetype");
-        nodeType.setProperty(IndexConstants.DECLARING_NODE_TYPES, new String[] {"oak:QueryIndexDefinition"}, PropertyType.NAME);
-        session.save();
-        session.logout();
-    }
-
-    private void addTestContent() throws IOException, RepositoryException {
-        Session session = fixture.getAdminSession();
-        for (int i = 0; i < 100; i++) {
-            getOrCreateByPath("/testNode/a"+i,
-                    "oak:Unstructured", session).setProperty("foo", "bar");
-        }
-        session.save();
-        session.logout();
-    }
-
-    private void createLuceneIndex(boolean asyncIndex) throws IOException, RepositoryException {
-        IndexDefinitionBuilder idxBuilder = new IndexDefinitionBuilder();
-        if (!asyncIndex) {
-            idxBuilder.noAsync();
-        }
-        idxBuilder.indexRule("nt:base").property("foo").propertyIndex();
-
-        Session session = fixture.getAdminSession();
-        Node fooIndex = getOrCreateByPath("/oak:index/fooIndex",
-                "oak:QueryIndexDefinition", session);
-
-        idxBuilder.build(fooIndex);
-        session.save();
-        session.logout();
-    }
 }
\ No newline at end of file