Search in sources :

Example 1 with RequestsSent

use of org.webpieces.http2client.util.RequestsSent 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 2 with RequestsSent

use of org.webpieces.http2client.util.RequestsSent in project webpieces by deanhiller.

the class TestCMaxConcurrentSetting method testSend2ndRequestOnlyOnAfterSettingsFrameMaxConcurrentBigger.

@Test
public void testSend2ndRequestOnlyOnAfterSettingsFrameMaxConcurrentBigger() throws InterruptedException, ExecutionException {
    RequestsSent sent = sendTwoRequests();
    Assert.assertFalse(sent.getRequest2().getFuture().isDone());
    //server's settings frame is finally coming in as well with maxConcurrent=1
    HeaderSettings settings = new HeaderSettings();
    settings.setMaxConcurrentStreams(2L);
    mockChannel.write(HeaderSettings.createSettingsFrame(settings));
    //ack client frame
    mockChannel.write(new SettingsFrame(true));
    List<Http2Msg> msgs = mockChannel.getFramesAndClear();
    Assert.assertEquals(sent.getRequest2().getRequest(), msgs.get(0));
    Assert.assertTrue(sent.getRequest2().getFuture().isDone());
    SettingsFrame ack = (SettingsFrame) msgs.get(1);
    Assert.assertEquals(true, ack.isAck());
}
Also used : SettingsFrame(com.webpieces.http2parser.api.dto.SettingsFrame) HeaderSettings(com.webpieces.http2engine.impl.shared.data.HeaderSettings) RequestsSent(org.webpieces.http2client.util.RequestsSent) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) Test(org.junit.Test)

Example 3 with RequestsSent

use of org.webpieces.http2client.util.RequestsSent 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)

Aggregations

RequestsSent (org.webpieces.http2client.util.RequestsSent)3 StreamWriter (com.webpieces.http2engine.api.StreamWriter)2 Http2Msg (com.webpieces.http2parser.api.dto.lib.Http2Msg)2 Test (org.junit.Test)2 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)2 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)2 RequestHolder (org.webpieces.http2client.util.RequestHolder)2 Http2Headers (com.webpieces.hpack.api.dto.Http2Headers)1 Http2Request (com.webpieces.hpack.api.dto.Http2Request)1 HeaderSettings (com.webpieces.http2engine.impl.shared.data.HeaderSettings)1 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)1 SettingsFrame (com.webpieces.http2parser.api.dto.SettingsFrame)1 StreamMsg (com.webpieces.http2parser.api.dto.lib.StreamMsg)1