Search in sources :

Example 6 with ConnectionClosedException

use of com.webpieces.http2engine.api.error.ConnectionClosedException 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)

Aggregations

ConnectionClosedException (com.webpieces.http2engine.api.error.ConnectionClosedException)6 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)5 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)5 GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)5 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)5 Test (org.junit.Test)5 DataWrapper (org.webpieces.data.api.DataWrapper)5 StreamRef (com.webpieces.http2.api.streaming.StreamRef)4 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)4 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)4 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)2 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)1 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)1 ConnectionFailure (com.webpieces.http2engine.api.error.ConnectionFailure)1 ResponseStream (org.webpieces.frontend2.api.ResponseStream)1 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)1 MockStreamRef (org.webpieces.httpfrontend2.api.mock2.MockStreamRef)1 MockStreamWriter (org.webpieces.httpfrontend2.api.mock2.MockStreamWriter)1 XFuture (org.webpieces.util.futures.XFuture)1