Search in sources :

Example 11 with Http2Response

use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.

the class TestSBasicRequestResponse method testWithDataAndTrailingHeaders.

@Test
public void testWithDataAndTrailingHeaders() throws InterruptedException, ExecutionException, TimeoutException {
    MockStreamWriter mockSw = new MockStreamWriter();
    mockSw.setDefaultRetValToThis();
    mockListener.addMockStreamToReturn(mockSw);
    Http2Request request1 = Http2Requests.createRequest(1, false);
    DataFrame data1 = Http2Requests.createData1(request1.getStreamId(), false);
    Http2Trailers trailing = Http2Requests.createTrailers(request1.getStreamId());
    mockChannel.send(request1);
    PassedIn incoming1 = mockListener.getSingleRequest();
    Assert.assertEquals(request1, incoming1.request);
    mockChannel.send(data1);
    DataFrame incoming2 = (DataFrame) mockSw.getSingleFrame();
    Assert.assertEquals(3, incoming2.getData().getReadableSize());
    // clear window update frames
    Assert.assertEquals(2, mockChannel.getFramesAndClear().size());
    mockChannel.send(trailing);
    Http2Headers incoming = (Http2Headers) mockSw.getSingleFrame();
    Assert.assertEquals(trailing, incoming);
    Http2Response resp = Http2Requests.createResponse(request1.getStreamId(), false);
    XFuture<StreamWriter> future = incoming1.stream.process(resp);
    Http2Msg response = mockChannel.getFrameAndClear();
    Assert.assertEquals(resp, response);
    StreamWriter writer = future.get(2, TimeUnit.SECONDS);
    DataFrame data2 = Http2Requests.createData2(request1.getStreamId(), false);
    writer.processPiece(data2);
    DataFrame dataResp = (DataFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(1, dataResp.getData().getReadableSize());
    Http2Trailers trailingResp = Http2Requests.createTrailers(request1.getStreamId());
    writer.processPiece(trailingResp);
    Http2Headers trailers = (Http2Headers) mockChannel.getFrameAndClear();
    Assert.assertEquals(trailingResp, trailers);
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Headers(com.webpieces.http2.api.dto.highlevel.Http2Headers) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) Http2Trailers(com.webpieces.http2.api.dto.highlevel.Http2Trailers) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Example 12 with Http2Response

use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.

the class TestSBasicRequestResponse method testWithData.

@Test
public void testWithData() throws InterruptedException, ExecutionException, TimeoutException {
    MockStreamWriter mockSw = new MockStreamWriter();
    mockSw.setDefaultRetValToThis();
    mockListener.addMockStreamToReturn(mockSw);
    Http2Request request1 = Http2Requests.createRequest(1, false);
    DataFrame data = Http2Requests.createData1(request1.getStreamId(), true);
    mockChannel.send(request1);
    PassedIn incoming1 = mockListener.getSingleRequest();
    Assert.assertEquals(request1, incoming1.request);
    mockChannel.send(data);
    DataFrame incoming = (DataFrame) mockSw.getSingleFrame();
    Assert.assertEquals(3, incoming.getData().getReadableSize());
    // clear window update frames
    Assert.assertEquals(2, mockChannel.getFramesAndClear().size());
    Http2Response resp = Http2Requests.createResponse(request1.getStreamId(), false);
    XFuture<StreamWriter> future = incoming1.stream.process(resp);
    Http2Msg response = mockChannel.getFrameAndClear();
    Assert.assertEquals(resp, response);
    StreamWriter writer = future.get(2, TimeUnit.SECONDS);
    DataFrame data2 = Http2Requests.createData2(request1.getStreamId(), true);
    writer.processPiece(data2);
    DataFrame dataResp = (DataFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(1, dataResp.getData().getReadableSize());
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Example 13 with Http2Response

use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.

the class TestSMaxConcurrentSetting method sendTwoRequests.

private WriterHolder sendTwoRequests() throws InterruptedException, ExecutionException, TimeoutException {
    PassedIn in1 = sendRequestToServer(1, true);
    PassedIn in2 = sendRequestToServer(3, true);
    Assert.assertTrue(in1.stream != in2.stream);
    Http2Push push1 = Http2Requests.createPush(in1.request.getStreamId());
    XFuture<PushPromiseListener> future1 = in1.stream.openPushStream().process(push1);
    Http2Msg push1Recv = mockChannel.getFrameAndClear();
    Assert.assertEquals(push1, push1Recv);
    PushPromiseListener pushWriter1 = future1.get(2, TimeUnit.SECONDS);
    Http2Push push2 = Http2Requests.createPush(in2.request.getStreamId());
    XFuture<PushPromiseListener> future2 = in2.stream.openPushStream().process(push2);
    Http2Msg push2Recv = mockChannel.getFrameAndClear();
    Assert.assertEquals(push2, push2Recv);
    Assert.assertEquals(push1, push1Recv);
    PushPromiseListener writer2 = future2.get(2, TimeUnit.SECONDS);
    // send the two responses following the pushes
    Http2Response resp1 = Http2Requests.createResponse(push1.getPromisedStreamId(), false);
    XFuture<StreamWriter> fut1 = pushWriter1.processPushResponse(resp1);
    StreamWriter writer1 = fut1.get(2, TimeUnit.SECONDS);
    Http2Response resp2 = Http2Requests.createResponse(push2.getPromisedStreamId(), false);
    XFuture<StreamWriter> fut2 = writer2.processPushResponse(resp2);
    Assert.assertTrue(!fut2.isDone());
    Http2Response clientRecvResp = (Http2Response) mockChannel.getFrameAndClear();
    Assert.assertEquals(resp1, clientRecvResp);
    return new WriterHolder(writer1, fut2, resp1, resp2);
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) PushPromiseListener(com.webpieces.http2.api.streaming.PushPromiseListener) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)

Example 14 with Http2Response

use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.

the class ErrorTest method testNoMethod.

@Test
public void testNoMethod() {
    log.info("starting");
    String moduleFileContents = NoMethodRouterModules.class.getName();
    RouterService server = ErrorCommonTest.createServer(true, moduleFileContents);
    try {
        server.start();
        Assert.fail("Should have thrown exception on start since this is prod");
    } catch (RuntimeException e) {
        Assert.assertTrue(e.getMessage().contains("Cannot find 'public' method='thisMethodNotExist' on class="));
    }
    Http2Request req = RequestCreation.createHttpRequest(HttpMethod.GET, "/something");
    MockStreamHandle mockStream = new MockStreamHandle();
    StreamRef ref = server.incomingRequest(req, mockStream);
    XFuture<StreamWriter> future = ref.getWriter();
    // done and no exception SINCE we responded to client successfully
    Assert.assertTrue(future.isDone() && !future.isCompletedExceptionally());
    Http2Response response = mockStream.getLastResponse();
    String body = mockStream.getResponseBody();
    Assert.assertEquals(StatusCode.HTTP_500_INTERNAL_SERVER_ERROR, response.getKnownStatusCode());
    Assert.assertTrue(body.contains("There was a bug in the developers application or webpieces server"));
}
Also used : RouterService(org.webpieces.router.api.RouterService) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) StreamRef(com.webpieces.http2.api.streaming.StreamRef) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) MockStreamHandle(org.webpieces.router.api.error.MockStreamHandle) Test(org.junit.Test) ErrorCommonTest(org.webpieces.router.api.error.ErrorCommonTest)

Example 15 with Http2Response

use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.

the class TestSimpleRoutes method testOneParamRoute.

@Test
public void testOneParamRoute() {
    Http2Request req = RequestCreation.createHttpRequest(HttpMethod.POST, "/meeting");
    MockStreamHandle mockStream = new MockStreamHandle();
    StreamRef ref = server.incomingRequest(req, mockStream);
    XFuture<StreamWriter> future = ref.getWriter();
    Assert.assertTrue(future.isDone() && !future.isCompletedExceptionally());
    Http2Response resp = mockStream.getLastResponse();
    Assert.assertEquals("http://" + req.getAuthority() + "/meeting/888", resp.getSingleHeaderValue(Http2HeaderName.LOCATION));
}
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) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) MockStreamHandle(org.webpieces.router.api.error.MockStreamHandle) 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