Search in sources :

Example 1 with MockStreamRef

use of org.webpieces.httpfrontend2.api.mock2.MockStreamRef in project webpieces by deanhiller.

the class TestHttp11Backpressure method testInitializeThenPostWithChunkingBackpressure.

@Test
public void testInitializeThenPostWithChunkingBackpressure() throws InterruptedException, ExecutionException, TimeoutException {
    // send first request to get past protocoal detection(ie. initialize) and send response
    initialize();
    List<ByteBuffer> buffers = create4SplitPayloads();
    XFuture<Void> ackBytePayload1 = mockChannel.sendToSvr(buffers.get(0));
    // not enough data.  parser consumes and acks future for more data(no client ack needed right now)
    Assert.assertTrue(ackBytePayload1.isDone());
    XFuture<StreamWriter> ackRequest = new XFuture<StreamWriter>();
    mockListener.addMockStreamToReturn(new MockStreamRef(ackRequest));
    XFuture<Void> ackBytePayload2 = mockChannel.sendToSvr(buffers.get(1));
    Assert.assertFalse(ackBytePayload2.isDone());
    // This releases the response msg acking 10 bytes
    ackRequest.complete(mockStreamWriter);
    Assert.assertTrue(ackBytePayload2.isDone());
    // feed the rest of first chunk in and feed part of last chunk
    XFuture<Void> firstChunkAck = new XFuture<Void>();
    mockStreamWriter.addProcessResponse(firstChunkAck);
    XFuture<Void> ackBytePayload3 = mockChannel.sendToSvr(buffers.get(2));
    Assert.assertFalse(ackBytePayload3.isDone());
    // ack the http chunk packet
    firstChunkAck.complete(null);
    Assert.assertTrue(ackBytePayload3.isDone());
    XFuture<Void> lastChunkAck = new XFuture<Void>();
    mockStreamWriter.addProcessResponse(lastChunkAck);
    XFuture<Void> ackBytePayload4 = mockChannel.sendToSvr(buffers.get(3));
    Assert.assertFalse(ackBytePayload4.isDone());
    lastChunkAck.complete(null);
    Assert.assertTrue(ackBytePayload4.isDone());
}
Also used : XFuture(org.webpieces.util.futures.XFuture) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) ByteBuffer(java.nio.ByteBuffer) MockStreamRef(org.webpieces.httpfrontend2.api.mock2.MockStreamRef) Test(org.junit.Test)

Example 2 with MockStreamRef

use of org.webpieces.httpfrontend2.api.mock2.MockStreamRef in project webpieces by deanhiller.

the class TestHttp11Backpressure method testPostWithChunkingBackpressure.

@Test
public void testPostWithChunkingBackpressure() throws InterruptedException, ExecutionException, TimeoutException {
    List<ByteBuffer> buffers = create4SplitPayloads();
    XFuture<Void> ackBytePayload1 = mockChannel.sendToSvr(buffers.get(0));
    ackBytePayload1.get(2, TimeUnit.SECONDS);
    XFuture<StreamWriter> ackRequest = new XFuture<StreamWriter>();
    mockListener.addMockStreamToReturn(new MockStreamRef(ackRequest));
    XFuture<Void> ackBytePayload2 = mockChannel.sendToSvr(buffers.get(1));
    // have to ack TWO...the stream writer AND the first HttpData fed in
    Assert.assertFalse(ackBytePayload2.isDone());
    XFuture<Void> firstChunkAck1 = new XFuture<Void>();
    mockStreamWriter.addProcessResponse(firstChunkAck1);
    ackRequest.complete(mockStreamWriter);
    Assert.assertFalse(ackBytePayload2.isDone());
    firstChunkAck1.complete(null);
    Assert.assertTrue(ackBytePayload2.isDone());
    // feed the rest of first chunk in and feed part of last chunk
    XFuture<Void> firstChunkAck = new XFuture<Void>();
    mockStreamWriter.addProcessResponse(firstChunkAck);
    XFuture<Void> ackBytePayload3 = mockChannel.sendToSvr(buffers.get(2));
    Assert.assertFalse(ackBytePayload3.isDone());
    // ack the http chunk packet
    firstChunkAck.complete(null);
    Assert.assertTrue(ackBytePayload3.isDone());
    XFuture<Void> lastChunkAck = new XFuture<Void>();
    mockStreamWriter.addProcessResponse(lastChunkAck);
    XFuture<Void> ackBytePayload4 = mockChannel.sendToSvr(buffers.get(3));
    Assert.assertFalse(ackBytePayload4.isDone());
    lastChunkAck.complete(null);
    ackBytePayload4.get(2, TimeUnit.SECONDS);
}
Also used : XFuture(org.webpieces.util.futures.XFuture) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) ByteBuffer(java.nio.ByteBuffer) MockStreamRef(org.webpieces.httpfrontend2.api.mock2.MockStreamRef) Test(org.junit.Test)

Example 3 with MockStreamRef

use of org.webpieces.httpfrontend2.api.mock2.MockStreamRef in project webpieces by deanhiller.

the class TestHttp11Errors method testCloseBeforeFirstRequestCompletes.

@Test
public void testCloseBeforeFirstRequestCompletes() throws InterruptedException, ExecutionException, TimeoutException {
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
    HttpRequest req2 = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
    XFuture<StreamWriter> futA = XFuture.completedFuture(null);
    MockStreamRef mockStreamRefA = new MockStreamRef(futA);
    mockListener.addMockStreamToReturn(mockStreamRefA);
    mockChannel.sendToSvr(req);
    PassedIn in1 = mockListener.getSingleRequest();
    XFuture<StreamWriter> futB = XFuture.completedFuture(null);
    MockStreamRef mockStreamRefB = new MockStreamRef(futB);
    mockListener.addMockStreamToReturn(mockStreamRefB);
    XFuture<Void> fut1 = mockChannel.sendToSvrAsync(req2);
    Assert.assertFalse(fut1.isDone());
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    HttpResponse resp1 = Requests.createResponse(1);
    resp1.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "10"));
    Http2Response headers1 = Http11ToHttp2.responseToHeaders(resp1);
    XFuture<StreamWriter> future = in1.stream.process(headers1);
    HttpPayload payload = mockChannel.getFrameAndClear();
    Assert.assertEquals(resp1, payload);
    StreamWriter writer = future.get(2, TimeUnit.SECONDS);
    Assert.assertFalse(fut1.isDone());
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    Assert.assertFalse(mockStreamRefA.isCancelled());
    Assert.assertFalse(mockStreamRefB.isCancelled());
    mockChannel.simulateClose();
    // this request is done, nothing to cancel
    Assert.assertTrue(mockStreamRefA.isCancelled());
    Assert.assertFalse(mockStreamRefB.isCancelled());
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Header(org.webpieces.httpparser.api.common.Header) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) MockStreamRef(org.webpieces.httpfrontend2.api.mock2.MockStreamRef) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Example 4 with MockStreamRef

use of org.webpieces.httpfrontend2.api.mock2.MockStreamRef in project webpieces by deanhiller.

the class TestHttp2Errors method testFarEndClosedSocket.

@Test
public void testFarEndClosedSocket() throws InterruptedException, ExecutionException {
    MockStreamWriter mockSw = new MockStreamWriter();
    MockStreamRef ref1 = new MockStreamRef(mockSw);
    mockListener.addMockStreamToReturn(ref1);
    MockStreamWriter mockSw2 = new MockStreamWriter();
    MockStreamRef ref2 = new MockStreamRef(mockSw2);
    mockListener.addMockStreamToReturn(ref2);
    Http2Request request1 = Http2Requests.createRequest(1, true);
    Http2Request request2 = Http2Requests.createRequest(3, true);
    mockChannel.send(request1);
    PassedIn in1 = mockListener.getSingleRequest();
    mockChannel.send(request2);
    PassedIn in2 = mockListener.getSingleRequest();
    mockChannel.close();
    Assert.assertTrue(ref1.isCancelled());
    Assert.assertTrue(ref2.isCancelled());
}
Also used : Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) MockStreamRef(org.webpieces.httpfrontend2.api.mock2.MockStreamRef) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Example 5 with MockStreamRef

use of org.webpieces.httpfrontend2.api.mock2.MockStreamRef in project webpieces by deanhiller.

the class TestS5x1StreamStates method testSection5_1BadFrameReceivedInReservedRemoteState.

/**
 * reserved local
 *
 * A PRIORITY or WINDOW_UPDATE frame MAY be received in this state. Receiving any
 * type of frame other than RST_STREAM, PRIORITY, or WINDOW_UPDATE on a stream
 * in this state MUST be treated as a connection error (Section 5.4.1) of type PROTOCOL_ERROR.
 */
@Test
public void testSection5_1BadFrameReceivedInReservedRemoteState() {
    MockStreamWriter mockWriter = new MockStreamWriter();
    XFuture<StreamWriter> futA = XFuture.completedFuture(mockWriter);
    MockStreamRef mockStream = new MockStreamRef(futA);
    mockListener.addMockStreamToReturn(mockStream);
    Http2Request request = Http2Requests.createRequest(1, true);
    mockChannel.send(request);
    PassedIn in = mockListener.getSingleRequest();
    ResponseStream stream = in.stream;
    Http2Push push = Http2Requests.createPush(request.getStreamId());
    stream.openPushStream().process(push);
    Http2Msg pushMsg = mockChannel.getFrameAndClear();
    Assert.assertEquals(push, pushMsg);
    // send bad frame in this state
    DataFrame data = Http2Requests.createData1(push.getPromisedStreamId(), false);
    mockChannel.send(data);
    Assert.assertTrue(mockStream.isCancelled());
    // remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.PROTOCOL_ERROR, goAway.getKnownErrorCode());
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertEquals("ConnectionException: HttpSocket[Http2ChannelCache1]:stream2:(BAD_FRAME_RECEIVED_FOR_THIS_STATE) " + "No transition defined on statemachine for event=RECV_DATA when in state=Reserved(local)", msg);
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : 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) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) ResponseStream(org.webpieces.frontend2.api.ResponseStream) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) DataWrapper(org.webpieces.data.api.DataWrapper) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) MockStreamRef(org.webpieces.httpfrontend2.api.mock2.MockStreamRef) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 MockStreamRef (org.webpieces.httpfrontend2.api.mock2.MockStreamRef)9 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)8 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)6 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)4 MockStreamWriter (org.webpieces.httpfrontend2.api.mock2.MockStreamWriter)4 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)3 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)3 DataWrapper (org.webpieces.data.api.DataWrapper)3 Header (org.webpieces.httpparser.api.common.Header)3 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)3 GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)2 ByteBuffer (java.nio.ByteBuffer)2 ResponseStream (org.webpieces.frontend2.api.ResponseStream)2 HttpPayload (org.webpieces.httpparser.api.dto.HttpPayload)2 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)2 XFuture (org.webpieces.util.futures.XFuture)2 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)1 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)1 RstStreamFrame (com.webpieces.http2.api.dto.lowlevel.RstStreamFrame)1