Search in sources :

Example 11 with RequestStreamHandle

use of com.webpieces.http2.api.streaming.RequestStreamHandle in project webpieces by deanhiller.

the class TestC5x1StreamStates 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(XFuture.<StreamWriter>completedFuture(null));
    Http2Request request1 = Requests.createRequest();
    RequestStreamHandle stream = httpSocket.openStream();
    StreamRef streamRef = httpSocket.openStream().process(request1, listener1);
    XFuture<StreamWriter> future = streamRef.getWriter();
    @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);
    XFuture<Void> cancel = streamRef.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 : RequestStreamHandle(com.webpieces.http2.api.streaming.RequestStreamHandle) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) StreamRef(com.webpieces.http2.api.streaming.StreamRef) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) RstStreamFrame(com.webpieces.http2.api.dto.lowlevel.RstStreamFrame) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) Test(org.junit.Test)

Aggregations

RequestStreamHandle (com.webpieces.http2.api.streaming.RequestStreamHandle)11 StreamRef (com.webpieces.http2.api.streaming.StreamRef)11 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)10 Test (org.junit.Test)9 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)7 MockResponseListener (org.webpieces.httpclient.api.mocks.MockResponseListener)6 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)4 XFuture (org.webpieces.util.futures.XFuture)4 RstStreamFrame (com.webpieces.http2.api.dto.lowlevel.RstStreamFrame)3 InetSocketAddress (java.net.InetSocketAddress)3 ByteBuffer (java.nio.ByteBuffer)3 DataListener (org.webpieces.nio.api.handlers.DataListener)3 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)2 DataWrapper (org.webpieces.data.api.DataWrapper)2 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)2 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)2 MockStreamWriter (org.webpieces.httpclient.api.mocks.MockStreamWriter)2 Http2Trailers (com.webpieces.http2.api.dto.highlevel.Http2Trailers)1 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)1 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)1