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());
}
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());
}
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;
}
Aggregations