Added test for the lost messages bug.
This commit is contained in:
parent
ba87334389
commit
0f8939dd96
|
@ -9,7 +9,6 @@ import java.net.ConnectException;
|
|||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Exchanger;
|
||||
|
@ -23,9 +22,11 @@ import java.util.concurrent.atomic.AtomicLong;
|
|||
|
||||
import org.eclipse.jetty.util.BlockingArrayQueue;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class WebSocketClientTest
|
||||
|
@ -52,6 +53,56 @@ public class WebSocketClientTest
|
|||
_factory.stop();
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testMessageBiggerThanBufferSize() throws Exception
|
||||
{
|
||||
int bufferSize = 512;
|
||||
WebSocketClientFactory factory = new WebSocketClientFactory(new QueuedThreadPool(), new ZeroMaskGen(), bufferSize);
|
||||
factory.start();
|
||||
WebSocketClient client = new WebSocketClient(factory);
|
||||
|
||||
final CountDownLatch openLatch = new CountDownLatch(1);
|
||||
final CountDownLatch dataLatch = new CountDownLatch(1);
|
||||
WebSocket.OnTextMessage websocket = new WebSocket.OnTextMessage()
|
||||
{
|
||||
public void onOpen(Connection connection)
|
||||
{
|
||||
openLatch.countDown();
|
||||
}
|
||||
|
||||
public void onMessage(String data)
|
||||
{
|
||||
System.out.println("data = " + data);
|
||||
dataLatch.countDown();
|
||||
}
|
||||
|
||||
public void onClose(int closeCode, String message)
|
||||
{
|
||||
}
|
||||
};
|
||||
Future<WebSocket.Connection> future = client.open(new URI("ws://127.0.0.1:" + _serverPort + "/"), websocket);
|
||||
|
||||
Socket socket = _server.accept();
|
||||
accept(socket);
|
||||
|
||||
Assert.assertTrue(openLatch.await(1, TimeUnit.SECONDS));
|
||||
OutputStream serverOutput = socket.getOutputStream();
|
||||
|
||||
int length = bufferSize + bufferSize / 2;
|
||||
serverOutput.write(0x80 | 0x01); // FIN + TEXT
|
||||
serverOutput.write(0x7E); // No MASK and 2 bytes length
|
||||
serverOutput.write(length >> 8); // first length byte
|
||||
serverOutput.write(length & 0xFF); // second length byte
|
||||
for (int i = 0; i < length; ++i)
|
||||
serverOutput.write('x');
|
||||
serverOutput.flush();
|
||||
|
||||
Assert.assertTrue(dataLatch.await(1000, TimeUnit.SECONDS));
|
||||
|
||||
factory.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadURL() throws Exception
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue