use of com.webpieces.http2.api.streaming.StreamWriter in project webpieces by deanhiller.
the class TestC4FrameSizeAndHeaders method testSection4_2CanSendLargestFrame.
/**
* success case of edge testing off by one or not
*/
@Test
public void testSection4_2CanSendLargestFrame() {
MockStreamWriter mockStreamWriter = new MockStreamWriter();
MockResponseListener listener1 = new MockResponseListener();
listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(mockStreamWriter));
Http2Request request = sendRequestToServer(listener1);
sendResponseFromServer(listener1, request);
DataFrame dataFrame = new DataFrame(request.getStreamId(), false);
byte[] buf = new byte[localSettings.getMaxFrameSize()];
dataFrame.setData(DATA_GEN.wrapByteArray(buf));
// endOfStream=false
mockChannel.write(dataFrame);
DataFrame fr = (DataFrame) mockStreamWriter.getSingleFrame();
Assert.assertEquals(localSettings.getMaxFrameSize(), fr.getData().getReadableSize());
}
use of com.webpieces.http2.api.streaming.StreamWriter in project webpieces by deanhiller.
the class TestC4FrameSizeAndHeaders method testSection4_3BadDecompression.
// /**
// * A decoding error in a header block MUST be treated as a connection error (Section 5.4.1) of type COMPRESSION_ERROR.
// *
// */
@Test
public void testSection4_3BadDecompression() {
MockResponseListener listener1 = new MockResponseListener();
listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(null));
Http2Request request = sendRequestToServer(listener1);
// has to be 1 since we use 1 in the response
Assert.assertEquals(1, request.getStreamId());
String badHeaderFrame = // length
"00 00 10" + // type
"01" + // flags (ack)
"05" + // R + streamid
"00 00 00 01" + // payload
"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00";
// endOfStream=false
mockChannel.writeHexBack(badHeaderFrame);
// remote receives goAway
GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
Assert.assertEquals(Http2ErrorCode.COMPRESSION_ERROR, goAway.getKnownErrorCode());
DataWrapper debugData = goAway.getDebugData();
String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
Assert.assertEquals("ConnectionException: MockHttp2Channel1:stream1:(HEADER_DECODE) Error from hpack library", msg);
Assert.assertTrue(mockChannel.isClosed());
List<CancelReason> results = listener1.getRstStreams();
Assert.assertEquals(1, results.size());
ShutdownStream failResp = (ShutdownStream) results.get(0);
Assert.assertEquals(CancelReasonCode.HEADER_DECODE, failResp.getCause().getReasonCode());
}
use of com.webpieces.http2.api.streaming.StreamWriter in project webpieces by deanhiller.
the class TestCMaxConcurrentSetting method testSend2ndRequestOnlyOnCompletionOfFirst.
@Test
public void testSend2ndRequestOnlyOnCompletionOfFirst() throws InterruptedException, ExecutionException {
RequestsSent sent = sendTwoRequests();
int streamId1 = sent.getRequest1().getRequest().getStreamId();
XFuture<StreamWriter> future2 = sent.getRequest2().getFuture();
RequestHolder holder1 = sent.getRequest1();
RequestHolder holder2 = sent.getRequest2();
MockResponseListener listener1 = holder1.getListener();
MockStreamWriter writer1 = holder1.getWriter();
// endOfStream=false
mockChannel.write(Requests.createResponse(streamId1));
listener1.getSingleReturnValueIncomingResponse();
// endOfStream=false
mockChannel.write(new DataFrame(streamId1, false));
writer1.getSingleFrame();
// at this point, should not have a call outstanding
mockChannel.assertNoIncomingMessages();
Assert.assertFalse(future2.isDone());
MockResponseListener listener2 = holder2.getListener();
MockStreamWriter writer2 = holder2.getWriter();
listener2.addReturnValueIncomingResponse(XFuture.completedFuture(writer2));
Assert.assertFalse(future2.isDone());
DataFrame dataFrame = new DataFrame(streamId1, true);
// endOfStream = true
mockChannel.write(dataFrame);
StreamMsg data = writer1.getSingleFrame();
Assert.assertEquals(dataFrame.getStreamId(), data.getStreamId());
Http2Headers frame = (Http2Headers) mockChannel.getFrameAndClear();
Assert.assertEquals(sent.getRequest2().getRequest(), frame);
Assert.assertTrue(future2.isDone());
}
use of com.webpieces.http2.api.streaming.StreamWriter in project webpieces by deanhiller.
the class TestCMaxConcurrentSetting method sendTwoRequests.
private RequestsSent sendTwoRequests() {
Http2Request request1 = Requests.createRequest();
Http2Request request2 = Requests.createRequest();
MockStreamWriter writer1 = new MockStreamWriter();
MockStreamWriter writer2 = new MockStreamWriter();
MockResponseListener listener1 = new MockResponseListener();
listener1.setIncomingRespDefault(XFuture.completedFuture(writer1));
// do not set default incoming response as we want to delay the resolution of the future
MockResponseListener listener2 = new MockResponseListener();
StreamRef streamRef1 = httpSocket.openStream().process(request1, listener1);
XFuture<StreamWriter> future = streamRef1.getWriter();
StreamRef streamRef2 = httpSocket.openStream().process(request2, listener2);
XFuture<StreamWriter> future2 = streamRef2.getWriter();
RequestHolder r1 = new RequestHolder(request1, listener1, writer1, future);
RequestHolder r2 = new RequestHolder(request2, listener2, writer2, future2);
RequestsSent requests = new RequestsSent(r1, r2);
Http2Msg req = mockChannel.getFrameAndClear();
Assert.assertEquals(1, req.getStreamId());
Assert.assertEquals(request1, req);
Assert.assertTrue(future.isDone());
Assert.assertFalse(future2.isDone());
return requests;
}
use of com.webpieces.http2.api.streaming.StreamWriter in project webpieces by deanhiller.
the class TestBackpressure method testBasicBackpressureChunked.
@Test
public void testBasicBackpressureChunked() throws InterruptedException, ExecutionException, TimeoutException {
MockResponseListener listener = new MockResponseListener();
RequestStreamHandle handle = httpSocket.openStream();
mockChannel.addWriteResponse(XFuture.completedFuture(null));
Http2Request request = Requests.createRequest();
StreamRef streamRef = handle.process(request, listener);
XFuture<StreamWriter> writer = streamRef.getWriter();
Assert.assertTrue(writer.isDone());
Assert.assertEquals(request, mockChannel.getFrameAndClear());
List<ByteBuffer> buffers = create4BuffersWith3Messags();
DataListener dataListener = mockChannel.getConnectedListener();
XFuture<Void> fut1 = dataListener.incomingData(mockChannel, buffers.get(0));
// consume since not enough data for client
Assert.assertTrue(fut1.isDone());
XFuture<StreamWriter> future = new XFuture<StreamWriter>();
listener.addReturnValueIncomingResponse(future);
XFuture<Void> fut2 = dataListener.incomingData(mockChannel, buffers.get(1));
// not resolved yet since client only has part of the data
Assert.assertFalse(fut2.isDone());
MockStreamWriter mockWriter = new MockStreamWriter();
// This releases the response msg acking 10 bytes
future.complete(mockWriter);
fut2.get(2, TimeUnit.SECONDS);
// feed the rest of first chunk in and feed part of last chunk
XFuture<Void> firstChunkAck = new XFuture<Void>();
mockWriter.addProcessResponse(firstChunkAck);
XFuture<Void> fut3 = dataListener.incomingData(mockChannel, buffers.get(2));
Assert.assertFalse(fut3.isDone());
// ack the http chunk packet
firstChunkAck.complete(null);
fut3.get(2, TimeUnit.SECONDS);
XFuture<Void> lastChunkAck = new XFuture<Void>();
mockWriter.addProcessResponse(lastChunkAck);
XFuture<Void> fut4 = dataListener.incomingData(mockChannel, buffers.get(3));
Assert.assertFalse(fut4.isDone());
lastChunkAck.complete(null);
fut4.get(2, TimeUnit.SECONDS);
}
Aggregations