use of org.webpieces.httpparser.api.dto.HttpPayload in project webpieces by deanhiller.
the class TestHttp11Errors method testCloseBeforeFirstRequestCompletes.
@Test
public void testCloseBeforeFirstRequestCompletes() throws InterruptedException, ExecutionException, TimeoutException {
HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
HttpRequest req2 = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
XFuture<StreamWriter> futA = XFuture.completedFuture(null);
MockStreamRef mockStreamRefA = new MockStreamRef(futA);
mockListener.addMockStreamToReturn(mockStreamRefA);
mockChannel.sendToSvr(req);
PassedIn in1 = mockListener.getSingleRequest();
XFuture<StreamWriter> futB = XFuture.completedFuture(null);
MockStreamRef mockStreamRefB = new MockStreamRef(futB);
mockListener.addMockStreamToReturn(mockStreamRefB);
XFuture<Void> fut1 = mockChannel.sendToSvrAsync(req2);
Assert.assertFalse(fut1.isDone());
Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
HttpResponse resp1 = Requests.createResponse(1);
resp1.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "10"));
Http2Response headers1 = Http11ToHttp2.responseToHeaders(resp1);
XFuture<StreamWriter> future = in1.stream.process(headers1);
HttpPayload payload = mockChannel.getFrameAndClear();
Assert.assertEquals(resp1, payload);
StreamWriter writer = future.get(2, TimeUnit.SECONDS);
Assert.assertFalse(fut1.isDone());
Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
Assert.assertFalse(mockStreamRefA.isCancelled());
Assert.assertFalse(mockStreamRefB.isCancelled());
mockChannel.simulateClose();
// this request is done, nothing to cancel
Assert.assertTrue(mockStreamRefA.isCancelled());
Assert.assertFalse(mockStreamRefB.isCancelled());
}
use of org.webpieces.httpparser.api.dto.HttpPayload in project webpieces by deanhiller.
the class Http11SynchronousClient method startImpl.
public void startImpl(InetSocketAddress svrAddress) throws UnknownHostException, IOException {
@SuppressWarnings("resource") Socket socket = new Socket(svrAddress.getHostName(), svrAddress.getPort());
OutputStream output = socket.getOutputStream();
Runnable client = new ClientWriter(parser, output);
Thread t1 = new Thread(client);
t1.setName("clientWriter");
t1.start();
InputStream input = socket.getInputStream();
RateRecorder recorder = new RateRecorder(10);
while (true) {
byte[] bytes = new byte[1024];
int read = input.read(bytes);
if (read < 0)
break;
DataWrapper dataWrapper = dataGen.wrapByteArray(bytes, 0, read);
List<HttpPayload> messages = parser.parse(dataWrapper);
// simulate going all the way to http2 like the other test does as well
for (HttpPayload p : messages) {
HttpResponse resp = (HttpResponse) p;
Http2Msg translate = Http11ToHttp2.responseToHeaders(resp);
translate.getMessageType();
recorder.increment();
}
}
}
use of org.webpieces.httpparser.api.dto.HttpPayload in project webpieces by deanhiller.
the class TestBeansAndSplit method create.
private ResponseWrapper create() {
List<HttpPayload> payloads = parser.parse(dataReceived);
HttpResponse response = (HttpResponse) payloads.get(0);
DataWrapper all = dataGen.emptyWrapper();
for (int i = 1; i < payloads.size(); i++) {
HttpData d = (HttpData) payloads.get(i);
all = dataGen.chainDataWrappers(all, d.getBodyNonNull());
}
HttpFullResponse fResponse = new HttpFullResponse(response, all);
return new ResponseWrapper(fResponse);
}
use of org.webpieces.httpparser.api.dto.HttpPayload in project webpieces by deanhiller.
the class MockChannel method write.
@SuppressWarnings("unchecked")
@Override
public XFuture<Void> write(ByteBuffer b) {
DataWrapper wrapper = dataGen.wrapByteBuffer(b);
List<HttpPayload> parsedData = parser.parse(wrapper);
if (parsedData.size() != 1)
throw new IllegalArgumentException("The impl should be writing out full single payloads each write call");
HttpPayload payload = parsedData.get(0);
Http2Msg http2 = Http11ToHttp2.translate(payload, false);
return (XFuture<Void>) super.calledMethod(Method.WRITE, http2);
}
use of org.webpieces.httpparser.api.dto.HttpPayload in project webpieces by deanhiller.
the class MockChannel method write.
@SuppressWarnings("unchecked")
@Override
public XFuture<Void> write(ByteBuffer b) {
DataWrapper wrapper = dataGen.wrapByteBuffer(b);
List<HttpPayload> parsedData = parser.parse(wrapper);
if (parsedData.size() != 1)
throw new IllegalArgumentException("The impl should be writing out full single payloads each write call");
HttpPayload payload = parsedData.get(0);
return (XFuture<Void>) super.calledMethod(Method.WRITE, payload);
}
Aggregations