Search in sources :

Example 6 with StreamMsg

use of com.webpieces.http2.api.dto.lowlevel.lib.StreamMsg 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();
    XFuture<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(XFuture.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.http2.api.dto.lowlevel.lib.StreamMsg) Http2Headers(com.webpieces.http2.api.dto.highlevel.Http2Headers) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) RequestsSent(org.webpieces.http2client.util.RequestsSent) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) RequestHolder(org.webpieces.http2client.util.RequestHolder) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) Test(org.junit.Test)

Aggregations

DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)5 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)3 Http2Headers (com.webpieces.http2.api.dto.highlevel.Http2Headers)2 StreamMsg (com.webpieces.http2.api.dto.lowlevel.lib.StreamMsg)2 Test (org.junit.Test)2 DataWrapper (org.webpieces.data.api.DataWrapper)2 ConnectionException (com.webpieces.http2.api.dto.error.ConnectionException)1 StreamException (com.webpieces.http2.api.dto.error.StreamException)1 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)1 ByteBuffer (java.nio.ByteBuffer)1 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)1 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)1 RequestHolder (org.webpieces.http2client.util.RequestHolder)1 RequestsSent (org.webpieces.http2client.util.RequestsSent)1 HttpFullRequest (org.webpieces.httpclient11.api.HttpFullRequest)1 DataListener (org.webpieces.nio.api.handlers.DataListener)1 XFuture (org.webpieces.util.futures.XFuture)1 PrivateWebserverForTest (org.webpieces.webserver.PrivateWebserverForTest)1 AbstractWebpiecesTest (org.webpieces.webserver.test.sockets.AbstractWebpiecesTest)1 MockChannel (org.webpieces.webserver.test.sockets.MockChannel)1