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 ng...@apache.org on 2020/03/26 12:20:52 UTC

svn commit: r1875706 - /jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchPropertyIndexTest.java

Author: ngupta
Date: Thu Mar 26 12:20:52 2020
New Revision: 1875706

URL: http://svn.apache.org/viewvc?rev=1875706&view=rev
Log:
OAK-8965 : skip tests that need ES when docker is not available

Modified:
    jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchPropertyIndexTest.java

Modified: jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchPropertyIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchPropertyIndexTest.java?rev=1875706&r1=1875705&r2=1875706&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchPropertyIndexTest.java (original)
+++ jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elasticsearch/ElasticsearchPropertyIndexTest.java Thu Mar 26 12:20:52 2020
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.elasticsearch;
 
+import com.github.dockerjava.api.DockerClient;
 import org.apache.commons.io.FileUtils;
 import org.apache.jackrabbit.oak.InitialContentHelper;
 import org.apache.jackrabbit.oak.Oak;
@@ -35,8 +36,12 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.elasticsearch.Version;
 import org.junit.Assert;
-import org.junit.ClassRule;
+import org.junit.BeforeClass;
+import org.junit.Rule;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.DockerClientFactory;
 import org.testcontainers.elasticsearch.ElasticsearchContainer;
 
 import java.util.Arrays;
@@ -46,19 +51,33 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.PROPDEF_PROP_NODE_NAME;
 import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assume.assumeNotNull;
 
 public class ElasticsearchPropertyIndexTest extends AbstractQueryTest {
 
-    @ClassRule
-    public static final ElasticsearchContainer ELASTIC =
+    private static final Logger LOG = LoggerFactory.getLogger(ElasticsearchPropertyIndexTest.class);
+
+    @Rule
+    public final ElasticsearchContainer elastic =
             new ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch:" + Version.CURRENT);
 
+    @BeforeClass
+    public static void beforeMethod() {
+        DockerClient client = null;
+        try {
+            client = DockerClientFactory.instance().client();
+        } catch (Exception e) {
+            LOG.warn("Docker is not available, ElasticsearchPropertyIndexTest will be skipped");
+        }
+        assumeNotNull(client);
+    }
+
     @Override
     protected ContentRepository createRepository() {
         ElasticsearchConnection coordinate = new ElasticsearchConnection(
                 ElasticsearchConnection.DEFAULT_SCHEME,
-                ELASTIC.getContainerIpAddress(),
-                ELASTIC.getMappedPort(ElasticsearchConnection.DEFAULT_PORT)
+                elastic.getContainerIpAddress(),
+                elastic.getMappedPort(ElasticsearchConnection.DEFAULT_PORT)
         );
         ElasticsearchIndexEditorProvider editorProvider = new ElasticsearchIndexEditorProvider(coordinate,
                 new ExtractedTextCache(10 * FileUtils.ONE_MB, 100));
@@ -185,4 +204,4 @@ public class ElasticsearchPropertyIndexT
         String explain = "explain " + query;
         return executeQuery(explain, "JCR-SQL2").get(0);
     }
-}
\ No newline at end of file
+}