Search in sources :

Example 1 with MockPushListener

use of org.webpieces.http2client.mock.MockPushListener in project webpieces by deanhiller.

the class AbstractTest method sendPushPromise.

protected void sendPushPromise(MockResponseListener listener1, int streamId, boolean eos) {
    MockPushListener pushListener = new MockPushListener();
    pushListener.setDefaultResponse(CompletableFuture.completedFuture(null));
    listener1.addReturnValuePush(pushListener);
    Http2Push push = Requests.createPush(streamId);
    //endOfStream=false
    mockChannel.write(push);
    Assert.assertEquals(push, listener1.getSinglePush());
    Http2Response preemptiveResponse = Requests.createEosResponse(2);
    mockChannel.write(preemptiveResponse);
    Http2Response frame2 = (Http2Response) pushListener.getSingleParam();
    Assert.assertEquals(preemptiveResponse, frame2);
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) Http2Push(com.webpieces.hpack.api.dto.Http2Push) MockPushListener(org.webpieces.http2client.mock.MockPushListener)

Example 2 with MockPushListener

use of org.webpieces.http2client.mock.MockPushListener 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());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) Http2Request(com.webpieces.hpack.api.dto.Http2Request) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) Http2Push(com.webpieces.hpack.api.dto.Http2Push) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) MockPushListener(org.webpieces.http2client.mock.MockPushListener) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Aggregations

Http2Push (com.webpieces.hpack.api.dto.Http2Push)2 MockPushListener (org.webpieces.http2client.mock.MockPushListener)2 Http2Request (com.webpieces.hpack.api.dto.Http2Request)1 Http2Response (com.webpieces.hpack.api.dto.Http2Response)1 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)1 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)1 GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)1 Test (org.junit.Test)1 DataWrapper (org.webpieces.data.api.DataWrapper)1 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)1