use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class TestC5_1StreamStates method testSection5_1BadFrameReceivedInReservedRemoteState.
/**
* Receiving any type of frame other than HEADERS, RST_STREAM, or PRIORITY on a
* stream in this state MUST be treated as a connection
* error (Section 5.4.1) of type PROTOCOL_ERROR.
*/
@Test
public void testSection5_1BadFrameReceivedInReservedRemoteState() {
MockPushListener pushListener = new MockPushListener();
pushListener.setIncomingRespDefault(CompletableFuture.<Void>completedFuture(null));
MockResponseListener listener1 = new MockResponseListener();
listener1.setIncomingRespDefault(CompletableFuture.<StreamWriter>completedFuture(null));
listener1.addReturnValuePush(pushListener);
Http2Request request = sendRequestToServer(listener1);
Http2Push push = sendPushFromServer(listener1, request);
DataFrame dataFrame = new DataFrame(push.getPromisedStreamId(), false);
mockChannel.write(dataFrame);
//remote receives goAway
GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
Assert.assertEquals(Http2ErrorCode.PROTOCOL_ERROR, goAway.getKnownErrorCode());
DataWrapper debugData = goAway.getDebugData();
String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
Assert.assertEquals("ConnectionException: MockHttp2Channel1:stream2:(BAD_FRAME_RECEIVED_FOR_THIS_STATE) " + "No transition defined on statemachine for event=RECV_DATA when in state=Reserved(remote)", msg);
Assert.assertTrue(mockChannel.isClosed());
ShutdownStream failResp1 = (ShutdownStream) listener1.getSingleRstStream();
Assert.assertEquals(CancelReasonCode.BAD_FRAME_RECEIVED_FOR_THIS_STATE, failResp1.getCause().getReasonCode());
ShutdownStream failResp2 = (ShutdownStream) listener1.getSingleCancelPush();
Assert.assertEquals(CancelReasonCode.BAD_FRAME_RECEIVED_FOR_THIS_STATE, failResp2.getCause().getReasonCode());
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class TestC5_1StreamStates method testSection5_1BadFrameReceivedInIdleState.
/**
* Receiving any frame other than HEADERS or PRIORITY on a stream in this state
* MUST be treated as a connection error (Section 5.4.1) of type PROTOCOL_ERROR.
*/
@Test
public void testSection5_1BadFrameReceivedInIdleState() {
DataFrame dataFrame = new DataFrame(1, false);
//endOfStream=false
mockChannel.write(dataFrame);
//remote receives goAway
GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
Assert.assertEquals(Http2ErrorCode.PROTOCOL_ERROR, goAway.getKnownErrorCode());
DataWrapper debugData = goAway.getDebugData();
String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
Assert.assertEquals("ConnectionException: MockHttp2Channel1:stream1:(BAD_FRAME_RECEIVED_FOR_THIS_STATE) " + "Stream in idle state and received this frame which should not happen in " + "idle state. frame=DataFrame{streamId=1, endStream=false, data.len=0, padding=0}", msg);
Assert.assertTrue(mockChannel.isClosed());
//send new request on closed connection
MockResponseListener listener1 = new MockResponseListener();
Http2Request request1 = Requests.createRequest();
CompletableFuture<StreamWriter> future = httpSocket.openStream().process(request1, listener1);
ConnectionClosedException intercept = (ConnectionClosedException) TestAssert.intercept(future);
Assert.assertTrue(intercept.getMessage().contains("Connection closed or closing"));
Assert.assertEquals(0, mockChannel.getFramesAndClear().size());
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class Http2SocketImpl method createData.
private DataFrame createData(FullRequest request, boolean isEndOfStream) {
DataWrapper payload = request.getPayload();
DataFrame data = new DataFrame();
data.setEndOfStream(isEndOfStream);
data.setData(payload);
return data;
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class TestC6_5SettingsFrameErrors method testSection6_5AckNonEmptyPayload.
@Test
public void testSection6_5AckNonEmptyPayload() {
//server's settings frame is finally coming in as well with maxConcurrent=1
HeaderSettings settings = new HeaderSettings();
settings.setMaxConcurrentStreams(1L);
mockChannel.write(HeaderSettings.createSettingsFrame(settings));
//clear the ack frame
mockChannel.getFrameAndClear();
String badAckFrame = // length
"00 00 01" + // type
"04" + // flags (ack)
"01" + // R + streamid
"00 00 00 00" + //payload
"00";
//ack client frame
mockChannel.writeHexBack(badAckFrame);
//remote receives goAway
GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
DataWrapper debugData = goAway.getDebugData();
String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
Assert.assertEquals("ConnectionException: stream0:(FRAME_SIZE_INCORRECT) size of payload of a settings frame ack must be 0 but was=1", msg);
Assert.assertTrue(mockChannel.isClosed());
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class TestGooglePlayback method runPlayback.
private List<HttpPayload> runPlayback(String name) {
Memento mem = parser.prepareToParse();
int counter = 0;
ClassLoader cl = getClass().getClassLoader();
InputStream in = cl.getResourceAsStream(name);
//This loads relative to this test class package(while the above does not).
//InputStream in = getClass().getResourceAsStream(name);
Playback playback = RecordingPlaybackFactory.createPlayback(in, 1);
List<HttpPayload> results = new ArrayList<>();
while (true) {
counter++;
if (counter > 1000)
throw new IllegalArgumentException("Is your simulation really this long...1000+ buffers?");
ByteBuffer buffer = playback.getNextPacket();
if (buffer == null)
return results;
DataWrapper data = dataGen.wrapByteBuffer(buffer);
mem = parser.parse(mem, data);
List<HttpPayload> parsedMessages = mem.getParsedMessages();
results.addAll(parsedMessages);
}
}
Aggregations