Search in sources :

Example 21 with MockResponseListener

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

the class TestC5x1StreamStates 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();
    StreamRef streamRef = httpSocket.openStream().process(request1, listener1);
    XFuture<StreamWriter> future = streamRef.getWriter();
    ConnectionClosedException intercept = (ConnectionClosedException) TestAssert.intercept(future);
    Assert.assertTrue(intercept.getMessage().contains("Connection closed or closing"));
    Assert.assertEquals(0, mockChannel.getFramesAndClear().size());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) StreamRef(com.webpieces.http2.api.streaming.StreamRef) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) ConnectionClosedException(com.webpieces.http2engine.api.error.ConnectionClosedException) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) Test(org.junit.Test)

Example 22 with MockResponseListener

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

the class TestCBasicRequestResponse method testPushPromise.

@Test
public void testPushPromise() {
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(null));
    Http2Request request = sendRequestToServer(listener1);
    sendPushPromise(listener1, request.getStreamId(), true);
    sendResponseFromServer(listener1, request);
}
Also used : Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) Test(org.junit.Test)

Aggregations

MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)22 Test (org.junit.Test)21 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)15 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)14 DataWrapper (org.webpieces.data.api.DataWrapper)11 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)9 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)8 StreamRef (com.webpieces.http2.api.streaming.StreamRef)8 GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)7 Http2Request (com.webpieces.hpack.api.dto.Http2Request)6 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)5 StreamWriter (com.webpieces.http2engine.api.StreamWriter)4 ConnectionClosedException (com.webpieces.http2engine.api.error.ConnectionClosedException)4 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)4 GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)4 ConnectionClosedException (com.webpieces.http2engine.api.ConnectionClosedException)3 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)2 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)2 RequestStreamHandle (com.webpieces.http2.api.streaming.RequestStreamHandle)2 MockPushListener (org.webpieces.http2client.mock.MockPushListener)2