use of org.eclipse.jetty.io.ByteArrayEndPoint in project jetty.project by eclipse.
the class HttpReceiverOverHTTPTest method init.
@Before
public void init() throws Exception {
client = new HttpClient();
client.start();
destination = new HttpDestinationOverHTTP(client, new Origin("http", "localhost", 8080));
destination.start();
endPoint = new ByteArrayEndPoint();
connection = new HttpConnectionOverHTTP(endPoint, destination, new Promise.Adapter<>());
endPoint.setConnection(connection);
}
use of org.eclipse.jetty.io.ByteArrayEndPoint in project jetty.project by eclipse.
the class HttpSenderOverHTTPTest method test_Send_NoRequestContent_IncompleteFlush.
@Slow
@Test
public void test_Send_NoRequestContent_IncompleteFlush() throws Exception {
ByteArrayEndPoint endPoint = new ByteArrayEndPoint("", 16);
HttpDestinationOverHTTP destination = new HttpDestinationOverHTTP(client, new Origin("http", "localhost", 8080));
destination.start();
HttpConnectionOverHTTP connection = new HttpConnectionOverHTTP(endPoint, destination, new Promise.Adapter<Connection>());
Request request = client.newRequest(URI.create("http://localhost/"));
connection.send(request, null);
// This take will free space in the buffer and allow for the write to complete
StringBuilder builder = new StringBuilder(endPoint.takeOutputString());
// Wait for the write to complete
TimeUnit.SECONDS.sleep(1);
String chunk = endPoint.takeOutputString();
while (chunk.length() > 0) {
builder.append(chunk);
chunk = endPoint.takeOutputString();
}
String requestString = builder.toString();
Assert.assertTrue(requestString.startsWith("GET "));
Assert.assertTrue(requestString.endsWith("\r\n\r\n"));
}
use of org.eclipse.jetty.io.ByteArrayEndPoint in project jetty.project by eclipse.
the class HttpSenderOverHTTPTest method test_Send_NoRequestContent_Exception.
@Test
public void test_Send_NoRequestContent_Exception() throws Exception {
ByteArrayEndPoint endPoint = new ByteArrayEndPoint();
// Shutdown output to trigger the exception on write
endPoint.shutdownOutput();
HttpDestinationOverHTTP destination = new HttpDestinationOverHTTP(client, new Origin("http", "localhost", 8080));
destination.start();
HttpConnectionOverHTTP connection = new HttpConnectionOverHTTP(endPoint, destination, new Promise.Adapter<Connection>());
Request request = client.newRequest(URI.create("http://localhost/"));
final CountDownLatch failureLatch = new CountDownLatch(2);
request.listener(new Request.Listener.Adapter() {
@Override
public void onFailure(Request request, Throwable x) {
failureLatch.countDown();
}
});
connection.send(request, new Response.Listener.Adapter() {
@Override
public void onComplete(Result result) {
Assert.assertTrue(result.isFailed());
failureLatch.countDown();
}
});
Assert.assertTrue(failureLatch.await(5, TimeUnit.SECONDS));
}
use of org.eclipse.jetty.io.ByteArrayEndPoint in project jetty.project by eclipse.
the class ResponseTest method init.
@Before
public void init() throws Exception {
_server = new Server();
Scheduler _scheduler = new TimerScheduler();
HttpConfiguration config = new HttpConfiguration();
LocalConnector connector = new LocalConnector(_server, null, _scheduler, null, 1, new HttpConnectionFactory(config));
_server.addConnector(connector);
_server.setHandler(new DumpHandler());
_server.start();
AbstractEndPoint endp = new ByteArrayEndPoint(_scheduler, 5000) {
@Override
public InetSocketAddress getLocalAddress() {
return LOCALADDRESS;
}
};
_channel = new HttpChannel(connector, new HttpConfiguration(), endp, new HttpTransport() {
private Throwable _channelError;
@Override
public void send(MetaData.Response info, boolean head, ByteBuffer content, boolean lastContent, Callback callback) {
if (_channelError == null)
callback.succeeded();
else
callback.failed(_channelError);
}
@Override
public boolean isPushSupported() {
return false;
}
@Override
public void push(org.eclipse.jetty.http.MetaData.Request request) {
}
@Override
public void onCompleted() {
}
@Override
public void abort(Throwable failure) {
_channelError = failure;
}
@Override
public boolean isOptimizedForDirectBuffers() {
return false;
}
});
}
use of org.eclipse.jetty.io.ByteArrayEndPoint in project jetty.project by eclipse.
the class HttpSenderOverHTTPTest method test_Send_NoRequestContent.
@Test
public void test_Send_NoRequestContent() throws Exception {
ByteArrayEndPoint endPoint = new ByteArrayEndPoint();
HttpDestinationOverHTTP destination = new HttpDestinationOverHTTP(client, new Origin("http", "localhost", 8080));
destination.start();
HttpConnectionOverHTTP connection = new HttpConnectionOverHTTP(endPoint, destination, new Promise.Adapter<Connection>());
Request request = client.newRequest(URI.create("http://localhost/"));
final CountDownLatch headersLatch = new CountDownLatch(1);
final CountDownLatch successLatch = new CountDownLatch(1);
request.listener(new Request.Listener.Adapter() {
@Override
public void onHeaders(Request request) {
headersLatch.countDown();
}
@Override
public void onSuccess(Request request) {
successLatch.countDown();
}
});
connection.send(request, null);
String requestString = endPoint.takeOutputString();
Assert.assertTrue(requestString.startsWith("GET "));
Assert.assertTrue(requestString.endsWith("\r\n\r\n"));
Assert.assertTrue(headersLatch.await(5, TimeUnit.SECONDS));
Assert.assertTrue(successLatch.await(5, TimeUnit.SECONDS));
}
Aggregations