use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.
the class AbstractTest method sendPushPromise.
protected void sendPushPromise(MockResponseListener listener1, int streamId, boolean eos) {
MockPushListener pushListener = new MockPushListener();
pushListener.setDefaultResponse(XFuture.completedFuture(null));
listener1.addReturnValuePush(pushListener);
Http2Push push = Requests.createPush(streamId);
// endOfStream=false
mockChannel.write(push);
Assert.assertEquals(push, listener1.getSinglePush());
Http2Response preemptiveResponse = Requests.createEosResponse(2);
mockChannel.write(preemptiveResponse);
Http2Response frame2 = (Http2Response) pushListener.getSingleParam();
Assert.assertEquals(preemptiveResponse, frame2);
}
use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.
the class AbstractTest method sendResponseFromServer.
protected void sendResponseFromServer(MockResponseListener listener1, Http2Request request) {
Http2Response resp1 = Requests.createResponse(request.getStreamId());
// endOfStream=false
mockChannel.write(resp1);
Http2Response response1 = listener1.getSingleReturnValueIncomingResponse();
Assert.assertEquals(resp1, response1);
}
use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.
the class TestC4FrameSizeAndHeaders method fillHeaders.
private void fillHeaders(Http2Response response1) {
String value = "heaheaheaheaheaheahahoz.zhxheh,h,he,he,heaheaeaheaheahoahoahozzoqorqzro.zo.zrszaroatroathoathoathoathoatoh";
for (int i = 0; i < 10; i++) {
value = value + value;
response1.addHeader(new Http2Header("eaheahaheaheaeha" + i, value));
}
}
use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.
the class TestC4FrameSizeAndHeaders method createInterleavedFrames.
private List<Http2Frame> createInterleavedFrames() {
Http2Response response1 = new Http2Response();
response1.setStreamId(1);
response1.setEndOfStream(true);
fillHeaders(response1);
HeaderEncoding encoding = new HeaderEncoding();
List<Http2Frame> frames1 = encoding.translateToFrames(localSettings.getMaxFrameSize(), new Encoder(localSettings.getHeaderTableSize()), response1);
Http2Response response2 = new Http2Response();
response2.setStreamId(3);
response1.setEndOfStream(true);
response2.addHeader(new Http2Header(Http2HeaderName.ACCEPT, "value"));
List<Http2Frame> frames2 = encoding.translateToFrames(localSettings.getMaxFrameSize(), new Encoder(localSettings.getHeaderTableSize()), response2);
List<Http2Frame> frames = new ArrayList<>();
frames.addAll(frames1);
frames.add(1, frames2.get(0));
return frames;
}
use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.
the class TestBasicHttp2Client method testMaxConcurrentOne.
@Test
public void testMaxConcurrentOne() throws InterruptedException, ExecutionException {
Http2Request request1 = Requests.createRequest();
Http2Request request2 = Requests.createRequest();
MockStreamWriter writer1 = new MockStreamWriter();
MockResponseListener respListener1 = new MockResponseListener();
respListener1.setIncomingRespDefault(XFuture.completedFuture(writer1));
MockResponseListener respListener2 = new MockResponseListener();
StreamRef streamRef1 = httpSocket.openStream().process(request1, respListener1);
XFuture<StreamWriter> future = streamRef1.getWriter();
StreamRef streamRef2 = httpSocket.openStream().process(request2, respListener2);
XFuture<StreamWriter> future2 = streamRef2.getWriter();
// max concurrent only 1 so only get 1
Http2Request req = (Http2Request) mockChannel.getFrameAndClear();
Assert.assertEquals(1, req.getStreamId());
Assert.assertEquals(request1, req);
Assert.assertTrue(future.isDone());
// do not ack upstream until out the door(backpressure)
Assert.assertFalse(future2.isDone());
Http2Response resp1 = Requests.createResponse(request1.getStreamId());
// endOfStream=false
mockChannel.write(resp1);
Http2Response response1 = respListener1.getSingleReturnValueIncomingResponse();
Assert.assertEquals(resp1, response1);
Assert.assertFalse(future2.isDone());
// endOfStream=false
mockChannel.write(new DataFrame(request1.getStreamId(), false));
writer1.getSingleFrame();
// at this point, should not have a call outstanding
mockChannel.assertNoIncomingMessages();
// WRITE OUT END STREAM data so the first request starts going again!!
Assert.assertFalse(future2.isDone());
DataFrame dataLast = new DataFrame(request1.getStreamId(), true);
// endOfStream = true
mockChannel.write(dataLast);
Assert.assertTrue(future2.isDone());
DataFrame data = (DataFrame) writer1.getSingleFrame();
Assert.assertEquals(dataLast.getStreamId(), data.getStreamId());
Http2Request req2 = (Http2Request) mockChannel.getFrameAndClear();
Assert.assertEquals(request2, req2);
}
Aggregations