This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jobs-it.git
commit e76a057773274a160e4c33115c729a96d42de124 Author: Ian Boston <[email protected]> AuthorDate: Mon Oct 3 16:05:02 2016 +0000 SLING-5645 moved jobs out of examples git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1763181 13f79535-47bb-0310-9956-ffa450edef68 --- .gitignore | 1 + README.md | 6 + pom.xml | 131 +++++++++++++++++++++ .../java/org/apache/sling/jobs/it/CheckRootIT.java | 50 ++++++++ src/test/java/org/apache/sling/jobs/it/Models.java | 27 +++++ .../apache/sling/jobs/it/TestSuiteLauncherIT.java | 87 ++++++++++++++ src/test/resources/crankstart-model.txt | 46 ++++++++ src/test/resources/provisioning-model/base.txt | 41 +++++++ .../provisioning-model/crankstart-test-support.txt | 29 +++++ .../resources/provisioning-model/jobs-runtime.txt | 42 +++++++ src/test/resources/sling-launchpad.txt | 65 ++++++++++ 11 files changed, 525 insertions(+) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d18955 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +activemq-data diff --git a/README.md b/README.md new file mode 100644 index 0000000..a3996ab --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# Job IT tests launcher. + +This project runs a test launcher that creates an OSGi instance with only what is required to run Server Side tests. +Unfurtunately, since OSGi is a multi classloader environment its not possible to perform tests in this bundle, except +tests over http as any references made to APIs will get resolved with the wrong classloader and so wont be able to +interact with OSGi. Hence the tests are in a separate bundle that is loaded by the launchpad. \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..8ac0d0c --- /dev/null +++ b/pom.xml @@ -0,0 +1,131 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache</groupId> + <artifactId>apache</artifactId> + <version>10</version> + <relativePath /> + </parent> + + <artifactId>org.apache.sling.jobs-it</artifactId> + <packaging>jar</packaging> + <version>0.0.1-SNAPSHOT</version> + + <name>Apache Sling Jobs Integration Tests</name> + <description> + Integration testing Support for Job processing using message passing.. + </description> + + <scm> + <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/contrib/commons/mom/jobs/it</connection> + <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/contrib/commons/mom/jobs/it</developerConnection> + <url>http://svn.apache.org/viewvc/sling/trunk/contrib/commons/mom/jobs/it</url> + </scm> + + <properties> + <site.jira.version.id>12315369</site.jira.version.id> + <sling.java.version>7</sling.java.version> + <exam.version>4.4.0</exam.version> + <url.version>2.4.5</url.version> + <pax.url.version>2.1.0</pax.url.version> + <bundle.build.dir>${basedir}/target</bundle.build.dir> + <bundle.file.name>${bundle.build.dir}/${project.build.finalName}.jar</bundle.file.name> + <min.port>37000</min.port> + <max.port>37999</max.port> + </properties> + + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.6</source> + <target>1.6</target> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.crankstart.launcher</artifactId> + <version>1.9.9-SNAPSHOT</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.commons.testing</artifactId> + <version>2.0.16</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.jmock</groupId> + <artifactId>jmock-junit4</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.commons.json</artifactId> + <version>2.0.10</version> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <version>4.1</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.7.6</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <version>1.7.6</version> + <scope>test</scope> + </dependency> + </dependencies> +</project> diff --git a/src/test/java/org/apache/sling/jobs/it/CheckRootIT.java b/src/test/java/org/apache/sling/jobs/it/CheckRootIT.java new file mode 100644 index 0000000..a40846f --- /dev/null +++ b/src/test/java/org/apache/sling/jobs/it/CheckRootIT.java @@ -0,0 +1,50 @@ +package org.apache.sling.jobs.it; + +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.sling.commons.testing.junit.Retry; +import org.apache.sling.commons.testing.junit.RetryRule; +import org.apache.sling.crankstart.junit.CrankstartSetup; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; + +import java.io.IOException; + +import static org.junit.Assert.*; + +/** + */ +public class CheckRootIT { + + + @Rule + public final RetryRule retryRule = new RetryRule(); + + private DefaultHttpClient client; + + + @Before + public void setup() throws IOException { + client = new DefaultHttpClient(); + } + + @Test + @Retry(timeoutMsec=Models.LONG_TIMEOUT_MSEC, intervalMsec=Models.STD_INTERVAL) + public void testHttpRoot() throws Exception { + final HttpUriRequest get = new HttpGet(TestSuiteLauncherIT.crankstartSetup.getBaseUrl()); + HttpResponse response = null; + try { + response = client.execute(get); + assertEquals("Expecting page not found at " + get.getURI(), 404, response.getStatusLine().getStatusCode()); + } finally { + Models.closeConnection(response); + } + } + + +} diff --git a/src/test/java/org/apache/sling/jobs/it/Models.java b/src/test/java/org/apache/sling/jobs/it/Models.java new file mode 100644 index 0000000..7fcd479 --- /dev/null +++ b/src/test/java/org/apache/sling/jobs/it/Models.java @@ -0,0 +1,27 @@ +package org.apache.sling.jobs.it; + +import org.apache.http.HttpResponse; +import org.apache.http.util.EntityUtils; + +import java.io.IOException; + +/** + */ +public class Models { + public static final int LONG_TIMEOUT_SECONDS = 2; // TODO 10 + public static final int LONG_TIMEOUT_MSEC = LONG_TIMEOUT_SECONDS * 1000; + public static final int STD_INTERVAL = 250; + + static final String[] DEFAULT_MODELS = { + "/crankstart-model.txt", + "/provisioning-model/base.txt", + "/provisioning-model/jobs-runtime.txt", + "/provisioning-model/crankstart-test-support.txt" + }; + + static void closeConnection(HttpResponse r) throws IOException { + if(r != null && r.getEntity() != null) { + EntityUtils.consume(r.getEntity()); + } + } +} diff --git a/src/test/java/org/apache/sling/jobs/it/TestSuiteLauncherIT.java b/src/test/java/org/apache/sling/jobs/it/TestSuiteLauncherIT.java new file mode 100644 index 0000000..18c6662 --- /dev/null +++ b/src/test/java/org/apache/sling/jobs/it/TestSuiteLauncherIT.java @@ -0,0 +1,87 @@ +package org.apache.sling.jobs.it; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.sling.crankstart.junit.CrankstartSetup; +import org.junit.ClassRule; +import org.junit.rules.ExternalResource; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** Basic tests of the launcher, verify that we + * can start the Felix HTTP service and a few + * other things. + */ +@RunWith(Suite.class) [email protected](CheckRootIT.class) +public class TestSuiteLauncherIT { + + private static final Logger LOGGER = LoggerFactory.getLogger(TestSuiteLauncherIT.class); + private static final long classSetup = System.currentTimeMillis(); + private static final long MAX_BACKOFF = 5000; + private static final long INITIAL_BACKOFF = 100; + + @ClassRule + public final static CrankstartSetup crankstartSetup = new CrankstartSetup().withModelResources(Models.DEFAULT_MODELS); + + + @ClassRule + public final static ExternalResource R = new ExternalResource() { + @Override + protected void before() throws Throwable { + LOGGER.info("Waiting for Crankstart to start"); + while(crankstartSetup.getTotalBundles() == 0) { + Thread.sleep(100); + } + if (crankstartSetup.getBundlesFailed() > 0) { + LOGGER.error("Bundles failed to start {} ",crankstartSetup.getBundlesFailed()); + fail(); + } + LOGGER.info("Crankstart to started {} bundles ", crankstartSetup.getBundlesStarted()); + DefaultHttpClient client = new DefaultHttpClient(); + final HttpUriRequest get = new HttpGet(crankstartSetup.getBaseUrl()); + HttpResponse response = null; + long backoff = INITIAL_BACKOFF; + boolean noresponse = false; + long ttl = System.currentTimeMillis()+60000; + // try for no more than 60s + while(System.currentTimeMillis() < ttl) { + try { + response = client.execute(get); + if (noresponse) { + backoff = INITIAL_BACKOFF; + noresponse = false; + } + if (response.getStatusLine().getStatusCode() == 404) { + LOGGER.info("Sever up and responding to http requests, startup complete"); + Thread.sleep(60000); + return; + } + LOGGER.info("Server not respoding as expected to http requests, waiting {} ms", backoff); + Thread.sleep(backoff); + backoff = Math.min((long)(backoff*1.5), MAX_BACKOFF); + } catch (Exception ex) { + noresponse = true; + LOGGER.info("Server not respoding waiting {} ms {} ", backoff, ex.getClass()); + Thread.sleep(backoff); + backoff = Math.min(backoff*2, MAX_BACKOFF); + } finally { + Models.closeConnection(response); + } + + } + fail("Unable to contact server"); + } + + }; + + +} \ No newline at end of file diff --git a/src/test/resources/crankstart-model.txt b/src/test/resources/crankstart-model.txt new file mode 100644 index 0000000..c32cb3d --- /dev/null +++ b/src/test/resources/crankstart-model.txt @@ -0,0 +1,46 @@ +# +# 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. +# + +# Test the crankstart launcher by setting up an HTTP +# server with a few servlets that require specific OSGi configurations +[feature name=:crankstart] + +[variables] + felix.framework.version=5.0.0 + slf4j.version = 1.7.6 + http.port = 8080 + osgi.storage.path = CRANKSTART/felix + osgi.start.level = 42 + osgi-core-packages=org.osgi.dto; version=1.0.0, org.osgi.framework; version=1.8.0, org.osgi.framework.dto; version=1.8.0, org.osgi.framework.hooks.bundle; version=1.1.0, org.osgi.framework.hooks.resolver; version=1.0.0, org.osgi.framework.hooks.service; version=1.1.0, org.osgi.framework.hooks.weaving; version=1.1.0, org.osgi.framework.launch; version=1.2.0, org.osgi.framework.namespace; version=1.1.0, org.osgi.framework.startlevel; version=1.0.0, org.osgi.framework.startlevel.dto; vers [...] + osgi-compendium-services=org.osgi.util.tracker; version=1.5.1 + jre-1.8=javax.accessibility;uses:="javax.swing.text";version="0.0.0.1_008_JavaSE", javax.activity;version="0.0.0.1_008_JavaSE", javax.annotation.processing;uses:="javax.tools,javax.lang.model,javax.lang.model.element,javax.lang.model.util";version="0.0.0.1_008_JavaSE", javax.annotation;version="0.0.0.1_008_JavaSE", javax.crypto.interfaces;uses:="javax.crypto.spec,javax.crypto";version="0.0.0.1_008_JavaSE", javax.crypto.spec;uses:="javax.crypto";version="0.0.0.1_008_JavaSE", javax.crypt [...] + system-customise= javax.xml.namespace, javax.xml.parsers, javax.xml.xpath, javax.xml.transform, javax.transaction, javax.transaction.xa, javax.xml.transform.dom, javax.xml.transform.stream, org.xml.sax, org.w3c.dom + + +[settings] + org.osgi.service.http.port = ${http.port} + org.osgi.framework.storage = ${osgi.storage.path} + org.osgi.framework.startlevel.beginning = ${osgi.start.level} + org.osgi.framework.system.packages=${osgi-core-packages}, ${osgi-compendium-services}, ${jre-1.8}, ${system-customise} + + +[artifacts] + org.apache.felix/org.apache.felix.framework/${felix.framework.version} + org.slf4j/slf4j-api/${slf4j.version} + org.slf4j/slf4j-simple/${slf4j.version} diff --git a/src/test/resources/provisioning-model/base.txt b/src/test/resources/provisioning-model/base.txt new file mode 100644 index 0000000..751ad8a --- /dev/null +++ b/src/test/resources/provisioning-model/base.txt @@ -0,0 +1,41 @@ +# +# 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. +# +# This is a feature description +# +# A feature consists of variables and run mode dependent artifacts. +# + +# Test our Sling extension commands, that add a bundle via the Sling installer +# (which requires commons.json and jcr-wrapper) +[feature name=crankstart.test.base] + +[variables] + felix.http.jetty.version=2.2.0 + +[artifacts] + # artifacts that are usually provided by the Sling launchpad + org.apache.sling/org.apache.sling.launchpad.api/1.1.0 + org.apache.felix/org.apache.felix.http.jetty/${felix.http.jetty.version} + org.apache.felix/org.apache.felix.eventadmin/1.3.2 + org.apache.felix/org.apache.felix.scr/1.8.2 + org.apache.felix/org.apache.felix.metatype/1.0.10 + org.apache.sling/org.apache.sling.commons.osgi/2.2.0 + org.apache.sling/org.apache.sling.commons.log/2.1.2 + org.apache.felix/org.apache.felix.configadmin/1.6.0 + org.apache.felix/org.apache.felix.webconsole/3.1.6 diff --git a/src/test/resources/provisioning-model/crankstart-test-support.txt b/src/test/resources/provisioning-model/crankstart-test-support.txt new file mode 100644 index 0000000..e8b42d6 --- /dev/null +++ b/src/test/resources/provisioning-model/crankstart-test-support.txt @@ -0,0 +1,29 @@ +# +# 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. +# + +[feature name=crankstart.test.support] + +[artifacts] + org.apache.sling/org.apache.sling.jcr.jcr-wrapper/2.0.0 + org.apache.sling/org.apache.sling.commons.json/2.0.6 + org.apache.sling/org.apache.sling.junit.core/1.0.10 + org.apache.sling/org.apache.sling.commons.mime/2.1.8 + org.apache.sling/org.apache.sling.settings/1.3.6 + + diff --git a/src/test/resources/provisioning-model/jobs-runtime.txt b/src/test/resources/provisioning-model/jobs-runtime.txt new file mode 100644 index 0000000..1649559 --- /dev/null +++ b/src/test/resources/provisioning-model/jobs-runtime.txt @@ -0,0 +1,42 @@ +# +# 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. +# +# Load this bundle to run tests, it built with mvn clean install after each test. + +[feature name=sling.extensions.jobs] + +[artifacts] + com.google.code.gson/gson/2.2.4 + org.apache.geronimo.specs/geronimo-j2ee-management_1.1_spec/1.0.1 + org.apache.geronimo.specs/geronimo-jms_1.1_spec/1.1.1 + org.ow2.asm/asm/4.1 + com.google.guava/guava/16.0.1 + org.apache.commons/commons-pool2/2.4.2 + org.apache.sling/org.apache.sling.mom/0.0.1-SNAPSHOT + org.apache.sling/org.apache.sling.jobs/0.0.1-SNAPSHOT + org.apache.sling/org.apache.sling.jms/0.0.1-SNAPSHOT + org.apache.sling/org.apache.sling.jobs-it-services/0.0.1-SNAPSHOT + +[configurations] + # Configure a queue to listen to the queue used in the IT Services components. + # In general a queue should only be activated on an instance if the + # instance is configured with consumers for that queue. + # If consumers are not present, then the queue will dequeue and force a retry + # of each item it can process untill the retry limit is reached. + org.apache.sling.jobs.impl.JobQueueConsumerFactory + queue-name="org/apache/sling/jobs/it/services" diff --git a/src/test/resources/sling-launchpad.txt b/src/test/resources/sling-launchpad.txt new file mode 100644 index 0000000..5af8839 --- /dev/null +++ b/src/test/resources/sling-launchpad.txt @@ -0,0 +1,65 @@ +# +# 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. +# + +# Start the Sling Launchpad including whatever is required to +# run the Sling integration tests. +# +# Currently all those 529 tests pass if started with +# java -Xmx1G -XX:MaxPermSize=256m \ +# -Dsling.run.modes=:standalone,jackrabbit -Dsling.home=CRANKSTART \ +# -jar target/org.apache.sling.crankstart.launcher-1.9.9-SNAPSHOT.jar \ +# src/test/resources/crankstart-model.txt \ +# src/test/resources/sling-launchpad.txt + +[feature name=sling.launchpad] + +[settings] + org.apache.sling.commons.log.julenabled=true + +[artifacts] + # karaf bunde provides Sling Launchpad startup services + org.apache.sling/org.apache.sling.launchpad.karaf/0.1.1-SNAPSHOT + + # artifacts that are usually provided by the Sling launchpad + org.apache.sling/org.apache.sling.launchpad.api/1.1.0 + + # The launchpad itself + org.apache.sling/org.apache.sling.launchpad/8/txt/slingfeature + + # Sling integration tests support + # TODO problem with the test-service bundles with 2 run modes + # org.apache.sling/org.apache.sling.launchpad.test-bundles/0.0.1-SNAPSHOT/txt + +# TODO remove those once nested test-bundles model works +[artifacts startLevel=2] + org.apache.sling/org.apache.sling.servlets.compat/1.0.3-SNAPSHOT + org.apache.sling/org.apache.sling.junit.core/1.0.11-SNAPSHOT + org.apache.sling/org.apache.sling.junit.remote/1.0.11-SNAPSHOT + org.apache.sling/org.apache.sling.junit.scriptable/1.0.11-SNAPSHOT + org.apache.sling/org.apache.sling.launchpad.test-fragment/2.0.9-SNAPSHOT + org.apache.sling/org.apache.sling.launchpad.test-services-war/2.0.8/war + org.apache.sling/org.apache.sling.launchpad.test-services/2.0.9-SNAPSHOT + +[configurations] + integrationTestsConfig + message="This test config should be loaded at startup" + + org.apache.sling.servlets.resolver.SlingServletResolver + # Set the servlet resolver's cache size to zero for testing + servletresolver.cacheSize=I"0" -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
