use of com.webpieces.http2.api.streaming.StreamRef 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);
}
use of com.webpieces.http2.api.streaming.StreamRef in project webpieces by deanhiller.
the class Level8NotifySvrListeners method sendRstToApp.
@Override
public XFuture<Void> sendRstToApp(Stream stream, CancelReason payload) {
if (stream instanceof ServerStream) {
ServerStream str = (ServerStream) stream;
StreamRef streamRef = str.getStreamRef();
return streamRef.cancel(payload);
}
// since the stream is closed, any writes to the push streams will automatically close and be cancelled
return XFuture.completedFuture(null);
}
use of com.webpieces.http2.api.streaming.StreamRef in project webpieces by deanhiller.
the class Level8NotifySvrListeners method fireRequestToApp.
public XFuture<Void> fireRequestToApp(ServerStream stream, Http2Request payload) {
SvrSideResponseHandler handler = new SvrSideResponseHandler(level1ServerEngine, stream, pushIdGenerator);
RequestStreamHandle streamHandle = listener.openStream();
StreamRef streamRef = streamHandle.process(payload, handler);
stream.setStreamHandle(streamHandle, streamRef);
return streamRef.getWriter().thenApply(w -> null);
}
use of com.webpieces.http2.api.streaming.StreamRef in project webpieces by deanhiller.
the class ErrorCommonTest method testArgsTypeMismatch.
@Test
public void testArgsTypeMismatch() {
log.info("starting");
String moduleFileContents = CommonRoutesModules.class.getName();
RouterService server = createServer(isProdTest, moduleFileContents);
server.start();
Http2Request req = RequestCreation.createHttpRequest(HttpMethod.GET, "/something");
MockStreamHandle mockStream = new MockStreamHandle();
StreamRef ref = server.incomingRequest(req, mockStream);
XFuture<StreamWriter> future = ref.getWriter();
Assert.assertTrue(future.isDone() && !future.isCompletedExceptionally());
Http2Response response = mockStream.getLastResponse();
String contents = mockStream.getResponseBody();
verifyNotFoundRendered(response, contents);
// We did not send a keep alive so it should close
Assert.assertTrue(mockStream.isWasClosed());
}
use of com.webpieces.http2.api.streaming.StreamRef in project webpieces by deanhiller.
the class ErrorCommonTest method testRedirectRouteNotEnoughArguments.
@Test
public void testRedirectRouteNotEnoughArguments() {
// say method is something(int arg, String this)
// we verify redirects MUST match type and number of method arguments every time
// then when we form url, we put the stuff in the path OR put it as query params so it works on the way back in again too
String moduleFileContents = CommonRoutesModules.class.getName();
RouterService server = createServer(isProdTest, moduleFileContents);
server.start();
Http2Request req = RequestCreation.createHttpRequest(HttpMethod.GET, "/user/5553");
MockStreamHandle mockStream = new MockStreamHandle();
StreamRef ref = server.incomingRequest(req, mockStream);
XFuture<StreamWriter> future = ref.getWriter();
Assert.assertTrue(future.isDone() && !future.isCompletedExceptionally());
Http2Response response = mockStream.getLastResponse();
String contents = mockStream.getResponseBody();
Assert.assertEquals(response.getSingleHeaderValue(Http2HeaderName.STATUS), "500");
if (isProdTest) {
// prod template to use
Assert.assertTrue(contents.contains("There was a bug in the developers application or webpieces server"));
} else {
// The internalError template for DevServer should run...
Assert.assertTrue(contents.contains("NullTemplateApi.java is running for templatePath=org.webpieces.devrouter.impl.internalError_html"));
}
// We did not send a keep alive so it should close
Assert.assertTrue(mockStream.isWasClosed());
}
Aggregations