use of com.webpieces.http2engine.api.PushPromiseListener in project webpieces by deanhiller.
the class TestSMaxConcurrentSetting method sendTwoRequests.
private WriterHolder sendTwoRequests() throws InterruptedException, ExecutionException, TimeoutException {
PassedIn in1 = sendRequestToServer(1, true);
PassedIn in2 = sendRequestToServer(3, true);
Assert.assertTrue(in1.stream != in2.stream);
Http2Push push1 = Http2Requests.createPush(in1.request.getStreamId());
CompletableFuture<PushPromiseListener> future1 = in1.stream.openPushStream().process(push1);
Http2Msg push1Recv = mockChannel.getFrameAndClear();
Assert.assertEquals(push1, push1Recv);
PushPromiseListener pushWriter1 = future1.get(2, TimeUnit.SECONDS);
Http2Push push2 = Http2Requests.createPush(in2.request.getStreamId());
CompletableFuture<PushPromiseListener> future2 = in2.stream.openPushStream().process(push2);
Http2Msg push2Recv = mockChannel.getFrameAndClear();
Assert.assertEquals(push2, push2Recv);
Assert.assertEquals(push1, push1Recv);
PushPromiseListener writer2 = future2.get(2, TimeUnit.SECONDS);
//send the two responses following the pushes
Http2Response resp1 = Http2Requests.createResponse(push1.getPromisedStreamId(), false);
CompletableFuture<StreamWriter> fut1 = pushWriter1.processPushResponse(resp1);
StreamWriter writer1 = fut1.get(2, TimeUnit.SECONDS);
Http2Response resp2 = Http2Requests.createResponse(push2.getPromisedStreamId(), false);
CompletableFuture<StreamWriter> fut2 = writer2.processPushResponse(resp2);
Assert.assertTrue(!fut2.isDone());
Http2Response clientRecvResp = (Http2Response) mockChannel.getFrameAndClear();
Assert.assertEquals(resp1, clientRecvResp);
return new WriterHolder(writer1, fut2, resp1, resp2);
}
use of com.webpieces.http2engine.api.PushPromiseListener in project webpieces by deanhiller.
the class Level8NotifyClntListeners method sendResponseToApp.
public CompletableFuture<Void> sendResponseToApp(Stream stream, Http2Response response) {
if (stream instanceof ClientStream) {
ClientStream str = (ClientStream) stream;
ResponseHandler listener = str.getResponseListener();
return listener.process(response).thenApply(w -> {
str.setResponseWriter(w);
return null;
});
}
ClientPushStream str = (ClientPushStream) stream;
PushPromiseListener pushListener = str.getPushPromiseListener();
return pushListener.processPushResponse(response).thenApply(w -> {
str.setPushResponseWriter(w);
return null;
});
}
use of com.webpieces.http2engine.api.PushPromiseListener in project webpieces by deanhiller.
the class TestSBasicRequestResponse method testPushPromise.
@Test
public void testPushPromise() throws InterruptedException, ExecutionException, TimeoutException {
Http2Request request1 = Http2Requests.createRequest(1, true);
mockChannel.send(request1);
PassedIn incoming = mockListener.getSingleRequest();
Assert.assertEquals(request1, incoming.request);
Http2Push push = Http2Requests.createPush(request1.getStreamId());
CompletableFuture<PushPromiseListener> future = incoming.stream.openPushStream().process(push);
PushPromiseListener pushWriter = future.get(2, TimeUnit.SECONDS);
Http2Push pushRecv = (Http2Push) mockChannel.getFrameAndClear();
Assert.assertEquals(push, pushRecv);
Http2Response preEmptive = Http2Requests.createResponse(push.getPromisedStreamId());
pushWriter.processPushResponse(preEmptive);
Http2Headers preEmptRecv = (Http2Headers) mockChannel.getFrameAndClear();
Assert.assertEquals(preEmptive, preEmptRecv);
Http2Response response = Http2Requests.createResponse(request1.getStreamId());
incoming.stream.sendResponse(response);
Http2Headers responseRecv = (Http2Headers) mockChannel.getFrameAndClear();
Assert.assertEquals(response, responseRecv);
}
Aggregations