You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2021/05/25 12:54:40 UTC

[sling-org-apache-sling-starter] 01/01: SLING-10402 - run SmokeIT on both tar and mongo instances

This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a commit to branch SLING-10402/also-test-mongo
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-starter.git

commit 51317bd523e6636670dfe9d41fee2d73487410c8
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue May 25 14:52:08 2021 +0200

    SLING-10402 - run SmokeIT on both tar and mongo instances
---
 pom.xml                                            | 79 +++++++++++++++++++++-
 .../java/org/apache/sling/launchpad/SmokeIT.java   | 33 +++++++--
 2 files changed, 104 insertions(+), 8 deletions(-)

diff --git a/pom.xml b/pom.xml
index dd85a2c..05d6128 100644
--- a/pom.xml
+++ b/pom.xml
@@ -199,9 +199,70 @@
                             </portNames>
                         </configuration>
                     </execution>
+                    <execution>
+                        <id>reserve-network-port-mongo</id>
+                        <goals>
+                            <goal>reserve-network-port</goal>
+                        </goals>
+                        <phase>pre-integration-test</phase>
+                        <configuration>
+                            <portNames>
+                                <portName>http.port.mongo</portName>
+                            </portNames>
+                        </configuration>
+                    </execution>
                 </executions>
             </plugin>
-            <!-- launch the oak_tar aggregate for the integration tests -->
+            <!--
+                Start a MongoDB container for the corresponding tests.
+                Must be declared before the feature-launcher-maven-plugin
+                so that the container is up before the corresponding Sling
+                instance starts.
+            -->
+            <plugin>
+                <groupId>io.fabric8</groupId>
+                <artifactId>docker-maven-plugin</artifactId>
+                <version>0.19.1</version>
+                <configuration>
+                    <images>
+                        <image>
+                            <alias>mongo</alias>
+                            <name>mongo:4.4.6</name>
+                            <run>
+                                <ports>
+                                    <!--
+                                        TODO the local port should by dynamic for tests, but
+                                        currently the oak feature file hardcodes the default port
+                                    -->
+                                    <port>27017:27017</port>
+                                </ports>
+                                <wait>
+                                    <log>CONTROL</log>
+                                    <time>60000</time>
+                                </wait>
+                            </run>
+                        </image>
+                    </images>
+                    <stopMode>kill</stopMode>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>start-mongo</id>
+                        <phase>pre-integration-test</phase>
+                        <goals>
+                            <goal>start</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>stop-mongo</id>
+                        <phase>post-integration-test</phase>
+                        <goals>
+                            <goal>stop</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <!-- launch the Sling instances to test -->
             <plugin>
                 <groupId>org.apache.sling</groupId>
                 <artifactId>feature-launcher-maven-plugin</artifactId>
@@ -223,6 +284,21 @@
                                 </frameworkProperties>
                             </launcherArguments>
                         </launch>
+                        <launch>
+                            <id>sling-12-oak-mongo</id>
+                            <feature>
+                                <groupId>${project.groupId}</groupId>
+                                <artifactId>${project.artifactId}</artifactId>
+                                <version>${project.version}</version>
+                                <classifier>oak_mongo</classifier>
+                                <type>slingosgifeature</type>
+                            </feature>
+                            <launcherArguments>
+                                <frameworkProperties>
+                                    <org.osgi.service.http.port>${http.port.mongo}</org.osgi.service.http.port>
+                                </frameworkProperties>
+                            </launcherArguments>
+                        </launch>
                     </launches>
                 </configuration>
                 <executions>
@@ -248,6 +324,7 @@
                <configuration>
                    <systemPropertyVariables>
                        <starter.http.port>${http.port}</starter.http.port>
+                       <starter.http.port.mongo>${http.port.mongo}</starter.http.port.mongo>
                        <starter.min.bundles.count>${starter.min.bundles.count}</starter.min.bundles.count>
                    </systemPropertyVariables>
                </configuration>
diff --git a/src/test/java/org/apache/sling/launchpad/SmokeIT.java b/src/test/java/org/apache/sling/launchpad/SmokeIT.java
index 26381fc..c3e5d0e 100644
--- a/src/test/java/org/apache/sling/launchpad/SmokeIT.java
+++ b/src/test/java/org/apache/sling/launchpad/SmokeIT.java
@@ -21,6 +21,8 @@ import static org.hamcrest.CoreMatchers.notNullValue;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.fail;
 
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
@@ -44,31 +46,48 @@ import org.apache.http.impl.client.HttpClientBuilder;
 import org.hamcrest.CoreMatchers;
 import org.junit.Before;
 import org.junit.ClassRule;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 
+@RunWith(Parameterized.class)
 public class SmokeIT {
 
-    private static final int STARTER_HTTP_PORT = Integer.getInteger("starter.http.port", 8080);
+    private final int slingHttpPort;
     private static final int STARTER_MIN_BUNDLES_COUNT = Integer.getInteger("starter.min.bundles.count", Integer.MAX_VALUE);
 
-    @ClassRule
-    public static StarterReadyRule LAUNCHPAD = new StarterReadyRule(STARTER_HTTP_PORT);
+    @Rule
+    public final StarterReadyRule launchpadRule;
     private HttpClientContext httpClientContext;
 
+    @Parameterized.Parameters(name = "{0}")
+    public static Collection<Object[]> data() {
+        return Arrays.asList(new Object[][] {
+            {"starter.http.port", 8080},
+            {"starter.http.port.mongo", 8081}
+        });
+    }
+
+    public SmokeIT(String propName, int defaultPort) {
+        slingHttpPort = Integer.getInteger(propName, defaultPort);
+        launchpadRule = new StarterReadyRule(slingHttpPort);
+    }
+
     @Before
     public void prepareHttpContext() {
 
         CredentialsProvider credsProvider = new BasicCredentialsProvider();
         UsernamePasswordCredentials creds = new UsernamePasswordCredentials("admin", "admin");
-        credsProvider.setCredentials(new AuthScope("localhost", STARTER_HTTP_PORT), creds);
+        credsProvider.setCredentials(new AuthScope("localhost", slingHttpPort), creds);
 
         BasicAuthCache authCache = new BasicAuthCache();
         BasicScheme basicAuth = new BasicScheme();
-        authCache.put(new HttpHost("localhost", STARTER_HTTP_PORT, "http"), basicAuth);
+        authCache.put(new HttpHost("localhost", slingHttpPort, "http"), basicAuth);
 
         httpClientContext = HttpClientContext.create();
         httpClientContext.setCredentialsProvider(credsProvider);
@@ -87,7 +106,7 @@ public class SmokeIT {
 
         try ( CloseableHttpClient client = newClient() ) {
 
-            HttpGet get = new HttpGet("http://localhost:" + STARTER_HTTP_PORT + "/system/console/bundles.json");
+            HttpGet get = new HttpGet("http://localhost:" + slingHttpPort + "/system/console/bundles.json");
 
             // pass the context to ensure preemptive basic auth is used
             // https://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html
@@ -148,7 +167,7 @@ public class SmokeIT {
     public void ensureRepositoryIsStarted() throws Exception {
         try ( CloseableHttpClient client = newClient() ) {
 
-            HttpGet get = new HttpGet("http://localhost:" + STARTER_HTTP_PORT + "/server/default/jcr:root/content");
+            HttpGet get = new HttpGet("http://localhost:" + slingHttpPort + "/server/default/jcr:root/content");
 
             try ( CloseableHttpResponse response = client.execute(get) ) {