Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-10.0.x
This commit is contained in:
commit
cb626e72bc
|
@ -176,7 +176,7 @@ public class WebSocketProxy
|
|||
{
|
||||
// If we have sent out a ping then we have already responded with automatic pong.
|
||||
// If this is an unsolicited pong we still need to forward it to the server.
|
||||
int valueBeforeUpdate = pingsReceived.getAndUpdate(i -> i > 0 ? i - 1 : i);
|
||||
int valueBeforeUpdate = proxyToServer.pingsReceived.getAndUpdate(i -> i > 0 ? i - 1 : i);
|
||||
if (valueBeforeUpdate == 0)
|
||||
proxyToServer.getSession().getRemote().sendPong(BufferUtil.copy(payload));
|
||||
}
|
||||
|
@ -297,7 +297,7 @@ public class WebSocketProxy
|
|||
{
|
||||
// If we have sent out a ping then we have already responded with automatic pong.
|
||||
// If this is an unsolicited pong we still need to forward it to the client.
|
||||
int valueBeforeUpdate = pingsReceived.getAndUpdate(i -> i > 0 ? i - 1 : i);
|
||||
int valueBeforeUpdate = clientToProxy.pingsReceived.getAndUpdate(i -> i > 0 ? i - 1 : i);
|
||||
if (valueBeforeUpdate == 0)
|
||||
clientToProxy.getSession().getRemote().sendPong(BufferUtil.copy(payload));
|
||||
}
|
||||
|
|
|
@ -283,21 +283,21 @@ public class WebSocketProxyTest
|
|||
assertThat(clientSocket.pongMessages.poll(5, TimeUnit.SECONDS), is(BufferUtil.toBuffer("unsolicited pong from server")));
|
||||
|
||||
// Test pings from client.
|
||||
for (int i = 0; i < 10; i++)
|
||||
clientSocket.session.getRemote().sendPing(BufferUtil.toBuffer(i));
|
||||
for (int i = 0; i < 10; i++)
|
||||
for (int i = 0; i < 15; i++)
|
||||
clientSocket.session.getRemote().sendPing(intToStringByteBuffer(i));
|
||||
for (int i = 0; i < 15; i++)
|
||||
{
|
||||
assertThat(serverEndpoint.pingMessages.poll(5, TimeUnit.SECONDS), is(BufferUtil.toBuffer(i)));
|
||||
assertThat(clientSocket.pongMessages.poll(5, TimeUnit.SECONDS), is(BufferUtil.toBuffer(i)));
|
||||
assertThat(serverEndpoint.pingMessages.poll(5, TimeUnit.SECONDS), is(intToStringByteBuffer(i)));
|
||||
assertThat(clientSocket.pongMessages.poll(5, TimeUnit.SECONDS), is(intToStringByteBuffer(i)));
|
||||
}
|
||||
|
||||
// Test pings from server.
|
||||
for (int i = 0; i < 10; i++)
|
||||
serverEndpoint.session.getRemote().sendPing(BufferUtil.toBuffer(i));
|
||||
for (int i = 0; i < 10; i++)
|
||||
for (int i = 0; i < 23; i++)
|
||||
serverEndpoint.session.getRemote().sendPing(intToStringByteBuffer(i));
|
||||
for (int i = 0; i < 23; i++)
|
||||
{
|
||||
assertThat(clientSocket.pingMessages.poll(5, TimeUnit.SECONDS), is(BufferUtil.toBuffer(i)));
|
||||
assertThat(serverEndpoint.pongMessages.poll(5, TimeUnit.SECONDS), is(BufferUtil.toBuffer(i)));
|
||||
assertThat(clientSocket.pingMessages.poll(5, TimeUnit.SECONDS), is(intToStringByteBuffer(i)));
|
||||
assertThat(serverEndpoint.pongMessages.poll(5, TimeUnit.SECONDS), is(intToStringByteBuffer(i)));
|
||||
}
|
||||
|
||||
clientSocket.session.close(StatusCode.NORMAL, "closing from test");
|
||||
|
@ -322,6 +322,11 @@ public class WebSocketProxyTest
|
|||
assertThat(serverEndpoint.pingMessages.size(), is(0));
|
||||
}
|
||||
|
||||
private ByteBuffer intToStringByteBuffer(int i)
|
||||
{
|
||||
return BufferUtil.toBuffer(Integer.toString(i));
|
||||
}
|
||||
|
||||
@WebSocket
|
||||
public static class PingPongSocket extends EventSocket
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue