{
goAwayReceivedLatch.countDown();
}
});
final Generator generator = new Generator(new MappedByteBufferPool(), new StandardCompressionFactory().newCompressor());
int streamId = 1;
ByteBuffer synData = generator.control(new SynStreamFrame(version,SynInfo.FLAG_CLOSE, streamId,0,(byte)0,(short)0,new Fields()));
final SocketChannel socketChannel = SocketChannel.open(startServer);
socketChannel.write(synData);
assertThat("synData is fully written", synData.hasRemaining(), is(false));
assertThat("server: push reply is sent",serverReplySentLatch.await(5,TimeUnit.SECONDS),is(true));
Parser parser = new Parser(new StandardCompressionFactory.StandardDecompressor());
parser.addListener(new Listener.Adapter()
{
@Override
public void onControlFrame(ControlFrame frame)
{
if (frame instanceof SynReplyFrame)
{
SynReplyFrame synReplyFrame = (SynReplyFrame)frame;
clientReplyReceivedLatch.countDown();
int streamId = synReplyFrame.getStreamId();
ByteBuffer data = generator.data(streamId,0,new StringDataInfo("data",false));
try
{
socketChannel.write(data);
}
catch (IOException e)
{
e.printStackTrace();
}
}
else if (frame instanceof RstStreamFrame)
{
clientResetReceivedLatch.countDown();
}
}
});
ByteBuffer response = ByteBuffer.allocate(28);
socketChannel.read(response);
response.flip();
parser.parse(response);
assertThat("server didn't receive data",serverDataReceivedLatch.await(1,TimeUnit.SECONDS),not(true));
assertThat("client didn't receive reset",clientResetReceivedLatch.await(1,TimeUnit.SECONDS),not(true));
ByteBuffer buffer = generator.control(new GoAwayFrame(version, streamId, SessionStatus.OK.getCode()));
socketChannel.write(buffer);
Assert.assertThat(buffer.hasRemaining(), is(false));
assertThat("GoAway frame is received by server", goAwayReceivedLatch.await(5,TimeUnit.SECONDS), is(true));