Search in sources :

Example 1 with PromiseListener

use of com.linkedin.parseq.promise.PromiseListener in project rest.li by linkedin.

the class TestParseqTraceDebugRequestHandler method executeRequestThroughParseqDebugHandler.

private void executeRequestThroughParseqDebugHandler(URI uri, Callback<RestResponse> callback) {
    ParseqTraceDebugRequestHandler requestHandler = new ParseqTraceDebugRequestHandler();
    RestRequestBuilder requestBuilder = new RestRequestBuilder(uri);
    RestRequest request = requestBuilder.build();
    RequestContext requestContext = new RequestContext();
    requestHandler.handleRequest(request, requestContext, new RestLiDebugRequestHandler.ResourceDebugRequestHandler() {

        @Override
        @SuppressWarnings("unchecked")
        public void handleRequest(RestRequest request, RequestContext requestContext, Callback<RestResponse> callback) {
            RestResponse response = EasyMock.createMock(RestResponse.class);
            JsonTraceCodec jsonTraceCodec = new JsonTraceCodec();
            Trace t = null;
            try {
                t = jsonTraceCodec.decode(TEST_TRACE);
            } catch (IOException exc) {
            // test will fail later
            }
            Task<Object> task = EasyMock.createMock(Task.class);
            EasyMock.expect(task.getTrace()).andReturn(t);
            EasyMock.replay(task);
            PromiseListener<Object> promiseListener = (PromiseListener<Object>) requestContext.getLocalAttr(RestLiMethodInvoker.ATTRIBUTE_PROMISE_LISTENER);
            promiseListener.onResolved(task);
            callback.onSuccess(response);
        }
    }, callback);
}
Also used : Task(com.linkedin.parseq.Task) PromiseListener(com.linkedin.parseq.promise.PromiseListener) RestResponse(com.linkedin.r2.message.rest.RestResponse) IOException(java.io.IOException) Trace(com.linkedin.parseq.trace.Trace) RestRequest(com.linkedin.r2.message.rest.RestRequest) JsonTraceCodec(com.linkedin.parseq.trace.codec.json.JsonTraceCodec) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) RequestContext(com.linkedin.r2.message.RequestContext)

Aggregations

Task (com.linkedin.parseq.Task)1 PromiseListener (com.linkedin.parseq.promise.PromiseListener)1 Trace (com.linkedin.parseq.trace.Trace)1 JsonTraceCodec (com.linkedin.parseq.trace.codec.json.JsonTraceCodec)1 RequestContext (com.linkedin.r2.message.RequestContext)1 RestRequest (com.linkedin.r2.message.rest.RestRequest)1 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)1 RestResponse (com.linkedin.r2.message.rest.RestResponse)1 IOException (java.io.IOException)1