use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg in project webpieces by deanhiller.
the class TestSBasicRequestResponse method testWithNoData.
@Test
public void testWithNoData() throws InterruptedException, ExecutionException, TimeoutException {
Http2Request request1 = Http2Requests.createRequest(1, true);
mockChannel.send(request1);
PassedIn incoming = mockListener.getSingleRequest();
Assert.assertEquals(request1, incoming.request);
Http2Response resp = Http2Requests.createResponse(request1.getStreamId(), true);
incoming.stream.process(resp);
Http2Msg response = mockChannel.getFrameAndClear();
Assert.assertEquals(resp, response);
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg in project webpieces by deanhiller.
the class TestC3InitialHttpsConnections method setUp.
@Before
public void setUp() throws InterruptedException, ExecutionException, TimeoutException {
mockChannel.setIncomingFrameDefaultReturnValue(XFuture.completedFuture(null));
Http2Config config = new Http2Config();
// start with 1 max concurrent
config.setInitialRemoteMaxConcurrent(1);
config.setLocalSettings(localSettings);
SimpleMeterRegistry metrics = new SimpleMeterRegistry();
InjectionConfig injConfig = new InjectionConfig(mockTime, config, metrics);
Http2Client client = Http2ClientFactory.createHttpClient("test2Client", mockChanMgr, injConfig);
mockChanMgr.addSSLChannelToReturn(mockChannel);
InetSocketAddress addr = new InetSocketAddress("somehost.com", 555);
String host = addr.getHostName();
int port = addr.getPort();
ForTestSslClientEngineFactory ssl = new ForTestSslClientEngineFactory();
SSLEngine engine = ssl.createSslEngine(host, port);
socket = client.createHttpsSocket(engine, new SocketListener());
XFuture<Void> connect = socket.connect(addr);
connect.get(2, TimeUnit.SECONDS);
// verify settings on connect were sent
// verify settings on connect were sent
List<Http2Msg> frames = mockChannel.getFramesAndClear();
Preface preface = (Preface) frames.get(0);
preface.verify();
Http2Msg settings1 = frames.get(1);
Assert.assertEquals(HeaderSettings.createSettingsFrame(localSettings), settings1);
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg in project webpieces by deanhiller.
the class TestC5x1StreamStates method testSection5_1ReceiveValidFramesAfterSendRstStreamFrame.
/**
* If this state is reached as a result of sending a RST_STREAM frame, the
* peer that receives the RST_STREAM might have already sent — or enqueued for
* sending — frames on the stream that cannot be withdrawn. An endpoint MUST ignore
* frames that it receives on closed streams after it has sent a RST_STREAM frame. An
* endpoint MAY choose to limit the period over which it ignores frames and
* treat frames that arrive after this time as being in error.
* @throws TimeoutException
* @throws ExecutionException
* @throws InterruptedException
*/
@Test
public void testSection5_1ReceiveValidFramesAfterSendRstStreamFrame() throws InterruptedException, ExecutionException, TimeoutException {
MockResponseListener listener1 = new MockResponseListener();
listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(null));
Http2Request request1 = Requests.createRequest();
RequestStreamHandle stream = httpSocket.openStream();
StreamRef streamRef = httpSocket.openStream().process(request1, listener1);
XFuture<StreamWriter> future = streamRef.getWriter();
@SuppressWarnings("unused") StreamWriter writer = future.get(2, TimeUnit.SECONDS);
Http2Msg req = mockChannel.getFrameAndClear();
Assert.assertEquals(request1, req);
RstStreamFrame rst = new RstStreamFrame(request1.getStreamId(), Http2ErrorCode.CANCEL);
XFuture<Void> cancel = streamRef.cancel(rst);
cancel.get(2, TimeUnit.SECONDS);
Http2Msg svrRst = mockChannel.getFrameAndClear();
Assert.assertEquals(rst, svrRst);
// simulate server responding before receiving the cancel
Http2Response resp1 = Requests.createEosResponse(request1.getStreamId());
// endOfStream=true
mockChannel.write(resp1);
// Assert.assertEquals(0, mockChannel.getFramesAndClear().size());
// Assert.assertFalse(mockChannel.isClosed());
//
// Assert.assertEquals(0, listener1.getReturnValuesIncomingResponse().size());
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg in project webpieces by deanhiller.
the class TestCBasicRequestResponse method testWithData.
@Test
public void testWithData() throws InterruptedException, ExecutionException, TimeoutException {
FullRequest request1 = Requests.createHttp2Request();
XFuture<FullResponse> future = httpSocket.send(request1);
Assert.assertFalse(future.isDone());
List<Http2Msg> frames = mockChannel.getFramesAndClear();
Assert.assertEquals(2, frames.size());
Http2Response resp = Requests.createResponse(request1.getHeaders().getStreamId());
mockChannel.write(resp);
Assert.assertFalse(future.isDone());
DataFrame data = Requests.createData(request1.getHeaders().getStreamId(), true);
mockChannel.write(data);
FullResponse response = future.get(2, TimeUnit.SECONDS);
Assert.assertEquals(2, response.getPayload().getReadableSize());
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg in project webpieces by deanhiller.
the class TestCBasicRequestResponse method testWithDataAndTrailingHeaders.
@Test
public void testWithDataAndTrailingHeaders() throws InterruptedException, ExecutionException, TimeoutException {
FullRequest request1 = Requests.createHttp2Request();
Http2Trailers trailing = Requests.createTrailers();
request1.setTrailingHeaders(trailing);
XFuture<FullResponse> future = httpSocket.send(request1);
Assert.assertFalse(future.isDone());
List<Http2Msg> frames = mockChannel.getFramesAndClear();
Assert.assertEquals(3, frames.size());
Http2Response resp = Requests.createResponse(request1.getHeaders().getStreamId());
mockChannel.write(resp);
Assert.assertFalse(future.isDone());
DataFrame data = Requests.createData(request1.getHeaders().getStreamId(), false);
mockChannel.write(data);
Assert.assertFalse(future.isDone());
mockChannel.write(trailing);
FullResponse response = future.get(2, TimeUnit.SECONDS);
Assert.assertEquals(2, response.getPayload().getReadableSize());
Assert.assertNotNull(response.getTrailingHeaders());
}
Aggregations