Search in sources :

Example 6 with Http2Msg

use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg 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 7 with Http2Msg

use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg 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 8 with Http2Msg

use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg 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 9 with Http2Msg

use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg in project webpieces by deanhiller.

the class Level5AStates method translate.

protected Http2Event translate(Http2SendRecieve sendRecv, Http2Msg payload) {
    Http2PayloadType payloadType;
    if (payload instanceof Http2Headers) {
        Http2Headers head = (Http2Headers) payload;
        if (head.isEndOfStream())
            payloadType = Http2PayloadType.HEADERS_EOS;
        else
            payloadType = Http2PayloadType.HEADERS;
    } else if (payload instanceof DataFrame) {
        DataFrame data = (DataFrame) payload;
        if (data.isEndOfStream())
            payloadType = Http2PayloadType.DATA_EOS;
        else
            payloadType = Http2PayloadType.DATA;
    } else if (payload instanceof Http2Push) {
        payloadType = Http2PayloadType.PUSH_PROMISE;
    } else if (payload instanceof CancelReason) {
        payloadType = Http2PayloadType.RESET_STREAM;
    } else
        throw new IllegalArgumentException("unknown payload type for payload=" + payload);
    return Http2Event.lookup(sendRecv, payloadType);
}
Also used : Http2PayloadType(com.webpieces.http2engine.impl.shared.data.Http2PayloadType) CancelReason(com.webpieces.http2.api.dto.lowlevel.CancelReason) Http2Headers(com.webpieces.http2.api.dto.highlevel.Http2Headers) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push)

Example 10 with Http2Msg

use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg in project webpieces by deanhiller.

the class Level5AStates method fireToStateMachine.

private XFuture<Void> fireToStateMachine(Http2SendRecieve type, Stream stream, Http2Msg payload, boolean keepDelayedState) {
    Http2Event event = translate(type, payload);
    XFuture<Void> future = stream.getLock().synchronizeD(() -> {
        fireToStatemachineImpl(stream, event);
        return checkForClosedState(stream, payload, keepDelayedState);
    }).thenApply(isReleased -> {
        release(isReleased, stream, payload);
        return null;
    });
    return future.handle((v, e) -> {
        if (e == null) {
            return XFuture.completedFuture(v);
        } else {
            return translateException(stream, e);
        }
    }).thenCompose(Function.identity());
}
Also used : NoTransitionConnectionError(com.webpieces.http2engine.impl.shared.data.NoTransitionConnectionError) SENT_DATA_EOS(com.webpieces.http2engine.impl.shared.data.Http2Event.SENT_DATA_EOS) RECV_RST(com.webpieces.http2engine.impl.shared.data.Http2Event.RECV_RST) NoTransitionListener(org.webpieces.javasm.api.NoTransitionListener) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) RECV_DATA_EOS(com.webpieces.http2engine.impl.shared.data.Http2Event.RECV_DATA_EOS) LoggerFactory(org.slf4j.LoggerFactory) NoTransitionStreamError(com.webpieces.http2engine.impl.shared.data.NoTransitionStreamError) Function(java.util.function.Function) Supplier(java.util.function.Supplier) RECV_HEADERS_EOS(com.webpieces.http2engine.impl.shared.data.Http2Event.RECV_HEADERS_EOS) Http2SendRecieve(com.webpieces.http2engine.impl.shared.data.Http2Event.Http2SendRecieve) StateMachineFactory(org.webpieces.javasm.api.StateMachineFactory) Http2Event(com.webpieces.http2engine.impl.shared.data.Http2Event) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) State(org.webpieces.javasm.api.State) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException) StateMachine(org.webpieces.javasm.api.StateMachine) PermitQueue(org.webpieces.util.locking.PermitQueue) Stream(com.webpieces.http2engine.impl.shared.data.Stream) SENT_RST(com.webpieces.http2engine.impl.shared.data.Http2Event.SENT_RST) Memento(org.webpieces.javasm.api.Memento) Logger(org.slf4j.Logger) AsyncLock(org.webpieces.util.locking.AsyncLock) CancelReason(com.webpieces.http2.api.dto.lowlevel.CancelReason) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push) SENT_HEADERS_EOS(com.webpieces.http2engine.impl.shared.data.Http2Event.SENT_HEADERS_EOS) CancelReasonCode(com.webpieces.http2.api.dto.error.CancelReasonCode) StreamException(com.webpieces.http2.api.dto.error.StreamException) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) XFuture(org.webpieces.util.futures.XFuture) Http2PayloadType(com.webpieces.http2engine.impl.shared.data.Http2PayloadType) Http2Headers(com.webpieces.http2.api.dto.highlevel.Http2Headers) Http2Event(com.webpieces.http2engine.impl.shared.data.Http2Event)

Aggregations

Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)27 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)12 Test (org.junit.Test)12 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)8 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)8 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)7 DataWrapper (org.webpieces.data.api.DataWrapper)7 XFuture (org.webpieces.util.futures.XFuture)7 HeaderSettings (com.webpieces.http2engine.impl.shared.data.HeaderSettings)6 SettingsFrame (com.webpieces.http2.api.dto.lowlevel.SettingsFrame)5 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)4 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)4 ConnectionException (com.webpieces.http2.api.dto.error.ConnectionException)3 Http2Headers (com.webpieces.http2.api.dto.highlevel.Http2Headers)3 Http2Trailers (com.webpieces.http2.api.dto.highlevel.Http2Trailers)3 MockStreamWriter (org.webpieces.httpfrontend2.api.mock2.MockStreamWriter)3 UnmarshalState (com.webpieces.hpack.api.UnmarshalState)2 CancelReasonCode (com.webpieces.http2.api.dto.error.CancelReasonCode)2 StreamException (com.webpieces.http2.api.dto.error.StreamException)2 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)2