You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2019/10/18 14:51:23 UTC
[sling-org-apache-sling-connection-timeout-agent] branch
feature/SLING-8787 created (now 618349e)
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a change to branch feature/SLING-8787
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-connection-timeout-agent.git.
at 618349e SLING-8787 - Add OSGi smoke test
This branch includes the following new commits:
new 618349e SLING-8787 - Add OSGi smoke test
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[sling-org-apache-sling-connection-timeout-agent] 01/01: SLING-8787
- Add OSGi smoke test
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch feature/SLING-8787
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-connection-timeout-agent.git
commit 618349edbdc1fe5e121492b98db25ddf02ec24b5
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Fri Oct 18 16:50:57 2019 +0200
SLING-8787 - Add OSGi smoke test
---
pom.xml | 35 +++++++++
.../java/org/apache/sling/cta/impl/OsgiIT.java | 90 ++++++++++++++++++++++
2 files changed, 125 insertions(+)
diff --git a/pom.xml b/pom.xml
index 22ad48a..0a9d90e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -121,6 +121,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.junit.vintage</groupId>
+ <artifactId>junit-vintage-engine</artifactId>
+ <version>5.4.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
@@ -144,5 +150,34 @@
<version>3.14.2</version>
<scope>test</scope>
</dependency>
+ <!-- Pax Exam Dependencies -->
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-container-forked</artifactId>
+ <version>${pax-exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit4</artifactId>
+ <version>${pax-exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-link-mvn</artifactId>
+ <version>${pax-exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <!-- Felix framework for Pax-Exam -->
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.framework</artifactId>
+ <version>6.0.3</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
+ <properties>
+ <pax-exam.version>4.13.0</pax-exam.version>
+ </properties>
</project>
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/cta/impl/OsgiIT.java b/src/test/java/org/apache/sling/cta/impl/OsgiIT.java
new file mode 100644
index 0000000..7100d0e
--- /dev/null
+++ b/src/test/java/org/apache/sling/cta/impl/OsgiIT.java
@@ -0,0 +1,90 @@
+/*
+ * 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.sling.cta.impl;
+
+import static org.junit.Assert.fail;
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.vmOption;
+
+import java.io.IOException;
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.PathMatcher;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.conn.ConnectTimeoutException;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+/**
+ * Smoke test to ensure that the agent works as expected inside an OSGi container
+ *
+ * <p>It only validates one scenario, and it's not terribly important which one, just that it uses
+ * a library, and not the built-in HttpClient, as the class loading requirements are more strict.</p>
+ *
+ */
+@RunWith(PaxExam.class)
+public class OsgiIT {
+
+ @Configuration
+ public Option[] config() throws IOException {
+
+ FileSystem fs = FileSystems.getDefault();
+ PathMatcher matcher = fs.getPathMatcher("glob:org.apache.sling.connection-timeout-agent-*-jar-with-dependencies.jar");
+
+ List<Path> agentCandidates = Files.list(Paths.get("target"))
+ .filter(Files::isRegularFile)
+ .filter(p -> matcher.matches(p.getFileName()))
+ .collect(Collectors.toList());
+
+ if ( agentCandidates.size() != 1 )
+ throw new RuntimeException("Expected exactly one agent jar, but found " + agentCandidates);
+
+ return options(
+ junitBundles(),
+ mavenBundle("org.apache.httpcomponents", "httpcore-osgi", "4.4.12"),
+ mavenBundle("org.apache.httpcomponents", "httpclient-osgi", "4.5.10"),
+ vmOption("-javaagent:" + agentCandidates.get(0) +"=1,1,v")
+ );
+ }
+
+ @Test(expected = ConnectTimeoutException.class)
+ public void callTimesOut() throws IOException {
+ try ( CloseableHttpClient httpclient = HttpClients.createDefault() ) {
+ // the used host does not really matter, the connect timeout of 1 ms
+ // should kick in almost instantly
+ HttpGet get = new HttpGet("https://sling.apache.org");
+ try ( CloseableHttpResponse response = httpclient.execute(get)) {
+ fail("Request should have failed");
+ }
+ }
+ }
+
+}