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);
}
use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.
the class TestC5x1StreamStates method sendEosResponseFromServer.
private void sendEosResponseFromServer(MockResponseListener listener1, Http2Request request) {
Http2Response resp1 = Requests.createEosResponse(request.getStreamId());
// endOfStream=true
mockChannel.write(resp1);
Http2Response response1 = (Http2Response) listener1.getSingleReturnValueIncomingResponse();
Assert.assertEquals(resp1, response1);
}
use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.
the class TestCBasicRequestResponse method testWithNoData.
@Test
public void testWithNoData() throws InterruptedException, ExecutionException, TimeoutException {
FullRequest request1 = new FullRequest();
request1.setHeaders(Requests.createRequest());
XFuture<FullResponse> future = httpSocket.send(request1);
Assert.assertFalse(future.isDone());
Http2Headers frame = (Http2Headers) mockChannel.getFrameAndClear();
Assert.assertEquals(1, frame.getStreamId());
Http2Response resp = Requests.createResponse(request1.getHeaders().getStreamId());
resp.setEndOfStream(true);
mockChannel.write(resp);
FullResponse response = future.get(2, TimeUnit.SECONDS);
Assert.assertEquals(0, response.getPayload().getReadableSize());
}
use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.
the class EchoStreamingClient method stream.
public StreamRef stream(ResponseStreamHandle handle) {
ProxyStreamHandle h = (ProxyStreamHandle) handle;
Http2Request req = Current.request().originalRequest;
Http2Response response = h.createBaseResponse(req, "application/ndjson", 200, "OK");
try {
StreamWriter writer = h.process(response).get();
return new ProxyStreamRef(new EchoWriter(writer));
} catch (InterruptedException | ExecutionException e) {
throw SneakyThrow.sneak(e);
}
}
use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.
the class TestHttp11Basic method testSendTwoRequestsStreamSecond.
@Test
public void testSendTwoRequestsStreamSecond() throws InterruptedException, ExecutionException, TimeoutException {
HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
HttpRequest req2 = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
mockChannel.sendToSvr(req);
PassedIn in1 = mockListener.getSingleRequest();
req2.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "20"));
XFuture<Void> fut = mockChannel.sendToSvrAsync(req2);
Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
Assert.assertFalse(fut.isDone());
byte[] buf = new byte[10];
DataWrapper dataWrapper = DATA_GEN.wrapByteArray(buf);
HttpData data1 = new HttpData(dataWrapper, false);
XFuture<Void> fut2 = mockChannel.sendToSvrAsync(data1);
Assert.assertFalse(fut.isDone());
Assert.assertFalse(fut2.isDone());
DataWrapper dataWrapper2 = DATA_GEN.wrapByteArray(buf);
HttpData data2 = new HttpData(dataWrapper2, true);
XFuture<Void> fut3 = mockChannel.sendToSvrAsync(data2);
Assert.assertFalse(fut.isDone());
Assert.assertFalse(fut2.isDone());
Assert.assertFalse(fut3.isDone());
Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
HttpResponse resp1 = Requests.createResponse(1);
resp1.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "0"));
Http2Response headers1 = Http11ToHttp2.responseToHeaders(resp1);
in1.stream.process(headers1);
HttpPayload payload = mockChannel.getFrameAndClear();
Assert.assertEquals(resp1, payload);
fut.get(2, TimeUnit.SECONDS);
fut2.get(2, TimeUnit.SECONDS);
fut3.get(2, TimeUnit.SECONDS);
PassedIn in2 = mockListener.getSingleRequest();
HttpResponse resp2 = Requests.createResponse(2);
resp2.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "0"));
Http2Response headers2 = Http11ToHttp2.responseToHeaders(resp2);
in2.stream.process(headers2);
HttpPayload payload2 = mockChannel.getFrameAndClear();
Assert.assertEquals(resp2, payload2);
}
Aggregations