use of okhttp3.internal.http2.MockHttp2Peer.InFrame in project okhttp by square.
the class Http2ConnectionTest method remoteSendsDataAfterInFinished.
@Test
public void remoteSendsDataAfterInFinished() throws Exception {
// write the mocking script
peer.sendFrame().settings(new Settings());
// ACK
peer.acceptFrame();
// SYN_STREAM
peer.acceptFrame();
peer.sendFrame().synReply(false, 3, headerEntries("a", "android"));
peer.sendFrame().data(true, 3, new Buffer().writeUtf8("robot"), 5);
peer.sendFrame().data(true, 3, new Buffer().writeUtf8("c3po"), 4);
// RST_STREAM
peer.acceptFrame();
// Ping just to make sure the stream was fastforwarded.
peer.sendFrame().ping(false, 2, 0);
// PING
peer.acceptFrame();
peer.play();
// play it back
Http2Connection connection = connect(peer);
Http2Stream stream = connection.newStream(headerEntries("b", "banana"), false);
assertEquals(headerEntries("a", "android"), stream.takeResponseHeaders());
assertStreamData("robot", stream.getSource());
// verify the peer received what was expected
InFrame synStream = peer.takeFrame();
assertEquals(Http2.TYPE_HEADERS, synStream.type);
InFrame rstStream = peer.takeFrame();
assertEquals(Http2.TYPE_RST_STREAM, rstStream.type);
assertEquals(3, rstStream.streamId);
InFrame ping = peer.takeFrame();
assertEquals(Http2.TYPE_PING, ping.type);
assertEquals(2, ping.payload1);
}
use of okhttp3.internal.http2.MockHttp2Peer.InFrame in project okhttp by square.
the class Http2ConnectionTest method maxFrameSizeHonored.
@Test
public void maxFrameSizeHonored() throws Exception {
byte[] buff = new byte[peer.maxOutboundDataLength() + 1];
Arrays.fill(buff, (byte) '*');
// write the mocking script
peer.sendFrame().settings(new Settings());
// ACK
peer.acceptFrame();
// SYN_STREAM
peer.acceptFrame();
peer.sendFrame().synReply(false, 3, headerEntries("a", "android"));
// DATA
peer.acceptFrame();
// DATA
peer.acceptFrame();
peer.play();
// play it back
Http2Connection connection = connect(peer);
Http2Stream stream = connection.newStream(headerEntries("b", "banana"), true);
BufferedSink out = Okio.buffer(stream.getSink());
out.write(buff);
out.flush();
out.close();
InFrame synStream = peer.takeFrame();
assertEquals(Http2.TYPE_HEADERS, synStream.type);
InFrame data = peer.takeFrame();
assertEquals(peer.maxOutboundDataLength(), data.data.length);
data = peer.takeFrame();
assertEquals(1, data.data.length);
}
use of okhttp3.internal.http2.MockHttp2Peer.InFrame in project okhttp by square.
the class Http2ConnectionTest method clientCreatesStreamAndServerRepliesWithFin.
@Test
public void clientCreatesStreamAndServerRepliesWithFin() throws Exception {
// write the mocking script
peer.sendFrame().settings(new Settings());
// ACK
peer.acceptFrame();
// SYN_STREAM
peer.acceptFrame();
// PING
peer.acceptFrame();
peer.sendFrame().synReply(true, 3, headerEntries("a", "android"));
peer.sendFrame().ping(true, 1, 0);
peer.play();
// play it back
Http2Connection connection = connect(peer);
connection.newStream(headerEntries("b", "banana"), false);
assertEquals(1, connection.openStreamCount());
// Ensure that the SYN_REPLY has been received.
connection.ping().roundTripTime();
assertEquals(0, connection.openStreamCount());
// verify the peer received what was expected
InFrame synStream = peer.takeFrame();
assertEquals(Http2.TYPE_HEADERS, synStream.type);
InFrame ping = peer.takeFrame();
assertEquals(Http2.TYPE_PING, ping.type);
}
use of okhttp3.internal.http2.MockHttp2Peer.InFrame in project okhttp by square.
the class Http2ConnectionTest method noPingsAfterShutdown.
@Test
public void noPingsAfterShutdown() throws Exception {
// write the mocking script
peer.sendFrame().settings(new Settings());
// ACK
peer.acceptFrame();
// GOAWAY
peer.acceptFrame();
peer.play();
// play it back
Http2Connection connection = connect(peer);
connection.shutdown(ErrorCode.INTERNAL_ERROR);
try {
connection.ping();
fail();
} catch (ConnectionShutdownException expected) {
}
// verify the peer received what was expected
InFrame goaway = peer.takeFrame();
assertEquals(Http2.TYPE_GOAWAY, goaway.type);
assertEquals(ErrorCode.INTERNAL_ERROR, goaway.errorCode);
}
use of okhttp3.internal.http2.MockHttp2Peer.InFrame in project okhttp by square.
the class Http2ConnectionTest method remoteSendsRefusedStreamBeforeReplyHeaders.
@Test
public void remoteSendsRefusedStreamBeforeReplyHeaders() throws Exception {
// write the mocking script
peer.sendFrame().settings(new Settings());
// ACK
peer.acceptFrame();
// SYN_STREAM
peer.acceptFrame();
peer.sendFrame().rstStream(3, ErrorCode.REFUSED_STREAM);
peer.sendFrame().ping(false, 2, 0);
// PING
peer.acceptFrame();
peer.play();
// play it back
Http2Connection connection = connect(peer);
Http2Stream stream = connection.newStream(headerEntries("a", "android"), false);
try {
stream.takeResponseHeaders();
fail();
} catch (IOException expected) {
assertEquals("stream was reset: REFUSED_STREAM", expected.getMessage());
}
assertEquals(0, connection.openStreamCount());
// verify the peer received what was expected
InFrame synStream = peer.takeFrame();
assertEquals(Http2.TYPE_HEADERS, synStream.type);
InFrame ping = peer.takeFrame();
assertEquals(Http2.TYPE_PING, ping.type);
assertEquals(2, ping.payload1);
}
Aggregations