use of com.yahoo.jdisc.handler.BufferedContentChannel in project vespa by vespa-engine.
the class ThreadedRequestHandler method handleRequest.
/**
* Handles a request by assigning a worker thread to it.
*
* @throws OverloadException if thread pool has no available thread
*/
@Override
public final ContentChannel handleRequest(Request request, ResponseHandler responseHandler) {
metric.add("handled.requests", 1, contextFor(request.getBindingMatch()));
if (request.getTimeout(TimeUnit.SECONDS) == null) {
Duration timeout = getTimeout();
if (timeout != null) {
request.setTimeout(timeout.getSeconds(), TimeUnit.SECONDS);
}
}
BufferedContentChannel content = new BufferedContentChannel();
final RequestTask command = new RequestTask(request, content, responseHandler);
try {
executor.execute(command);
} catch (RejectedExecutionException e) {
command.failOnOverload();
throw new OverloadException("No available threads for " + getClass().getSimpleName(), e);
} finally {
logRejectedRequests();
}
return content;
}
use of com.yahoo.jdisc.handler.BufferedContentChannel in project vespa by vespa-engine.
the class StateHandlerTest method requestAsString.
private String requestAsString(String requestUri) throws Exception {
final BufferedContentChannel content = new BufferedContentChannel();
Response response = driver.dispatchRequest(requestUri, new ResponseHandler() {
@Override
public ContentChannel handleResponse(Response response) {
return content;
}
}).get(60, TimeUnit.SECONDS);
assertNotNull(response);
assertEquals(Response.Status.OK, response.getStatus());
StringBuilder str = new StringBuilder();
Reader in = new InputStreamReader(content.toStream(), StandardCharsets.UTF_8);
for (int c; (c = in.read()) != -1; ) {
str.append((char) c);
}
return str.toString();
}
use of com.yahoo.jdisc.handler.BufferedContentChannel in project vespa by vespa-engine.
the class LoggingRequestHandlerTestCase method checkStartIsNotZeroWithoutTimingInstance.
@Test
public final void checkStartIsNotZeroWithoutTimingInstance() throws InterruptedException {
Long startTime;
MockResponseHandler responseHandler = new MockResponseHandler();
com.yahoo.jdisc.http.HttpRequest request = createRequest();
BufferedContentChannel requestContent = new BufferedContentChannel();
requestContent.close(null);
handler.handleRequest(request, requestContent, responseHandler);
startTime = accessLogging.starts.poll(5, TimeUnit.MINUTES);
if (startTime == null) {
// test timed out, ignoring
} else {
assertFalse("Start time was 0, that should never happen after the first millisecond of 1970.", startTime.longValue() == 0L);
}
}
use of com.yahoo.jdisc.handler.BufferedContentChannel in project vespa by vespa-engine.
the class VipStatusHandlerTestCase method testFileFound.
@Test
public final void testFileFound() throws IOException {
final File statusFile = File.createTempFile("VipStatusHandlerTestCase", null);
try {
final FileWriter writer = new FileWriter(statusFile);
final String OK = "OK\n";
writer.write(OK);
writer.close();
final VipStatusConfig config = new VipStatusConfig(new VipStatusConfig.Builder().accessdisk(true).statusfile(statusFile.getAbsolutePath()).noSearchBackendsImpliesOutOfService(false));
final VipStatusHandler handler = new VipStatusHandler(Executors.newCachedThreadPool(), config, metric);
final MockResponseHandler responseHandler = new MockResponseHandler();
final HttpRequest request = createRequest();
final BufferedContentChannel requestContent = createChannel();
handler.handleRequest(request, requestContent, responseHandler);
final ByteBuffer b = responseHandler.channel.read();
final byte[] asBytes = new byte[b.remaining()];
b.get(asBytes);
assertEquals(OK, Utf8.toString(asBytes));
} finally {
statusFile.delete();
}
}
use of com.yahoo.jdisc.handler.BufferedContentChannel in project vespa by vespa-engine.
the class VipStatusHandlerTestCase method testProgrammaticallyRemovedFromRotation.
@Test
public final void testProgrammaticallyRemovedFromRotation() throws IOException {
VipStatus vipStatus = new VipStatus();
final VipStatusConfig config = new VipStatusConfig(new VipStatusConfig.Builder().accessdisk(false).noSearchBackendsImpliesOutOfService(true));
final VipStatusHandler handler = new VipStatusHandler(Executors.newCachedThreadPool(), config, metric, vipStatus);
vipStatus.removeFromRotation(this);
{
final MockResponseHandler responseHandler = new MockResponseHandler();
final HttpRequest request = createRequest();
final BufferedContentChannel requestContent = createChannel();
handler.handleRequest(request, requestContent, responseHandler);
final ByteBuffer b = responseHandler.channel.read();
final byte[] asBytes = new byte[b.remaining()];
b.get(asBytes);
assertEquals(VipStatusHandler.StatusResponse.NO_SEARCH_BACKENDS, Utf8.toString(asBytes));
}
vipStatus.addToRotation(this);
{
final MockResponseHandler responseHandler = new MockResponseHandler();
final HttpRequest request = createRequest();
final BufferedContentChannel requestContent = createChannel();
handler.handleRequest(request, requestContent, responseHandler);
final ByteBuffer b = responseHandler.channel.read();
final byte[] asBytes = new byte[b.remaining()];
b.get(asBytes);
assertEquals(VipStatusHandler.OK_MESSAGE, Utf8.toString(asBytes));
}
}
Aggregations