use of org.webpieces.util.futures.XFuture 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 org.webpieces.util.futures.XFuture in project webpieces by deanhiller.
the class Level4PreconditionChecks method createExcepted.
public XFuture<Void> createExcepted(Http2Msg payload, String extra, ConnectionCancelled closedReason) {
log.info("returning XFuture.exception since this socket is closed('" + extra + "' frame=" + payload + "):" + closedReason.getReasonCode());
XFuture<Void> future = new XFuture<>();
ConnectionClosedException exception = new ConnectionClosedException(closedReason, "Connection closed or closing:" + closedReason.getReasonCode());
if (closedReason instanceof ConnectionFailure) {
ConnectionFailure fail = (ConnectionFailure) closedReason;
exception.initCause(fail.getCause());
}
future.completeExceptionally(exception);
return future;
}
use of org.webpieces.util.futures.XFuture in project webpieces by deanhiller.
the class Level7MarshalAndPing method sendPing.
// public XFuture<Void> sendControlFrameToClient(Http2Msg msg) {
// return finalLayer.sendControlFrameToClient(msg);
// }
public XFuture<Void> sendPing() {
PingFrame ping = new PingFrame();
ping.setOpaqueData(8L);
XFuture<Void> newFuture = new XFuture<>();
boolean wasSet = pingFutureRef.compareAndSet(null, newFuture);
if (!wasSet) {
throw new IllegalStateException(key + "You must wait until the first ping you sent is complete. 2nd ping=" + ping);
}
return sendFrameToSocket(ping).thenCompose(c -> newFuture);
}
use of org.webpieces.util.futures.XFuture in project webpieces by deanhiller.
the class AsyncSSLEngine3Impl method doHandshakeLoop.
private XFuture<Void> doHandshakeLoop() {
SSLEngine engine = mem.getEngine();
HandshakeStatus hsStatus = engine.getHandshakeStatus();
List<XFuture<Void>> futures = new ArrayList<>();
while ((hsStatus == HandshakeStatus.NEED_WRAP && !sslEngineIsFarting) || hsStatus == HandshakeStatus.NEED_TASK) {
XFuture<Void> future = doHandshakeWork();
futures.add(future);
hsStatus = engine.getHandshakeStatus();
}
sslEngineIsFarting = false;
XFuture<Void> futureAll = XFuture.allOf(futures.toArray(new XFuture[futures.size()]));
return futureAll;
}
use of org.webpieces.util.futures.XFuture in project webpieces by deanhiller.
the class Http2ChannelCache method write.
@SuppressWarnings("unchecked")
@Override
public XFuture<Void> write(ByteBuffer b) {
DataWrapper data = dataGen.wrapByteBuffer(b);
parser.unmarshal(unmarshalState, data);
List<Http2Msg> parsedFrames = unmarshalState.getParsedFrames();
return (XFuture<Void>) super.calledMethod(Method.INCOMING_FRAME, parsedFrames);
}
Aggregations