Skip to content

Commit

Permalink
Use dynamic port allocation in HTTP tests (instead of hardcoded port …
Browse files Browse the repository at this point in the history
…8280).
  • Loading branch information
veithen committed May 15, 2010
1 parent 5b95776 commit 446a106
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
import org.apache.axis2.description.TransportInDescription;
import org.apache.axis2.description.TransportOutDescription;
import org.apache.axis2.transport.testkit.axis2.TransportDescriptionFactory;
import org.apache.axis2.transport.testkit.http.HttpTestEnvironment;
import org.apache.axis2.transport.testkit.tests.Setup;
import org.apache.axis2.transport.testkit.util.LifecycleFixTransportListenerProxy;

public class HttpTransportDescriptionFactory implements TransportDescriptionFactory {
private final int port;
private int port;

public HttpTransportDescriptionFactory(int port) {
this.port = port;
@Setup @SuppressWarnings("unused")
private void setUp(HttpTestEnvironment env) {
port = env.getServerPort();
}

public TransportInDescription createTransportInDescription() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class SimpleHTTPServerTest extends TestCase {
public static TestSuite suite() throws Exception {
ManagedTestSuite suite = new ManagedTestSuite(SimpleHTTPServerTest.class);

TransportDescriptionFactory tdf = new HttpTransportDescriptionFactory(8280);
TransportDescriptionFactory tdf = new HttpTransportDescriptionFactory();

new HttpTransportTestSuiteBuilder(suite, tdf).build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.apache.axis2.transport.testkit.http;

import java.net.InetSocketAddress;
import java.util.UUID;

import org.apache.axis2.addressing.EndpointReference;
Expand All @@ -28,14 +27,15 @@
import org.apache.axis2.transport.testkit.tests.Setup;
import org.apache.axis2.transport.testkit.tests.TearDown;
import org.apache.axis2.transport.testkit.tests.Transient;
import org.apache.axis2.transport.testkit.util.tcpmon.Tunnel;

public class HttpChannel implements AsyncChannel, RequestResponseChannel {
private int serverPort;
private @Transient String serviceName;
// private @Transient Tunnel tunnel;

@Setup @SuppressWarnings("unused")
private void setUp() throws Exception {
private void setUp(HttpTestEnvironment env) throws Exception {
serverPort = env.getServerPort();
serviceName = "TestService-" + UUID.randomUUID();
// tunnel = new Tunnel(new InetSocketAddress("127.0.0.1", 8280));
// tunnel.start();
Expand All @@ -51,6 +51,6 @@ public String getServiceName() {
}

public EndpointReference getEndpointReference() throws Exception {
return new EndpointReference("http://localhost:" + /* tunnel.getPort() */ 8280 + CONTEXT_PATH + "/" + serviceName);
return new EndpointReference("http://localhost:" + /* tunnel.getPort() */ serverPort + CONTEXT_PATH + "/" + serviceName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.axis2.transport.testkit.http;

import org.apache.axis2.transport.testkit.tests.Setup;
import org.apache.axis2.transport.testkit.tests.TearDown;
import org.apache.axis2.transport.testkit.tests.Transient;
import org.apache.axis2.transport.testkit.util.PortAllocator;

public class HttpTestEnvironment {
public static final HttpTestEnvironment INSTANCE = new HttpTestEnvironment();

private @Transient PortAllocator portAllocator;
private int serverPort;

private HttpTestEnvironment() {}

@Setup @SuppressWarnings("unused")
private void setUp(PortAllocator portAllocator) throws Exception {
this.portAllocator = portAllocator;
serverPort = portAllocator.allocatePort();
}

public int getServerPort() {
return serverPort;
}

@TearDown @SuppressWarnings("unused")
private void tearDown() throws Exception {
portAllocator.releasePort(serverPort);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public class JettyServer {
private JettyServer() {}

@Setup @SuppressWarnings("unused")
private void setUp() throws Exception {
private void setUp(HttpTestEnvironment env) throws Exception {
server = new Server();
SocketListener listener = new SocketListener();
listener.setPort(8280);
listener.setPort(env.getServerPort());
server.addListener(listener);
context = new HttpContext(server, Channel.CONTEXT_PATH + "/*");
server.start();
Expand Down

0 comments on commit 446a106

Please sign in to comment.