Search in sources :

Example 1 with Http2Response

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);
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) StreamRef(com.webpieces.http2.api.streaming.StreamRef) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) Test(org.junit.Test)

Example 2 with Http2Response

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);
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response)

Example 3 with Http2Response

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());
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) FullResponse(org.webpieces.http2client.api.dto.FullResponse) Http2Headers(com.webpieces.http2.api.dto.highlevel.Http2Headers) FullRequest(org.webpieces.http2client.api.dto.FullRequest) Test(org.junit.Test)

Example 4 with Http2Response

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);
    }
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) ProxyStreamHandle(org.webpieces.router.impl.proxyout.ProxyStreamHandle) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with Http2Response

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);
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) DataWrapper(org.webpieces.data.api.DataWrapper) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Header(org.webpieces.httpparser.api.common.Header) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) HttpData(org.webpieces.httpparser.api.dto.HttpData) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Aggregations

Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)66 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)32 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)30 Test (org.junit.Test)30 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)24 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)16 StreamRef (com.webpieces.http2.api.streaming.StreamRef)15 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)14 DataWrapper (org.webpieces.data.api.DataWrapper)13 Header (org.webpieces.httpparser.api.common.Header)13 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)12 ArrayList (java.util.ArrayList)10 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)10 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)9 HttpPayload (org.webpieces.httpparser.api.dto.HttpPayload)9 HttpData (org.webpieces.httpparser.api.dto.HttpData)8 XFuture (org.webpieces.util.futures.XFuture)8 RouterService (org.webpieces.router.api.RouterService)5 Http2Headers (com.webpieces.http2.api.dto.highlevel.Http2Headers)4 Http2HeaderName (com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName)4