use of okhttp3.internal.http2.MockHttp2Peer.InFrame in project okhttp by square.
the class Http2ConnectionTest method serverSendsEmptyDataClientDoesntSendWindowUpdate.
@Test
public void serverSendsEmptyDataClientDoesntSendWindowUpdate() 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, data(0), 0);
peer.play();
// Play it back.
Http2Connection connection = connect(peer);
Http2Stream client = connection.newStream(headerEntries("b", "banana"), false);
assertEquals(-1, client.getSource().read(new Buffer(), 1));
// Verify the peer received what was expected.
InFrame synStream = peer.takeFrame();
assertEquals(Http2.TYPE_HEADERS, synStream.type);
assertEquals(5, peer.frameCount());
}
use of okhttp3.internal.http2.MockHttp2Peer.InFrame in project okhttp by square.
the class Http2ConnectionTest method serverPingsClient.
@Test
public void serverPingsClient() throws Exception {
// write the mocking script
peer.sendFrame().settings(new Settings());
// ACK
peer.acceptFrame();
peer.sendFrame().ping(false, 2, 0);
// PING
peer.acceptFrame();
peer.play();
// play it back
connect(peer);
// verify the peer received what was expected
InFrame ping = peer.takeFrame();
assertEquals(0, ping.streamId);
assertEquals(2, ping.payload1);
assertEquals(0, ping.payload2);
assertTrue(ping.ack);
}
use of okhttp3.internal.http2.MockHttp2Peer.InFrame in project okhttp by square.
the class Http2ConnectionTest method clientCreatesStreamAndServerReplies.
@Test
public void clientCreatesStreamAndServerReplies() throws Exception {
// write the mocking script
peer.sendFrame().settings(new Settings());
// ACK
peer.acceptFrame();
// SYN_STREAM
peer.acceptFrame();
// DATA
peer.acceptFrame();
peer.sendFrame().synReply(false, 3, headerEntries("a", "android"));
peer.sendFrame().data(true, 3, new Buffer().writeUtf8("robot"), 5);
// PING
peer.acceptFrame();
// PING
peer.sendFrame().ping(true, 1, 0);
peer.play();
// play it back
Http2Connection connection = connect(peer);
Http2Stream stream = connection.newStream(headerEntries("b", "banana"), true);
BufferedSink out = Okio.buffer(stream.getSink());
out.writeUtf8("c3po");
out.close();
assertEquals(headerEntries("a", "android"), stream.takeResponseHeaders());
assertStreamData("robot", stream.getSource());
connection.ping().roundTripTime();
assertEquals(0, connection.openStreamCount());
// verify the peer received what was expected
InFrame synStream = peer.takeFrame();
assertEquals(Http2.TYPE_HEADERS, synStream.type);
assertFalse(synStream.outFinished);
assertEquals(3, synStream.streamId);
assertEquals(-1, synStream.associatedStreamId);
assertEquals(headerEntries("b", "banana"), synStream.headerBlock);
InFrame requestData = peer.takeFrame();
assertTrue(Arrays.equals("c3po".getBytes("UTF-8"), requestData.data));
}
use of okhttp3.internal.http2.MockHttp2Peer.InFrame in project okhttp by square.
the class Http2ConnectionTest method clientDoesNotLimitFlowControl.
@Test
public void clientDoesNotLimitFlowControl() throws Exception {
int dataLength = 16384;
// write the mocking script
peer.sendFrame().settings(new Settings());
// ACK
peer.acceptFrame();
// SYN_STREAM
peer.acceptFrame();
peer.sendFrame().synReply(false, 3, headerEntries("b", "banana"));
peer.sendFrame().data(false, 3, new Buffer().write(new byte[dataLength]), dataLength);
peer.sendFrame().data(false, 3, new Buffer().write(new byte[dataLength]), dataLength);
peer.sendFrame().data(false, 3, new Buffer().write(new byte[dataLength]), dataLength);
peer.sendFrame().data(false, 3, new Buffer().write(new byte[dataLength]), dataLength);
peer.sendFrame().data(false, 3, new Buffer().write(new byte[1]), 1);
// 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("a", "android"), false);
assertEquals(headerEntries("b", "banana"), stream.takeResponseHeaders());
// 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