Issue #207 - more test failure fixes

This commit is contained in:
Joakim Erdfelt 2017-04-27 16:26:32 -07:00
parent d216206fcd
commit 56fac5fdb1
11 changed files with 158 additions and 176 deletions

View File

@ -20,10 +20,10 @@ package org.eclipse.jetty.websocket.jsr356.server;
import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import java.net.URI; import java.net.URI;
import java.util.List;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -33,7 +33,6 @@ import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.client.WebSocketClient; import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.jsr356.server.samples.echo.BasicEchoSocket; import org.eclipse.jetty.websocket.jsr356.server.samples.echo.BasicEchoSocket;
import org.junit.Assert;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -72,14 +71,16 @@ public class AltFilterTest
try try
{ {
client.start(); client.start();
JettyEchoSocket clientEcho = new JettyEchoSocket(); JettyEchoSocket clientSocket = new JettyEchoSocket();
Future<List<String>> clientMessagesFuture = clientEcho.expectedMessages(1); Future<Session> clientConnectFuture = client.connect(clientSocket,uri.resolve("echo"));
Future<Session> future = client.connect(clientEcho,uri.resolve("echo"));
// wait for connect // wait for connect
future.get(1,TimeUnit.SECONDS); Session clientSession = clientConnectFuture.get(5,TimeUnit.SECONDS);
clientEcho.sendMessage("Hello Echo"); clientSocket.sendMessage("Hello Echo");
List<String> msgs = clientMessagesFuture.get(1, TimeUnit.SECONDS);
Assert.assertEquals("Expected message","Hello Echo",msgs.get(0)); String incomingMessage = clientSocket.messageQueue.poll(1, TimeUnit.SECONDS);
assertEquals("Expected message","Hello Echo",incomingMessage);
clientSession.close();
clientSocket.awaitCloseEvent("Client");
} }
finally finally
{ {

View File

@ -22,7 +22,6 @@ import static org.hamcrest.Matchers.containsString;
import java.net.URI; import java.net.URI;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -75,29 +74,28 @@ public class AnnotatedServerEndpointTest
server.stop(); server.stop();
} }
private void assertResponse(String message, String... expectedTexts) throws Exception private void assertResponse(String message, String expectedText) throws Exception
{ {
WebSocketClient client = new WebSocketClient(bufferPool); WebSocketClient client = new WebSocketClient(bufferPool);
try try
{ {
client.start(); client.start();
JettyEchoSocket clientEcho = new JettyEchoSocket(); JettyEchoSocket clientSocket = new JettyEchoSocket();
Future<List<String>> clientMessagesFuture = clientEcho.expectedMessages(1);
URI uri = server.getServerBaseURI().resolve("echo"); URI uri = server.getServerBaseURI().resolve("echo");
ClientUpgradeRequest req = new ClientUpgradeRequest(); ClientUpgradeRequest req = new ClientUpgradeRequest();
req.setSubProtocols("echo"); req.setSubProtocols("echo");
Future<Session> foo = client.connect(clientEcho,uri,req); Future<Session> clientConnectFuture = client.connect(clientSocket,uri,req);
// wait for connect // wait for connect
foo.get(1,TimeUnit.SECONDS); Session clientSession = clientConnectFuture.get(5,TimeUnit.SECONDS);
clientEcho.sendMessage(message); clientSocket.sendMessage(message);
List<String> msgs = clientMessagesFuture.get(1, TimeUnit.SECONDS);
String incomingMessage = clientSocket.messageQueue.poll(1, TimeUnit.SECONDS);
Assert.assertThat("Expected message",incomingMessage,containsString(expectedText));
String response = msgs.get(0); clientSession.close();
for (String expected : expectedTexts) clientSocket.awaitCloseEvent("Client");
{
Assert.assertThat("Expected message",response,containsString(expected));
}
} }
finally finally
{ {

View File

@ -19,7 +19,6 @@
package org.eclipse.jetty.websocket.jsr356.server; package org.eclipse.jetty.websocket.jsr356.server;
import java.net.URI; import java.net.URI;
import java.util.List;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -68,14 +67,16 @@ public class BasicEndpointTest
try try
{ {
client.start(); client.start();
JettyEchoSocket clientEcho = new JettyEchoSocket(); JettyEchoSocket clientSocket = new JettyEchoSocket();
Future<List<String>> clientMessagesFuture = clientEcho.expectedMessages(1); Future<Session> clientConnectFuture = client.connect(clientSocket,uri.resolve("echo"));
Future<Session> future = client.connect(clientEcho,uri.resolve("echo"));
// wait for connect // wait for connect
future.get(1,TimeUnit.SECONDS); Session clientSession = clientConnectFuture.get(5,TimeUnit.SECONDS);
clientEcho.sendMessage("Hello World"); clientSocket.sendMessage("Hello World");
List<String> msgs = clientMessagesFuture.get(1, TimeUnit.SECONDS);
Assert.assertEquals("Expected message","Hello World",msgs.get(0)); String incomingMessage = clientSocket.messageQueue.poll(1, TimeUnit.SECONDS);
Assert.assertEquals("Expected message","Hello World",incomingMessage);
clientSession.close();
} }
finally finally
{ {

View File

@ -19,24 +19,18 @@
package org.eclipse.jetty.websocket.jsr356.server; package org.eclipse.jetty.websocket.jsr356.server;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.TestingDir; import org.eclipse.jetty.toolchain.test.TestingDir;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.websocket.api.CloseException;
import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.StatusCode; import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.client.WebSocketClient; import org.eclipse.jetty.websocket.client.WebSocketClient;
@ -86,50 +80,30 @@ public class IdleTimeoutTest
server.stop(); server.stop();
} }
private void assertConnectionTimeout(URI uri) throws Exception, IOException, InterruptedException, ExecutionException, TimeoutException private void assertConnectionTimeout(URI uri) throws Exception
{ {
WebSocketClient client = new WebSocketClient(bufferPool); WebSocketClient client = new WebSocketClient(bufferPool);
try try
{ {
client.start(); client.start();
JettyEchoSocket clientEcho = new JettyEchoSocket(); JettyEchoSocket clientSocket = new JettyEchoSocket();
Future<List<String>> clientMessagesFuture = clientEcho.expectedMessages(1);
if (LOG.isDebugEnabled()) Future<Session> clientConnectFuture = client.connect(clientSocket,uri);
LOG.debug("Client Attempting to connnect");
Future<Session> future = client.connect(clientEcho,uri);
// wait for connect // wait for connect
future.get(1,TimeUnit.SECONDS); clientConnectFuture.get(1,TimeUnit.SECONDS);
if (LOG.isDebugEnabled())
LOG.debug("Client Connected");
// wait 1 second // wait 1 second
if (LOG.isDebugEnabled())
LOG.debug("Waiting 1 second");
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
if (LOG.isDebugEnabled())
LOG.debug("Waited 1 second");
// Try to write // Try to write
clientEcho.sendMessage("You shouldn't be there"); clientSocket.sendMessage("You shouldn't be there");
try
{ // See if remote sent anything (it shouldn't have)
List<String> msgs = clientMessagesFuture.get(1, TimeUnit.SECONDS); String incomingMessage = clientSocket.messageQueue.poll(1, TimeUnit.SECONDS);
assertThat("Should not have received messages echoed back",msgs,is(empty())); assertThat("Should not have received messages echoed back",incomingMessage,nullValue());
}
catch (ExecutionException e) // wait for local close
{ clientSocket.awaitCloseEvent("Client");
Throwable cause = e.getCause(); clientSocket.assertCloseInfo("Client", StatusCode.SHUTDOWN, containsString("Idle Timeout"));
if(cause instanceof CloseException)
{
CloseException ce = (CloseException) cause;
assertThat("CloseException.statusCode", ce.getStatusCode(), is(StatusCode.SHUTDOWN));
assertThat("CloseException.reason", ce.getMessage(), containsString("Idle Timeout"));
}
else
{
throw e;
}
}
} }
finally finally
{ {

View File

@ -18,25 +18,29 @@
package org.eclipse.jetty.websocket.jsr356.server; package org.eclipse.jetty.websocket.jsr356.server;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.concurrent.BlockingQueue;
import java.util.List; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.Future; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.BatchMode; import org.eclipse.jetty.websocket.api.BatchMode;
import org.eclipse.jetty.websocket.api.CloseException;
import org.eclipse.jetty.websocket.api.RemoteEndpoint; import org.eclipse.jetty.websocket.api.RemoteEndpoint;
import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose; import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect; import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError; import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket; import org.eclipse.jetty.websocket.api.annotations.WebSocket;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
/** /**
* This is a Jetty API version of a websocket. * This is a Jetty API version of a websocket.
@ -48,53 +52,30 @@ public class JettyEchoSocket
{ {
private static final Logger LOG = Log.getLogger(JettyEchoSocket.class); private static final Logger LOG = Log.getLogger(JettyEchoSocket.class);
private RemoteEndpoint remote; private RemoteEndpoint remote;
private CompletableFuture<List<String>> expectedMessagesFuture; public CountDownLatch closeLatch = new CountDownLatch(1);
private AtomicInteger expectedMessageCount; public BlockingQueue<String> messageQueue = new LinkedBlockingDeque<>();
private List<String> messages = new ArrayList<>(); public AtomicReference<CloseInfo> closeInfo = new AtomicReference<>();
public Future<List<String>> expectedMessages(int expected)
{
expectedMessagesFuture = new CompletableFuture<>();
expectedMessageCount = new AtomicInteger(expected);
return expectedMessagesFuture;
}
@OnWebSocketClose @OnWebSocketClose
public void onClose(int code, String reason) public void onClose(int statusCode, String reason)
{ {
remote = null; remote = null;
synchronized (expectedMessagesFuture) CloseInfo close = new CloseInfo(statusCode, reason);
{ boolean closeTracked = closeInfo.compareAndSet(null, close);
if ((code != StatusCode.NORMAL) || this.closeLatch.countDown();
(code != StatusCode.NO_CODE)) assertTrue("Close only happened once", closeTracked);
{
expectedMessagesFuture.completeExceptionally(new CloseException(code, reason));
}
}
} }
@OnWebSocketError @OnWebSocketError
public void onError(Throwable t) public void onError(Throwable t)
{ {
LOG.warn(t); LOG.warn(t);
synchronized (expectedMessagesFuture)
{
expectedMessagesFuture.completeExceptionally(t);
}
} }
@OnWebSocketMessage @OnWebSocketMessage
public void onMessage(String msg) throws IOException public void onMessage(String msg) throws IOException
{ {
messages.add(msg); messageQueue.offer(msg);
synchronized (expectedMessagesFuture)
{
int countLeft = expectedMessageCount.decrementAndGet();
if (countLeft <= 0)
{
expectedMessagesFuture.complete(messages);
}
}
sendMessage(msg); sendMessage(msg);
} }
@ -104,6 +85,19 @@ public class JettyEchoSocket
this.remote = session.getRemote(); this.remote = session.getRemote();
} }
public void awaitCloseEvent(String prefix) throws InterruptedException
{
assertTrue(prefix + " onClose event", closeLatch.await(5, TimeUnit.SECONDS));
}
public void assertCloseInfo(String prefix, int expectedCloseStatusCode, Matcher<? super String> reasonMatcher) throws InterruptedException
{
CloseInfo close = closeInfo.get();
assertThat(prefix + " close info", close, Matchers.notNullValue());
assertThat(prefix + " received close code", close.getStatusCode(), Matchers.is(expectedCloseStatusCode));
assertThat(prefix + " received close reason", close.getReason(), reasonMatcher);
}
public void sendMessage(String msg) throws IOException public void sendMessage(String msg) throws IOException
{ {
RemoteEndpoint r = remote; RemoteEndpoint r = remote;

View File

@ -18,10 +18,12 @@
package org.eclipse.jetty.websocket.jsr356.server; package org.eclipse.jetty.websocket.jsr356.server;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import java.net.URI; import java.net.URI;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -31,7 +33,6 @@ import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.client.WebSocketClient; import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule;
import org.eclipse.jetty.websocket.jsr356.server.samples.echo.LargeEchoConfiguredSocket; import org.eclipse.jetty.websocket.jsr356.server.samples.echo.LargeEchoConfiguredSocket;
import org.junit.Assert;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -68,18 +69,24 @@ public class LargeAnnotatedTest
{ {
client.getPolicy().setMaxTextMessageSize(128*1024); client.getPolicy().setMaxTextMessageSize(128*1024);
client.start(); client.start();
JettyEchoSocket clientEcho = new JettyEchoSocket();
Future<List<String>> clientMessagesFuture = clientEcho.expectedMessages(1); JettyEchoSocket clientSocket = new JettyEchoSocket();
Future<Session> foo = client.connect(clientEcho,uri.resolve("echo/large"));
Future<Session> clientConnectFuture = client.connect(clientSocket,uri.resolve("echo/large"));
// wait for connect // wait for connect
foo.get(1,TimeUnit.SECONDS); Session clientSession = clientConnectFuture.get(1,TimeUnit.SECONDS);
// The message size should be bigger than default, but smaller than the limit that LargeEchoSocket specifies // The message size should be bigger than default, but smaller than the limit that LargeEchoSocket specifies
byte txt[] = new byte[100 * 1024]; byte txt[] = new byte[100 * 1024];
Arrays.fill(txt,(byte)'o'); Arrays.fill(txt,(byte)'o');
String msg = new String(txt,StandardCharsets.UTF_8); String msg = new String(txt,StandardCharsets.UTF_8);
clientEcho.sendMessage(msg); clientSocket.sendMessage(msg);
List<String> msgs = clientMessagesFuture.get(1, TimeUnit.SECONDS);
Assert.assertEquals("Expected message",msg,msgs.get(0)); // Receive echo
String incomingMessage = clientSocket.messageQueue.poll(5, TimeUnit.SECONDS);
assertThat("Expected message",incomingMessage,is(msg));
clientSession.close();
} }
finally finally
{ {

View File

@ -18,10 +18,12 @@
package org.eclipse.jetty.websocket.jsr356.server; package org.eclipse.jetty.websocket.jsr356.server;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import java.net.URI; import java.net.URI;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -31,7 +33,6 @@ import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.client.WebSocketClient; import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule;
import org.eclipse.jetty.websocket.jsr356.server.samples.echo.LargeEchoDefaultSocket; import org.eclipse.jetty.websocket.jsr356.server.samples.echo.LargeEchoDefaultSocket;
import org.junit.Assert;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -68,18 +69,24 @@ public class LargeContainerTest
{ {
client.getPolicy().setMaxTextMessageSize(128*1024); client.getPolicy().setMaxTextMessageSize(128*1024);
client.start(); client.start();
JettyEchoSocket clientEcho = new JettyEchoSocket();
Future<List<String>> clientMessagesFuture = clientEcho.expectedMessages(1); JettyEchoSocket clientSocket = new JettyEchoSocket();
Future<Session> foo = client.connect(clientEcho,uri.resolve("echo/large")); Future<Session> clientConnectFuture = client.connect(clientSocket,uri.resolve("echo/large"));
// wait for connect // wait for connect
foo.get(1,TimeUnit.SECONDS); Session clientSession = clientConnectFuture.get(5,TimeUnit.SECONDS);
// The message size should be bigger than default, but smaller than the limit that LargeEchoSocket specifies // The message size should be bigger than default, but smaller than the limit that LargeEchoSocket specifies
byte txt[] = new byte[100 * 1024]; byte txt[] = new byte[100 * 1024];
Arrays.fill(txt,(byte)'o'); Arrays.fill(txt,(byte)'o');
String msg = new String(txt,StandardCharsets.UTF_8); String msg = new String(txt,StandardCharsets.UTF_8);
clientEcho.sendMessage(msg); clientSocket.sendMessage(msg);
List<String> msgs = clientMessagesFuture.get(1, TimeUnit.SECONDS);
Assert.assertEquals("Expected message",msg,msgs.get(0)); // Confirm echo
String incomingMessage = clientSocket.messageQueue.poll(5, TimeUnit.SECONDS);
assertThat("Expected message",incomingMessage,is(msg));
clientSession.close();
} }
finally finally
{ {

View File

@ -18,8 +18,10 @@
package org.eclipse.jetty.websocket.jsr356.server; package org.eclipse.jetty.websocket.jsr356.server;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import java.net.URI; import java.net.URI;
import java.util.List;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -29,7 +31,6 @@ import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.client.WebSocketClient; import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule; import org.eclipse.jetty.websocket.common.test.LeakTrackingBufferPoolRule;
import org.eclipse.jetty.websocket.jsr356.server.samples.echo.EchoReturnEndpoint; import org.eclipse.jetty.websocket.jsr356.server.samples.echo.EchoReturnEndpoint;
import org.junit.Assert;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -60,14 +61,21 @@ public class OnMessageReturnTest
try try
{ {
client.start(); client.start();
JettyEchoSocket clientEcho = new JettyEchoSocket();
Future<List<String>> clientMessagesFuture = clientEcho.expectedMessages(1); JettyEchoSocket clientSocket = new JettyEchoSocket();
Future<Session> future = client.connect(clientEcho,uri.resolve("echoreturn")); Future<Session> clientConnectFuture = client.connect(clientSocket,uri.resolve("echoreturn"));
// wait for connect // wait for connect
future.get(1,TimeUnit.SECONDS); Session clientSession = clientConnectFuture.get(5,TimeUnit.SECONDS);
clientEcho.sendMessage("Hello World");
List<String> msgs = clientMessagesFuture.get(1, TimeUnit.SECONDS); // Send message
Assert.assertEquals("Expected message","Hello World",msgs.get(0)); clientSocket.sendMessage("Hello World");
// Confirm response
String incomingMessage = clientSocket.messageQueue.poll(5, TimeUnit.SECONDS);
assertThat("Expected message",incomingMessage,is("Hello World"));
clientSession.close();
} }
finally finally
{ {

View File

@ -46,9 +46,9 @@ import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class) @RunWith(Parameterized.class)
public class SessionTest public class SessionTest
{ {
private static interface Case private interface Case
{ {
public void customize(WebAppContext context); void customize(WebAppContext context);
} }
@Parameters @Parameters
@ -56,44 +56,28 @@ public class SessionTest
{ {
List<Case[]> cases = new ArrayList<>(); List<Case[]> cases = new ArrayList<>();
cases.add(new Case[] cases.add(new Case[]
{ new Case() {context ->
{ {
@Override // no customization
public void customize(WebAppContext context) }});
{
// no customization
}
} });
cases.add(new Case[] cases.add(new Case[]
{ new Case() {context ->
{ {
@Override // Test with DefaultServlet only
public void customize(WebAppContext context) context.addServlet(DefaultServlet.class,"/");
{ }});
// Test with DefaultServlet only
context.addServlet(DefaultServlet.class,"/");
}
} });
cases.add(new Case[] cases.add(new Case[]
{ new Case() {context ->
{ {
@Override // Test with Servlet mapped to "/*"
public void customize(WebAppContext context) context.addServlet(DefaultServlet.class,"/*");
{ }});
// Test with Servlet mapped to "/*"
context.addServlet(DefaultServlet.class,"/*");
}
} });
cases.add(new Case[] cases.add(new Case[]
{ new Case() {context ->
{ {
@Override // Test with Servlet mapped to "/info/*"
public void customize(WebAppContext context) context.addServlet(DefaultServlet.class,"/info/*");
{ }});
// Test with Servlet mapped to "/info/*"
context.addServlet(DefaultServlet.class,"/info/*");
}
} });
return cases; return cases;
} }
@ -137,14 +121,18 @@ public class SessionTest
try try
{ {
client.start(); client.start();
JettyEchoSocket clientEcho = new JettyEchoSocket();
Future<List<String>> clientMessagesFuture = clientEcho.expectedMessages(1); JettyEchoSocket clientSocket = new JettyEchoSocket();
Future<Session> future = client.connect(clientEcho,serverUri.resolve(requestPath)); Future<Session> clientConnectFuture = client.connect(clientSocket,serverUri.resolve(requestPath));
// wait for connect // wait for connect
future.get(1,TimeUnit.SECONDS); Session clientSession = clientConnectFuture.get(5,TimeUnit.SECONDS);
clientEcho.sendMessage(requestMessage); clientSocket.sendMessage(requestMessage);
List<String> msgs = clientMessagesFuture.get(1, TimeUnit.SECONDS);
Assert.assertThat("Expected message",msgs.get(0),is(expectedResponse)); String incomingMessage = clientSocket.messageQueue.poll(5, TimeUnit.SECONDS);
Assert.assertThat("Expected message",incomingMessage,is(expectedResponse));
clientSession.close();
clientSocket.awaitCloseEvent("Client");
} }
finally finally
{ {

View File

@ -133,6 +133,7 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketCont
public WebSocketClient(ByteBufferPool bufferPool) public WebSocketClient(ByteBufferPool bufferPool)
{ {
this(new HttpClient()); this(new HttpClient());
addBean(this.httpClient);
this.httpClient.setByteBufferPool(bufferPool); this.httpClient.setByteBufferPool(bufferPool);
} }
@ -145,6 +146,7 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketCont
public WebSocketClient(SslContextFactory sslContextFactory) public WebSocketClient(SslContextFactory sslContextFactory)
{ {
this(new HttpClient(sslContextFactory)); this(new HttpClient(sslContextFactory));
addBean(this.httpClient);
} }
/** /**
@ -158,6 +160,7 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketCont
public WebSocketClient(SslContextFactory sslContextFactory, Executor executor) public WebSocketClient(SslContextFactory sslContextFactory, Executor executor)
{ {
this(new HttpClient(sslContextFactory)); this(new HttpClient(sslContextFactory));
addBean(this.httpClient);
this.httpClient.setExecutor(executor); this.httpClient.setExecutor(executor);
} }

View File

@ -162,6 +162,7 @@ public class WSServer
{ {
contexts.addHandler(webapp); contexts.addHandler(webapp);
contexts.manage(webapp); contexts.manage(webapp);
webapp.setThrowUnavailableOnStartupException(true);
webapp.start(); webapp.start();
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
{ {