This is an automated email from the ASF dual-hosted git repository.
fortino pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/trunk by this push:
new 6737636 introduce reliability tests on elastic (#431)
6737636 is described below
commit 67376364f2ac1f59615bb55d429ddb599ecfd097
Author: Fabrizio Fortino <[email protected]>
AuthorDate: Wed Dec 15 14:47:02 2021 +0100
introduce reliability tests on elastic (#431)
* introduce reliability tests on elastic
* OAK-9633: removed unused code
* OAK-9633: reintroduced index cleanup (now part of
ElasticAbstractQueryTest)
* OAK-9633: align @After method signature in Elastic tests
---
oak-parent/pom.xml | 2 +-
oak-search-elastic/pom.xml | 6 ++
.../index/elastic/ElasticAbstractQueryTest.java | 20 ++--
.../index/elastic/ElasticConnectionRule.java | 104 +++++++++------------
.../plugins/index/elastic/ElasticFacetTest.java | 14 +--
.../elastic/ElasticFunctionIndexCommonTest.java | 19 +---
...ElasticIndexDescendantSpellcheckCommonTest.java | 18 +---
...ElasticIndexDescendantSuggestionCommonTest.java | 18 +---
.../ElasticIndexImproperUsageCommonTest.java | 20 +---
.../index/elastic/ElasticIndexQueryCommonTest.java | 20 +---
.../elastic/ElasticIndexSuggestionCommonTest.java | 19 +---
.../elastic/ElasticPropertyIndexCommonTest.java | 19 +---
.../plugins/index/elastic/ElasticReindexTest.java | 21 +----
.../index/elastic/ElasticReliabilityTest.java | 100 ++++++++++++++++++++
.../elastic/ElasticSecureFacetCommonTest.java | 19 +---
.../index/elastic/ElasticSpellcheckCommonTest.java | 17 +---
.../index/elastic/ElasticSpellcheckTest.java | 14 +--
...asticStrictPathRestrictionEnableCommonTest.java | 19 +---
.../plugins/index/elastic/ElasticTestUtils.java | 7 ++
19 files changed, 199 insertions(+), 277 deletions(-)
diff --git a/oak-parent/pom.xml b/oak-parent/pom.xml
index f2145eb..1add918 100644
--- a/oak-parent/pom.xml
+++ b/oak-parent/pom.xml
@@ -67,7 +67,7 @@
<!-- jackson-databind versions prior to 2.10.5.1 are affected by security
vulnerability CVE-2020-25649.
When upgrading jackson, try to align them to the same version -->
<jackson.databind.version>2.10.5.1</jackson.databind.version>
- <testcontainers.version>1.16.0</testcontainers.version>
+ <testcontainers.version>1.16.2</testcontainers.version>
<java.version>1.8</java.version>
<java.version.signature>java18</java.version.signature>
diff --git a/oak-search-elastic/pom.xml b/oak-search-elastic/pom.xml
index 232e184..3b2c2a1 100644
--- a/oak-search-elastic/pom.xml
+++ b/oak-search-elastic/pom.xml
@@ -264,6 +264,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>toxiproxy</artifactId>
+ <version>${testcontainers.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>oak-jcr</artifactId>
<version>${project.version}</version>
diff --git
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticAbstractQueryTest.java
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticAbstractQueryTest.java
index 35c901a..9e52739 100644
---
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticAbstractQueryTest.java
+++
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticAbstractQueryTest.java
@@ -40,6 +40,7 @@ import
org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeStore;
import org.apache.jackrabbit.oak.stats.StatisticsProvider;
+import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.core.CountRequest;
import org.elasticsearch.client.indices.GetIndexRequest;
@@ -81,12 +82,12 @@ public abstract class ElasticAbstractQueryTest extends
AbstractQueryTest {
@ClassRule
public static ElasticConnectionRule elasticRule = new
ElasticConnectionRule(elasticConnectionString);
- /*
- Close the ES connection after every test method execution
- */
@After
- public void cleanup() throws IOException {
- elasticRule.closeElasticConnection();
+ public void tearDown() throws IOException {
+ if (esConnection != null) {
+ esConnection.getClient().indices().delete(new
DeleteIndexRequest(esConnection.getIndexPrefix() + "*"),
RequestOptions.DEFAULT);
+ esConnection.close();
+ }
}
// Override this in extending test class to provide different
ExtractedTextCache if needed
@@ -137,11 +138,14 @@ public abstract class ElasticAbstractQueryTest extends
AbstractQueryTest {
return oak.withAsyncIndexing("async",
DEFAULT_ASYNC_INDEXING_TIME_IN_SECONDS);
}
+ protected ElasticConnection getElasticConnection() {
+ return elasticRule.useDocker() ?
elasticRule.getElasticConnectionForDocker() :
+ elasticRule.getElasticConnectionFromString();
+ }
+
@Override
protected ContentRepository createRepository() {
-
- esConnection = elasticRule.useDocker() ?
elasticRule.getElasticConnectionForDocker() :
- elasticRule.getElasticConnectionFromString();
+ esConnection = getElasticConnection();
ElasticIndexEditorProvider editorProvider =
getElasticIndexEditorProvider(esConnection);
ElasticIndexProvider indexProvider = new
ElasticIndexProvider(esConnection, getMetricHandler());
diff --git
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticConnectionRule.java
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticConnectionRule.java
index 89d8881..395d74f 100644
---
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticConnectionRule.java
+++
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticConnectionRule.java
@@ -23,14 +23,13 @@ import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.jackrabbit.oak.commons.IOUtils;
import org.elasticsearch.Version;
-import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
-import org.elasticsearch.client.RequestOptions;
import org.junit.rules.ExternalResource;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.DockerClientFactory;
+import org.testcontainers.containers.Network;
import org.testcontainers.elasticsearch.ElasticsearchContainer;
import org.testcontainers.utility.MountableFile;
@@ -52,12 +51,13 @@ To be used as a @ClassRule
public class ElasticConnectionRule extends ExternalResource {
private static final Logger LOG =
LoggerFactory.getLogger(ElasticConnectionRule.class);
- private ElasticConnection elasticConnection;
- private final String elasticConnectionString;
+
private static final String INDEX_PREFIX = "elastic_test";
private static final String PLUGIN_DIGEST =
"060117b4150c87274d9cff0925ec16e714f28a40906a53a2cd2a23322bbb3189";
private static boolean useDocker = false;
+ private final String elasticConnectionString;
+
public ElasticConnectionRule(String elasticConnectionString) {
this.elasticConnectionString = elasticConnectionString;
}
@@ -65,16 +65,6 @@ public class ElasticConnectionRule extends ExternalResource {
public ElasticsearchContainer elastic;
/*
- Executed once in the test class' execution lifecycle, after the execution
of apply()
- */
- @Override
- protected void before() {
- if (useDocker()) {
- elasticConnection = getElasticConnectionForDocker();
- }
- }
-
- /*
This is the first method to be executed. It gets executed exactly once at
the beginning of the test class execution.
*/
@Override
@@ -87,11 +77,15 @@ public class ElasticConnectionRule extends ExternalResource
{
downloadSimilaritySearchPluginIfNotExists(localPluginPath,
pluginVersion);
if (elasticConnectionString == null ||
getElasticConnectionFromString() == null) {
checkIfDockerClientAvailable();
+ Network network = Network.newNetwork();
+
elastic = new
ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch:" +
Version.CURRENT)
.withCopyFileToContainer(MountableFile.forHostPath(localPluginPath),
"/tmp/plugins/" + pluginFileName)
.withCopyFileToContainer(MountableFile.forClasspathResource("elasticstartscript.sh"),
"/tmp/elasticstartscript.sh")
- .withCommand("bash /tmp/elasticstartscript.sh");
- s = elastic.apply(s, description);
+ .withCommand("bash /tmp/elasticstartscript.sh")
+ .withNetwork(network);
+ elastic.start();
+
setUseDocker(true);
}
return s;
@@ -99,7 +93,9 @@ public class ElasticConnectionRule extends ExternalResource {
@Override
protected void after() {
- //TODO: See if something needs to be cleaned up at test class level ??
+ if (elastic != null && elastic.isRunning()) {
+ elastic.stop();
+ }
}
private void downloadSimilaritySearchPluginIfNotExists(String
localPluginPath, String pluginVersion) {
@@ -108,7 +104,7 @@ public class ElasticConnectionRule extends ExternalResource
{
LOG.info("Plugin file {} doesn't exist. Trying to download.",
localPluginPath);
try (CloseableHttpClient client = HttpClients.createDefault()) {
HttpGet get = new
HttpGet("https://github.com/alexklibisz/elastiknn/releases/download/" +
pluginVersion
- +"/elastiknn-" + pluginVersion +".zip");
+ + "/elastiknn-" + pluginVersion + ".zip");
CloseableHttpResponse response = client.execute(get);
InputStream inputStream = response.getEntity().getContent();
MessageDigest messageDigest =
MessageDigest.getInstance("SHA-256");
@@ -126,62 +122,50 @@ public class ElasticConnectionRule extends
ExternalResource {
if (!pluginFile.delete()) {
deleteString = "Could not delete downloaded plugin
file.";
}
- throw new RuntimeException("Plugin digest unequal. Found "
+ result.toString() + ". Expected " + PLUGIN_DIGEST + ". " + deleteString);
+ throw new RuntimeException("Plugin digest unequal. Found "
+ result + ". Expected " + PLUGIN_DIGEST + ". " + deleteString);
}
- } catch (IOException|NoSuchAlgorithmException e) {
+ } catch (IOException | NoSuchAlgorithmException e) {
throw new RuntimeException("Could not download similarity
search plugin", e);
}
}
}
public ElasticConnection getElasticConnectionFromString() {
- if (elasticConnection == null) {
- try {
- URI uri = new URI(elasticConnectionString);
- String host = uri.getHost();
- String scheme = uri.getScheme();
- int port = uri.getPort();
- String query = uri.getQuery();
-
- String api_key = null;
- String api_secret = null;
- if (query != null) {
- api_key = query.split(",")[0].split("=")[1];
- api_secret = query.split(",")[1].split("=")[1];
- }
- elasticConnection = ElasticConnection.newBuilder()
- .withIndexPrefix(INDEX_PREFIX +
System.currentTimeMillis())
- .withConnectionParameters(scheme, host, port)
- .withApiKeys(api_key, api_secret)
- .build();
- } catch (URISyntaxException e) {
- return null;
+ try {
+ URI uri = new URI(elasticConnectionString);
+ String host = uri.getHost();
+ String scheme = uri.getScheme();
+ int port = uri.getPort();
+ String query = uri.getQuery();
+
+ String api_key = null;
+ String api_secret = null;
+ if (query != null) {
+ api_key = query.split(",")[0].split("=")[1];
+ api_secret = query.split(",")[1].split("=")[1];
}
+ return ElasticConnection.newBuilder()
+ .withIndexPrefix(INDEX_PREFIX + System.currentTimeMillis())
+ .withConnectionParameters(scheme, host, port)
+ .withApiKeys(api_key, api_secret)
+ .build();
+ } catch (URISyntaxException e) {
+ return null;
}
- return elasticConnection;
}
public ElasticConnection getElasticConnectionForDocker() {
- if (elasticConnection == null) {
- elasticConnection = ElasticConnection.newBuilder()
- .withIndexPrefix(INDEX_PREFIX + System.currentTimeMillis())
- .withConnectionParameters(ElasticConnection.DEFAULT_SCHEME,
- elastic.getContainerIpAddress(),
-
elastic.getMappedPort(ElasticConnection.DEFAULT_PORT))
- .withApiKeys(null, null)
- .build();
- }
- return elasticConnection;
+ return getElasticConnectionForDocker(elastic.getContainerIpAddress(),
+ elastic.getMappedPort(ElasticConnection.DEFAULT_PORT));
}
- public void closeElasticConnection() throws IOException {
- if (elasticConnection != null) {
- elasticConnection.getClient().indices().delete(new
DeleteIndexRequest(elasticConnection.getIndexPrefix() + "*"),
RequestOptions.DEFAULT);
- elasticConnection.close();
- // Make this object null otherwise tests after the first test would
- // receive an client that is closed.
- elasticConnection = null;
- }
+ public ElasticConnection getElasticConnectionForDocker(String
containerIpAddress, int port) {
+ return ElasticConnection.newBuilder()
+ .withIndexPrefix(INDEX_PREFIX + System.currentTimeMillis())
+ .withConnectionParameters(ElasticConnection.DEFAULT_SCHEME,
+ containerIpAddress, port)
+ .withApiKeys(null, null)
+ .build();
}
private void checkIfDockerClientAvailable() {
diff --git
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticFacetTest.java
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticFacetTest.java
index e6a01df..20a1582 100644
---
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticFacetTest.java
+++
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticFacetTest.java
@@ -51,7 +51,6 @@ import javax.jcr.query.Query;
import javax.jcr.query.QueryManager;
import javax.jcr.query.QueryResult;
import javax.jcr.security.Privilege;
-import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@@ -91,24 +90,17 @@ public class ElasticFacetTest {
private final Map<String, Integer> actualAclLabelCount = new HashMap<>();
private final Map<String, Integer> actualAclPar1LabelCount = new
HashMap<>();
- // Set this connection string as
- // <scheme>://<hostname>:<port>?key_id=<>,key_secret=<>
- // key_id and key_secret are optional in case the ES server
- // needs authentication
- // Do not set this if docker is running and you want to run the tests on
docker instead.
- private static final String elasticConnectionString =
System.getProperty("elasticConnectionString");
-
@ClassRule
- public static final ElasticConnectionRule elasticRule = new
ElasticConnectionRule(elasticConnectionString);
+ public static final ElasticConnectionRule elasticRule =
+ new
ElasticConnectionRule(ElasticTestUtils.ELASTIC_CONNECTION_STRING);
/*
Close the ES connection after every test method execution
*/
@After
- public void cleanup() throws IOException {
+ public void cleanup() {
anonymousSession.logout();
adminSession.logout();
- elasticRule.closeElasticConnection();
}
@Before
diff --git
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticFunctionIndexCommonTest.java
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticFunctionIndexCommonTest.java
index 716f086..4164f4b 100644
---
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticFunctionIndexCommonTest.java
+++
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticFunctionIndexCommonTest.java
@@ -23,11 +23,9 @@ import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.plugins.index.FunctionIndexCommonTest;
import org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants;
import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
-import org.junit.After;
import org.junit.ClassRule;
import org.junit.Ignore;
-import java.io.IOException;
import java.util.Set;
import static
org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME;
@@ -37,22 +35,9 @@ import static
org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPER
@Ignore
public class ElasticFunctionIndexCommonTest extends FunctionIndexCommonTest {
- // Set this connection string as
- // <scheme>://<hostname>:<port>?key_id=<>,key_secret=<>
- // key_id and key_secret are optional in case the ES server
- // needs authentication
- // Do not set this if docker is running and you want to run the tests on
docker instead.
- private static String elasticConnectionString =
System.getProperty("elasticConnectionString");
@ClassRule
- public static ElasticConnectionRule elasticRule = new
ElasticConnectionRule(elasticConnectionString);
-
- /*
- Close the ES connection after every test method execution
- */
- @After
- public void cleanup() throws IOException {
- elasticRule.closeElasticConnection();
- }
+ public static final ElasticConnectionRule elasticRule =
+ new
ElasticConnectionRule(ElasticTestUtils.ELASTIC_CONNECTION_STRING);
public ElasticFunctionIndexCommonTest() {
indexOptions = new ElasticIndexOptions();
diff --git
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexDescendantSpellcheckCommonTest.java
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexDescendantSpellcheckCommonTest.java
index 0bd615e..a428a54 100644
---
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexDescendantSpellcheckCommonTest.java
+++
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexDescendantSpellcheckCommonTest.java
@@ -19,22 +19,15 @@ package org.apache.jackrabbit.oak.plugins.index.elastic;
import org.apache.jackrabbit.oak.Oak;
import org.apache.jackrabbit.oak.jcr.Jcr;
import
org.apache.jackrabbit.oak.plugins.index.IndexDescendantSpellcheckCommonTest;
-import org.junit.After;
import org.junit.ClassRule;
import javax.jcr.Repository;
-import java.io.IOException;
public class ElasticIndexDescendantSpellcheckCommonTest extends
IndexDescendantSpellcheckCommonTest {
- // Set this connection string as
- // <scheme>://<hostname>:<port>?key_id=<>,key_secret=<>
- // key_id and key_secret are optional in case the ES server
- // needs authentication
- // Do not set this if docker is running and you want to run the tests on
docker instead.
- private static String elasticConnectionString =
System.getProperty("elasticConnectionString");
@ClassRule
- public static ElasticConnectionRule elasticRule = new
ElasticConnectionRule(elasticConnectionString);
+ public static final ElasticConnectionRule elasticRule =
+ new
ElasticConnectionRule(ElasticTestUtils.ELASTIC_CONNECTION_STRING);
@Override
protected Repository createJcrRepository() {
@@ -45,11 +38,4 @@ public class ElasticIndexDescendantSpellcheckCommonTest
extends IndexDescendantS
return jcr.createRepository();
}
- /**
- * Close the ES connection after every test method execution
- */
- @After
- public void cleanup() throws IOException {
- elasticRule.closeElasticConnection();
- }
}
diff --git
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexDescendantSuggestionCommonTest.java
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexDescendantSuggestionCommonTest.java
index b273515..4f40594 100644
---
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexDescendantSuggestionCommonTest.java
+++
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexDescendantSuggestionCommonTest.java
@@ -19,22 +19,15 @@ package org.apache.jackrabbit.oak.plugins.index.elastic;
import org.apache.jackrabbit.oak.Oak;
import org.apache.jackrabbit.oak.jcr.Jcr;
import
org.apache.jackrabbit.oak.plugins.index.IndexDescendantSuggestionCommonTest;
-import org.junit.After;
import org.junit.ClassRule;
import javax.jcr.Repository;
-import java.io.IOException;
public class ElasticIndexDescendantSuggestionCommonTest extends
IndexDescendantSuggestionCommonTest {
- // Set this connection string as
- // <scheme>://<hostname>:<port>?key_id=<>,key_secret=<>
- // key_id and key_secret are optional in case the ES server
- // needs authentication
- // Do not set this if docker is running and you want to run the tests on
docker instead.
- private static String elasticConnectionString =
System.getProperty("elasticConnectionString");
@ClassRule
- public static ElasticConnectionRule elasticRule = new
ElasticConnectionRule(elasticConnectionString);
+ public static final ElasticConnectionRule elasticRule =
+ new
ElasticConnectionRule(ElasticTestUtils.ELASTIC_CONNECTION_STRING);
@Override
protected Repository createJcrRepository() {
@@ -45,11 +38,4 @@ public class ElasticIndexDescendantSuggestionCommonTest
extends IndexDescendantS
return jcr.createRepository();
}
- /**
- * Close the ES connection after every test method execution
- */
- @After
- public void cleanup() throws IOException {
- elasticRule.closeElasticConnection();
- }
}
diff --git
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexImproperUsageCommonTest.java
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexImproperUsageCommonTest.java
index 2ff5171..188f514 100644
---
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexImproperUsageCommonTest.java
+++
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexImproperUsageCommonTest.java
@@ -20,21 +20,13 @@ import org.apache.jackrabbit.oak.api.ContentRepository;
import org.apache.jackrabbit.oak.api.StrictPathRestriction;
import org.apache.jackrabbit.oak.plugins.index.IndexImproperUsageCommonTest;
import org.apache.jackrabbit.oak.query.QueryEngineSettings;
-import org.junit.After;
import org.junit.ClassRule;
-import java.io.IOException;
-
public class ElasticIndexImproperUsageCommonTest extends
IndexImproperUsageCommonTest {
- // Set this connection string as
- // <scheme>://<hostname>:<port>?key_id=<>,key_secret=<>
- // key_id and key_secret are optional in case the ES server
- // needs authentication
- // Do not set this if docker is running and you want to run the tests on
docker instead.
- private static String elasticConnectionString =
System.getProperty("elasticConnectionString");
@ClassRule
- public static ElasticConnectionRule elasticRule = new
ElasticConnectionRule(elasticConnectionString);
+ public static final ElasticConnectionRule elasticRule =
+ new
ElasticConnectionRule(ElasticTestUtils.ELASTIC_CONNECTION_STRING);
@Override
protected ContentRepository createRepository() {
@@ -46,12 +38,4 @@ public class ElasticIndexImproperUsageCommonTest extends
IndexImproperUsageCommo
repositoryOptionsUtil = elasticTestRepositoryBuilder.build();
return repositoryOptionsUtil.getOak().createContentRepository();
}
-
- /**
- * Close the ES connection after every test method execution
- */
- @After
- public void cleanup() throws IOException {
- elasticRule.closeElasticConnection();
- }
}
diff --git
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexQueryCommonTest.java
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexQueryCommonTest.java
index b8de889..4ec7a00 100644
---
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexQueryCommonTest.java
+++
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexQueryCommonTest.java
@@ -20,21 +20,13 @@ import org.apache.jackrabbit.oak.InitialContentHelper;
import org.apache.jackrabbit.oak.api.ContentRepository;
import org.apache.jackrabbit.oak.plugins.index.IndexQueryCommonTest;
import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
-import org.junit.After;
import org.junit.ClassRule;
-import java.io.IOException;
-
public class ElasticIndexQueryCommonTest extends IndexQueryCommonTest {
- // Set this connection string as
- // <scheme>://<hostname>:<port>?key_id=<>,key_secret=<>
- // key_id and key_secret are optional in case the ES server
- // needs authentication
- // Do not set this if docker is running and you want to run the tests on
docker instead.
- private static String elasticConnectionString =
System.getProperty("elasticConnectionString");
@ClassRule
- public static ElasticConnectionRule elasticRule = new
ElasticConnectionRule(elasticConnectionString);
+ public static final ElasticConnectionRule elasticRule =
+ new
ElasticConnectionRule(ElasticTestUtils.ELASTIC_CONNECTION_STRING);
public ElasticIndexQueryCommonTest() {
indexOptions = new ElasticIndexOptions();
@@ -47,12 +39,4 @@ public class ElasticIndexQueryCommonTest extends
IndexQueryCommonTest {
repositoryOptionsUtil = elasticTestRepositoryBuilder.build();
return repositoryOptionsUtil.getOak().createContentRepository();
}
-
- /**
- * Close the ES connection after every test method execution
- */
- @After
- public void cleanup() throws IOException {
- elasticRule.closeElasticConnection();
- }
}
diff --git
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexSuggestionCommonTest.java
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexSuggestionCommonTest.java
index 13c35a7..0d376aa 100644
---
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexSuggestionCommonTest.java
+++
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexSuggestionCommonTest.java
@@ -20,30 +20,15 @@ import org.apache.jackrabbit.oak.Oak;
import org.apache.jackrabbit.oak.jcr.Jcr;
import org.apache.jackrabbit.oak.plugins.index.IndexSuggestionCommonTest;
import org.apache.jackrabbit.oak.plugins.index.TestUtils;
-import org.junit.After;
import org.junit.ClassRule;
import javax.jcr.Repository;
-import java.io.IOException;
public class ElasticIndexSuggestionCommonTest extends
IndexSuggestionCommonTest {
- // Set this connection string as
- // <scheme>://<hostname>:<port>?key_id=<>,key_secret=<>
- // key_id and key_secret are optional in case the ES server
- // needs authentication
- // Do not set this if docker is running and you want to run the tests on
docker instead.
- private static String elasticConnectionString =
System.getProperty("elasticConnectionString");
@ClassRule
- public static ElasticConnectionRule elasticRule = new
ElasticConnectionRule(elasticConnectionString);
-
- /*
- Close the ES connection after every test method execution
- */
- @After
- public void cleanup() throws IOException {
- elasticRule.closeElasticConnection();
- }
+ public static final ElasticConnectionRule elasticRule =
+ new
ElasticConnectionRule(ElasticTestUtils.ELASTIC_CONNECTION_STRING);
protected Repository createJcrRepository() {
indexOptions = new ElasticIndexOptions();
diff --git
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticPropertyIndexCommonTest.java
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticPropertyIndexCommonTest.java
index 86d91ab..a5b4980 100644
---
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticPropertyIndexCommonTest.java
+++
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticPropertyIndexCommonTest.java
@@ -18,21 +18,13 @@ package org.apache.jackrabbit.oak.plugins.index.elastic;
import org.apache.jackrabbit.oak.api.ContentRepository;
import org.apache.jackrabbit.oak.plugins.index.PropertyIndexCommonTest;
-import org.junit.After;
import org.junit.ClassRule;
-import java.io.IOException;
-
public class ElasticPropertyIndexCommonTest extends PropertyIndexCommonTest {
- // Set this connection string as
- // <scheme>://<hostname>:<port>?key_id=<>,key_secret=<>
- // key_id and key_secret are optional in case the ES server
- // needs authentication
- // Do not set this if docker is running and you want to run the tests on
docker instead.
- private static String elasticConnectionString =
System.getProperty("elasticConnectionString");
@ClassRule
- public static ElasticConnectionRule elasticRule = new
ElasticConnectionRule(elasticConnectionString);
+ public static final ElasticConnectionRule elasticRule =
+ new
ElasticConnectionRule(ElasticTestUtils.ELASTIC_CONNECTION_STRING);
public ElasticPropertyIndexCommonTest() {
indexOptions = new ElasticIndexOptions();
@@ -49,11 +41,4 @@ public class ElasticPropertyIndexCommonTest extends
PropertyIndexCommonTest {
setTraversalEnabled(false);
}
- /*
- Close the ES connection after every test method execution
- */
- @After
- public void cleanup() throws IOException {
- elasticRule.closeElasticConnection();
- }
}
diff --git
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticReindexTest.java
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticReindexTest.java
index 1c410be..6cf63df 100644
---
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticReindexTest.java
+++
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticReindexTest.java
@@ -34,7 +34,6 @@ 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.jackrabbit.oak.stats.StatisticsProvider;
-import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.ClassRule;
@@ -49,7 +48,6 @@ import javax.jcr.query.Query;
import javax.jcr.query.QueryManager;
import javax.jcr.query.QueryResult;
import javax.jcr.query.Row;
-import java.io.IOException;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.UUID;
@@ -66,28 +64,13 @@ public class ElasticReindexTest {
protected int DEFAULT_ASYNC_INDEXING_TIME_IN_SECONDS = 5;
- // Set this connection string as
- // <scheme>://<hostname>:<port>?key_id=<>,key_secret=<>
- // key_id and key_secret are optional in case the ES server
- // needs authentication
- // Do not set this if docker is running and you want to run the tests on
docker instead.
- private static final String elasticConnectionString =
System.getProperty("elasticConnectionString");
-
@ClassRule
- public static final ElasticConnectionRule elasticRule = new
ElasticConnectionRule(elasticConnectionString);
+ public static final ElasticConnectionRule elasticRule =
+ new
ElasticConnectionRule(ElasticTestUtils.ELASTIC_CONNECTION_STRING);
private Session adminSession;
private QueryManager qe;
- /*
- Close the ES connection after every test method execution
- */
- @After
- public void cleanup() throws IOException {
- adminSession.logout();
- elasticRule.closeElasticConnection();
- }
-
@Before
public void setup() throws Exception {
createRepository();
diff --git
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticReliabilityTest.java
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticReliabilityTest.java
new file mode 100644
index 0000000..2a4ce06
--- /dev/null
+++
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticReliabilityTest.java
@@ -0,0 +1,100 @@
+/*
+ * 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.elastic;
+
+import eu.rekawek.toxiproxy.model.ToxicDirection;
+import eu.rekawek.toxiproxy.model.toxic.LimitData;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.junit.After;
+import org.junit.Test;
+import org.testcontainers.containers.ToxiproxyContainer;
+import org.testcontainers.utility.DockerImageName;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class ElasticReliabilityTest extends ElasticAbstractQueryTest {
+
+ private static final DockerImageName TOXIPROXY_IMAGE =
DockerImageName.parse("shopify/toxiproxy:2.1.4");
+
+ private ToxiproxyContainer internalToxiProxy;
+ private ToxiproxyContainer.ContainerProxy toxiProxy;
+
+ @Override
+ public void before() throws Exception {
+ internalToxiProxy = new
ToxiproxyContainer(TOXIPROXY_IMAGE).withNetwork(elasticRule.elastic.getNetwork());
+ internalToxiProxy.start();
+ toxiProxy = internalToxiProxy.getProxy(elasticRule.elastic, 9200);
+ super.before();
+ }
+
+ @After
+ @Override
+ public void tearDown() throws IOException {
+ super.tearDown();
+ if (internalToxiProxy.isRunning()) {
+ internalToxiProxy.stop();
+ }
+ }
+
+ @Override
+ protected void createTestIndexNode() {
+ setTraversalEnabled(true);
+ }
+
+ @Override
+ protected ElasticConnection getElasticConnection() {
+ return elasticRule.useDocker() ?
+
elasticRule.getElasticConnectionForDocker(toxiProxy.getContainerIpAddress(),
toxiProxy.getProxyPort()) :
+ elasticRule.getElasticConnectionFromString();
+ }
+
+ @Test
+ public void connectionCutOnQuery() throws Exception {
+ setIndex("test1", createIndex("propa", "propb"));
+
+ Tree test = root.getTree("/").addChild("test");
+ test.addChild("a").setProperty("propa", "a");
+ test.addChild("b").setProperty("propa", "c");
+ test.addChild("c").setProperty("propb", "e");
+ root.commit(Collections.singletonMap("sync-mode", "rt"));
+
+ String query = "select [jcr:path] from [nt:base] where propa is not
null";
+
+ // simulate an upstream connection cut
+ LimitData cutConnectionUpstream = toxiProxy.toxics()
+ .limitData("CUT_CONNECTION_UPSTREAM", ToxicDirection.UPSTREAM,
0L);
+
+ // elastic is down, query should not use it
+ assertThat(explain(query), not(containsString("elasticsearch:test1")));
+
+ // result set should be correct anyway since traversal is enabled
+ assertQuery(query, Arrays.asList("/test/a", "/test/b"));
+
+ // re-establish connection
+ cutConnectionUpstream.remove();
+
+ // result set should be the same as before but this time elastic
should be used
+ assertThat(explain(query), containsString("elasticsearch:test1"));
+ assertQuery(query, Arrays.asList("/test/a", "/test/b"));
+ }
+}
diff --git
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticSecureFacetCommonTest.java
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticSecureFacetCommonTest.java
index 0a5bc84..1318ef8 100644
---
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticSecureFacetCommonTest.java
+++
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticSecureFacetCommonTest.java
@@ -20,30 +20,15 @@ import org.apache.jackrabbit.oak.Oak;
import org.apache.jackrabbit.oak.jcr.Jcr;
import org.apache.jackrabbit.oak.plugins.index.SecureFacetCommonTest;
import org.apache.jackrabbit.oak.plugins.index.TestUtils;
-import org.junit.After;
import org.junit.ClassRule;
import javax.jcr.Repository;
-import java.io.IOException;
public class ElasticSecureFacetCommonTest extends SecureFacetCommonTest {
- // Set this connection string as
- // <scheme>://<hostname>:<port>?key_id=<>,key_secret=<>
- // key_id and key_secret are optional in case the ES server
- // needs authentication
- // Do not set this if docker is running and you want to run the tests on
docker instead.
- private static String elasticConnectionString =
System.getProperty("elasticConnectionString");
@ClassRule
- public static ElasticConnectionRule elasticRule = new
ElasticConnectionRule(elasticConnectionString);
-
- /*
- Close the ES connection after every test method execution
- */
- @After
- public void cleanup() throws IOException {
- elasticRule.closeElasticConnection();
- }
+ public static final ElasticConnectionRule elasticRule =
+ new
ElasticConnectionRule(ElasticTestUtils.ELASTIC_CONNECTION_STRING);
protected Repository createJcrRepository() {
indexOptions = new ElasticIndexOptions();
diff --git
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticSpellcheckCommonTest.java
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticSpellcheckCommonTest.java
index 992d6b3..efa2fc1 100644
---
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticSpellcheckCommonTest.java
+++
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticSpellcheckCommonTest.java
@@ -23,28 +23,17 @@ import org.junit.After;
import org.junit.ClassRule;
import javax.jcr.Repository;
-import java.io.IOException;
public class ElasticSpellcheckCommonTest extends SpellcheckCommonTest {
- // Set this connection string as
- // <scheme>://<hostname>:<port>?key_id=<>,key_secret=<>
- // key_id and key_secret are optional in case the ES server
- // needs authentication
- // Do not set this if docker is running and you want to run the tests on
docker instead.
- private static final String elasticConnectionString =
System.getProperty("elasticConnectionString");
-
@ClassRule
- public static final ElasticConnectionRule elasticRule = new
ElasticConnectionRule(elasticConnectionString);
+ public static final ElasticConnectionRule elasticRule =
+ new
ElasticConnectionRule(ElasticTestUtils.ELASTIC_CONNECTION_STRING);
- /*
- Close the ES connection after every test method execution
- */
@After
- public void cleanup() throws IOException {
+ public void cleanup() {
anonymousSession.logout();
adminSession.logout();
- elasticRule.closeElasticConnection();
}
protected Repository createJcrRepository() {
diff --git
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticSpellcheckTest.java
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticSpellcheckTest.java
index 5688cdb..5529070 100644
---
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticSpellcheckTest.java
+++
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticSpellcheckTest.java
@@ -49,7 +49,6 @@ import javax.jcr.query.QueryResult;
import javax.jcr.query.Row;
import javax.jcr.query.RowIterator;
import javax.jcr.security.Privilege;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@@ -70,24 +69,17 @@ public class ElasticSpellcheckTest {
private QueryManager qe;
private Node indexNode;
- // Set this connection string as
- // <scheme>://<hostname>:<port>?key_id=<>,key_secret=<>
- // key_id and key_secret are optional in case the ES server
- // needs authentication
- // Do not set this if docker is running and you want to run the tests on
docker instead.
- private static final String elasticConnectionString =
System.getProperty("elasticConnectionString");
-
@ClassRule
- public static final ElasticConnectionRule elasticRule = new
ElasticConnectionRule(elasticConnectionString);
+ public static final ElasticConnectionRule elasticRule =
+ new
ElasticConnectionRule(ElasticTestUtils.ELASTIC_CONNECTION_STRING);
/*
Close the ES connection after every test method execution
*/
@After
- public void cleanup() throws IOException {
+ public void cleanup() {
anonymousSession.logout();
adminSession.logout();
- elasticRule.closeElasticConnection();
}
@Before
diff --git
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticStrictPathRestrictionEnableCommonTest.java
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticStrictPathRestrictionEnableCommonTest.java
index 6e29659..8d633f3 100644
---
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticStrictPathRestrictionEnableCommonTest.java
+++
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticStrictPathRestrictionEnableCommonTest.java
@@ -20,21 +20,13 @@ import org.apache.jackrabbit.oak.api.ContentRepository;
import org.apache.jackrabbit.oak.api.StrictPathRestriction;
import
org.apache.jackrabbit.oak.plugins.index.StrictPathRestrictionEnableCommonTest;
import org.apache.jackrabbit.oak.query.QueryEngineSettings;
-import org.junit.After;
import org.junit.ClassRule;
-import java.io.IOException;
-
public class ElasticStrictPathRestrictionEnableCommonTest extends
StrictPathRestrictionEnableCommonTest {
- // Set this connection string as
- // <scheme>://<hostname>:<port>?key_id=<>,key_secret=<>
- // key_id and key_secret are optional in case the ES server
- // needs authentication
- // Do not set this if docker is running and you want to run the tests on
docker instead.
- private static String elasticConnectionString =
System.getProperty("elasticConnectionString");
@ClassRule
- public static ElasticConnectionRule elasticRule = new
ElasticConnectionRule(elasticConnectionString);
+ public static final ElasticConnectionRule elasticRule =
+ new
ElasticConnectionRule(ElasticTestUtils.ELASTIC_CONNECTION_STRING);
@Override
protected ContentRepository createRepository() {
@@ -47,11 +39,4 @@ public class ElasticStrictPathRestrictionEnableCommonTest
extends StrictPathRest
return repositoryOptionsUtil.getOak().createContentRepository();
}
- /**
- * Close the ES connection after every test method execution
- */
- @After
- public void cleanup() throws IOException {
- elasticRule.closeElasticConnection();
- }
}
diff --git
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticTestUtils.java
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticTestUtils.java
index 8a89ab9..62eb4f5 100644
---
a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticTestUtils.java
+++
b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticTestUtils.java
@@ -24,6 +24,13 @@ import java.util.Random;
public final class ElasticTestUtils {
private static final Logger LOG =
LoggerFactory.getLogger(ElasticTestUtils.class);
+ // Set this connection string as
+ // <scheme>://<hostname>:<port>?key_id=<>,key_secret=<>
+ // key_id and key_secret are optional in case the ES server
+ // needs authentication
+ // Do not set this if docker is running and you want to run the tests on
docker instead.
+ public static final String ELASTIC_CONNECTION_STRING =
System.getProperty("elasticConnectionString");
+
public static void assertEventually(Runnable r, long timeoutMillis) {
final long start = System.currentTimeMillis();
long lastAttempt = 0;