diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java index 55c81cd0883..43711b206c4 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.websocket.client; import static org.hamcrest.Matchers.*; +import java.net.InetSocketAddress; import java.net.URI; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -128,6 +129,45 @@ public class WebSocketClientTest wsocket.assertMessage("Hello World"); } + @Test + public void testLocalRemoteAddress() throws Exception + { + WebSocketClientFactory fact = new WebSocketClientFactory(); + fact.start(); + try + { + TrackingSocket wsocket = new TrackingSocket(); + WebSocketClient client = fact.newWebSocketClient(wsocket); + + URI wsUri = server.getWsUri(); + Future future = client.connect(wsUri); + + ServerConnection ssocket = server.accept(); + ssocket.upgrade(); + + future.get(500,TimeUnit.MILLISECONDS); + + Assert.assertTrue(wsocket.openLatch.await(1,TimeUnit.SECONDS)); + + InetSocketAddress local = wsocket.getConnection().getLocalAddress(); + InetSocketAddress remote = wsocket.getConnection().getRemoteAddress(); + + Assert.assertThat("Local Socket Address",local,notNullValue()); + Assert.assertThat("Remote Socket Address",remote,notNullValue()); + + // Hard to validate (in a portable unit test) the local address that was used/bound in the low level Jetty Endpoint + Assert.assertThat("Local Socket Address / Host",local.getAddress().getHostAddress(),notNullValue()); + Assert.assertThat("Local Socket Address / Port",local.getPort(),greaterThan(0)); + + Assert.assertThat("Remote Socket Address / Host",remote.getAddress().getHostAddress(),is(wsUri.getHost())); + Assert.assertThat("Remote Socket Address / Port",remote.getPort(),greaterThan(0)); + } + finally + { + fact.stop(); + } + } + @Test public void testMessageBiggerThanBufferSize() throws Exception {