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());
}
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);
}
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());
}
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());
}
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());
}
Aggregations