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 <[email protected]> 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
