Search in sources :

Example 1 with MockStreamWriter

use of org.webpieces.httpfrontend2.api.mock2.MockStreamWriter in project webpieces by deanhiller.

the class TestSBasicRequestResponse method testWithDataAndTrailingHeaders.

@Test
public void testWithDataAndTrailingHeaders() throws InterruptedException, ExecutionException, TimeoutException {
    MockStreamWriter mockSw = new MockStreamWriter();
    mockSw.setDefaultRetValToThis();
    mockListener.addMockStreamToReturn(mockSw);
    Http2Request request1 = Http2Requests.createRequest(1, false);
    DataFrame data1 = Http2Requests.createData1(request1.getStreamId(), false);
    Http2Trailers trailing = Http2Requests.createTrailers(request1.getStreamId());
    mockChannel.send(request1);
    PassedIn incoming1 = mockListener.getSingleRequest();
    Assert.assertEquals(request1, incoming1.request);
    mockChannel.send(data1);
    DataFrame incoming2 = (DataFrame) mockSw.getSingleFrame();
    Assert.assertEquals(3, incoming2.getData().getReadableSize());
    //clear window update frames
    Assert.assertEquals(2, mockChannel.getFramesAndClear().size());
    mockChannel.send(trailing);
    Http2Headers incoming = (Http2Headers) mockSw.getSingleFrame();
    Assert.assertEquals(trailing, incoming);
    Http2Response resp = Http2Requests.createResponse(request1.getStreamId(), false);
    CompletableFuture<StreamWriter> future = incoming1.stream.sendResponse(resp);
    Http2Msg response = mockChannel.getFrameAndClear();
    Assert.assertEquals(resp, response);
    StreamWriter writer = future.get(2, TimeUnit.SECONDS);
    DataFrame data2 = Http2Requests.createData2(request1.getStreamId(), false);
    writer.processPiece(data2);
    DataFrame dataResp = (DataFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(1, dataResp.getData().getReadableSize());
    Http2Trailers trailingResp = Http2Requests.createTrailers(request1.getStreamId());
    writer.processPiece(trailingResp);
    Http2Headers trailers = (Http2Headers) mockChannel.getFrameAndClear();
    Assert.assertEquals(trailingResp, trailers);
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) Http2Request(com.webpieces.hpack.api.dto.Http2Request) Http2Headers(com.webpieces.hpack.api.dto.Http2Headers) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) StreamWriter(com.webpieces.http2engine.api.StreamWriter) Http2Trailers(com.webpieces.hpack.api.dto.Http2Trailers) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Example 2 with MockStreamWriter

use of org.webpieces.httpfrontend2.api.mock2.MockStreamWriter in project webpieces by deanhiller.

the class TestSBasicRequestResponse method testWithData.

@Test
public void testWithData() throws InterruptedException, ExecutionException, TimeoutException {
    MockStreamWriter mockSw = new MockStreamWriter();
    mockSw.setDefaultRetValToThis();
    mockListener.addMockStreamToReturn(mockSw);
    Http2Request request1 = Http2Requests.createRequest(1, false);
    DataFrame data = Http2Requests.createData1(request1.getStreamId(), true);
    mockChannel.send(request1);
    PassedIn incoming1 = mockListener.getSingleRequest();
    Assert.assertEquals(request1, incoming1.request);
    mockChannel.send(data);
    DataFrame incoming = (DataFrame) mockSw.getSingleFrame();
    Assert.assertEquals(3, incoming.getData().getReadableSize());
    //clear window update frames
    Assert.assertEquals(2, mockChannel.getFramesAndClear().size());
    Http2Response resp = Http2Requests.createResponse(request1.getStreamId(), false);
    CompletableFuture<StreamWriter> future = incoming1.stream.sendResponse(resp);
    Http2Msg response = mockChannel.getFrameAndClear();
    Assert.assertEquals(resp, response);
    StreamWriter writer = future.get(2, TimeUnit.SECONDS);
    DataFrame data2 = Http2Requests.createData2(request1.getStreamId(), true);
    writer.processPiece(data2);
    DataFrame dataResp = (DataFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(1, dataResp.getData().getReadableSize());
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) Http2Request(com.webpieces.hpack.api.dto.Http2Request) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) StreamWriter(com.webpieces.http2engine.api.StreamWriter) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Example 3 with MockStreamWriter

use of org.webpieces.httpfrontend2.api.mock2.MockStreamWriter in project webpieces by deanhiller.

the class AbstractHttp2Test method setUp.

@Before
public void setUp() throws InterruptedException, ExecutionException, TimeoutException {
    MockTcpServerChannel svrChannel = new MockTcpServerChannel();
    mockChanMgr.addTCPSvrChannelToReturn(svrChannel);
    mockTcpChannel.setIncomingFrameDefaultReturnValue(CompletableFuture.completedFuture(mockTcpChannel));
    mockListener.setDefaultRetVal(mockStreamWriter);
    mockStreamWriter.setDefaultRetValToThis();
    Http2Config config = new Http2Config();
    config.setLocalSettings(localSettings);
    InjectionConfig injConfig = new InjectionConfig(mockTime, config);
    FrontendConfig frontendConfig = new FrontendConfig("http", new InetSocketAddress("me", 8080));
    HttpFrontendManager manager = HttpFrontendFactory.createFrontEnd(mockChanMgr, mockTimer, injConfig);
    HttpServer httpServer = manager.createHttpServer(frontendConfig, mockListener);
    httpServer.start();
    simulateClientConnecting();
    simulateClientSendingPrefaceAndSettings();
}
Also used : FrontendConfig(org.webpieces.frontend2.api.FrontendConfig) HttpFrontendManager(org.webpieces.frontend2.api.HttpFrontendManager) InetSocketAddress(java.net.InetSocketAddress) Http2Config(com.webpieces.http2engine.api.client.Http2Config) HttpServer(org.webpieces.frontend2.api.HttpServer) InjectionConfig(com.webpieces.http2engine.api.client.InjectionConfig) MockTcpServerChannel(org.webpieces.httpfrontend2.api.mock2.MockTcpServerChannel) Before(org.junit.Before)

Example 4 with MockStreamWriter

use of org.webpieces.httpfrontend2.api.mock2.MockStreamWriter in project webpieces by deanhiller.

the class TestHttp2Errors method testFarEndClosedSocket.

@Test
public void testFarEndClosedSocket() throws InterruptedException, ExecutionException {
    MockStreamWriter mockSw = new MockStreamWriter();
    mockListener.addMockStreamToReturn(mockSw);
    MockStreamWriter mockSw2 = new MockStreamWriter();
    mockListener.addMockStreamToReturn(mockSw2);
    Http2Request request1 = Http2Requests.createRequest(1, true);
    Http2Request request2 = Http2Requests.createRequest(3, true);
    mockChannel.send(request1);
    PassedIn in1 = mockListener.getSingleRequest();
    mockChannel.send(request2);
    PassedIn in2 = mockListener.getSingleRequest();
    mockChannel.close();
    List<Cancel> cancels = mockListener.getCancels();
    Assert.assertEquals(in1.stream, cancels.get(0).stream);
    Assert.assertEquals(in2.stream, cancels.get(1).stream);
}
Also used : Http2Request(com.webpieces.hpack.api.dto.Http2Request) Cancel(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.Cancel) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Example 5 with MockStreamWriter

use of org.webpieces.httpfrontend2.api.mock2.MockStreamWriter in project webpieces by deanhiller.

the class TestBasicHttp2Server method testBasicIntegration.

@Test
public void testBasicIntegration() throws InterruptedException, ExecutionException {
    MockStreamWriter mockSw = new MockStreamWriter();
    mockListener.addMockStreamToReturn(mockSw);
    MockStreamWriter mockSw2 = new MockStreamWriter();
    mockListener.addMockStreamToReturn(mockSw2);
    Http2Request request1 = Http2Requests.createRequest(1, true);
    Http2Request request2 = Http2Requests.createRequest(3, true);
    mockChannel.send(request1);
    PassedIn requestAndStream1 = mockListener.getSingleRequest();
    mockChannel.send(request2);
    PassedIn requestAndStream2 = mockListener.getSingleRequest();
    //each stream given to webapp is a unique one....
    Assert.assertTrue(requestAndStream1.stream != requestAndStream2.stream);
    Assert.assertEquals(request1, requestAndStream1.request);
    Assert.assertEquals(request2, requestAndStream2.request);
    Assert.assertEquals(1, request1.getStreamId());
    Assert.assertEquals(3, request2.getStreamId());
    Http2Response resp2 = Http2Requests.createResponse(request2.getStreamId());
    CompletableFuture<StreamWriter> future = requestAndStream2.stream.sendResponse(resp2);
    Assert.assertTrue(future.isDone());
    Http2Response frame2 = (Http2Response) mockChannel.getFrameAndClear();
    Assert.assertEquals(resp2, frame2);
    Http2Response resp1 = Http2Requests.createResponse(request1.getStreamId());
    CompletableFuture<StreamWriter> future1 = requestAndStream1.stream.sendResponse(resp1);
    Assert.assertTrue(future1.isDone());
    Http2Response frame1 = (Http2Response) mockChannel.getFrameAndClear();
    Assert.assertEquals(resp1, frame1);
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) Http2Request(com.webpieces.hpack.api.dto.Http2Request) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) StreamWriter(com.webpieces.http2engine.api.StreamWriter) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Aggregations

Http2Request (com.webpieces.hpack.api.dto.Http2Request)4 Test (org.junit.Test)4 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)4 MockStreamWriter (org.webpieces.httpfrontend2.api.mock2.MockStreamWriter)4 Http2Response (com.webpieces.hpack.api.dto.Http2Response)3 StreamWriter (com.webpieces.http2engine.api.StreamWriter)3 Http2Config (com.webpieces.http2engine.api.client.Http2Config)3 InjectionConfig (com.webpieces.http2engine.api.client.InjectionConfig)3 InetSocketAddress (java.net.InetSocketAddress)3 Before (org.junit.Before)3 FrontendConfig (org.webpieces.frontend2.api.FrontendConfig)3 HttpFrontendManager (org.webpieces.frontend2.api.HttpFrontendManager)3 HttpServer (org.webpieces.frontend2.api.HttpServer)3 MockTcpServerChannel (org.webpieces.httpfrontend2.api.mock2.MockTcpServerChannel)3 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)2 Http2Msg (com.webpieces.http2parser.api.dto.lib.Http2Msg)2 Http2Headers (com.webpieces.hpack.api.dto.Http2Headers)1 Http2Trailers (com.webpieces.hpack.api.dto.Http2Trailers)1 Cancel (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.Cancel)1 ConnectionListener (org.webpieces.nio.api.handlers.ConnectionListener)1