Search in sources :

Example 21 with StreamWriter

use of com.webpieces.http2engine.api.StreamWriter in project webpieces by deanhiller.

the class TestC5_1StreamStates method testSection5_1ReceiveBadFrameAfterReceiveEndStream.

/**
	 * An endpoint MUST NOT send frames other than PRIORITY on a closed stream. An endpoint 
	 * that receives any frame other than PRIORITY after receiving a RST_STREAM MUST 
	 * treat that as a stream error (Section 5.4.2) of type STREAM_CLOSED. Similarly, an 
	 * endpoint that receives any frames after receiving a frame with the 
	 * -----END_STREAM flag---- set MUST treat that as a connection error (Section 5.4.1) of 
	 * type STREAM_CLOSED, unless the frame is permitted as described below.
	 * 
	 */
@Test
public void testSection5_1ReceiveBadFrameAfterReceiveEndStream() {
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(CompletableFuture.<StreamWriter>completedFuture(null));
    Http2Request request = sendRequestToServer(listener1);
    sendEosResponseFromServer(listener1, request);
    DataFrame dataFrame = new DataFrame(request.getStreamId(), false);
    mockChannel.write(dataFrame);
    //remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.STREAM_CLOSED, goAway.getKnownErrorCode());
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertEquals("ConnectionException: MockHttp2Channel1:stream1:" + "(CLOSED_STREAM) Stream must have been closed as it no longer exists.  " + "high mark=1  your frame=DataFrame{streamId=1, endStream=false, data.len=0, padding=0}", msg);
    Assert.assertTrue(mockChannel.isClosed());
    Assert.assertEquals(0, listener1.getReturnValuesIncomingResponse().size());
    //send new request on closed connection
    Http2Request request1 = Requests.createRequest();
    CompletableFuture<StreamWriter> future = httpSocket.openStream().process(request1, listener1);
    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) Http2Request(com.webpieces.hpack.api.dto.Http2Request) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2engine.api.StreamWriter) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) ConnectionClosedException(com.webpieces.http2engine.api.ConnectionClosedException) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Example 22 with StreamWriter

use of com.webpieces.http2engine.api.StreamWriter in project webpieces by deanhiller.

the class TestC5_1StreamStates 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();
    CompletableFuture<StreamWriter> future = httpSocket.openStream().process(request1, listener1);
    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) Http2Request(com.webpieces.hpack.api.dto.Http2Request) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2engine.api.StreamWriter) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) ConnectionClosedException(com.webpieces.http2engine.api.ConnectionClosedException) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Example 23 with StreamWriter

use of com.webpieces.http2engine.api.StreamWriter in project webpieces by deanhiller.

the class TestCMaxConcurrentSetting method testSend2ndRequestOnlyOnCompletionOfFirst.

@Test
public void testSend2ndRequestOnlyOnCompletionOfFirst() throws InterruptedException, ExecutionException {
    RequestsSent sent = sendTwoRequests();
    int streamId1 = sent.getRequest1().getRequest().getStreamId();
    CompletableFuture<StreamWriter> future2 = sent.getRequest2().getFuture();
    RequestHolder holder1 = sent.getRequest1();
    RequestHolder holder2 = sent.getRequest2();
    MockResponseListener listener1 = holder1.getListener();
    MockStreamWriter writer1 = holder1.getWriter();
    //endOfStream=false
    mockChannel.write(Requests.createResponse(streamId1));
    listener1.getSingleReturnValueIncomingResponse();
    //endOfStream=false
    mockChannel.write(new DataFrame(streamId1, false));
    writer1.getSingleFrame();
    //at this point, should not have a call outstanding
    mockChannel.assertNoIncomingMessages();
    Assert.assertFalse(future2.isDone());
    MockResponseListener listener2 = holder2.getListener();
    MockStreamWriter writer2 = holder2.getWriter();
    listener2.addReturnValueIncomingResponse(CompletableFuture.completedFuture(writer2));
    Assert.assertFalse(future2.isDone());
    DataFrame dataFrame = new DataFrame(streamId1, true);
    //endOfStream = true
    mockChannel.write(dataFrame);
    StreamMsg data = writer1.getSingleFrame();
    Assert.assertEquals(dataFrame.getStreamId(), data.getStreamId());
    Http2Headers frame = (Http2Headers) mockChannel.getFrameAndClear();
    Assert.assertEquals(sent.getRequest2().getRequest(), frame);
    Assert.assertTrue(future2.isDone());
}
Also used : StreamMsg(com.webpieces.http2parser.api.dto.lib.StreamMsg) Http2Headers(com.webpieces.hpack.api.dto.Http2Headers) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2engine.api.StreamWriter) RequestsSent(org.webpieces.http2client.util.RequestsSent) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) RequestHolder(org.webpieces.http2client.util.RequestHolder) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) Test(org.junit.Test)

Example 24 with StreamWriter

use of com.webpieces.http2engine.api.StreamWriter in project webpieces by deanhiller.

the class TestCMaxConcurrentSetting method sendTwoRequests.

private RequestsSent sendTwoRequests() {
    Http2Request request1 = Requests.createRequest();
    Http2Request request2 = Requests.createRequest();
    MockStreamWriter writer1 = new MockStreamWriter();
    MockStreamWriter writer2 = new MockStreamWriter();
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(CompletableFuture.completedFuture(writer1));
    //do not set default incoming response as we want to delay the resolution of the future
    MockResponseListener listener2 = new MockResponseListener();
    CompletableFuture<StreamWriter> future = httpSocket.openStream().process(request1, listener1);
    CompletableFuture<StreamWriter> future2 = httpSocket.openStream().process(request2, listener2);
    RequestHolder r1 = new RequestHolder(request1, listener1, writer1, future);
    RequestHolder r2 = new RequestHolder(request2, listener2, writer2, future2);
    RequestsSent requests = new RequestsSent(r1, r2);
    Http2Msg req = mockChannel.getFrameAndClear();
    Assert.assertEquals(1, req.getStreamId());
    Assert.assertEquals(request1, req);
    Assert.assertTrue(future.isDone());
    Assert.assertFalse(future2.isDone());
    return requests;
}
Also used : Http2Request(com.webpieces.hpack.api.dto.Http2Request) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2engine.api.StreamWriter) RequestsSent(org.webpieces.http2client.util.RequestsSent) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) RequestHolder(org.webpieces.http2client.util.RequestHolder) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter)

Example 25 with StreamWriter

use of com.webpieces.http2engine.api.StreamWriter in project webpieces by deanhiller.

the class Level8NotifyClntListeners method sendPieceToApp.

@Override
public CompletableFuture<Void> sendPieceToApp(Stream stream, Http2Trailers payload) {
    ClientStream str = (ClientStream) stream;
    StreamWriter writer = str.getResponseWriter();
    return writer.processPiece(payload).thenApply(null);
}
Also used : StreamWriter(com.webpieces.http2engine.api.StreamWriter)

Aggregations

StreamWriter (com.webpieces.http2engine.api.StreamWriter)26 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)17 Test (org.junit.Test)16 Http2Response (com.webpieces.hpack.api.dto.Http2Response)13 Http2Request (com.webpieces.hpack.api.dto.Http2Request)12 DataWrapper (org.webpieces.data.api.DataWrapper)9 Http2Msg (com.webpieces.http2parser.api.dto.lib.Http2Msg)8 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)8 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)8 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)8 ConnectionClosedException (com.webpieces.http2engine.api.ConnectionClosedException)5 GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)5 Header (org.webpieces.httpparser.api.common.Header)4 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)4 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)3 Http2HeaderName (com.webpieces.http2parser.api.dto.lib.Http2HeaderName)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ResponseStream (org.webpieces.frontend2.api.ResponseStream)3 MockStreamWriter (org.webpieces.httpfrontend2.api.mock2.MockStreamWriter)3 HttpData (org.webpieces.httpparser.api.dto.HttpData)3