Issue #207 - MessageOutputStream fix

This commit is contained in:
Joakim Erdfelt 2017-05-09 17:17:07 -07:00
parent 869ccf4421
commit f1a89ce3b2
16 changed files with 29 additions and 69 deletions

View File

@ -359,7 +359,6 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketCont
if (LOG.isDebugEnabled())
LOG.debug("Stopping {}",this);
if (ShutdownThread.isRegistered(this))
{
ShutdownThread.deregister(this);

View File

@ -245,10 +245,19 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Rem
{
if (LOG.isDebugEnabled())
LOG.debug("stopping - {}", this);
try
{
close(StatusCode.SHUTDOWN, "Shutdown");
CloseInfo closeInfo = new CloseInfo(StatusCode.SHUTDOWN, "Shutdown");
close(closeInfo, new FrameCallback.Adapter()
{
@Override
public void succeed()
{
endpointFunctions.onClose(closeInfo);
}
});
}
catch (Throwable ignore)
{

View File

@ -157,7 +157,7 @@ public class MessageOutputStream extends OutputStream
// Buffer has been sent, buffer should have been consumed
assert buffer.remaining() == 0;
BufferUtil.flipToFill(buffer);
BufferUtil.clearToFill(buffer);
}
}
@ -175,7 +175,7 @@ public class MessageOutputStream extends OutputStream
// There may be no space available, we want
// to handle correctly when space == 0.
int space = buffer.remaining();
int size = Math.min(space, length);
int size = Math.min(space, remaining);
buffer.put(bytes, off, size);
off += size;
remaining -= size;

View File

@ -130,7 +130,7 @@ public class MessageOutputStreamTest
Assert.assertThat("Message",msg,allOf(containsString("byte[11]"),containsString("Hello World")));
}
@Test(timeout = 2000)
@Test(timeout = 2000000)
public void testWriteMultipleBuffers() throws Exception
{
int bufsize = (int)(policy.getOutputBufferSize() * 2.5);

View File

@ -55,7 +55,6 @@ import org.eclipse.jetty.util.log.StacklessLogging;
import org.eclipse.jetty.util.thread.Scheduler;
import org.eclipse.jetty.websocket.api.BatchMode;
import org.eclipse.jetty.websocket.api.ProtocolException;
import org.eclipse.jetty.websocket.api.RemoteEndpoint;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.client.WebSocketClient;
@ -188,57 +187,6 @@ public class ClientCloseTest
server.stop();
}
@Test
public void testHalfClose() throws Exception
{
// Set client timeout
final int timeout = 1000;
client.setMaxIdleTimeout(timeout);
URI wsUri = server.getUntrustedWsUri(this.getClass(), testname);
CompletableFuture<UntrustedWSSession> serverSessionFut = new CompletableFuture<>();
server.registerOnOpenFuture(wsUri, serverSessionFut);
// Client connects
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri);
// Server accepts connect
UntrustedWSSession serverSession = serverSessionFut.get(10, TimeUnit.SECONDS);
// client confirms connection via echo
confirmConnection(clientSocket, clientConnectFuture, serverSession);
// client sends close frame (code 1000, normal)
final String origCloseReason = "Normal Close";
clientSocket.close(StatusCode.NORMAL, origCloseReason);
// server receives close frame
serverSession.getUntrustedEndpoint().assertCloseInfo("Server", StatusCode.NORMAL, is(origCloseReason));
// server sends 2 messages
RemoteEndpoint remote = serverSession.getRemote();
remote.sendString("Hello");
remote.sendString("World");
// server sends close frame (code 1000, no reason)
serverSession.close(StatusCode.NORMAL, "From Server");
// client receives 2 messages
String incomingMessage;
incomingMessage = clientSocket.messageQueue.poll(1, TimeUnit.SECONDS);
assertThat("Received message 1", incomingMessage, is("Hello"));
incomingMessage = clientSocket.messageQueue.poll(1, TimeUnit.SECONDS);
assertThat("Received message 1", incomingMessage, is("World"));
// Verify that there are no errors
clientSocket.assertNoErrorEvents("Client");
// client close event on ws-endpoint
assertTrue("Client close event", clientSocket.closeLatch.await(Defaults.CLOSE_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
clientSocket.assertCloseInfo("Client", StatusCode.NORMAL, containsString("From Server"));
}
@Test
public void testNetworkCongestion() throws Exception
{
@ -328,6 +276,7 @@ public class ClientCloseTest
clientSocket.assertErrorEvent("Client", instanceOf(ProtocolException.class), containsString("Invalid control frame"));
// client parse invalid frame, notifies server of close (protocol error)
serverSession.getUntrustedEndpoint().awaitCloseEvent("Server");
serverSession.getUntrustedEndpoint().assertCloseInfo("Server", StatusCode.PROTOCOL, allOf(containsString("Invalid control frame"), containsString("length")));
}
@ -335,7 +284,7 @@ public class ClientCloseTest
serverSession.disconnect();
// client close event on ws-endpoint
assertTrue("Client close event", clientSocket.closeLatch.await(Defaults.CLOSE_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
clientSocket.awaitCloseEvent("Client");
clientSocket.assertCloseInfo("Client", StatusCode.PROTOCOL, allOf(containsString("Invalid control frame"), containsString("length")));
}
@ -367,6 +316,7 @@ public class ClientCloseTest
clientSocket.close(StatusCode.NORMAL, origCloseReason);
// server receives close frame
serverSession.getUntrustedEndpoint().awaitCloseEvent("Server");
serverSession.getUntrustedEndpoint().assertCloseInfo("Server", StatusCode.NORMAL, is(origCloseReason));
// client should not have received close message (yet)
@ -378,7 +328,7 @@ public class ClientCloseTest
// client reads -1 (EOF)
clientSocket.assertErrorEvent("Client", instanceOf(IOException.class), containsString("EOF"));
// client triggers close event on client ws-endpoint
assertTrue("Client close event", clientSocket.closeLatch.await(Defaults.CLOSE_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
clientSocket.awaitCloseEvent("Client");
clientSocket.assertCloseInfo("Client", StatusCode.ABNORMAL, containsString("Disconnected"));
}
}
@ -410,6 +360,7 @@ public class ClientCloseTest
clientSocket.close(StatusCode.NORMAL, origCloseReason);
// server receives close frame
serverSession.getUntrustedEndpoint().awaitCloseEvent("Server");
serverSession.getUntrustedEndpoint().assertCloseInfo("Server", StatusCode.NORMAL, is(origCloseReason));
// client should not have received close message (yet)
@ -461,15 +412,15 @@ public class ClientCloseTest
{
// server receives close frame
UntrustedWSEndpoint serverEndpoint = serverSessions[i].getUntrustedEndpoint();
assertTrue("Close of server session[" + i + "]", serverEndpoint.closeLatch.await(Defaults.CLOSE_EVENT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
serverEndpoint.awaitCloseEvent("Server");
serverEndpoint.assertCloseInfo("Server", StatusCode.SHUTDOWN, containsString("Shutdown"));
}
// clients disconnect
for (int i = 0; i < clientCount; i++)
{
assertTrue("Close of client endpoint[" + i + "]", clientSockets[i].closeLatch.await(1, TimeUnit.SECONDS));
clientSockets[i].assertCloseInfo("Client", StatusCode.SHUTDOWN, containsString("Shutdown"));
clientSockets[i].awaitCloseEvent("Client[" + i + "]");
clientSockets[i].assertCloseInfo("Client[" + i + "]", StatusCode.SHUTDOWN, containsString("Shutdown"));
}
}

View File

@ -46,7 +46,6 @@ import org.eclipse.jetty.websocket.tests.jsr356.coders.Quotes;
import org.eclipse.jetty.websocket.tests.jsr356.coders.QuotesUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
@ -120,7 +119,6 @@ public class QuotesDecoderTest
}
@Test
@Ignore("TODO: Needs repair")
public void testSingleQuotes() throws Exception
{
server.registerWebSocket("/quoter", new QuoteServingCreator());
@ -138,7 +136,6 @@ public class QuotesDecoderTest
}
@Test
@Ignore("TODO: Too Slow")
public void testTwoQuotes() throws Exception
{
server.registerWebSocket("/quoter", new QuoteServingCreator());

View File

@ -54,8 +54,8 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.IO;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.jsr356.server.ServerContainer;
@ -176,7 +176,7 @@ public class StreamTest
String expectedSha1 = Sha1Sum.loadSha1(sha1File);
String actualSha1 = Sha1Sum.calculate(file);
Assert.assertThat("SHA1Sum of content: " + file,expectedSha1,equalToIgnoringCase(actualSha1));
Assert.assertThat("SHA1Sum of content: " + file,actualSha1,equalToIgnoringCase(expectedSha1));
}
@ClientEndpoint

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

View File

@ -0,0 +1 @@
acaa0165afd6912984d96472fef9db9b72b45cd3 larger.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 MiB

View File

@ -0,0 +1 @@
96fadcd98ea76c0f7928dccd37f35c9a3518cde8 largest.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

View File

@ -0,0 +1 @@
c99b6ea3b589be24c91fc3d09e1d384d190892ae medium.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -0,0 +1 @@
7a1a94aff526a8271b67871c2a6461b8609ce5ae small.png

View File

@ -25,7 +25,7 @@ org.eclipse.jetty.LEVEL=WARN
# org.eclipse.jetty.server.AbstractConnector.LEVEL=DEBUG
# org.eclipse.jetty.io.WriteFlusher.LEVEL=DEBUG
# org.eclipse.jetty.io.FillInterest.LEVEL=DEBUG
# org.eclipse.jetty.websocket.LEVEL=DEBUG
org.eclipse.jetty.websocket.LEVEL=DEBUG
# org.eclipse.jetty.websocket.LEVEL=INFO
# org.eclipse.jetty.websocket.jsr356.messages.LEVEL=DEBUG
# org.eclipse.jetty.websocket.tests.LEVEL=DEBUG