You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by cw...@apache.org on 2018/12/22 01:05:22 UTC
svn commit: r1849509 - in
/uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps:
Client.java service/JunitPullServiceTestCase.java
service/wrapper/JUnitServiceWrapperTestCase.java
transport/JunitTransportTestCase.java
Author: cwiklik
Date: Sat Dec 22 01:05:22 2018
New Revision: 1849509
URL: http://svn.apache.org/viewvc?rev=1849509&view=rev
Log:
UIMA-5942 modified to use an open port for Jetty instead of statically defined port 8080 which may be already taken.
Modified:
uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/Client.java
uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/JunitPullServiceTestCase.java
uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/wrapper/JUnitServiceWrapperTestCase.java
uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/transport/JunitTransportTestCase.java
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/Client.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/Client.java?rev=1849509&r1=1849508&r2=1849509&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/Client.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/Client.java Sat Dec 22 01:05:22 2018
@@ -20,6 +20,7 @@ package org.apache.uima.ducc.ps;
import java.io.BufferedReader;
import java.io.IOException;
+import java.net.ServerSocket;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
@@ -52,7 +53,7 @@ public class Client {
private boolean block = false;
private AtomicLong errorCount = new AtomicLong();
private final static String app="test";
- private int httpPort = 8080;
+ private int httpPort = 12222;
private int maxThreads = 50;
private static UimaSerializer uimaSerializer = new UimaSerializer();
private AtomicInteger correlationIdCounter =
@@ -65,7 +66,27 @@ public class Client {
protected String getApp() {
return app;
}
+ protected int getJettyPort() {
+ while(true) {
+ ServerSocket socket=null;
+ try {
+ socket = new ServerSocket(httpPort);
+ break;
+ } catch( IOException e) {
+ httpPort++;
+ } finally {
+ if ( socket != null ) {
+ try {
+ socket.close();
+ } catch( Exception ee) {}
+
+ }
+ }
+ }
+ return httpPort;
+ }
protected int getPort() {
+
return httpPort;
}
@@ -86,9 +107,9 @@ public class Client {
// Server connector
ServerConnector connector = new ServerConnector(server);
- connector.setPort(httpPort);
+ connector.setPort(getJettyPort());
server.setConnectors(new Connector[] { connector });
-
+ System.out.println("launching Jetty on Port:"+connector.getPort());
ServletContextHandler context = new ServletContextHandler(
ServletContextHandler.SESSIONS);
context.setContextPath("/");
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/JunitPullServiceTestCase.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/JunitPullServiceTestCase.java?rev=1849509&r1=1849508&r2=1849509&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/JunitPullServiceTestCase.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/JunitPullServiceTestCase.java Sat Dec 22 01:05:22 2018
@@ -52,7 +52,7 @@ public class JunitPullServiceTestCase ex
IServiceProcessor processor = new
UimaServiceProcessor(analysisEngineDescriptor);
- String tasURL = "http://localhost:8080/test";
+ String tasURL = "http://localhost:"+super.getPort()+"/test";
IService service = PullServiceStepBuilder.newBuilder().withProcessor(processor)
.withClientURL(tasURL).withType("Note Service").withScaleout(scaleout)
@@ -70,6 +70,8 @@ public class JunitPullServiceTestCase ex
throw e;
} catch (Exception e) {
throw e;
+ } finally {
+ super.stopJetty();
}
}
@Test
@@ -82,7 +84,7 @@ public class JunitPullServiceTestCase ex
IServiceProcessor processor = new
UimaServiceProcessor(analysisEngineDescriptor);
- String tasURL = "http://localhost:8080/test";
+ String tasURL = "http://localhost:"+super.getPort()+"/test";
IService service = PullServiceStepBuilder.newBuilder().withProcessor(processor)
.withClientURL(tasURL).withType("Note Service").withScaleout(scaleout)
@@ -100,6 +102,8 @@ public class JunitPullServiceTestCase ex
throw e;
} catch (Exception e) {
throw e;
+ }finally {
+ super.stopJetty();
}
}
@@ -112,7 +116,7 @@ public class JunitPullServiceTestCase ex
IServiceProcessor processor = new
UimaServiceProcessor(analysisEngineDescriptor);
- String tasURL ="http://localhost:8080/test";
+ String tasURL ="http://localhost:"+super.getPort()+"/test";
IService service = PullServiceStepBuilder.newBuilder().withProcessor(processor)
.withClientURL(tasURL).withType("Note Service").withScaleout(scaleout)
@@ -132,6 +136,8 @@ public class JunitPullServiceTestCase ex
throw e;
} catch (Exception e) {
throw e;
+ }finally {
+ super.stopJetty();
}
}
@@ -148,7 +154,7 @@ public class JunitPullServiceTestCase ex
// fail on 1st error
processor.setErrorHandlerWindow(1, 5);
- String tasURL = "http://localhost:8080/test";
+ String tasURL = "http://localhost:"+super.getPort()+"/test";
IService service = PullServiceStepBuilder.newBuilder().withProcessor(processor)
.withClientURL(tasURL).withType("Note Service").withScaleout(scaleout)
@@ -166,6 +172,7 @@ public class JunitPullServiceTestCase ex
throw e;
} finally {
System.getProperties().remove("ProcessFail");
+ super.stopJetty();
}
}
@Test
@@ -180,7 +187,7 @@ public class JunitPullServiceTestCase ex
new UimaServiceProcessor(analysisEngineDescriptor);
// fail on 2nd error in a window of 5
processor.setErrorHandlerWindow(2, 5);
- String tasURL = "http://localhost:8080/test";
+ String tasURL = "http://localhost:"+super.getPort()+"/test";
IService service = PullServiceStepBuilder.newBuilder().withProcessor(processor)
.withClientURL(tasURL).withType("Note Service").withScaleout(scaleout)
@@ -199,6 +206,7 @@ public class JunitPullServiceTestCase ex
throw e;
} finally {
System.getProperties().remove("ProcessFail");
+ super.stopJetty();
}
}
@Test
@@ -210,7 +218,7 @@ public class JunitPullServiceTestCase ex
IServiceProcessor processor = new
UimaServiceProcessor(analysisEngineDescriptor);
- String tasURL = "http://localhost:8080/test";
+ String tasURL = "http://localhost:"+super.getPort()+"/test";
IService service = PullServiceStepBuilder.newBuilder().withProcessor(processor)
.withClientURL(tasURL).withType("Note Service").withScaleout(scaleout)
@@ -232,6 +240,7 @@ public class JunitPullServiceTestCase ex
throw e;
} finally {
System.getProperties().remove("ProcessFail");
+ super.stopJetty();
}
}
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/wrapper/JUnitServiceWrapperTestCase.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/wrapper/JUnitServiceWrapperTestCase.java?rev=1849509&r1=1849508&r2=1849509&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/wrapper/JUnitServiceWrapperTestCase.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/wrapper/JUnitServiceWrapperTestCase.java Sat Dec 22 01:05:22 2018
@@ -59,7 +59,7 @@ public class JUnitServiceWrapperTestCase
String analysisEngineDescriptor = "TestAAE";
System.setProperty("ducc.deploy.JpType", "uima");
- String tasURL = "http://localhost:8080/test";
+ String tasURL = "http://localhost:"+super.getPort()+"/test";
try {
System.setProperty("ducc.deploy.JdURL", tasURL);
System.setProperty("ducc.deploy.JpThreadCount","4");
@@ -83,6 +83,7 @@ public class JUnitServiceWrapperTestCase
throw e;
} finally {
monitor.stop();
+ super.stopJetty();
}
}
@@ -97,7 +98,7 @@ public class JUnitServiceWrapperTestCase
super.startJetty(false); // don't block
String analysisEngineDescriptor = "NoOpAE";
- String tasURL = "http://localhost:8080/test";
+ String tasURL = "http://localhost:"+super.getPort()+"/test";
try {
// Force process failure of the first task
System.setProperty("ProcessFail","1");
@@ -125,6 +126,7 @@ public class JUnitServiceWrapperTestCase
} finally {
monitor.stop();
System.getProperties().remove("ProcessFail");
+ super.stopJetty();
}
}
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/transport/JunitTransportTestCase.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/transport/JunitTransportTestCase.java?rev=1849509&r1=1849508&r2=1849509&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/transport/JunitTransportTestCase.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/transport/JunitTransportTestCase.java Sat Dec 22 01:05:22 2018
@@ -20,6 +20,7 @@ package org.apache.uima.ducc.ps.transpor
import java.io.BufferedReader;
import java.io.IOException;
+import java.net.ServerSocket;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@@ -44,8 +45,31 @@ import org.junit.Test;
public class JunitTransportTestCase {
private Server server;
private final static String app="test";
- private int httpPort = 8080;
+ private int httpPort = 12222;
private int maxThreads = 20;
+ private int getJettyPort() {
+ while(true) {
+ ServerSocket socket=null;
+ try {
+ socket = new ServerSocket(httpPort);
+ break;
+ } catch( IOException e) {
+ httpPort++;
+ } finally {
+ if ( socket != null ) {
+ try {
+ socket.close();
+ } catch( Exception ee) {}
+
+ }
+ }
+ }
+ return httpPort;
+ }
+ private int getPort() {
+
+ return httpPort;
+ }
@Before
public void startJetty() throws Exception
{
@@ -64,9 +88,9 @@ public class JunitTransportTestCase {
// Server connector
ServerConnector connector = new ServerConnector(server);
- connector.setPort(httpPort);
+ connector.setPort(getJettyPort());
server.setConnectors(new Connector[] { connector });
-
+ System.out.println("launching Jetty on Port:"+connector.getPort());
ServletContextHandler context = new ServletContextHandler(
ServletContextHandler.SESSIONS);
context.setContextPath("/");
@@ -104,7 +128,7 @@ public class JunitTransportTestCase {
public void testTransportBasicConnectivity() throws Exception
{
int scaleout = 12;
- ITargetURI targetUrl = new HttpTargetURI("http://localhost:"+httpPort+"/"+app);
+ ITargetURI targetUrl = new HttpTargetURI("http://localhost:"+getPort()+"/"+app);
DefaultRegistryClient registryClient =
new DefaultRegistryClient(targetUrl);
HttpServiceTransport transport = new HttpServiceTransport(registryClient, scaleout);
@@ -119,7 +143,7 @@ public class JunitTransportTestCase {
{
System.out.println(".... Test::testTransportIOException");
int scaleout = 12;
- ITargetURI targetUrl = new HttpTargetURI("http://localhost:"+httpPort+"/"+app);
+ ITargetURI targetUrl = new HttpTargetURI("http://localhost:"+getPort()+"/"+app);
DefaultRegistryClient registryClient =
new DefaultRegistryClient(targetUrl);
HttpServiceTransport transport = new HttpServiceTransport(registryClient, scaleout);
@@ -134,7 +158,7 @@ public class JunitTransportTestCase {
{
System.out.println(".... Test::testTransportNoRoutToHostException");
int scaleout = 12;
- ITargetURI targetUrl = new HttpTargetURI("http://localhost:"+httpPort+"/"+app);
+ ITargetURI targetUrl = new HttpTargetURI("http://localhost:"+getPort()+"/"+app);
DefaultRegistryClient registryClient =
new DefaultRegistryClient(targetUrl);
HttpServiceTransport transport = new HttpServiceTransport(registryClient, scaleout);
@@ -149,7 +173,7 @@ public class JunitTransportTestCase {
{
System.out.println(".... Test::testTransportURISyntaxException");
int scaleout = 12;
- ITargetURI targetUrl = new HttpTargetURI("http://localhost:"+httpPort+"/"+app);
+ ITargetURI targetUrl = new HttpTargetURI("http://localhost:"+getPort()+"/"+app);
DefaultRegistryClient registryClient =
new DefaultRegistryClient(targetUrl);
HttpServiceTransport transport = new HttpServiceTransport(registryClient, scaleout);