Fix problems with close unit tests before creating open unit tests
Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
parent
5f20651d06
commit
f170191003
|
@ -88,7 +88,13 @@ public class WebSocketCloseTest extends WebSocketTester
|
||||||
|
|
||||||
assertTrue(server.handler.opened.await(10, TimeUnit.SECONDS));
|
assertTrue(server.handler.opened.await(10, TimeUnit.SECONDS));
|
||||||
|
|
||||||
assertThat(server.handler.getCoreSession().toString(), containsString("OPEN"));
|
assertThat(server.handler.state, containsString("CONNECTED"));
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
Thread.yield();
|
||||||
|
if (server.handler.getCoreSession().toString().contains("OPEN"))
|
||||||
|
break;
|
||||||
|
}
|
||||||
LOG.info("Server: OPEN");
|
LOG.info("Server: OPEN");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -102,6 +108,12 @@ public class WebSocketCloseTest extends WebSocketTester
|
||||||
client = newClient(server.getLocalPort());
|
client = newClient(server.getLocalPort());
|
||||||
|
|
||||||
assertTrue(server.handler.opened.await(10, TimeUnit.SECONDS));
|
assertTrue(server.handler.opened.await(10, TimeUnit.SECONDS));
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
Thread.yield();
|
||||||
|
if (server.handler.getCoreSession().toString().contains("OPEN"))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
server.handler.getCoreSession().demand(1);
|
server.handler.getCoreSession().demand(1);
|
||||||
client.getOutputStream().write(RawFrameBuilder.buildClose(new CloseStatus(CloseStatus.NORMAL), true));
|
client.getOutputStream().write(RawFrameBuilder.buildClose(new CloseStatus(CloseStatus.NORMAL), true));
|
||||||
|
@ -123,6 +135,12 @@ public class WebSocketCloseTest extends WebSocketTester
|
||||||
client = newClient(server.getLocalPort());
|
client = newClient(server.getLocalPort());
|
||||||
|
|
||||||
assertTrue(server.handler.opened.await(10, TimeUnit.SECONDS));
|
assertTrue(server.handler.opened.await(10, TimeUnit.SECONDS));
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
Thread.yield();
|
||||||
|
if (server.handler.getCoreSession().toString().contains("OPEN"))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
server.sendFrame(CloseStatus.toFrame(CloseStatus.NORMAL));
|
server.sendFrame(CloseStatus.toFrame(CloseStatus.NORMAL));
|
||||||
Frame frame = receiveFrame(client.getInputStream());
|
Frame frame = receiveFrame(client.getInputStream());
|
||||||
|
@ -138,7 +156,7 @@ public class WebSocketCloseTest extends WebSocketTester
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void serverClose_ICLOSED() throws Exception
|
public void serverClose_ISHUT() throws Exception
|
||||||
{
|
{
|
||||||
setup(State.ISHUT);
|
setup(State.ISHUT);
|
||||||
|
|
||||||
|
@ -152,7 +170,7 @@ public class WebSocketCloseTest extends WebSocketTester
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void serverDifferentClose_ICLOSED() throws Exception
|
public void serverDifferentClose_ISHUT() throws Exception
|
||||||
{
|
{
|
||||||
setup(State.ISHUT);
|
setup(State.ISHUT);
|
||||||
|
|
||||||
|
@ -167,7 +185,7 @@ public class WebSocketCloseTest extends WebSocketTester
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void serverFailClose_ICLOSED() throws Exception
|
public void serverFailClose_ISHUT() throws Exception
|
||||||
{
|
{
|
||||||
try (StacklessLogging stackless = new StacklessLogging(WebSocketChannel.class))
|
try (StacklessLogging stackless = new StacklessLogging(WebSocketChannel.class))
|
||||||
{
|
{
|
||||||
|
@ -184,7 +202,7 @@ public class WebSocketCloseTest extends WebSocketTester
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void clientClose_OCLOSED() throws Exception
|
public void clientClose_OSHUT() throws Exception
|
||||||
{
|
{
|
||||||
setup(State.OSHUT);
|
setup(State.OSHUT);
|
||||||
server.handler.getCoreSession().demand(1);
|
server.handler.getCoreSession().demand(1);
|
||||||
|
@ -199,7 +217,7 @@ public class WebSocketCloseTest extends WebSocketTester
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void clientDifferentClose_OCLOSED() throws Exception
|
public void clientDifferentClose_OSHUT() throws Exception
|
||||||
{
|
{
|
||||||
setup(State.OSHUT);
|
setup(State.OSHUT);
|
||||||
server.handler.getCoreSession().demand(1);
|
server.handler.getCoreSession().demand(1);
|
||||||
|
@ -214,7 +232,7 @@ public class WebSocketCloseTest extends WebSocketTester
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void clientCloseServerFailClose_OCLOSED() throws Exception
|
public void clientCloseServerFailClose_OSHUT() throws Exception
|
||||||
{
|
{
|
||||||
try (StacklessLogging stackless = new StacklessLogging(WebSocketChannel.class))
|
try (StacklessLogging stackless = new StacklessLogging(WebSocketChannel.class))
|
||||||
{
|
{
|
||||||
|
@ -244,7 +262,7 @@ public class WebSocketCloseTest extends WebSocketTester
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void clientSendsBadFrame_OCLOSED() throws Exception
|
public void clientSendsBadFrame_OSHUT() throws Exception
|
||||||
{
|
{
|
||||||
setup(State.OSHUT);
|
setup(State.OSHUT);
|
||||||
|
|
||||||
|
@ -256,7 +274,7 @@ public class WebSocketCloseTest extends WebSocketTester
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void clientSendsBadFrame_ICLOSED() throws Exception
|
public void clientSendsBadFrame_ISHUT() throws Exception
|
||||||
{
|
{
|
||||||
setup(State.ISHUT);
|
setup(State.ISHUT);
|
||||||
|
|
||||||
|
@ -284,7 +302,7 @@ public class WebSocketCloseTest extends WebSocketTester
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void clientAborts_OCLOSED() throws Exception
|
public void clientAborts_OSHUT() throws Exception
|
||||||
{
|
{
|
||||||
setup(State.OSHUT);
|
setup(State.OSHUT);
|
||||||
|
|
||||||
|
@ -297,7 +315,7 @@ public class WebSocketCloseTest extends WebSocketTester
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void clientAborts_ICLOSED() throws Exception
|
public void clientAborts_ISHUT() throws Exception
|
||||||
{
|
{
|
||||||
setup(State.ISHUT);
|
setup(State.ISHUT);
|
||||||
|
|
||||||
|
@ -328,7 +346,7 @@ public class WebSocketCloseTest extends WebSocketTester
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onFrameThrows_OCLOSED() throws Exception
|
public void onFrameThrows_OSHUT() throws Exception
|
||||||
{
|
{
|
||||||
setup(State.OSHUT);
|
setup(State.OSHUT);
|
||||||
|
|
||||||
|
@ -347,6 +365,7 @@ public class WebSocketCloseTest extends WebSocketTester
|
||||||
static class TestFrameHandler implements FrameHandler
|
static class TestFrameHandler implements FrameHandler
|
||||||
{
|
{
|
||||||
private CoreSession session;
|
private CoreSession session;
|
||||||
|
String state;
|
||||||
|
|
||||||
protected BlockingQueue<Frame> receivedFrames = new BlockingArrayQueue<>();
|
protected BlockingQueue<Frame> receivedFrames = new BlockingArrayQueue<>();
|
||||||
protected BlockingQueue<Callback> receivedCallback = new BlockingArrayQueue<>();
|
protected BlockingQueue<Callback> receivedCallback = new BlockingArrayQueue<>();
|
||||||
|
@ -368,7 +387,8 @@ public class WebSocketCloseTest extends WebSocketTester
|
||||||
public void onOpen(CoreSession coreSession)
|
public void onOpen(CoreSession coreSession)
|
||||||
{
|
{
|
||||||
LOG.info("onOpen {}", coreSession);
|
LOG.info("onOpen {}", coreSession);
|
||||||
this.session = coreSession;
|
session = coreSession;
|
||||||
|
state = session.toString();
|
||||||
opened.countDown();
|
opened.countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,6 +396,7 @@ public class WebSocketCloseTest extends WebSocketTester
|
||||||
public void onFrame(Frame frame, Callback callback)
|
public void onFrame(Frame frame, Callback callback)
|
||||||
{
|
{
|
||||||
LOG.info("onFrame: " + BufferUtil.toDetailString(frame.getPayload()));
|
LOG.info("onFrame: " + BufferUtil.toDetailString(frame.getPayload()));
|
||||||
|
state = session.toString();
|
||||||
receivedCallback.offer(callback);
|
receivedCallback.offer(callback);
|
||||||
receivedFrames.offer(Frame.copy(frame));
|
receivedFrames.offer(Frame.copy(frame));
|
||||||
|
|
||||||
|
@ -387,6 +408,7 @@ public class WebSocketCloseTest extends WebSocketTester
|
||||||
public void onClosed(CloseStatus closeStatus)
|
public void onClosed(CloseStatus closeStatus)
|
||||||
{
|
{
|
||||||
LOG.info("onClosed {}", closeStatus);
|
LOG.info("onClosed {}", closeStatus);
|
||||||
|
state = session.toString();
|
||||||
this.closeStatus = closeStatus;
|
this.closeStatus = closeStatus;
|
||||||
closed.countDown();
|
closed.countDown();
|
||||||
}
|
}
|
||||||
|
@ -395,6 +417,7 @@ public class WebSocketCloseTest extends WebSocketTester
|
||||||
public void onError(Throwable cause) throws Exception
|
public void onError(Throwable cause) throws Exception
|
||||||
{
|
{
|
||||||
LOG.info("onError {} ", cause == null?null:cause.toString());
|
LOG.info("onError {} ", cause == null?null:cause.toString());
|
||||||
|
state = session.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -410,6 +433,7 @@ public class WebSocketCloseTest extends WebSocketTester
|
||||||
frame.setPayload(text);
|
frame.setPayload(text);
|
||||||
|
|
||||||
getCoreSession().sendFrame(frame, NOOP, false);
|
getCoreSession().sendFrame(frame, NOOP, false);
|
||||||
|
state = session.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue