Author: chetanm
Date: Tue May 16 14:56:04 2017
New Revision: 1795321
URL: http://svn.apache.org/viewvc?rev=1795321&view=rev
Log:
OAK-6224 - Enable dumping index definitions and stats via oak-run
-- Initial setup for index command
-- Added dependency on felix inventory api and redirected
test output to text file
-- Support for dumping stats and index definitions
Added:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexCommand.java
(with props)
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexHelper.java
(with props)
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexOptions.java
(with props)
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/PrinterDumper.java
(with props)
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IndexCommandIT.java
(with props)
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/RepositoryFixture.java
(with props)
Modified:
jackrabbit/oak/trunk/oak-run/pom.xml
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/AvailableModes.java
Modified: jackrabbit/oak/trunk/oak-run/pom.xml
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/pom.xml?rev=1795321&r1=1795320&r2=1795321&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-run/pom.xml Tue May 16 14:56:04 2017
@@ -171,6 +171,12 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <configuration>
+ <redirectTestOutputToFile>true</redirectTestOutputToFile>
+ </configuration>
+ </plugin>
</plugins>
</build>
@@ -295,6 +301,11 @@
<artifactId>tika-core</artifactId>
<version>1.5</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.inventory</artifactId>
+ <version>1.0.4</version>
+ </dependency>
<!-- Findbugs annotations -->
<dependency>
Added:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexCommand.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexCommand.java?rev=1795321&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexCommand.java
(added)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexCommand.java
Tue May 16 14:56:04 2017
@@ -0,0 +1,97 @@
+/*
+ * 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 java.nio.file.Path;
+
+import joptsimple.OptionParser;
+import joptsimple.OptionSet;
+import org.apache.felix.inventory.Format;
+import org.apache.jackrabbit.oak.console.NodeStoreFixture;
+import org.apache.jackrabbit.oak.run.cli.NodeStoreFixtureProvider;
+import org.apache.jackrabbit.oak.run.cli.Options;
+import org.apache.jackrabbit.oak.run.commons.Command;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+
+public class IndexCommand implements Command {
+
+ public static final String INDEX_DEFINITIONS_JSON =
"index-definitions.json";
+ public static final String INDEX_INFO_TXT = "index-info.txt";
+ private File info;
+ private File definitions;
+
+ @Override
+ public void execute(String... args) throws Exception {
+ OptionParser parser = new OptionParser();
+
+ Options opts = new Options();
+ opts.registerOptionsFactory(IndexOptions.FACTORY);
+
+ opts.parseAndConfigure(parser, args);
+
+ IndexOptions indexOpts = opts.getOptionBean(IndexOptions.class);
+
+ try (NodeStoreFixture fixture = NodeStoreFixtureProvider.create(opts))
{
+ execute(fixture.getStore(), indexOpts);
+ tellReportPaths();
+ }
+ }
+
+ private void tellReportPaths() {
+ if (info != null) {
+ System.out.printf("Index stats stored at %s%n", getPath(info));
+ }
+
+ if (definitions != null) {
+ System.out.printf("Index definitions stored at %s%n",
getPath(definitions));
+ }
+ }
+
+ private void execute(NodeStore store, IndexOptions indexOpts) throws
IOException {
+ IndexHelper indexHelper = new IndexHelper(store,
indexOpts.getOutDir(), indexOpts.getWorkDir());
+
+ dumpIndexStats(indexOpts, indexHelper);
+ dumpIndexDefinitions(indexOpts, indexHelper);
+ }
+
+ private void dumpIndexDefinitions(IndexOptions indexOpts, IndexHelper
indexHelper) throws IOException {
+ if (indexOpts.dumpDefinitions()) {
+ PrinterDumper dumper = new
PrinterDumper(indexHelper.getOutputDir(), INDEX_DEFINITIONS_JSON,
+ false, Format.JSON, indexHelper.getIndexDefnPrinter());
+ dumper.dump();
+ definitions = dumper.getOutFile();
+ }
+ }
+
+ private void dumpIndexStats(IndexOptions indexOpts, IndexHelper
indexHelper) throws IOException {
+ if (indexOpts.dumpStats()) {
+ PrinterDumper dumper = new
PrinterDumper(indexHelper.getOutputDir(), INDEX_INFO_TXT,
+ true, Format.TEXT, indexHelper.getIndexPrinter());
+ dumper.dump();
+ info = dumper.getOutFile();
+ }
+ }
+
+ private static Path getPath(File file) {
+ return file.toPath().normalize().toAbsolutePath();
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexHelper.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexHelper.java?rev=1795321&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexHelper.java
(added)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexHelper.java
Tue May 16 14:56:04 2017
@@ -0,0 +1,88 @@
+/*
+ * 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 org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoService;
+import org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoServiceImpl;
+import org.apache.jackrabbit.oak.plugins.index.IndexInfoService;
+import org.apache.jackrabbit.oak.plugins.index.IndexInfoServiceImpl;
+import org.apache.jackrabbit.oak.plugins.index.IndexPathService;
+import org.apache.jackrabbit.oak.plugins.index.IndexPathServiceImpl;
+import
org.apache.jackrabbit.oak.plugins.index.inventory.IndexDefinitionPrinter;
+import org.apache.jackrabbit.oak.plugins.index.inventory.IndexPrinter;
+import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexInfoProvider;
+import
org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexInfoProvider;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+
+class IndexHelper {
+ private final NodeStore store;
+ private final File outputDir;
+ private final File workDir;
+ private IndexInfoServiceImpl indexInfoService;
+ private IndexPathService indexPathService;
+ private AsyncIndexInfoService asyncIndexInfoService;
+
+ IndexHelper(NodeStore store, File outputDir, File workDir) {
+ this.store = store;
+ this.outputDir = outputDir;
+ this.workDir = workDir;
+ }
+
+ public File getOutputDir() {
+ return outputDir;
+ }
+
+ public IndexPrinter getIndexPrinter() {
+ return new IndexPrinter(getIndexInfoService(),
getAsyncIndexInfoService());
+ }
+
+ public IndexDefinitionPrinter getIndexDefnPrinter() {
+ return new IndexDefinitionPrinter(store, getIndexPathService());
+ }
+
+ private IndexPathService getIndexPathService() {
+ if (indexPathService == null) {
+ indexPathService = new IndexPathServiceImpl(store);
+ }
+ return indexPathService;
+ }
+
+ private AsyncIndexInfoService getAsyncIndexInfoService() {
+ if (asyncIndexInfoService == null) {
+ asyncIndexInfoService = new AsyncIndexInfoServiceImpl(store);
+ }
+ return asyncIndexInfoService;
+ }
+
+ private IndexInfoService getIndexInfoService() {
+ if (indexInfoService == null) {
+ indexInfoService = new IndexInfoServiceImpl(store,
getIndexPathService());
+ bindIndexInfoProviders(indexInfoService);
+ }
+ return indexInfoService;
+ }
+
+ private void bindIndexInfoProviders(IndexInfoServiceImpl indexInfoService)
{
+ indexInfoService.bindInfoProviders(new LuceneIndexInfoProvider(store,
getAsyncIndexInfoService(), workDir));
+ indexInfoService.bindInfoProviders(new
PropertyIndexInfoProvider(store));
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexOptions.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexOptions.java?rev=1795321&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexOptions.java
(added)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexOptions.java
Tue May 16 14:56:04 2017
@@ -0,0 +1,79 @@
+/*
+ * 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 joptsimple.OptionParser;
+import joptsimple.OptionSet;
+import joptsimple.OptionSpec;
+import org.apache.commons.io.FileUtils;
+import org.apache.jackrabbit.oak.run.cli.OptionsBean;
+import org.apache.jackrabbit.oak.run.cli.OptionsBeanFactory;
+
+public class IndexOptions implements OptionsBean {
+
+ public static final OptionsBeanFactory FACTORY = new OptionsBeanFactory() {
+ @Override
+ public OptionsBean newInstance(OptionParser parser) {
+ return new IndexOptions(parser);
+ }
+ };
+
+ private final OptionSpec<File> workDirOpt;
+ private final OptionSpec<File> outputDirOpt;
+ private final OptionSpec<Void> stats;
+ private final OptionSpec<Void> definitions;
+ private OptionSet options;
+
+
+ public IndexOptions(OptionParser parser){
+ workDirOpt = parser.accepts("index-work-dir", "Work directory used for
storing temp files")
+ .withRequiredArg().ofType(File.class).defaultsTo(new
File("target"));
+ outputDirOpt = parser.accepts("index-out-dir", "Directory used for
output files")
+ .withRequiredArg().ofType(File.class).defaultsTo(new
File("."));
+ stats = parser.accepts("index-info", "Collects and dumps information
related to the indexes");
+ definitions = parser.accepts("index-definitions", "Collects and dumps
index definitions");
+ }
+
+ @Override
+ public void configure(OptionSet options) {
+ this.options = options;
+ }
+
+ public File getWorkDir() throws IOException {
+ File workDir = workDirOpt.value(options);
+ FileUtils.forceMkdir(workDir);
+ return workDir;
+ }
+
+ public File getOutDir() {
+ return outputDirOpt.value(options);
+ }
+
+ public boolean dumpStats(){
+ return options.has(stats);
+ }
+
+ public boolean dumpDefinitions(){
+ return options.has(definitions);
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexOptions.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/PrinterDumper.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/PrinterDumper.java?rev=1795321&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/PrinterDumper.java
(added)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/PrinterDumper.java
Tue May 16 14:56:04 2017
@@ -0,0 +1,68 @@
+/*
+ * 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.BufferedOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.output.TeeOutputStream;
+import org.apache.felix.inventory.Format;
+import org.apache.felix.inventory.InventoryPrinter;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+class PrinterDumper {
+ private final File outDir;
+ private final String fileName;
+ private final boolean dumpToSysOut;
+ private final Format format;
+ private final InventoryPrinter printer;
+ private File outFile;
+
+ public PrinterDumper(File outDir, String fileName, boolean dumpToSysOut,
Format format, InventoryPrinter printer) {
+ this.outDir = outDir;
+ this.fileName = fileName;
+ this.dumpToSysOut = dumpToSysOut;
+ this.format = format;
+ this.printer = printer;
+ }
+
+ public void dump() throws IOException {
+ try (OutputStream os = newOutput()) {
+ OutputStream writerStream = dumpToSysOut ? new TeeOutputStream(os,
System.out) : os;
+ PrintWriter pw = new PrintWriter(writerStream);
+ printer.print(pw, format, false);
+ pw.flush();
+ }
+ }
+
+ public File getOutFile() {
+ return checkNotNull(outFile);
+ }
+
+ private OutputStream newOutput() throws IOException {
+ outFile = new File(outDir, fileName);
+ return new BufferedOutputStream(FileUtils.openOutputStream(outFile));
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/PrinterDumper.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/AvailableModes.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/AvailableModes.java?rev=1795321&r1=1795320&r2=1795321&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/AvailableModes.java
(original)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/AvailableModes.java
Tue May 16 14:56:04 2017
@@ -20,6 +20,7 @@
package org.apache.jackrabbit.oak.run;
import com.google.common.collect.ImmutableMap;
+import org.apache.jackrabbit.oak.index.IndexCommand;
import org.apache.jackrabbit.oak.run.commons.Command;
import org.apache.jackrabbit.oak.run.commons.Modes;
@@ -52,5 +53,6 @@ public final class AvailableModes {
.put("tika", new TikaCommand())
.put("upgrade", new UpgradeCommand())
.put("unlockupgrade", new UnlockUpgradeCommand())
+ .put("index", new IndexCommand())
.build());
}
Added:
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=1795321&view=auto
==============================================================================
---
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/IndexCommandIT.java
Tue May 16 14:56:04 2017
@@ -0,0 +1,126 @@
+/*
+ * 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 com.google.common.io.Files;
+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.Test;
+import org.junit.rules.TemporaryFolder;
+
+import static java.nio.charset.Charset.defaultCharset;
+import static org.apache.jackrabbit.commons.JcrUtils.getOrCreateByPath;
+import static org.hamcrest.CoreMatchers.containsString;
+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();
+ }
+ }
+
+ @Test
+ public void dumpStatsAndInfo() throws Exception{
+ createTestData();
+ //Close the repository so as all changes are flushed
+ fixture.close();
+
+ IndexCommand command = new IndexCommand();
+
+ File outDir = temporaryFolder.newFolder();
+ String[] args = {
+ "-index-work-dir=" +
temporaryFolder.newFolder().getAbsolutePath(),
+ "-index-out-dir=" + outDir.getAbsolutePath(),
+ "-index-info",
+ "-index-definitions",
+ fixture.getDir().getAbsolutePath()
+ };
+
+ command.execute(args);
+
+ File info = new File(outDir, IndexCommand.INDEX_INFO_TXT);
+ File defns = new File(outDir, IndexCommand.INDEX_DEFINITIONS_JSON);
+
+ assertTrue(info.exists());
+ assertTrue(defns.exists());
+
+ assertThat(Files.toString(info, defaultCharset()),
containsString("/oak:index/uuid"));
+ assertThat(Files.toString(info, defaultCharset()),
containsString("/oak:index/fooIndex"));
+ }
+
+ private void createTestData() throws IOException, RepositoryException {
+ fixture = new RepositoryFixture(temporaryFolder.newFolder());
+ indexIndexDefinitions();
+ createLuceneIndex();
+ 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() throws IOException, RepositoryException {
+ IndexDefinitionBuilder idxBuilder = new IndexDefinitionBuilder();
+ 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
Propchange:
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IndexCommandIT.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/RepositoryFixture.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/RepositoryFixture.java?rev=1795321&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/RepositoryFixture.java
(added)
+++
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/RepositoryFixture.java
Tue May 16 14:56:04 2017
@@ -0,0 +1,114 @@
+/*
+ * 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.Closeable;
+import java.io.File;
+import java.io.IOException;
+
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.jackrabbit.api.JackrabbitRepository;
+import org.apache.jackrabbit.oak.Oak;
+import org.apache.jackrabbit.oak.jcr.Jcr;
+import
org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorProvider;
+import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProvider;
+import org.apache.jackrabbit.oak.segment.SegmentNodeStoreBuilders;
+import org.apache.jackrabbit.oak.segment.file.FileStore;
+import org.apache.jackrabbit.oak.segment.file.FileStoreBuilder;
+import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
+import org.apache.jackrabbit.oak.spi.commit.Observer;
+import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+
+public class RepositoryFixture implements Closeable {
+ private final File dir;
+ private Repository repository;
+ private FileStore fileStore;
+ private NodeStore nodeStore;
+
+ public RepositoryFixture(File dir) {
+ this.dir = dir;
+ }
+
+ public Repository getRepository() throws IOException {
+ if (repository == null) {
+ repository = createRepository();
+ }
+ return repository;
+ }
+
+ public Session getAdminSession() throws IOException, RepositoryException {
+ return getRepository().login(new SimpleCredentials("admin",
"admin".toCharArray()));
+ }
+
+ public NodeStore getNodeStore() throws IOException {
+ if (nodeStore == null) {
+ nodeStore = createNodeStore();
+ }
+ return nodeStore;
+ }
+
+ @Override
+ public void close() throws IOException {
+ if (repository instanceof JackrabbitRepository) {
+ ((JackrabbitRepository) repository).shutdown();
+ repository = null;
+ }
+
+ if (fileStore != null) {
+ fileStore.close();
+ fileStore = null;
+ }
+ }
+
+ public File getDir() {
+ return dir;
+ }
+
+ private Repository createRepository() throws IOException {
+ Oak oak = new Oak(getNodeStore());
+ configureLuceneProvider(oak);
+
+ Jcr jcr = new Jcr(oak);
+ return jcr.createRepository();
+ }
+
+ private void configureLuceneProvider(Oak oak) throws IOException {
+ LuceneIndexEditorProvider ep = new LuceneIndexEditorProvider();
+ LuceneIndexProvider provider = new LuceneIndexProvider();
+ oak.with((QueryIndexProvider) provider)
+ .with((Observer) provider)
+ .with(ep);
+ }
+
+ private NodeStore createNodeStore() throws IOException {
+ FileStoreBuilder builder = FileStoreBuilder.fileStoreBuilder(dir);
+ try {
+ fileStore = builder.build();
+ } catch (InvalidFileStoreVersionException e) {
+ throw new IOException(e);
+ }
+ return SegmentNodeStoreBuilders.builder(fileStore).build();
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/RepositoryFixture.java
------------------------------------------------------------------------------
svn:eol-style = native