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/06/06 15:09:58 UTC

[sling-whiteboard] branch master updated (acc4c98 -> 2dbd960)

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

rombert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git.


    from acc4c98  Merge branch 'master' of github.com:apache/sling-whiteboard
     new b0fd4f8  Some work on integration tests
     new 4b2d40b  Migrate to Junit 5 for more fine-grained timeouts and exception checks.
     new f79ae3c  Provisional integration tests, currently setting the timeouts manually
     new 69bb6e4  Cleanups in tests
     new d4d8491  Allow accessing server as an instance field and stop hardcoding the local port.
     new 59c680c  Improved test support classes naming and documentation
     new 5360a60  Removed unused dependencies
     new 827efd0  Stubbed out a wait to launch external processes
     new 87cf8d7  Add missing license header
     new 89d2e52  Use Maven central for connect timeout tests. Accessing sling.apache.org failed with a 'connection refused' error on Jenkins, presumably since builds.apache.org has direct access to other apache.org servers.
     new 9a46cac  Converted IntegrationTest to a proper IT
     new e974da3  Move launcher out of the jar
     new f7693f1  Prepared testing infrastructure for multiple client implementations
     new 697c1b9  Prepare tests for running against multiple client types
     new cffc06e  Implement default timeouts for httpclient 3.x
     new 2dbd960  Updated README to reflect latest state.

The 16 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.


Summary of changes:
 url-connection-agent/README.md                     |  15 +-
 url-connection-agent/pom.xml                       |  61 ++++++-
 .../main/java/org/apache/sling/uca/impl/Agent.java |  12 +-
 .../uca/impl/HttpClient3TimeoutTransformer.java    |  67 +++++++
 ...sformer.java => JavaNetTimeoutTransformer.java} |   4 +-
 .../main/java/org/apache/sling/uca/impl/Main.java  |  47 -----
 .../java/org/apache/sling/uca/impl/AgentIT.java    | 200 +++++++++++++++++++++
 ...est.java => JaveNetTimeoutTransformerTest.java} |  22 ++-
 .../test/java/org/apache/sling/uca/impl/Main.java  | 107 +++++++++++
 .../sling/uca/impl/MisbehavingServerControl.java   |  14 +-
 .../sling/uca/impl/MisbehavingServerExtension.java | 114 ++++++++++++
 .../src/test/resources/simplelogger.properties     |   3 +-
 12 files changed, 594 insertions(+), 72 deletions(-)
 create mode 100644 url-connection-agent/src/main/java/org/apache/sling/uca/impl/HttpClient3TimeoutTransformer.java
 rename url-connection-agent/src/main/java/org/apache/sling/uca/impl/{URLTimeoutTransformer.java => JavaNetTimeoutTransformer.java} (95%)
 delete mode 100644 url-connection-agent/src/main/java/org/apache/sling/uca/impl/Main.java
 create mode 100644 url-connection-agent/src/test/java/org/apache/sling/uca/impl/AgentIT.java
 rename url-connection-agent/src/test/java/org/apache/sling/uca/impl/{UrlTimeoutTransformerTest.java => JaveNetTimeoutTransformerTest.java} (70%)
 create mode 100644 url-connection-agent/src/test/java/org/apache/sling/uca/impl/Main.java
 copy upgrade/src/main/java/org/apache/sling/upgrade/UpgradeResult.java => url-connection-agent/src/test/java/org/apache/sling/uca/impl/MisbehavingServerControl.java (75%)
 create mode 100644 url-connection-agent/src/test/java/org/apache/sling/uca/impl/MisbehavingServerExtension.java
 copy {upgrade => url-connection-agent}/src/test/resources/simplelogger.properties (94%)


[sling-whiteboard] 08/16: Stubbed out a wait to launch external processes

Posted by ro...@apache.org.
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-whiteboard.git

commit 827efd023823b04306c4bdd7c6247bc58ff11715
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Wed Jun 5 14:32:29 2019 +0200

    Stubbed out a wait to launch external processes
---
 .../java/org/apache/sling/uca/impl/IntegrationTest.java  | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
index 9dec971..0a3af13 100644
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
@@ -27,6 +27,8 @@ import java.net.MalformedURLException;
 import java.net.SocketTimeoutException;
 import java.net.URL;
 import java.net.URLConnection;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.concurrent.TimeUnit;
 
 import org.junit.jupiter.api.Test;
@@ -74,7 +76,19 @@ public class IntegrationTest {
     }
     
 
-    private void runTest(String urlSpec) throws MalformedURLException, IOException {
+    private void runTest(String urlSpec) throws MalformedURLException, IOException, InterruptedException {
+        
+        String javaHome = System.getProperty("java.home");
+        Path javaExe = Paths.get(javaHome, "bin", "java");
+        ProcessBuilder pb = new ProcessBuilder(javaExe.toString(), "-version");
+        pb.inheritIO();
+        Process process = pb.start();
+        
+        process.getInputStream();
+        
+        int exitCode = process.waitFor();
+        
+        LOG.info("Exited with code {}", exitCode);
         
         URL url = new URL(urlSpec);
         LOG.info("connecting to {}", url);


[sling-whiteboard] 14/16: Prepare tests for running against multiple client types

Posted by ro...@apache.org.
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-whiteboard.git

commit 697c1b9aa31ebd4c8f9a29fb39ee4c0c42bc352c
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Wed Jun 5 17:54:06 2019 +0200

    Prepare tests for running against multiple client types
---
 .../java/org/apache/sling/uca/impl/AgentIT.java    | 26 +++++++++++++---------
 .../test/java/org/apache/sling/uca/impl/Main.java  |  5 +++++
 2 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/AgentIT.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/AgentIT.java
index 58e713e..3c2b9e7 100644
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/AgentIT.java
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/AgentIT.java
@@ -32,8 +32,10 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 
-import org.junit.jupiter.api.Test;
+import org.apache.sling.uca.impl.Main.ClientType;
 import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -66,10 +68,11 @@ public class AgentIT {
      * 
      * @throws IOException various I/O problems 
      */
-    @Test
-    public void connectTimeout() throws IOException {
+    @ParameterizedTest
+    @EnumSource(Main.ClientType.class)
+    public void connectTimeout(ClientType clientType) throws IOException {
 
-        RecordedThrowable error = assertTimeout(ofSeconds(5),  () -> runTest("http://repo1.maven.org:81"));
+        RecordedThrowable error = assertTimeout(ofSeconds(5),  () -> runTest("http://repo1.maven.org:81", clientType));
         assertEquals(SocketTimeoutException.class.getName(), error.className);
         assertEquals("connect timed out", error.message);
     }
@@ -79,18 +82,19 @@ public class AgentIT {
      * 
      * @throws IOException various I/O problems
      */
-    @Test
-    public void readTimeout(MisbehavingServerControl server) throws IOException {
+    @ParameterizedTest
+    @EnumSource(Main.ClientType.class)
+    public void readTimeout(ClientType clientType, MisbehavingServerControl server) throws IOException {
         
-        RecordedThrowable error = assertTimeout(ofSeconds(5),  () -> runTest("http://localhost:" + server.getLocalPort()));
+        RecordedThrowable error = assertTimeout(ofSeconds(5),  () -> runTest("http://localhost:" + server.getLocalPort(), clientType));
         assertEquals(SocketTimeoutException.class.getName(), error.className);
         assertEquals("Read timed out", error.message);
     }
     
 
-    private RecordedThrowable runTest(String urlSpec) throws IOException, InterruptedException {
+    private RecordedThrowable runTest(String urlSpec, ClientType clientType) throws IOException, InterruptedException {
 
-        Process process = runForkedCommandWithAgent(new URL(urlSpec), 3, 3);
+        Process process = runForkedCommandWithAgent(new URL(urlSpec), 3, 3, clientType);
         boolean done = process.waitFor(10, TimeUnit.SECONDS);
         
         LOG.info("Dump of stdout: ");
@@ -121,7 +125,7 @@ public class AgentIT {
         return null;
     }
     
-    private Process runForkedCommandWithAgent(URL url, int connectTimeoutSeconds, int readTimeoutSeconds) throws IOException {
+    private Process runForkedCommandWithAgent(URL url, int connectTimeoutSeconds, int readTimeoutSeconds, ClientType clientType) throws IOException {
         
         Path jar = Files.list(Paths.get("target"))
             .filter( p -> p.getFileName().toString().endsWith("-jar-with-dependencies.jar"))
@@ -140,7 +144,7 @@ public class AgentIT {
             classPath,
             "org.apache.sling.uca.impl.Main",
             url.toString(),
-            "JavaNet"
+            clientType.toString()
         );
         
         pb.redirectInput(Redirect.INHERIT);
diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/Main.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/Main.java
index baf7feb..2b19902 100644
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/Main.java
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/Main.java
@@ -31,6 +31,11 @@ import org.apache.commons.httpclient.HttpMethod;
 import org.apache.commons.httpclient.methods.GetMethod;
 
 public class Main {
+    
+    // TODO - write help messages with the values from this enum
+    public enum ClientType {
+        JavaNet /* , HC3 */
+    }
 
     public static void main(String[] args) throws MalformedURLException, IOException {
         


[sling-whiteboard] 13/16: Prepared testing infrastructure for multiple client implementations

Posted by ro...@apache.org.
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-whiteboard.git

commit f7693f15424d2242626e5d9833f720e86ce6a675
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Wed Jun 5 17:39:07 2019 +0200

    Prepared testing infrastructure for multiple client implementations
---
 url-connection-agent/pom.xml                       | 26 +++++++++++
 .../java/org/apache/sling/uca/impl/AgentIT.java    | 32 ++++++++++++--
 .../test/java/org/apache/sling/uca/impl/Main.java  | 51 ++++++++++++++++++++--
 3 files changed, 101 insertions(+), 8 deletions(-)

diff --git a/url-connection-agent/pom.xml b/url-connection-agent/pom.xml
index 1e96414..f6b36e8 100644
--- a/url-connection-agent/pom.xml
+++ b/url-connection-agent/pom.xml
@@ -32,6 +32,7 @@
     <build>
         <plugins>
             <plugin>
+                <!-- package the agent as an all-in-one jar -->
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-assembly-plugin</artifactId>
                 <executions>
@@ -58,6 +59,25 @@
                 </executions>
             </plugin>
             <plugin>
+                <!-- save certain jars in a well-known location for easy usage in tests -->
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>copy-it-dependencies</id>
+                        <phase>pre-integration-test</phase>
+                        <goals>
+                            <goal>copy-dependencies</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <outputDirectory>${project.build.directory}/it-dependencies</outputDirectory>
+                    <stripVersion>true</stripVersion>
+                </configuration>
+            </plugin>
+            <plugin>
+                <!-- Run certain ITs in the integration-test phase, once the agent jar is packaged -->
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-failsafe-plugin</artifactId>
                 <executions>
@@ -95,5 +115,11 @@
             <version>5.4.2</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>commons-httpclient</groupId>
+            <artifactId>commons-httpclient</artifactId>
+            <version>3.1</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
\ No newline at end of file
diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/AgentIT.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/AgentIT.java
index 8cda1ae..58e713e 100644
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/AgentIT.java
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/AgentIT.java
@@ -20,6 +20,7 @@ import static java.time.Duration.ofSeconds;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTimeout;
 
+import java.io.File;
 import java.io.IOException;
 import java.lang.ProcessBuilder.Redirect;
 import java.net.SocketTimeoutException;
@@ -27,6 +28,8 @@ import java.net.URL;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.concurrent.TimeUnit;
 
 import org.junit.jupiter.api.Test;
@@ -88,9 +91,8 @@ public class AgentIT {
     private RecordedThrowable runTest(String urlSpec) throws IOException, InterruptedException {
 
         Process process = runForkedCommandWithAgent(new URL(urlSpec), 3, 3);
-        int exitCode = process.waitFor();
+        boolean done = process.waitFor(10, TimeUnit.SECONDS);
         
-        LOG.info("Exited with code {}", exitCode);
         LOG.info("Dump of stdout: ");
         Files
             .lines(STDOUT)
@@ -101,6 +103,13 @@ public class AgentIT {
             .lines(STDERR)
             .forEach(LOG::info);
 
+        if ( !done ) {
+            process.destroy();
+            throw new IllegalStateException("Terminated process since it did not exit in a reasonable amount of time.");
+        }
+        int exitCode = process.exitValue();
+        LOG.info("Exited with code {}", exitCode);
+        
         if ( exitCode != 0 ) {
             return Files.lines(STDERR)
                 .filter( l -> l.startsWith("Exception in thread \"main\""))
@@ -118,6 +127,8 @@ public class AgentIT {
             .filter( p -> p.getFileName().toString().endsWith("-jar-with-dependencies.jar"))
             .findFirst()
             .orElseThrow( () -> new IllegalStateException("Did not find the agent jar. Did you run mvn package first?"));
+        
+        String classPath = buildClassPath();
 
         String javaHome = System.getProperty("java.home");
         Path javaExe = Paths.get(javaHome, "bin", "java");
@@ -126,9 +137,10 @@ public class AgentIT {
             "-showversion",
             "-javaagent:" + jar +"=" + TimeUnit.SECONDS.toMillis(connectTimeoutSeconds) +"," + TimeUnit.SECONDS.toMillis(readTimeoutSeconds),
             "-cp",
-            Paths.get("target", "classes").toString(),
+            classPath,
             "org.apache.sling.uca.impl.Main",
-            url.toString()
+            url.toString(),
+            "JavaNet"
         );
         
         pb.redirectInput(Redirect.INHERIT);
@@ -138,6 +150,18 @@ public class AgentIT {
         return pb.start();
     }
     
+    private String buildClassPath() throws IOException {
+        
+        List<String> elements = new ArrayList<>();
+        elements.add(Paths.get("target", "test-classes").toString());
+        
+        Files.list(Paths.get("target", "it-dependencies"))
+            .filter( p -> p.getFileName().toString().startsWith("commons-"))
+            .forEach( p -> elements.add(p.toString()));
+        
+        return String.join(File.pathSeparator, elements);
+    }
+
     private RecordedThrowable newRecordedThrowable(String string) {
      
         string = string.replace("Exception in thread \"main\"", "");
diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/Main.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/Main.java
index e6bc48d..baf7feb 100644
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/Main.java
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/Main.java
@@ -24,14 +24,33 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
 
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+
 public class Main {
 
     public static void main(String[] args) throws MalformedURLException, IOException {
         
-        if ( args.length != 1 )
-            throw new IllegalArgumentException("Usage: java -jar ... <URL>");
+        if ( args.length != 2 )
+            throw new IllegalArgumentException("Usage: java -cp ... " + Main.class.getName() + " <URL> JavaNet|HC3|HC4");
+
+        switch ( args[1] ) {
+            case "JavaNet":
+                runUsingJavaNet(args[0]);
+                break;
+            case "HC3":
+                runUsingHttpClient3(args[0]);
+                break;
+            default:
+                throw new IllegalArgumentException("Usage: java -cp ... " + Main.class.getName() + " <URL> JavaNet|HC3|HC4");
+        }
+    }
 
-        URLConnection con = new URL(args[0]).openConnection();
+    private static void runUsingJavaNet(String targetUrl) throws MalformedURLException, IOException {
+        URLConnection con = new URL(targetUrl).openConnection();
         System.out.println("Connection type is " + con);
         
         try (InputStream in = con.getInputStream();
@@ -41,7 +60,31 @@ public class Main {
             while ( (line = br.readLine()) != null )
                 System.out.println("[WEB] " + line);
         }
-
     }
 
+
+    private static void runUsingHttpClient3(String targetUrl) throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+        HttpMethod get = new GetMethod(targetUrl);
+        
+        client.executeMethod(get);
+        
+        System.out.println("[WEB] " + get.getStatusLine());
+        
+        for ( Header header : get.getResponseHeaders() )
+            System.out.print("[WEB] " + header.toExternalForm());
+        
+        
+        try (InputStream in = get.getResponseBodyAsStream()) {
+            if (in != null) {
+                try (InputStreamReader isr = new InputStreamReader(in); 
+                        BufferedReader br = new BufferedReader(isr)) {
+                    String line;
+                    while ((line = br.readLine()) != null)
+                        System.out.println("[WEB] " + line);
+
+                }
+            }
+        }
+    }
 }


[sling-whiteboard] 10/16: Use Maven central for connect timeout tests. Accessing sling.apache.org failed with a 'connection refused' error on Jenkins, presumably since builds.apache.org has direct access to other apache.org servers.

Posted by ro...@apache.org.
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-whiteboard.git

commit 89d2e52a60ba4a65be05b3d366ce3cfcf9203b04
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Wed Jun 5 15:10:45 2019 +0200

    Use Maven central for connect timeout tests. Accessing sling.apache.org failed with a 'connection refused' error on Jenkins, presumably since builds.apache.org has direct access to other apache.org servers.
---
 .../src/test/java/org/apache/sling/uca/impl/IntegrationTest.java      | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
index 0a3af13..9e42394 100644
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
@@ -48,7 +48,7 @@ public class IntegrationTest {
      * <p>It is surprisingly hard to simulate a connnection timeout. The most reliable way seems to
      * be to get a firewall to drop packets, but this is very hard to do portably and safely
      * in a unit test. The least bad possible solution is to access an URL that we know will timeout
-     * and that is related to us - the Sling website.</p>
+     * and that is able to sustain additional traffic. Maven Central is a good candidate for that.</p>
      * 
      * @throws IOException various I/O problems 
      */
@@ -56,7 +56,7 @@ public class IntegrationTest {
     public void connectTimeout() throws IOException {
 
         SocketTimeoutException exception = assertThrows(SocketTimeoutException.class, 
-            () -> assertTimeout(ofSeconds(5),  () -> runTest("http://sling.apache.org:81"))
+            () -> assertTimeout(ofSeconds(5),  () -> runTest("http://repo1.maven.org:81"))
         );
         assertEquals("connect timed out", exception.getMessage());
     }


[sling-whiteboard] 09/16: Add missing license header

Posted by ro...@apache.org.
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-whiteboard.git

commit 87cf8d7d8d7884c2e31b2b77a3e6a20b48381dbe
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Wed Jun 5 14:37:17 2019 +0200

    Add missing license header
---
 .../src/test/resources/simplelogger.properties        | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/url-connection-agent/src/test/resources/simplelogger.properties b/url-connection-agent/src/test/resources/simplelogger.properties
index 6dfc7aa..0297949 100644
--- a/url-connection-agent/src/test/resources/simplelogger.properties
+++ b/url-connection-agent/src/test/resources/simplelogger.properties
@@ -1 +1,20 @@
+#
+#  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.
+#
+
 org.slf4j.simpleLogger.showDateTime=true
\ No newline at end of file


[sling-whiteboard] 02/16: Migrate to Junit 5 for more fine-grained timeouts and exception checks.

Posted by ro...@apache.org.
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-whiteboard.git

commit 4b2d40b7b986d45dd648c16fc4748a3818db09f8
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Wed Jun 5 11:34:02 2019 +0200

    Migrate to Junit 5 for more fine-grained timeouts and exception checks.
---
 url-connection-agent/pom.xml                       | 10 ++++---
 .../org/apache/sling/uca/impl/IntegrationTest.java | 31 ++++++++++++++--------
 .../java/org/apache/sling/uca/impl/ServerRule.java | 29 +++++++++++---------
 .../sling/uca/impl/UrlTimeoutTransformerTest.java  | 16 ++++++-----
 4 files changed, 52 insertions(+), 34 deletions(-)

diff --git a/url-connection-agent/pom.xml b/url-connection-agent/pom.xml
index e44e7ba..bc5a25f 100644
--- a/url-connection-agent/pom.xml
+++ b/url-connection-agent/pom.xml
@@ -67,10 +67,6 @@
             <version>3.24.0-GA</version>
         </dependency>
         <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-        </dependency>
-        <dependency>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-server</artifactId>
             <version>9.4.18.v20190429</version>
@@ -81,5 +77,11 @@
             <artifactId>slf4j-simple</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <version>5.4.2</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
\ No newline at end of file
diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
index b3d6816..d9a1d7c 100644
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
@@ -16,42 +16,51 @@
  */
 package org.apache.sling.uca.impl;
 
-import static org.junit.Assert.fail;
+import static java.time.Duration.ofSeconds;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTimeout;
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
+import java.net.SocketTimeoutException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.concurrent.TimeUnit;
 
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@ExtendWith(ServerRule.class)
 public class IntegrationTest {
     
     private static final Logger LOG = LoggerFactory.getLogger(IntegrationTest.class);
-    
-    @Rule
-    public ServerRule server = new ServerRule();
 
-    @Test(expected = IOException.class, timeout = 5000)
+    @Test
     public void connectTimeout() throws IOException {
 
-        runTest(false);
+        SocketTimeoutException exception = assertThrows(SocketTimeoutException.class, 
+            () -> assertTimeout(ofSeconds(5),  () -> runTest(false))
+        );
+        assertEquals("Connect timed out", exception.getMessage());
     }
 
-    @Test(expected = IOException.class, timeout = 15000)
+    @Test
     public void readTimeout() throws IOException {
         
-        runTest(true);
+        SocketTimeoutException exception = assertThrows(SocketTimeoutException.class, 
+            () -> assertTimeout(ofSeconds(10),  () -> runTest(false))
+        );
+        assertEquals("Read timed out", exception.getMessage());
     }
     
 
     private void runTest(boolean shouldConnect) throws MalformedURLException, IOException {
-        URL url = new URL("http://localhost:" + server.getLocalPort());
+        
+        URL url = new URL("http://localhost:" + ServerRule.getLocalPort());
         LOG.info("connecting");
         URLConnection connection = url.openConnection();
         // TODO - remove when running through the harness
diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerRule.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerRule.java
index 6bcad85..c047afd 100644
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerRule.java
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerRule.java
@@ -32,21 +32,28 @@ import org.eclipse.jetty.server.Request;
 import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.server.ServerConnector;
 import org.eclipse.jetty.server.handler.AbstractHandler;
-import org.junit.rules.ExternalResource;
+import org.junit.jupiter.api.extension.AfterAllCallback;
+import org.junit.jupiter.api.extension.BeforeAllCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-class ServerRule extends ExternalResource {
+class ServerRule implements BeforeAllCallback, AfterAllCallback {
     
     private static final Logger LOG = LoggerFactory.getLogger(ServerRule.class);
     
-    private Server server;
+    private static final int LOCAL_PORT = 12312;
     
-    private int localPort = 12312;
 
+    public static int getLocalPort() {
+        return LOCAL_PORT;
+    }
+    
+    private Server server;
+    
     @Override
-    protected void before() throws Throwable {
-        server = new Server(localPort);
+    public void beforeAll(ExtensionContext context) throws Exception {
+        server = new Server(LOCAL_PORT);
         ServerConnector connector = new ServerConnector(server) {
             @Override
             public void accept(int acceptorID) throws IOException {
@@ -61,7 +68,7 @@ class ServerRule extends ExternalResource {
                 LOG.info("Accepted");
             }
         };
-        connector.setPort(localPort);
+        connector.setPort(LOCAL_PORT);
         connector.setConnectionFactories(Collections.singleton(new HttpConnectionFactory() {
             @Override
             public Connection newConnection(Connector connector, EndPoint endPoint) {
@@ -104,9 +111,9 @@ class ServerRule extends ExternalResource {
         
         server.start();
     }
-    
+
     @Override
-    protected void after() {
+    public void afterAll(ExtensionContext context) throws Exception {
         if ( server != null )
             try {
                 server.stop();
@@ -114,8 +121,4 @@ class ServerRule extends ExternalResource {
                 e.printStackTrace();
             }
     }
-
-    public int getLocalPort() {
-        return localPort;
-    }
 }
\ No newline at end of file
diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/UrlTimeoutTransformerTest.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/UrlTimeoutTransformerTest.java
index 774b420..3847ef2 100644
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/UrlTimeoutTransformerTest.java
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/UrlTimeoutTransformerTest.java
@@ -16,10 +16,12 @@
  */
 package org.apache.sling.uca.impl;
 
-import static org.junit.Assert.assertNotNull;
 
-import org.junit.Before;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import javassist.NotFoundException;
 
@@ -27,7 +29,7 @@ public class UrlTimeoutTransformerTest {
     
     private URLTimeoutTransformer transformer;
 
-    @Before
+    @BeforeEach
     public void initFields() {
         transformer = new URLTimeoutTransformer(1, 1);
     }
@@ -37,11 +39,13 @@ public class UrlTimeoutTransformerTest {
         assertNotNull(transformer.findConnectMethod("sun/net/www/protocol/http/HttpURLConnection"));
     }
 
-    @Test(expected = NotFoundException.class)
+    @Test
     public void findInheritedConnectMethod() throws NotFoundException {
         // do NOT look for inherited methods, as we can only rewrite the precise classes the
         // retransform was triggered for
-        transformer.findConnectMethod("sun/net/www/protocol/https/DelegateHttpsURLConnection");
+        assertThrows( NotFoundException.class,
+            () -> transformer.findConnectMethod("sun/net/www/protocol/https/DelegateHttpsURLConnection")
+        );
     }
     
 }


[sling-whiteboard] 03/16: Provisional integration tests, currently setting the timeouts manually

Posted by ro...@apache.org.
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-whiteboard.git

commit f79ae3c3efb93dcdb963145390d056ec8fdfcdcc
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Wed Jun 5 13:51:45 2019 +0200

    Provisional integration tests, currently setting the timeouts manually
---
 url-connection-agent/pom.xml                              |  6 ++++++
 .../java/org/apache/sling/uca/impl/IntegrationTest.java   | 15 ++++++---------
 .../test/java/org/apache/sling/uca/impl/ServerRule.java   |  2 +-
 .../src/test/resources/simplelogger.properties            |  1 +
 4 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/url-connection-agent/pom.xml b/url-connection-agent/pom.xml
index bc5a25f..86da21d 100644
--- a/url-connection-agent/pom.xml
+++ b/url-connection-agent/pom.xml
@@ -83,5 +83,11 @@
             <version>5.4.2</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>2.6</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
\ No newline at end of file
diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
index d9a1d7c..31ba3bf 100644
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
@@ -43,33 +43,30 @@ public class IntegrationTest {
     public void connectTimeout() throws IOException {
 
         SocketTimeoutException exception = assertThrows(SocketTimeoutException.class, 
-            () -> assertTimeout(ofSeconds(5),  () -> runTest(false))
+            () -> assertTimeout(ofSeconds(5),  () -> runTest("http://sling.apache.org:81"))
         );
-        assertEquals("Connect timed out", exception.getMessage());
+        assertEquals("connect timed out", exception.getMessage());
     }
 
     @Test
     public void readTimeout() throws IOException {
         
         SocketTimeoutException exception = assertThrows(SocketTimeoutException.class, 
-            () -> assertTimeout(ofSeconds(10),  () -> runTest(false))
+            () -> assertTimeout(ofSeconds(10),  () -> runTest("http://localhost:" + ServerRule.getLocalPort()))
         );
         assertEquals("Read timed out", exception.getMessage());
     }
     
 
-    private void runTest(boolean shouldConnect) throws MalformedURLException, IOException {
+    private void runTest(String urlSpec) throws MalformedURLException, IOException {
         
-        URL url = new URL("http://localhost:" + ServerRule.getLocalPort());
-        LOG.info("connecting");
+        URL url = new URL(urlSpec);
+        LOG.info("connecting to {}", url);
         URLConnection connection = url.openConnection();
         // TODO - remove when running through the harness
         connection.setConnectTimeout((int) TimeUnit.SECONDS.toMillis(3));
         connection.setReadTimeout((int) TimeUnit.SECONDS.toMillis(3));
         connection.connect();
-        /*
-         * if ( !shouldConnect ) fail("Connection should not be succesful");
-         */        
         LOG.info("connected");
         try ( InputStream is = connection.getInputStream()) {
             while ( is.read() != -1)
diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerRule.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerRule.java
index c047afd..a799b55 100644
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerRule.java
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerRule.java
@@ -44,7 +44,6 @@ class ServerRule implements BeforeAllCallback, AfterAllCallback {
     
     private static final int LOCAL_PORT = 12312;
     
-
     public static int getLocalPort() {
         return LOCAL_PORT;
     }
@@ -53,6 +52,7 @@ class ServerRule implements BeforeAllCallback, AfterAllCallback {
     
     @Override
     public void beforeAll(ExtensionContext context) throws Exception {
+        
         server = new Server(LOCAL_PORT);
         ServerConnector connector = new ServerConnector(server) {
             @Override
diff --git a/url-connection-agent/src/test/resources/simplelogger.properties b/url-connection-agent/src/test/resources/simplelogger.properties
new file mode 100644
index 0000000..6dfc7aa
--- /dev/null
+++ b/url-connection-agent/src/test/resources/simplelogger.properties
@@ -0,0 +1 @@
+org.slf4j.simpleLogger.showDateTime=true
\ No newline at end of file


[sling-whiteboard] 07/16: Removed unused dependencies

Posted by ro...@apache.org.
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-whiteboard.git

commit 5360a60b0ea9ae3fce063414a3033cad91d529bd
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Wed Jun 5 14:21:15 2019 +0200

    Removed unused dependencies
---
 url-connection-agent/pom.xml | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/url-connection-agent/pom.xml b/url-connection-agent/pom.xml
index 86da21d..bc5a25f 100644
--- a/url-connection-agent/pom.xml
+++ b/url-connection-agent/pom.xml
@@ -83,11 +83,5 @@
             <version>5.4.2</version>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>commons-io</groupId>
-            <artifactId>commons-io</artifactId>
-            <version>2.6</version>
-            <scope>test</scope>
-        </dependency>
     </dependencies>
 </project>
\ No newline at end of file


[sling-whiteboard] 05/16: Allow accessing server as an instance field and stop hardcoding the local port.

Posted by ro...@apache.org.
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-whiteboard.git

commit d4d849133ac4d290f1bdb8f14f25f6b2422bfc97
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Wed Jun 5 14:13:00 2019 +0200

    Allow accessing server as an instance field and stop hardcoding the local port.
---
 .../org/apache/sling/uca/impl/IntegrationTest.java |  5 +--
 .../org/apache/sling/uca/impl/ServerControl.java   |  6 ++++
 .../java/org/apache/sling/uca/impl/ServerRule.java | 37 ++++++++++++++++++----
 3 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
index d952181..aa02dd1 100644
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
@@ -29,6 +29,7 @@ import java.net.URL;
 import java.net.URLConnection;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.sling.uca.impl.ServerRule.MisbehavingServer;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.slf4j.Logger;
@@ -65,10 +66,10 @@ public class IntegrationTest {
      * @throws IOException various I/O problems
      */
     @Test
-    public void readTimeout() throws IOException {
+    public void readTimeout(@MisbehavingServer ServerControl server) throws IOException {
         
         SocketTimeoutException exception = assertThrows(SocketTimeoutException.class, 
-            () -> assertTimeout(ofSeconds(10),  () -> runTest("http://localhost:" + ServerRule.getLocalPort()))
+            () -> assertTimeout(ofSeconds(10),  () -> runTest("http://localhost:" + server.getLocalPort()))
         );
         assertEquals("Read timed out", exception.getMessage());
     }
diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerControl.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerControl.java
new file mode 100644
index 0000000..e73d682
--- /dev/null
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerControl.java
@@ -0,0 +1,6 @@
+package org.apache.sling.uca.impl;
+
+public interface ServerControl {
+
+    int getLocalPort();
+}
diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerRule.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerRule.java
index 62a6380..80d4fc4 100644
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerRule.java
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerRule.java
@@ -17,6 +17,10 @@
 package org.apache.sling.uca.impl;
 
 import java.io.IOException;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
 import java.util.concurrent.TimeUnit;
 
 import javax.servlet.ServletException;
@@ -31,25 +35,45 @@ import org.eclipse.jetty.server.handler.AbstractHandler;
 import org.junit.jupiter.api.extension.AfterAllCallback;
 import org.junit.jupiter.api.extension.BeforeAllCallback;
 import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ParameterContext;
+import org.junit.jupiter.api.extension.ParameterResolutionException;
+import org.junit.jupiter.api.extension.ParameterResolver;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-class ServerRule implements BeforeAllCallback, AfterAllCallback {
+class ServerRule implements BeforeAllCallback, AfterAllCallback, ParameterResolver, ServerControl {
     
-    private final Logger logger = LoggerFactory.getLogger(getClass());
+    @Retention(RetentionPolicy.RUNTIME)
+    @Target(ElementType.PARAMETER)
+    public @interface MisbehavingServer { }
     
-    private static final int LOCAL_PORT = 12312;
+    private final Logger logger = LoggerFactory.getLogger(getClass());
     
-    public static int getLocalPort() {
-        return LOCAL_PORT;
+    public int getLocalPort() {
+        return ((ServerConnector) server.getConnectors()[0]).getLocalPort();
     }
     
     private Server server;
     
     @Override
+    public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
+            throws ParameterResolutionException {
+        return parameterContext.isAnnotated(MisbehavingServer.class);
+    }
+    
+    @Override
+    public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
+            throws ParameterResolutionException {
+        if ( parameterContext.getParameter().getType() == ServerControl.class )
+            return this;
+        
+        throw new ParameterResolutionException("Unable to get a Server instance for " + parameterContext);
+    }
+    
+    @Override
     public void beforeAll(ExtensionContext context) throws Exception {
         
-        server = new Server(LOCAL_PORT);
+        server = new Server();
         ServerConnector connector = new ServerConnector(server) {
             @Override
             public void accept(int acceptorID) throws IOException {
@@ -64,7 +88,6 @@ class ServerRule implements BeforeAllCallback, AfterAllCallback {
                 LOG.info("Accepted");
             }
         };
-        connector.setPort(LOCAL_PORT);
         server.setConnectors(new Connector[] { connector });
         server.setHandler(new AbstractHandler() {
             


[sling-whiteboard] 15/16: Implement default timeouts for httpclient 3.x

Posted by ro...@apache.org.
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-whiteboard.git

commit cffc06e75c769113cd44dd7d823b12a02b1f2577
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Thu Jun 6 16:51:45 2019 +0200

    Implement default timeouts for httpclient 3.x
---
 url-connection-agent/pom.xml                       |  6 ++
 .../main/java/org/apache/sling/uca/impl/Agent.java | 12 +++-
 .../uca/impl/HttpClient3TimeoutTransformer.java    | 67 ++++++++++++++++++++++
 ...sformer.java => JavaNetTimeoutTransformer.java} |  4 +-
 .../java/org/apache/sling/uca/impl/AgentIT.java    | 17 ++++--
 ...est.java => JaveNetTimeoutTransformerTest.java} |  6 +-
 .../test/java/org/apache/sling/uca/impl/Main.java  | 22 +++++--
 7 files changed, 117 insertions(+), 17 deletions(-)

diff --git a/url-connection-agent/pom.xml b/url-connection-agent/pom.xml
index f6b36e8..b020df3 100644
--- a/url-connection-agent/pom.xml
+++ b/url-connection-agent/pom.xml
@@ -121,5 +121,11 @@
             <version>3.1</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>jcl-over-slf4j</artifactId>
+            <version>1.7.25</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
\ No newline at end of file
diff --git a/url-connection-agent/src/main/java/org/apache/sling/uca/impl/Agent.java b/url-connection-agent/src/main/java/org/apache/sling/uca/impl/Agent.java
index 2b27373..4ed0067 100644
--- a/url-connection-agent/src/main/java/org/apache/sling/uca/impl/Agent.java
+++ b/url-connection-agent/src/main/java/org/apache/sling/uca/impl/Agent.java
@@ -16,13 +16,14 @@
  */
 package org.apache.sling.uca.impl;
 
+import java.lang.instrument.ClassFileTransformer;
 import java.lang.instrument.Instrumentation;
 import java.util.concurrent.TimeUnit;
 
 public class Agent {
 
     public static void premain(String args, Instrumentation inst) {
-
+        
         System.out.println("[AGENT] Loading agent...");
         String[] parsedArgs = args.split(",");
         long connectTimeout =  TimeUnit.MINUTES.toMillis(1);
@@ -34,9 +35,14 @@ public class Agent {
         
         System.out.format("[AGENT] Set connectTimeout : %d, readTimeout: %d%n", connectTimeout, readTimeout);
 
-        URLTimeoutTransformer transformer = new URLTimeoutTransformer(connectTimeout, readTimeout);
+        ClassFileTransformer[] transformers = new ClassFileTransformer[] {
+            new JavaNetTimeoutTransformer(connectTimeout, readTimeout),
+            new HttpClient3TimeoutTransformer(connectTimeout, readTimeout)
+        };
         
-        inst.addTransformer(transformer, true);
+        for ( ClassFileTransformer transformer : transformers )
+            inst.addTransformer(transformer, true);
+
         System.out.println("[AGENT] Loaded agent!");
     }
 
diff --git a/url-connection-agent/src/main/java/org/apache/sling/uca/impl/HttpClient3TimeoutTransformer.java b/url-connection-agent/src/main/java/org/apache/sling/uca/impl/HttpClient3TimeoutTransformer.java
new file mode 100644
index 0000000..b287447
--- /dev/null
+++ b/url-connection-agent/src/main/java/org/apache/sling/uca/impl/HttpClient3TimeoutTransformer.java
@@ -0,0 +1,67 @@
+/*
+ * 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.uca.impl;
+
+import java.lang.instrument.ClassFileTransformer;
+import java.lang.instrument.IllegalClassFormatException;
+import java.security.ProtectionDomain;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtMethod;
+import javassist.bytecode.Descriptor;
+
+public class HttpClient3TimeoutTransformer implements ClassFileTransformer {
+    
+    private static final String DEFAULT_HTTP_PARAMS_FACTORY_CLASS_NAME = Descriptor.toJvmName("org.apache.commons.httpclient.params.DefaultHttpParamsFactory");
+    
+    private final long connectTimeoutMillis;
+    private final long readTimeoutMillis;
+    
+    public HttpClient3TimeoutTransformer(long connectTimeoutMillis, long readTimeoutMillis) {
+        this.connectTimeoutMillis = connectTimeoutMillis;
+        this.readTimeoutMillis = readTimeoutMillis;
+    }
+
+    @Override
+    public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
+            ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
+        try {
+            if ( DEFAULT_HTTP_PARAMS_FACTORY_CLASS_NAME.equals(className) ) {
+                System.out.println("[AGENT] Asked to transform " + className);
+                
+                ClassPool defaultPool = ClassPool.getDefault();
+                CtClass cc = defaultPool.get(Descriptor.toJavaName(className));
+                
+                CtMethod getSoTimeout =  cc.getDeclaredMethod("createParams");
+                // javassist seems unable to resolve the constant values, so just inline them
+                // also, unable to resolve calls to setParameter with int values (no boxing?)
+                // HttpConnectionParams.CONNECTION_TIMEOUT
+                getSoTimeout.insertAfter("$_.setParameter(\"http.connection.timeout\", Integer.valueOf(" + connectTimeoutMillis + "));");
+                // HttpMethodParams.SO_TIMEOUT
+                getSoTimeout.insertAfter("$_.setParameter(\"http.socket.timeout\", Integer.valueOf(" + readTimeoutMillis + "));");
+                
+                classfileBuffer = cc.toBytecode();
+                cc.detach();
+            }
+            return classfileBuffer;
+        } catch (Exception e) {
+            e.printStackTrace(); // ensure _something_ is printed
+            throw new RuntimeException("[AGENT] Transformation failed", e);
+        }
+    }
+}
diff --git a/url-connection-agent/src/main/java/org/apache/sling/uca/impl/URLTimeoutTransformer.java b/url-connection-agent/src/main/java/org/apache/sling/uca/impl/JavaNetTimeoutTransformer.java
similarity index 95%
rename from url-connection-agent/src/main/java/org/apache/sling/uca/impl/URLTimeoutTransformer.java
rename to url-connection-agent/src/main/java/org/apache/sling/uca/impl/JavaNetTimeoutTransformer.java
index 1143004..d320875 100644
--- a/url-connection-agent/src/main/java/org/apache/sling/uca/impl/URLTimeoutTransformer.java
+++ b/url-connection-agent/src/main/java/org/apache/sling/uca/impl/JavaNetTimeoutTransformer.java
@@ -38,7 +38,7 @@ import javassist.bytecode.Descriptor;
  * @see URLConnection#getReadTimeout()
  *
  */
-class URLTimeoutTransformer implements ClassFileTransformer {
+class JavaNetTimeoutTransformer implements ClassFileTransformer {
 
     private static final Set<String> CLASSES_TO_TRANSFORM = new HashSet<>();
 
@@ -50,7 +50,7 @@ class URLTimeoutTransformer implements ClassFileTransformer {
     private final long readTimeoutMillis;
     private final long connectTimeoutMillis;
 
-    public URLTimeoutTransformer(long connectTimeout, long readTimeout) {
+    public JavaNetTimeoutTransformer(long connectTimeout, long readTimeout) {
         this.connectTimeoutMillis = connectTimeout;
         this.readTimeoutMillis = readTimeout;
     }
diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/AgentIT.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/AgentIT.java
index 3c2b9e7..65bd7af 100644
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/AgentIT.java
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/AgentIT.java
@@ -32,6 +32,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.commons.httpclient.ConnectTimeoutException;
 import org.apache.sling.uca.impl.Main.ClientType;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.junit.jupiter.params.ParameterizedTest;
@@ -73,8 +74,12 @@ public class AgentIT {
     public void connectTimeout(ClientType clientType) throws IOException {
 
         RecordedThrowable error = assertTimeout(ofSeconds(5),  () -> runTest("http://repo1.maven.org:81", clientType));
-        assertEquals(SocketTimeoutException.class.getName(), error.className);
-        assertEquals("connect timed out", error.message);
+        
+        Class<?> expectedClass = clientType == ClientType.HC3 ? ConnectTimeoutException.class : SocketTimeoutException.class;
+        String expectedMessage = clientType == ClientType.HC3 ? "The host did not accept the connection within timeout of 3000 ms" : "connect timed out";
+        
+        assertEquals(expectedClass.getName(), error.className);
+        assertEquals(expectedMessage, error.message);
     }
 
     /**
@@ -95,7 +100,7 @@ public class AgentIT {
     private RecordedThrowable runTest(String urlSpec, ClientType clientType) throws IOException, InterruptedException {
 
         Process process = runForkedCommandWithAgent(new URL(urlSpec), 3, 3, clientType);
-        boolean done = process.waitFor(10, TimeUnit.SECONDS);
+        boolean done = process.waitFor(30, TimeUnit.SECONDS);
         
         LOG.info("Dump of stdout: ");
         Files
@@ -160,7 +165,11 @@ public class AgentIT {
         elements.add(Paths.get("target", "test-classes").toString());
         
         Files.list(Paths.get("target", "it-dependencies"))
-            .filter( p -> p.getFileName().toString().startsWith("commons-"))
+            .filter( p -> p.getFileName().toString().equals("commons-httpclient.jar") 
+                    || p.getFileName().toString().equals("commons-codec.jar")
+                    || p.getFileName().toString().equals("slf4j-simple.jar")
+                    || p.getFileName().toString().equals("slf4j-api.jar")
+                    || p.getFileName().toString().equals("jcl-over-slf4j.jar"))
             .forEach( p -> elements.add(p.toString()));
         
         return String.join(File.pathSeparator, elements);
diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/UrlTimeoutTransformerTest.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/JaveNetTimeoutTransformerTest.java
similarity index 91%
rename from url-connection-agent/src/test/java/org/apache/sling/uca/impl/UrlTimeoutTransformerTest.java
rename to url-connection-agent/src/test/java/org/apache/sling/uca/impl/JaveNetTimeoutTransformerTest.java
index 3847ef2..c0abffc 100644
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/UrlTimeoutTransformerTest.java
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/JaveNetTimeoutTransformerTest.java
@@ -25,13 +25,13 @@ import org.junit.jupiter.api.Test;
 
 import javassist.NotFoundException;
 
-public class UrlTimeoutTransformerTest {
+public class JaveNetTimeoutTransformerTest {
     
-    private URLTimeoutTransformer transformer;
+    private JavaNetTimeoutTransformer transformer;
 
     @BeforeEach
     public void initFields() {
-        transformer = new URLTimeoutTransformer(1, 1);
+        transformer = new JavaNetTimeoutTransformer(1, 1);
     }
 
     @Test
diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/Main.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/Main.java
index 2b19902..de07a23 100644
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/Main.java
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/Main.java
@@ -23,24 +23,30 @@ import java.io.InputStreamReader;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
+import java.util.Date;
 
+import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
 import org.apache.commons.httpclient.Header;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpException;
 import org.apache.commons.httpclient.HttpMethod;
 import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.params.HttpClientParams;
+import org.apache.commons.httpclient.params.HttpMethodParams;
 
 public class Main {
     
     // TODO - write help messages with the values from this enum
     public enum ClientType {
-        JavaNet /* , HC3 */
+        JavaNet, HC3
     }
 
     public static void main(String[] args) throws MalformedURLException, IOException {
         
         if ( args.length != 2 )
             throw new IllegalArgumentException("Usage: java -cp ... " + Main.class.getName() + " <URL> JavaNet|HC3|HC4");
+        
+        System.out.println(new Date() + " [WEB] Executing request via " + args[1]);
 
         switch ( args[1] ) {
             case "JavaNet":
@@ -70,14 +76,20 @@ public class Main {
 
     private static void runUsingHttpClient3(String targetUrl) throws HttpException, IOException {
         HttpClient client = new HttpClient();
+        // disable retries, to make sure that we get equivalent behaviour with other implementations
+        client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false));
         HttpMethod get = new GetMethod(targetUrl);
-        
+        System.out.format("Connection timeouts: connect: %d, so: %s%n", 
+                client.getHttpConnectionManager().getParams().getConnectionTimeout(),
+                client.getHttpConnectionManager().getParams().getSoTimeout());
+        System.out.format("Client so timeout: %d (raw: %s) %n", client.getParams().getSoTimeout(), 
+                client.getParams().getParameter(HttpClientParams.SO_TIMEOUT));
         client.executeMethod(get);
         
-        System.out.println("[WEB] " + get.getStatusLine());
+        System.out.println(new Date() + " [WEB] " + get.getStatusLine());
         
         for ( Header header : get.getResponseHeaders() )
-            System.out.print("[WEB] " + header.toExternalForm());
+            System.out.print(new Date() + " [WEB] " + header.toExternalForm());
         
         
         try (InputStream in = get.getResponseBodyAsStream()) {
@@ -86,7 +98,7 @@ public class Main {
                         BufferedReader br = new BufferedReader(isr)) {
                     String line;
                     while ((line = br.readLine()) != null)
-                        System.out.println("[WEB] " + line);
+                        System.out.println(new Date() + " [WEB] " + line);
 
                 }
             }


[sling-whiteboard] 01/16: Some work on integration tests

Posted by ro...@apache.org.
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-whiteboard.git

commit b0fd4f8e0b252795849e9bd57ce1d16527d47674
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Wed Jun 5 11:03:49 2019 +0200

    Some work on integration tests
---
 url-connection-agent/pom.xml                       |  11 ++
 .../org/apache/sling/uca/impl/IntegrationTest.java |  71 ++++++++++++
 .../java/org/apache/sling/uca/impl/ServerRule.java | 121 +++++++++++++++++++++
 3 files changed, 203 insertions(+)

diff --git a/url-connection-agent/pom.xml b/url-connection-agent/pom.xml
index 01af5b3..e44e7ba 100644
--- a/url-connection-agent/pom.xml
+++ b/url-connection-agent/pom.xml
@@ -70,5 +70,16 @@
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-server</artifactId>
+            <version>9.4.18.v20190429</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
\ No newline at end of file
diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
new file mode 100644
index 0000000..b3d6816
--- /dev/null
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.uca.impl;
+
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.concurrent.TimeUnit;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class IntegrationTest {
+    
+    private static final Logger LOG = LoggerFactory.getLogger(IntegrationTest.class);
+    
+    @Rule
+    public ServerRule server = new ServerRule();
+
+    @Test(expected = IOException.class, timeout = 5000)
+    public void connectTimeout() throws IOException {
+
+        runTest(false);
+    }
+
+    @Test(expected = IOException.class, timeout = 15000)
+    public void readTimeout() throws IOException {
+        
+        runTest(true);
+    }
+    
+
+    private void runTest(boolean shouldConnect) throws MalformedURLException, IOException {
+        URL url = new URL("http://localhost:" + server.getLocalPort());
+        LOG.info("connecting");
+        URLConnection connection = url.openConnection();
+        // TODO - remove when running through the harness
+        connection.setConnectTimeout((int) TimeUnit.SECONDS.toMillis(3));
+        connection.setReadTimeout((int) TimeUnit.SECONDS.toMillis(3));
+        connection.connect();
+        /*
+         * if ( !shouldConnect ) fail("Connection should not be succesful");
+         */        
+        LOG.info("connected");
+        try ( InputStream is = connection.getInputStream()) {
+            while ( is.read() != -1)
+                ;
+        }
+        LOG.info("read");
+    }
+}
diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerRule.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerRule.java
new file mode 100644
index 0000000..6bcad85
--- /dev/null
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerRule.java
@@ -0,0 +1,121 @@
+/*
+ * 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.uca.impl;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.concurrent.TimeUnit;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.jetty.io.Connection;
+import org.eclipse.jetty.io.EndPoint;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.HttpConnectionFactory;
+import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.server.handler.AbstractHandler;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+class ServerRule extends ExternalResource {
+    
+    private static final Logger LOG = LoggerFactory.getLogger(ServerRule.class);
+    
+    private Server server;
+    
+    private int localPort = 12312;
+
+    @Override
+    protected void before() throws Throwable {
+        server = new Server(localPort);
+        ServerConnector connector = new ServerConnector(server) {
+            @Override
+            public void accept(int acceptorID) throws IOException {
+                LOG.info("Waiting before accepting");
+                try {
+                    Thread.sleep(TimeUnit.SECONDS.toMillis(10));
+                } catch (InterruptedException e) {
+                    Thread.currentThread().interrupt();
+                    return;
+                }
+                super.accept(acceptorID);
+                LOG.info("Accepted");
+            }
+        };
+        connector.setPort(localPort);
+        connector.setConnectionFactories(Collections.singleton(new HttpConnectionFactory() {
+            @Override
+            public Connection newConnection(Connector connector, EndPoint endPoint) {
+                LOG.info("Waiting before creating connection");
+                try {
+                    Thread.sleep(TimeUnit.SECONDS.toMillis(10));
+                } catch (InterruptedException e) {
+                    Thread.currentThread().interrupt();
+                    throw new RuntimeException("Interrupted");
+                }
+                
+                Connection connection = super.newConnection(connector, endPoint);
+                LOG.info("Connection created");
+                return connection;
+            }
+        }));
+        server.setConnectors(new Connector[] { 
+            connector
+        });
+        server.setHandler(new AbstractHandler() {
+            
+            @Override
+            public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
+                    throws IOException, ServletException {
+                
+                LOG.info("Waiting before handling");
+                
+                try {
+                    Thread.sleep(TimeUnit.SECONDS.toMillis(10));
+                } catch (InterruptedException e) {
+                    Thread.currentThread().interrupt();
+                    return;
+                }
+                
+                response.setStatus(HttpServletResponse.SC_NO_CONTENT);
+                baseRequest.setHandled(true);
+                LOG.info("Handled");
+            }
+        });
+        
+        server.start();
+    }
+    
+    @Override
+    protected void after() {
+        if ( server != null )
+            try {
+                server.stop();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+    }
+
+    public int getLocalPort() {
+        return localPort;
+    }
+}
\ No newline at end of file


[sling-whiteboard] 11/16: Converted IntegrationTest to a proper IT

Posted by ro...@apache.org.
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-whiteboard.git

commit 9a46cacd3b36be0f692af79601c6a04e5f9eb1d5
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Wed Jun 5 17:00:17 2019 +0200

    Converted IntegrationTest to a proper IT
    
    - load the java agent from the compiled jar
    - switch to using a surefire test
---
 url-connection-agent/pom.xml                       |  12 ++
 .../java/org/apache/sling/uca/impl/AgentIT.java    | 163 +++++++++++++++++++++
 .../org/apache/sling/uca/impl/IntegrationTest.java | 107 --------------
 3 files changed, 175 insertions(+), 107 deletions(-)

diff --git a/url-connection-agent/pom.xml b/url-connection-agent/pom.xml
index bc5a25f..1e96414 100644
--- a/url-connection-agent/pom.xml
+++ b/url-connection-agent/pom.xml
@@ -57,6 +57,18 @@
                     </execution>
                 </executions>
             </plugin>
+            <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>
         </plugins>
     </build>
 
diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/AgentIT.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/AgentIT.java
new file mode 100644
index 0000000..b67a650
--- /dev/null
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/AgentIT.java
@@ -0,0 +1,163 @@
+/*
+ * 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.uca.impl;
+
+import static java.time.Duration.ofSeconds;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTimeout;
+
+import java.io.IOException;
+import java.lang.ProcessBuilder.Redirect;
+import java.net.SocketTimeoutException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.concurrent.TimeUnit;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Validates that accessing URLs that exhibit connection problems results in a timeouts being fired when the agent is used
+ * 
+ * <p>This test validates that the agent works when statically loaded, i.e. with a <tt>-javaagent:</tt> flag
+ * passed to the JVM. As such it requires launching a new JVM instance each time, otherwise the results are
+ * not valid.</p>
+ * 
+ * <p>It does so by reusing the same JVM as the one running the test. Validation is done by looking for a
+ * Throwable information in the stderr and recording the exception class name and the message.</p>
+ *
+ */
+@ExtendWith(MisbehavingServerExtension.class)
+public class AgentIT {
+    
+    private static final Path STDERR = Paths.get("target", "stderr.txt");
+    private static final Path STDOUT = Paths.get("target", "stdout.txt");
+    private static final Logger LOG = LoggerFactory.getLogger(AgentIT.class);
+
+    /**
+     * Validates that connecting to a unaccessible port on an existing port fails with a connect 
+     * timeout exception
+     * 
+     * <p>It is surprisingly hard to simulate a connnection timeout. The most reliable way seems to
+     * be to get a firewall to drop packets, but this is very hard to do portably and safely
+     * in a unit test. The least bad possible solution is to access an URL that we know will timeout
+     * and that is able to sustain additional traffic. Maven Central is a good candidate for that.</p>
+     * 
+     * @throws IOException various I/O problems 
+     */
+    @Test
+    public void connectTimeout() throws IOException {
+
+        RecordedThrowable error = assertTimeout(ofSeconds(5),  () -> runTest("http://repo1.maven.org:81"));
+        assertEquals(SocketTimeoutException.class.getName(), error.className);
+        assertEquals("connect timed out", error.message);
+    }
+
+    /**
+     * Validates that connecting to a host that delays the response fails with a read timeout
+     * 
+     * @throws IOException various I/O problems
+     */
+    @Test
+    public void readTimeout(MisbehavingServerControl server) throws IOException {
+        
+        RecordedThrowable error = assertTimeout(ofSeconds(5),  () -> runTest("http://localhost:" + server.getLocalPort()));
+        assertEquals(SocketTimeoutException.class.getName(), error.className);
+        assertEquals("Read timed out", error.message);
+    }
+    
+
+    private RecordedThrowable runTest(String urlSpec) throws IOException, InterruptedException {
+
+        Process process = runForkedCommandWithAgent(new URL(urlSpec), 3, 3);
+        int exitCode = process.waitFor();
+        
+        LOG.info("Exited with code {}", exitCode);
+        LOG.info("Dump of stdout: ");
+        Files
+            .lines(STDOUT)
+            .forEach(LOG::info);
+
+        LOG.info("Dump of stderr: ");
+        Files
+            .lines(STDERR)
+            .forEach(LOG::info);
+
+        if ( exitCode != 0 ) {
+            return Files.lines(STDERR)
+                .filter( l -> l.startsWith("Exception in thread \"main\""))
+                .map( l -> newRecordedThrowable(l) )
+                .findFirst()
+                .orElseThrow(() -> new RuntimeException("Exit code was zero but did not find any exception information in stderr.txt"));
+        }
+        
+        return null;
+    }
+    
+    private Process runForkedCommandWithAgent(URL url, int connectTimeoutSeconds, int readTimeoutSeconds) throws IOException {
+        
+        Path jar = Files.list(Paths.get("target"))
+            .filter( p -> p.getFileName().toString().endsWith("-jar-with-dependencies.jar"))
+            .findFirst()
+            .orElseThrow( () -> new IllegalStateException("Did not find the agent jar. Did you run mvn package first?"));
+
+        String javaHome = System.getProperty("java.home");
+        Path javaExe = Paths.get(javaHome, "bin", "java");
+        ProcessBuilder pb = new ProcessBuilder(
+            javaExe.toString(),
+            "-showversion",
+            "-javaagent:" + jar +"=" + TimeUnit.SECONDS.toMillis(connectTimeoutSeconds) +"," + TimeUnit.SECONDS.toMillis(readTimeoutSeconds),
+            "-cp",
+            jar.toString(),
+            "org.apache.sling.uca.impl.Main",
+            url.toString()
+        );
+        
+        pb.redirectInput(Redirect.INHERIT);
+        pb.redirectOutput(STDOUT.toFile());
+        pb.redirectError(STDERR.toFile());
+        
+        return pb.start();
+    }
+    
+    private RecordedThrowable newRecordedThrowable(String string) {
+     
+        string = string.replace("Exception in thread \"main\"", "");
+        String[] parts = string.split(":");
+
+        return new RecordedThrowable(parts[0].trim(), parts[1].trim());
+    }
+    
+    /**
+     * Basic information about a {@link Throwable} that was recorded in a file
+     */
+    static class RecordedThrowable {
+        String className;
+        String message;
+
+        public RecordedThrowable(String className, String message) {
+            this.className = className;
+            this.message = message;
+        }
+        
+        
+    }
+}
diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
deleted file mode 100644
index 9e42394..0000000
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * 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.uca.impl;
-
-import static java.time.Duration.ofSeconds;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTimeout;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.SocketTimeoutException;
-import java.net.URL;
-import java.net.URLConnection;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.concurrent.TimeUnit;
-
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@ExtendWith(MisbehavingServerExtension.class)
-public class IntegrationTest {
-    
-    private static final Logger LOG = LoggerFactory.getLogger(IntegrationTest.class);
-
-    /**
-     * Validates that connecting to a unaccessible port on an existing port fails with a connect 
-     * timeout exception
-     * 
-     * <p>It is surprisingly hard to simulate a connnection timeout. The most reliable way seems to
-     * be to get a firewall to drop packets, but this is very hard to do portably and safely
-     * in a unit test. The least bad possible solution is to access an URL that we know will timeout
-     * and that is able to sustain additional traffic. Maven Central is a good candidate for that.</p>
-     * 
-     * @throws IOException various I/O problems 
-     */
-    @Test
-    public void connectTimeout() throws IOException {
-
-        SocketTimeoutException exception = assertThrows(SocketTimeoutException.class, 
-            () -> assertTimeout(ofSeconds(5),  () -> runTest("http://repo1.maven.org:81"))
-        );
-        assertEquals("connect timed out", exception.getMessage());
-    }
-
-    /**
-     * Validates that connecting to a host that delays the response fails with a read timeout
-     * 
-     * @throws IOException various I/O problems
-     */
-    @Test
-    public void readTimeout(MisbehavingServerControl server) throws IOException {
-        
-        SocketTimeoutException exception = assertThrows(SocketTimeoutException.class, 
-            () -> assertTimeout(ofSeconds(10),  () -> runTest("http://localhost:" + server.getLocalPort()))
-        );
-        assertEquals("Read timed out", exception.getMessage());
-    }
-    
-
-    private void runTest(String urlSpec) throws MalformedURLException, IOException, InterruptedException {
-        
-        String javaHome = System.getProperty("java.home");
-        Path javaExe = Paths.get(javaHome, "bin", "java");
-        ProcessBuilder pb = new ProcessBuilder(javaExe.toString(), "-version");
-        pb.inheritIO();
-        Process process = pb.start();
-        
-        process.getInputStream();
-        
-        int exitCode = process.waitFor();
-        
-        LOG.info("Exited with code {}", exitCode);
-        
-        URL url = new URL(urlSpec);
-        LOG.info("connecting to {}", url);
-        URLConnection connection = url.openConnection();
-        // TODO - remove when running through the harness
-        connection.setConnectTimeout((int) TimeUnit.SECONDS.toMillis(3));
-        connection.setReadTimeout((int) TimeUnit.SECONDS.toMillis(3));
-        connection.connect();
-        LOG.info("connected");
-        try ( InputStream is = connection.getInputStream()) {
-            while ( is.read() != -1)
-                ;
-        }
-        LOG.info("read");
-    }
-}


[sling-whiteboard] 12/16: Move launcher out of the jar

Posted by ro...@apache.org.
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-whiteboard.git

commit e974da34183a33cbde6d3b75f82dcc605b3e347c
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Wed Jun 5 17:10:04 2019 +0200

    Move launcher out of the jar
---
 .../src/test/java/org/apache/sling/uca/impl/AgentIT.java                | 2 +-
 .../src/{main => test}/java/org/apache/sling/uca/impl/Main.java         | 0
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/AgentIT.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/AgentIT.java
index b67a650..8cda1ae 100644
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/AgentIT.java
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/AgentIT.java
@@ -126,7 +126,7 @@ public class AgentIT {
             "-showversion",
             "-javaagent:" + jar +"=" + TimeUnit.SECONDS.toMillis(connectTimeoutSeconds) +"," + TimeUnit.SECONDS.toMillis(readTimeoutSeconds),
             "-cp",
-            jar.toString(),
+            Paths.get("target", "classes").toString(),
             "org.apache.sling.uca.impl.Main",
             url.toString()
         );
diff --git a/url-connection-agent/src/main/java/org/apache/sling/uca/impl/Main.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/Main.java
similarity index 100%
rename from url-connection-agent/src/main/java/org/apache/sling/uca/impl/Main.java
rename to url-connection-agent/src/test/java/org/apache/sling/uca/impl/Main.java


[sling-whiteboard] 06/16: Improved test support classes naming and documentation

Posted by ro...@apache.org.
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-whiteboard.git

commit 59c680c1fef9ed6d1c1984dc8a673d501df9b2be
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Wed Jun 5 14:20:44 2019 +0200

    Improved test support classes naming and documentation
---
 .../org/apache/sling/uca/impl/IntegrationTest.java |  5 ++--
 .../sling/uca/impl/MisbehavingServerControl.java   | 31 ++++++++++++++++++++++
 ...erRule.java => MisbehavingServerExtension.java} | 23 ++++++++--------
 .../org/apache/sling/uca/impl/ServerControl.java   |  6 -----
 4 files changed, 44 insertions(+), 21 deletions(-)

diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
index aa02dd1..9dec971 100644
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
@@ -29,13 +29,12 @@ import java.net.URL;
 import java.net.URLConnection;
 import java.util.concurrent.TimeUnit;
 
-import org.apache.sling.uca.impl.ServerRule.MisbehavingServer;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-@ExtendWith(ServerRule.class)
+@ExtendWith(MisbehavingServerExtension.class)
 public class IntegrationTest {
     
     private static final Logger LOG = LoggerFactory.getLogger(IntegrationTest.class);
@@ -66,7 +65,7 @@ public class IntegrationTest {
      * @throws IOException various I/O problems
      */
     @Test
-    public void readTimeout(@MisbehavingServer ServerControl server) throws IOException {
+    public void readTimeout(MisbehavingServerControl server) throws IOException {
         
         SocketTimeoutException exception = assertThrows(SocketTimeoutException.class, 
             () -> assertTimeout(ofSeconds(10),  () -> runTest("http://localhost:" + server.getLocalPort()))
diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/MisbehavingServerControl.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/MisbehavingServerControl.java
new file mode 100644
index 0000000..9b0bf93
--- /dev/null
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/MisbehavingServerControl.java
@@ -0,0 +1,31 @@
+/*
+ * 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.uca.impl;
+
+/**
+ * Allows control of a local server
+ *
+ */
+public interface MisbehavingServerControl {
+
+    /**
+     * Returns the port on which the local server is bound
+     * 
+     * @return the port
+     */
+    int getLocalPort();
+}
diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerRule.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/MisbehavingServerExtension.java
similarity index 85%
rename from url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerRule.java
rename to url-connection-agent/src/test/java/org/apache/sling/uca/impl/MisbehavingServerExtension.java
index 80d4fc4..702b82f 100644
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerRule.java
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/MisbehavingServerExtension.java
@@ -17,10 +17,6 @@
 package org.apache.sling.uca.impl;
 
 import java.io.IOException;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
 import java.util.concurrent.TimeUnit;
 
 import javax.servlet.ServletException;
@@ -41,11 +37,14 @@ import org.junit.jupiter.api.extension.ParameterResolver;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-class ServerRule implements BeforeAllCallback, AfterAllCallback, ParameterResolver, ServerControl {
-    
-    @Retention(RetentionPolicy.RUNTIME)
-    @Target(ElementType.PARAMETER)
-    public @interface MisbehavingServer { }
+/**
+ * Provides an Jetty-based local server that can be configured to timeout
+ * 
+ * <p>After extending a JUnit Jupiter test with this extension, any parameter of type {@link MisbehavingServerControl}
+ * will be resolved.</p>
+ *
+ */
+class MisbehavingServerExtension implements BeforeAllCallback, AfterAllCallback, ParameterResolver, MisbehavingServerControl {
     
     private final Logger logger = LoggerFactory.getLogger(getClass());
     
@@ -58,16 +57,16 @@ class ServerRule implements BeforeAllCallback, AfterAllCallback, ParameterResolv
     @Override
     public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
             throws ParameterResolutionException {
-        return parameterContext.isAnnotated(MisbehavingServer.class);
+        return parameterContext.getParameter().getType() == MisbehavingServerControl.class;
     }
     
     @Override
     public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
             throws ParameterResolutionException {
-        if ( parameterContext.getParameter().getType() == ServerControl.class )
+        if ( parameterContext.getParameter().getType() == MisbehavingServerControl.class )
             return this;
         
-        throw new ParameterResolutionException("Unable to get a Server instance for " + parameterContext);
+        throw new ParameterResolutionException("Unable to get a " + MisbehavingServerControl.class.getSimpleName() + " instance for " + parameterContext);
     }
     
     @Override
diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerControl.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerControl.java
deleted file mode 100644
index e73d682..0000000
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerControl.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package org.apache.sling.uca.impl;
-
-public interface ServerControl {
-
-    int getLocalPort();
-}


[sling-whiteboard] 16/16: Updated README to reflect latest state.

Posted by ro...@apache.org.
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-whiteboard.git

commit 2dbd96097fd48d715a1224c044a9c5b2573e62b8
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Thu Jun 6 17:02:11 2019 +0200

    Updated README to reflect latest state.
---
 url-connection-agent/README.md | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/url-connection-agent/README.md b/url-connection-agent/README.md
index 108d9db..d39b235 100644
--- a/url-connection-agent/README.md
+++ b/url-connection-agent/README.md
@@ -2,34 +2,37 @@
 
 This module is part of the [Apache Sling](https://sling.apache.org) project.
 
-This module provides a java agent that uses the instrumentation API to add timeouts to `connect` calls made via HTTP or HTTPs without setting read and connect timeouts.
+This module provides a java agent that uses the instrumentation API to add timeouts to `connect` calls made via HTTP or HTTPs without setting read and connect timeouts. It is intended as an additional layer of control to use when running unstrusted client code that may make calls without explicitly setting timeouts.
 
 ## Launching
 
 Build the project with `mvn clean package` and then run a simple connection test with 
 
-    java -javaagent:target/url-connection-agent-0.0.1-SNAPSHOT-jar-with-dependencies.jar -cp target/url-connection-agent-0.0.1-SNAPSHOT-jar-with-dependencies.jar=<connect-timeout>,<read-timeout> org.apache.sling.uca.impl.Main <url>
+    java -javaagent:target/url-connection-agent-0.0.1-SNAPSHOT-jar-with-dependencies.jar=<connect-timeout>,<read-timeout> -cp target/test-classes:target/it-dependencies/* org.apache.sling.uca.impl.Main <url> <client-type>
     
  The parameters are as follows:
  
  - `<connect-timeout>` - connection timeout in milliseconds
  - `<read-timeout>`- read timeout in milliseconds
  - `<url>` - the URL to access
+ - `<client-type>` - the client type, either `JavaNet` for java.net.URL-based connections or `HC3` for commons-httpclient 3.x
+ 
  
  For a test that always fails, set one of the timeouts to 1. Both executions listed below will typically fail:
  
  ```
-java -javaagent:target/url-connection-agent-0.0.1-SNAPSHOT-jar-with-dependencies.jar=1,1000 -cp target/url-connection-agent-0.0.1-SNAPSHOT-jar-with-dependencies.jar org.apache.sling.uca.impl.Main https://sling.apache.org
-java -javaagent:target/url-connection-agent-0.0.1-SNAPSHOT-jar-with-dependencies.jar=1000,1 -cp target/url-connection-agent-0.0.1-SNAPSHOT-jar-with-dependencies.jar org.apache.sling.uca.impl.Main https://sling.apache.org
+java -javaagent:target/url-connection-agent-0.0.1-SNAPSHOT-jar-with-dependencies.jar=1,1000 -cp target/test-classes:target/it-dependencies/* org.apache.sling.uca.impl.Main https://sling.apache.org JavaNet
+java -javaagent:target/url-connection-agent-0.0.1-SNAPSHOT-jar-with-dependencies.jar=1000,1 -cp target/test-classes:target/it-dependencies/* org.apache.sling.uca.impl.Main https://sling.apache.org JavaNet
  ```
  
 In contrast, the execution below should succeed:
 
 ```
-java -javaagent:target/url-connection-agent-0.0.1-SNAPSHOT-jar-with-dependencies.jar=1000,1000 -cp target/url-connection-agent-0.0.1-SNAPSHOT-jar-with-dependencies.jar org.apache.sling.uca.impl.Main https://sling.apache.org
+java -javaagent:target/url-connection-agent-0.0.1-SNAPSHOT-jar-with-dependencies.jar=1000,1000 -cp target/test-classes:target/it-dependencies/* org.apache.sling.uca.impl.Main https://sling.apache.org JavaNet
 ```
 
 ## Tested platforms
 
 * openjdk version "1.8.0_212"
-* openjdk version "11.0.2" 2019-01-15
\ No newline at end of file
+* openjdk version "11.0.2" 2019-01-15
+* commons-httpclient 3.1
\ No newline at end of file


[sling-whiteboard] 04/16: Cleanups in tests

Posted by ro...@apache.org.
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-whiteboard.git

commit 69bb6e40cbb4c571dbafdaa5b368036bdfb5bb27
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Wed Jun 5 13:59:43 2019 +0200

    Cleanups in tests
---
 .../org/apache/sling/uca/impl/IntegrationTest.java | 16 +++++++
 .../java/org/apache/sling/uca/impl/ServerRule.java | 50 ++++------------------
 2 files changed, 25 insertions(+), 41 deletions(-)

diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
index 31ba3bf..d952181 100644
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/IntegrationTest.java
@@ -39,6 +39,17 @@ public class IntegrationTest {
     
     private static final Logger LOG = LoggerFactory.getLogger(IntegrationTest.class);
 
+    /**
+     * Validates that connecting to a unaccessible port on an existing port fails with a connect 
+     * timeout exception
+     * 
+     * <p>It is surprisingly hard to simulate a connnection timeout. The most reliable way seems to
+     * be to get a firewall to drop packets, but this is very hard to do portably and safely
+     * in a unit test. The least bad possible solution is to access an URL that we know will timeout
+     * and that is related to us - the Sling website.</p>
+     * 
+     * @throws IOException various I/O problems 
+     */
     @Test
     public void connectTimeout() throws IOException {
 
@@ -48,6 +59,11 @@ public class IntegrationTest {
         assertEquals("connect timed out", exception.getMessage());
     }
 
+    /**
+     * Validates that connecting to a host that delays the response fails with a read timeout
+     * 
+     * @throws IOException various I/O problems
+     */
     @Test
     public void readTimeout() throws IOException {
         
diff --git a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerRule.java b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerRule.java
index a799b55..62a6380 100644
--- a/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerRule.java
+++ b/url-connection-agent/src/test/java/org/apache/sling/uca/impl/ServerRule.java
@@ -17,17 +17,13 @@
 package org.apache.sling.uca.impl;
 
 import java.io.IOException;
-import java.util.Collections;
 import java.util.concurrent.TimeUnit;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.eclipse.jetty.io.Connection;
-import org.eclipse.jetty.io.EndPoint;
 import org.eclipse.jetty.server.Connector;
-import org.eclipse.jetty.server.HttpConnectionFactory;
 import org.eclipse.jetty.server.Request;
 import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.server.ServerConnector;
@@ -40,7 +36,7 @@ import org.slf4j.LoggerFactory;
 
 class ServerRule implements BeforeAllCallback, AfterAllCallback {
     
-    private static final Logger LOG = LoggerFactory.getLogger(ServerRule.class);
+    private final Logger logger = LoggerFactory.getLogger(getClass());
     
     private static final int LOCAL_PORT = 12312;
     
@@ -69,43 +65,14 @@ class ServerRule implements BeforeAllCallback, AfterAllCallback {
             }
         };
         connector.setPort(LOCAL_PORT);
-        connector.setConnectionFactories(Collections.singleton(new HttpConnectionFactory() {
-            @Override
-            public Connection newConnection(Connector connector, EndPoint endPoint) {
-                LOG.info("Waiting before creating connection");
-                try {
-                    Thread.sleep(TimeUnit.SECONDS.toMillis(10));
-                } catch (InterruptedException e) {
-                    Thread.currentThread().interrupt();
-                    throw new RuntimeException("Interrupted");
-                }
-                
-                Connection connection = super.newConnection(connector, endPoint);
-                LOG.info("Connection created");
-                return connection;
-            }
-        }));
-        server.setConnectors(new Connector[] { 
-            connector
-        });
+        server.setConnectors(new Connector[] { connector });
         server.setHandler(new AbstractHandler() {
             
             @Override
             public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
                     throws IOException, ServletException {
-                
-                LOG.info("Waiting before handling");
-                
-                try {
-                    Thread.sleep(TimeUnit.SECONDS.toMillis(10));
-                } catch (InterruptedException e) {
-                    Thread.currentThread().interrupt();
-                    return;
-                }
-                
                 response.setStatus(HttpServletResponse.SC_NO_CONTENT);
                 baseRequest.setHandled(true);
-                LOG.info("Handled");
             }
         });
         
@@ -114,11 +81,12 @@ class ServerRule implements BeforeAllCallback, AfterAllCallback {
 
     @Override
     public void afterAll(ExtensionContext context) throws Exception {
-        if ( server != null )
-            try {
-                server.stop();
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
+        if ( server == null )
+            return;
+        try {
+            server.stop();
+        } catch (Exception e) {
+            logger.info("Failed shutting down server", e);
+        }
     }
 }
\ No newline at end of file