Search in sources :

Example 1 with RstStreamFrame

use of com.webpieces.http2parser.api.dto.RstStreamFrame in project webpieces by deanhiller.

the class TestC5_1StreamStates method testSection5_1ReceiveValidFramesAfterSendRstStreamFrame.

/**
	 * If this state is reached as a result of sending a RST_STREAM frame, the 
	 * peer that receives the RST_STREAM might have already sent — or enqueued for 
	 * sending — frames on the stream that cannot be withdrawn. An endpoint MUST ignore 
	 * frames that it receives on closed streams after it has sent a RST_STREAM frame. An 
	 * endpoint MAY choose to limit the period over which it ignores frames and 
	 * treat frames that arrive after this time as being in error.
	 * @throws TimeoutException 
	 * @throws ExecutionException 
	 * @throws InterruptedException 
	 */
@Test
public void testSection5_1ReceiveValidFramesAfterSendRstStreamFrame() throws InterruptedException, ExecutionException, TimeoutException {
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(CompletableFuture.<StreamWriter>completedFuture(null));
    Http2Request request1 = Requests.createRequest();
    StreamHandle stream = httpSocket.openStream();
    CompletableFuture<StreamWriter> future = stream.process(request1, listener1);
    @SuppressWarnings("unused") StreamWriter writer = future.get(2, TimeUnit.SECONDS);
    Http2Msg req = mockChannel.getFrameAndClear();
    Assert.assertEquals(request1, req);
    RstStreamFrame rst = new RstStreamFrame(request1.getStreamId(), Http2ErrorCode.CANCEL);
    CompletableFuture<Void> cancel = stream.cancel(rst);
    cancel.get(2, TimeUnit.SECONDS);
    Http2Msg svrRst = mockChannel.getFrameAndClear();
    Assert.assertEquals(rst, svrRst);
    //simulate server responding before receiving the cancel
    Http2Response resp1 = Requests.createEosResponse(request1.getStreamId());
    //endOfStream=true
    mockChannel.write(resp1);
//		Assert.assertEquals(0, mockChannel.getFramesAndClear().size());
//		Assert.assertFalse(mockChannel.isClosed());
//		
//		Assert.assertEquals(0, listener1.getReturnValuesIncomingResponse().size());
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) Http2Request(com.webpieces.hpack.api.dto.Http2Request) RstStreamFrame(com.webpieces.http2parser.api.dto.RstStreamFrame) StreamHandle(com.webpieces.http2engine.api.StreamHandle) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2engine.api.StreamWriter) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) Test(org.junit.Test)

Example 2 with RstStreamFrame

use of com.webpieces.http2parser.api.dto.RstStreamFrame in project webpieces by deanhiller.

the class TestS5_1StreamStates method testSection5_1_1TooLowStreamIdAfterHighStreamId.

/**
	 * The identifier of a newly established stream MUST be numerically 
	 * greater than all streams that the initiating endpoint has opened 
	 * or reserved. This governs streams that are opened using a HEADERS 
	 * frame and streams that are reserved using PUSH_PROMISE. An endpoint 
	 * that receives an unexpected stream identifier MUST respond with 
	 * a connection error (Section 5.4.1) of type PROTOCOL_ERROR.
	 * 
	 * This is in conflict with another part of the spec!!!!! and so we pretend
	 * the stream is closed(as in all likely hood, the stream was closed)!!!
	 * and do not shutdown the whole connection for a case like this.
	 * 
	 * The part it is in conflict with is closed state and receiving messages
	 * in closed state.  The only way to resolve conflict would be to KEEP around
	 * state that a connection is closed.  SORRY, the connection is closed so we
	 * clean up all memory!!!
	 */
@Test
public void testSection5_1_1TooLowStreamIdAfterHighStreamId() {
    Http2Request request1 = Http2Requests.createRequest(5, true);
    mockChannel.send(request1);
    mockListener.getSingleRequest();
    Http2Request request = Http2Requests.createRequest(3, true);
    mockChannel.send(request);
    //WE DO NOT DO THIS which spec wants(or another test we have starts failing)
    //we leave this here in case you want to comment back in and debug that.
    //		//no request comes in
    //		Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    //		//cancel the first stream since whole connection is going down.
    //		Assert.assertEquals(1, mockListener.getNumCancelsThatCameIn());
    //		
    //		//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.assertTrue(msg.contains("Bad stream id.  Event stream ids not allowed in requests to a server frame="));
    //		Assert.assertTrue(mockChannel.isClosed());
    //no request comes in
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    //no cancels(since we already cancelled it)
    Assert.assertEquals(0, mockListener.getNumCancelsThatCameIn());
    //remote receives goAway
    RstStreamFrame frame = (RstStreamFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.STREAM_CLOSED, frame.getKnownErrorCode());
    Assert.assertTrue(!mockChannel.isClosed());
}
Also used : Http2Request(com.webpieces.hpack.api.dto.Http2Request) RstStreamFrame(com.webpieces.http2parser.api.dto.RstStreamFrame) Test(org.junit.Test)

Example 3 with RstStreamFrame

use of com.webpieces.http2parser.api.dto.RstStreamFrame in project webpieces by deanhiller.

the class TestC5_1StreamStates method sendResetFromServer.

private void sendResetFromServer(MockResponseListener listener1, Http2Request request) {
    RstStreamFrame resp1 = Requests.createReset(request.getStreamId());
    //endOfStream=true
    mockChannel.write(resp1);
    RstStreamFrame response1 = (RstStreamFrame) listener1.getSingleRstStream();
    Assert.assertEquals(resp1, response1);
}
Also used : RstStreamFrame(com.webpieces.http2parser.api.dto.RstStreamFrame)

Aggregations

RstStreamFrame (com.webpieces.http2parser.api.dto.RstStreamFrame)3 Http2Request (com.webpieces.hpack.api.dto.Http2Request)2 Test (org.junit.Test)2 Http2Response (com.webpieces.hpack.api.dto.Http2Response)1 StreamHandle (com.webpieces.http2engine.api.StreamHandle)1 StreamWriter (com.webpieces.http2engine.api.StreamWriter)1 Http2Msg (com.webpieces.http2parser.api.dto.lib.Http2Msg)1 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)1 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)1