Repository: oozie Updated Branches: refs/heads/master 5998c18fd -> 787f1fef7
OOZIE-2928 Unit Tests using LocalOozie fail randomly (Denes Bodo via pbacsko) Project: http://git-wip-us.apache.org/repos/asf/oozie/repo Commit: http://git-wip-us.apache.org/repos/asf/oozie/commit/787f1fef Tree: http://git-wip-us.apache.org/repos/asf/oozie/tree/787f1fef Diff: http://git-wip-us.apache.org/repos/asf/oozie/diff/787f1fef Branch: refs/heads/master Commit: 787f1fef77581419592a89ae71d9ae0ffe9fea33 Parents: 5998c18 Author: Peter Bacsko <pbac...@cloudera.com> Authored: Fri Jun 16 12:20:50 2017 +0200 Committer: Peter Bacsko <pbac...@cloudera.com> Committed: Fri Jun 16 12:20:50 2017 +0200 ---------------------------------------------------------------------- .../oozie/test/EmbeddedServletContainer.java | 5 +- .../test/TestEmbeddedServletContainer.java | 59 +++++++++++++++++--- release-log.txt | 1 + 3 files changed, 52 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/oozie/blob/787f1fef/core/src/main/java/org/apache/oozie/test/EmbeddedServletContainer.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/oozie/test/EmbeddedServletContainer.java b/core/src/main/java/org/apache/oozie/test/EmbeddedServletContainer.java index 30b856c..eeb7717 100644 --- a/core/src/main/java/org/apache/oozie/test/EmbeddedServletContainer.java +++ b/core/src/main/java/org/apache/oozie/test/EmbeddedServletContainer.java @@ -97,12 +97,9 @@ public class EmbeddedServletContainer { */ public void start() throws Exception { host = InetAddress.getLocalHost().getHostName(); - ServerSocket ss = new ServerSocket(0); - port = ss.getLocalPort(); - ss.close(); server.getConnectors()[0].setHost(host); - server.getConnectors()[0].setPort(port); server.start(); + port = server.getConnectors()[0].getLocalPort(); System.out.println("Running embedded servlet container at: http://" + host + ":" + port); } http://git-wip-us.apache.org/repos/asf/oozie/blob/787f1fef/core/src/test/java/org/apache/oozie/test/TestEmbeddedServletContainer.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/oozie/test/TestEmbeddedServletContainer.java b/core/src/test/java/org/apache/oozie/test/TestEmbeddedServletContainer.java index 090857e..1fb0df1 100644 --- a/core/src/test/java/org/apache/oozie/test/TestEmbeddedServletContainer.java +++ b/core/src/test/java/org/apache/oozie/test/TestEmbeddedServletContainer.java @@ -19,9 +19,12 @@ package org.apache.oozie.test; import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.util.ArrayList; +import java.util.List; public class TestEmbeddedServletContainer extends XTestCase { @@ -34,19 +37,57 @@ public class TestEmbeddedServletContainer extends XTestCase { PingServlet.FILTER_INIT = false; PingServlet.DO_FILTER = false; container.start(); - URL url = new URL(container.getServletURL("/ping/*") + "bla"); - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - conn.connect(); - assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode()); - BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); - assertEquals("ping", reader.readLine()); - assertEquals(null, reader.readLine()); - assertTrue(PingServlet.FILTER_INIT); - assertTrue(PingServlet.DO_FILTER); + assertHttpResponse(container); } finally { container.stop(); } } + public void testMultipleParallelStarts() throws Exception { + final List<EmbeddedServletContainer> containers = new ArrayList<>(); + PingServlet.FILTER_INIT = false; + PingServlet.DO_FILTER = false; + + for(int i = 0; i < 10; ++i){ + final EmbeddedServletContainer c = new EmbeddedServletContainer("path"+i); + c.addServletEndpoint("/ping/*", PingServlet.class); + c.addFilter("/ping/*", PingServlet.class); + containers.add(c); + } + + startAllContainers(containers); + + for(final EmbeddedServletContainer c : containers){ + assertHttpResponse(c); + } + + stopAllContainers(containers); + + } + + private void stopAllContainers(List<EmbeddedServletContainer> containers) { + for(final EmbeddedServletContainer c : containers){ + c.stop(); + } + } + + private void startAllContainers(List<EmbeddedServletContainer> containers) throws Exception { + for(final EmbeddedServletContainer c : containers){ + c.start(); + } + } + + private void assertHttpResponse(EmbeddedServletContainer c) throws IOException { + final URL url = new URL(c.getServletURL("/ping/*") + "bla"); + final HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.connect(); + assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode()); + final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); + assertEquals("ping", reader.readLine()); + assertEquals(null, reader.readLine()); + assertTrue(PingServlet.FILTER_INIT); + assertTrue(PingServlet.DO_FILTER); + } + } http://git-wip-us.apache.org/repos/asf/oozie/blob/787f1fef/release-log.txt ---------------------------------------------------------------------- diff --git a/release-log.txt b/release-log.txt index e334a90..b50ad50 100644 --- a/release-log.txt +++ b/release-log.txt @@ -1,5 +1,6 @@ -- Oozie 5.0.0 release (trunk - unreleased) +OOZIE-2928 Unit Tests using LocalOozie fail randomly (Denes Bodo via pbacsko) OOZIE-2944 Shell action example does not work with Oozie on Yarn on hadoop 2.6 (asasvari via gezapeti) OOZIE-2933 Switch from Findbugs to Spotbugs (Jan Hentschel via gezapeti) OOZIE-2651 Set javax.xml.parsers.DocumentBuilderFactory sys prop to make XML handling faster (rkanter)