Issue #1650 - improving testcase reliability
This commit is contained in:
parent
2d65605de1
commit
ed692f3917
|
@ -21,10 +21,11 @@ package org.eclipse.jetty.cdi.websocket;
|
|||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jetty.toolchain.test.EventQueue;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
|
@ -37,7 +38,7 @@ public class CheckSocket extends WebSocketAdapter
|
|||
private static final Logger LOG = Log.getLogger(CheckSocket.class);
|
||||
private CountDownLatch closeLatch = new CountDownLatch(1);
|
||||
private CountDownLatch openLatch = new CountDownLatch(1);
|
||||
private EventQueue<String> textMessages = new EventQueue<>();
|
||||
private BlockingQueue<String> textMessages = new LinkedBlockingDeque<>();
|
||||
|
||||
public void awaitClose(int timeout, TimeUnit timeunit) throws InterruptedException
|
||||
{
|
||||
|
@ -49,7 +50,7 @@ public class CheckSocket extends WebSocketAdapter
|
|||
assertTrue("Timeout waiting for open",openLatch.await(timeout,timeunit));
|
||||
}
|
||||
|
||||
public EventQueue<String> getTextMessages()
|
||||
public BlockingQueue<String> getTextMessages()
|
||||
{
|
||||
return textMessages;
|
||||
}
|
||||
|
@ -81,7 +82,7 @@ public class CheckSocket extends WebSocketAdapter
|
|||
public void onWebSocketText(String message)
|
||||
{
|
||||
LOG.debug("TEXT: {}",message);
|
||||
textMessages.add(message);
|
||||
textMessages.offer(message);
|
||||
}
|
||||
|
||||
public void sendText(String msg) throws IOException
|
||||
|
|
|
@ -106,13 +106,13 @@ public class BasicAppTest
|
|||
CheckSocket socket = new CheckSocket();
|
||||
client.connect(socket,serverWebsocketURI.resolve("/echo"));
|
||||
|
||||
socket.awaitOpen(2,TimeUnit.SECONDS);
|
||||
socket.awaitOpen(5,TimeUnit.SECONDS);
|
||||
socket.sendText("Hello World");
|
||||
socket.close(StatusCode.NORMAL,"Test complete");
|
||||
socket.awaitClose(2,TimeUnit.SECONDS);
|
||||
socket.awaitClose(5,TimeUnit.SECONDS);
|
||||
|
||||
assertThat("Messages received",socket.getTextMessages().size(),is(1));
|
||||
String response = socket.getTextMessages().poll();
|
||||
String response = socket.getTextMessages().poll(5, TimeUnit.SECONDS);
|
||||
|
||||
assertThat("Message[0]",response,is("Hello World"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue