diff --git a/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticFullTextWithGlobalIndexSearchTest.java b/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticFullTextWithGlobalIndexSearchTest.java index 5f3b0fe..7670106 100644 --- a/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticFullTextWithGlobalIndexSearchTest.java +++ b/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticFullTextWithGlobalIndexSearchTest.java @@ -23,6 +23,7 @@ package org.apache.jackrabbit.oak.benchmark; import org.apache.commons.io.FileUtils; import org.apache.jackrabbit.oak.Oak; import org.apache.jackrabbit.oak.benchmark.util.ElasticGlobalInitializer; +import org.apache.jackrabbit.oak.benchmark.util.TestHelper; import org.apache.jackrabbit.oak.fixture.JcrCreator; import org.apache.jackrabbit.oak.fixture.OakRepositoryFixture; import org.apache.jackrabbit.oak.fixture.RepositoryFixture; @@ -40,15 +41,16 @@ import java.io.File; public class ElasticFullTextWithGlobalIndexSearchTest extends SearchTest { private ElasticsearchConnection coordinate; - private final String ELASTIC_GLOBAL_INDEX = "elasticGlobal" + System.nanoTime(); + private String ELASTIC_GLOBAL_INDEX; - public ElasticFullTextWithGlobalIndexSearchTest(File dump, boolean flat, boolean doReport, Boolean storageEnabled, ElasticsearchConnection coordinate) { + ElasticFullTextWithGlobalIndexSearchTest(File dump, boolean flat, boolean doReport, Boolean storageEnabled, ElasticsearchConnection coordinate) { super(dump, flat, doReport, storageEnabled); this.coordinate = coordinate; } @Override protected Repository[] createRepository(RepositoryFixture fixture) throws Exception { + ELASTIC_GLOBAL_INDEX = TestHelper.getUniqueIndexName("elasticGlobal"); if (fixture instanceof OakRepositoryFixture) { return ((OakRepositoryFixture) fixture).setUpCluster(1, new JcrCreator() { @Override diff --git a/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticFullTextWithoutGlobalIndexSearchTest.java b/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticFullTextWithoutGlobalIndexSearchTest.java index 26f05c8..6035e95 100644 --- a/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticFullTextWithoutGlobalIndexSearchTest.java +++ b/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticFullTextWithoutGlobalIndexSearchTest.java @@ -21,6 +21,7 @@ package org.apache.jackrabbit.oak.benchmark; import org.apache.commons.io.FileUtils; import org.apache.jackrabbit.oak.Oak; +import org.apache.jackrabbit.oak.benchmark.util.TestHelper; import org.apache.jackrabbit.oak.fixture.JcrCreator; import org.apache.jackrabbit.oak.fixture.OakRepositoryFixture; import org.apache.jackrabbit.oak.fixture.RepositoryFixture; @@ -42,7 +43,7 @@ public class ElasticFullTextWithoutGlobalIndexSearchTest extends SearchTest { private ElasticsearchConnection coordinate; - public ElasticFullTextWithoutGlobalIndexSearchTest(File dump, boolean flat, boolean doReport, Boolean storageEnabled, ElasticsearchConnection coordinate) { + ElasticFullTextWithoutGlobalIndexSearchTest(File dump, boolean flat, boolean doReport, Boolean storageEnabled, ElasticsearchConnection coordinate) { super(dump, flat, doReport, storageEnabled); this.coordinate = coordinate; } @@ -60,7 +61,7 @@ public class ElasticFullTextWithoutGlobalIndexSearchTest extends SearchTest { .with(indexProvider) .with(new PropertyIndexEditorProvider()) .with(new NodeTypeIndexProvider()) - .with(new PropertyFullTextTest.FullTextPropertyInitialiser("elasticText" + System.nanoTime(), of("text"), + .with(new PropertyFullTextTest.FullTextPropertyInitialiser(TestHelper.getUniqueIndexName("elasticText"), of("text"), ElasticsearchIndexDefinition.TYPE_ELASTICSEARCH).nodeScope().analyzed()); return new Jcr(oak); } diff --git a/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyFTIndexedContentAvailability.java b/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyFTIndexedContentAvailability.java index a9d5f05..a3e6dc8 100644 --- a/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyFTIndexedContentAvailability.java +++ b/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyFTIndexedContentAvailability.java @@ -20,6 +20,7 @@ package org.apache.jackrabbit.oak.benchmark; import org.apache.commons.io.FileUtils; import org.apache.jackrabbit.oak.Oak; import org.apache.jackrabbit.oak.benchmark.util.ElasticGlobalInitializer; +import org.apache.jackrabbit.oak.benchmark.util.TestHelper; import org.apache.jackrabbit.oak.benchmark.wikipedia.WikipediaImport; import org.apache.jackrabbit.oak.fixture.JcrCreator; import org.apache.jackrabbit.oak.fixture.OakRepositoryFixture; @@ -66,7 +67,7 @@ public class ElasticPropertyFTIndexedContentAvailability extends PropertyFullTex private static final Logger LOG = LoggerFactory.getLogger(ElasticPropertyFTIndexedContentAvailability.class); private String currentFixtureName; private ElasticsearchConnection coordinate; - private final String ELASTIC_GLOBAL_INDEX = "elasticGlobal" + System.nanoTime(); + private String ELASTIC_GLOBAL_INDEX; @Override public String getCurrentFixtureName() { @@ -79,7 +80,7 @@ public class ElasticPropertyFTIndexedContentAvailability extends PropertyFullTex } - public ElasticPropertyFTIndexedContentAvailability(final File dump, + ElasticPropertyFTIndexedContentAvailability(final File dump, final boolean flat, final boolean doReport, final Boolean storageEnabled, ElasticsearchConnection coordinate) { @@ -89,6 +90,7 @@ public class ElasticPropertyFTIndexedContentAvailability extends PropertyFullTex @Override protected Repository[] createRepository(RepositoryFixture fixture) throws Exception { + ELASTIC_GLOBAL_INDEX = TestHelper.getUniqueIndexName("elasticGlobal"); if (fixture instanceof OakRepositoryFixture) { currentFixtureName = fixture.toString(); return ((OakRepositoryFixture) fixture).setUpCluster(1, new JcrCreator() { @@ -101,7 +103,7 @@ public class ElasticPropertyFTIndexedContentAvailability extends PropertyFullTex .with(indexProvider) .with((new ElasticGlobalInitializer(ELASTIC_GLOBAL_INDEX, storageEnabled)).async()) // the WikipediaImporter set a property `title` - .with(new FullTextPropertyInitialiser("elasticTitle" + System.nanoTime(), of("title"), + .with(new FullTextPropertyInitialiser(TestHelper.getUniqueIndexName("elasticTitle"), of("title"), ElasticsearchIndexDefinition.TYPE_ELASTICSEARCH).async()) .withAsyncIndexing("async", 5); return new Jcr(oak); diff --git a/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyFTSeparatedIndexedContentAvailability.java b/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyFTSeparatedIndexedContentAvailability.java index 2c77c46..2859fe3 100644 --- a/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyFTSeparatedIndexedContentAvailability.java +++ b/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyFTSeparatedIndexedContentAvailability.java @@ -22,6 +22,7 @@ package org.apache.jackrabbit.oak.benchmark; import org.apache.commons.io.FileUtils; import org.apache.jackrabbit.oak.Oak; import org.apache.jackrabbit.oak.benchmark.util.ElasticGlobalInitializer; +import org.apache.jackrabbit.oak.benchmark.util.TestHelper; import org.apache.jackrabbit.oak.fixture.JcrCreator; import org.apache.jackrabbit.oak.fixture.OakRepositoryFixture; import org.apache.jackrabbit.oak.fixture.RepositoryFixture; @@ -45,9 +46,9 @@ public class ElasticPropertyFTSeparatedIndexedContentAvailability extends Proper private String currentFixtureName; private ElasticsearchConnection coordinate; - private final String ELASTIC_GLOBAL_INDEX = "elasticGlobal" + System.nanoTime(); + private String ELASTIC_GLOBAL_INDEX; - public ElasticPropertyFTSeparatedIndexedContentAvailability(final File dump, + ElasticPropertyFTSeparatedIndexedContentAvailability(final File dump, final boolean flat, final boolean doReport, final Boolean storageEnabled, ElasticsearchConnection coordinate) { @@ -67,6 +68,7 @@ public class ElasticPropertyFTSeparatedIndexedContentAvailability extends Proper @Override protected Repository[] createRepository(RepositoryFixture fixture) throws Exception { + ELASTIC_GLOBAL_INDEX = TestHelper.getUniqueIndexName("elasticGlobal"); if (fixture instanceof OakRepositoryFixture) { currentFixtureName = fixture.toString(); return ((OakRepositoryFixture) fixture).setUpCluster(1, new JcrCreator() { @@ -79,7 +81,7 @@ public class ElasticPropertyFTSeparatedIndexedContentAvailability extends Proper .with(indexProvider) .with((new ElasticGlobalInitializer(ELASTIC_GLOBAL_INDEX, storageEnabled)).async("fulltext-async")) // the WikipediaImporter set a property `title` - .with(new FullTextPropertyInitialiser("elasticTitle" + System.nanoTime(), of("title"), + .with(new FullTextPropertyInitialiser(TestHelper.getUniqueIndexName("elasticTitle"), of("title"), ElasticsearchIndexDefinition.TYPE_ELASTICSEARCH).async()) .withAsyncIndexing("async", 5) .withAsyncIndexing("fulltext-async", 5); diff --git a/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyTextSearchTest.java b/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyTextSearchTest.java index 7f84610..95179f5 100644 --- a/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyTextSearchTest.java +++ b/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/ElasticPropertyTextSearchTest.java @@ -21,6 +21,7 @@ package org.apache.jackrabbit.oak.benchmark; import org.apache.commons.io.FileUtils; import org.apache.jackrabbit.oak.Oak; +import org.apache.jackrabbit.oak.benchmark.util.TestHelper; import org.apache.jackrabbit.oak.fixture.JcrCreator; import org.apache.jackrabbit.oak.fixture.OakRepositoryFixture; import org.apache.jackrabbit.oak.fixture.RepositoryFixture; @@ -43,7 +44,7 @@ public class ElasticPropertyTextSearchTest extends SearchTest { private ElasticsearchConnection coordinate; - public ElasticPropertyTextSearchTest(File dump, boolean flat, boolean doReport, Boolean storageEnabled, ElasticsearchConnection coordinate) { + ElasticPropertyTextSearchTest(File dump, boolean flat, boolean doReport, Boolean storageEnabled, ElasticsearchConnection coordinate) { super(dump, flat, doReport, storageEnabled); this.coordinate = coordinate; } @@ -76,7 +77,7 @@ public class ElasticPropertyTextSearchTest extends SearchTest { .with(indexProvider) .with(new PropertyIndexEditorProvider()) .with(new NodeTypeIndexProvider()) - .with(new PropertyFullTextTest.FullTextPropertyInitialiser("elasticTitle" + System.nanoTime(), of("title"), + .with(new PropertyFullTextTest.FullTextPropertyInitialiser(TestHelper.getUniqueIndexName("elasticTitle"), of("title"), ElasticsearchIndexDefinition.TYPE_ELASTICSEARCH)); return new Jcr(oak); } diff --git a/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/util/TestHelper.java b/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/util/TestHelper.java new file mode 100644 index 0000000..b0949e1 --- /dev/null +++ b/oak-benchmarks-elastic/src/main/java/org/apache/jackrabbit/oak/benchmark/util/TestHelper.java @@ -0,0 +1,32 @@ +/* + * 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.benchmark.util; + +public class TestHelper { + + /** + * Generates a unique index name from the given suggestion. + * @param name name suggestion + * @return unique index name + */ + public static String getUniqueIndexName(String name) { + return name + System.currentTimeMillis(); + } + +} diff --git a/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchConnection.java b/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchConnection.java index d4ec221..a698ad7 100644 --- a/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchConnection.java +++ b/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchConnection.java @@ -37,14 +37,14 @@ import java.util.function.Supplier; */ public class ElasticsearchConnection implements Closeable { - protected static final String SCHEME_PROP = "elasticsearch.scheme"; - protected static final String DEFAULT_SCHEME = "http"; - protected static final String HOST_PROP = "elasticsearch.host"; - protected static final String DEFAULT_HOST = "127.0.0.1"; - protected static final String PORT_PROP = "elasticsearch.port"; - protected static final int DEFAULT_PORT = 9200; - - protected static final Supplier defaultConnection = () -> + static final String SCHEME_PROP = "elasticsearch.scheme"; + static final String DEFAULT_SCHEME = "http"; + static final String HOST_PROP = "elasticsearch.host"; + static final String DEFAULT_HOST = "127.0.0.1"; + static final String PORT_PROP = "elasticsearch.port"; + static final int DEFAULT_PORT = 9200; + + static final Supplier defaultConnection = () -> new ElasticsearchConnection(DEFAULT_SCHEME, DEFAULT_HOST, DEFAULT_PORT, "elastic"); private String scheme; @@ -57,9 +57,10 @@ public class ElasticsearchConnection implements Closeable { private AtomicBoolean isClosed = new AtomicBoolean(false); public ElasticsearchConnection(String scheme, String host, Integer port, String indexPrefix) { - if (scheme == null || host == null || port == null || indexPrefix == null) { - throw new IllegalArgumentException(); - } + Objects.requireNonNull(scheme, "Scheme is null"); + Objects.requireNonNull(host, "Host is null"); + Objects.requireNonNull(port, "Port is null"); + Objects.requireNonNull(indexPrefix, "Index prefix is null"); this.scheme = scheme; this.host = host; this.port = port; diff --git a/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchIndexDefinition.java b/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchIndexDefinition.java index b2abf04..99c6bc5 100644 --- a/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchIndexDefinition.java +++ b/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchIndexDefinition.java @@ -86,7 +86,7 @@ public class ElasticsearchIndexDefinition extends IndexDefinition { private String setupIndexName() { // TODO: implement advanced remote index name strategy that takes into account multiple tenants and re-index process - return getESSafeIndexName(indexPrefix + getIndexPath() + "-" + getReindexCount()); + return getESSafeIndexName(indexPrefix + "." + getIndexPath() + "-" + getReindexCount()); } /** diff --git a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchPropertyIndexTest.java b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchPropertyIndexTest.java index 689cc99..2dfac34 100644 --- a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchPropertyIndexTest.java +++ b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchPropertyIndexTest.java @@ -78,7 +78,7 @@ public class ElasticsearchPropertyIndexTest extends AbstractQueryTest { ElasticsearchConnection.DEFAULT_SCHEME, elastic.getContainerIpAddress(), elastic.getMappedPort(ElasticsearchConnection.DEFAULT_PORT), - "" + System.nanoTime() + "" + System.currentTimeMillis() ); ElasticsearchIndexEditorProvider editorProvider = new ElasticsearchIndexEditorProvider(coordinate, new ExtractedTextCache(10 * FileUtils.ONE_MB, 100));