use of com.linkedin.restli.server.config.ResourceMethodConfig in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testTimeoutParseqTraceTask.
@Test(dataProvider = "taskMethodConfigProviders")
public void testTimeoutParseqTraceTask(RestLiMethodConfig restliMethodConfig, String timeoutTaskName) throws Exception {
Map<String, ResourceModel> resourceModelMap = buildResourceModels(TaskStatusCollectionResource.class);
ResourceModel taskStatusResourceModel = resourceModelMap.get("/taskstatuses");
// #4: Task based Async Method Execution
RequestContext taskRequestContext = new RequestContext();
ResourceMethodDescriptor methodDescriptor = taskStatusResourceModel.findMethod(ResourceMethod.GET);
TaskStatusCollectionResource taskStatusResource = getMockResource(TaskStatusCollectionResource.class);
EasyMock.expect(taskStatusResource.get(eq(1L))).andReturn(Task.callable("myTask", new Callable<Status>() {
@Override
public Status call() throws Exception {
return new Status();
}
})).once();
// configure method-level timeout
ResourceMethodConfigProvider methodConfigProvider = ResourceMethodConfigProvider.build(restliMethodConfig);
ResourceMethodConfig methodConfig = methodConfigProvider.apply(methodDescriptor);
checkInvocation(taskStatusResource, taskRequestContext, methodDescriptor, methodConfig, "GET", version, "/taskstatuses/1", null, buildPathKeys("statusID", 1L), new Callback<RestResponse>() {
@Override
public void onError(Throwable e) {
Assert.fail("Request failed unexpectedly.");
}
@Override
public void onSuccess(RestResponse result) {
Trace parseqTrace = (Trace) taskRequestContext.getLocalAttr(ATTRIBUTE_PARSEQ_TRACE);
Assert.assertNotNull(parseqTrace);
if (timeoutTaskName != null) {
Assert.assertTrue(hasTask(timeoutTaskName, parseqTrace));
}
}
}, true, false, null, null);
}
use of com.linkedin.restli.server.config.ResourceMethodConfig in project rest.li by linkedin.
the class BaseRestLiServer method getRoutingResult.
protected RoutingResult getRoutingResult(Request request, RequestContext requestContext) {
ensureRequestUsesValidRestliProtocol(request, requestContext);
try {
ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), request, requestContext);
RestUtils.validateRequestHeadersAndUpdateResourceContext(request.getHeaders(), _supportedAcceptTypes, _customContentTypes, context, requestContext);
ResourceMethodDescriptor method = _router.process(context);
ResourceMethodConfig methodConfig = _methodConfigProvider.apply(method);
context.setAlwaysProjectedFields(methodConfig.getAlwaysProjectedFields().getValue());
context.setFillInDefaultValues(_fillInDefaultValueConfigured);
return new RoutingResult(context, method, methodConfig);
} catch (RestLiSyntaxException e) {
throw new RoutingException(e.getMessage(), HttpStatus.S_400_BAD_REQUEST.getCode());
}
}
use of com.linkedin.restli.server.config.ResourceMethodConfig in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testTimeoutParseqTracePromise.
@Test(dataProvider = "promiseMethodConfigProviders")
public void testTimeoutParseqTracePromise(RestLiMethodConfig restliMethodConfig, String timeoutTaskName) throws Exception {
Map<String, ResourceModel> resourceModelMap = buildResourceModels(PromiseStatusCollectionResource.class);
ResourceModel promiseStatusResourceModel = resourceModelMap.get("/promisestatuses");
// Promise based Async Method Execution
RequestContext promiseRequestContext = new RequestContext();
ResourceMethodDescriptor methodDescriptor = promiseStatusResourceModel.findMethod(ResourceMethod.GET);
PromiseStatusCollectionResource promiseStatusResource = getMockResource(PromiseStatusCollectionResource.class);
EasyMock.expect(promiseStatusResource.get(eq(1L))).andReturn(Promises.value(new Status())).once();
// configure method-level timeout
ResourceMethodConfigProvider methodConfigProvider = ResourceMethodConfigProvider.build(restliMethodConfig);
ResourceMethodConfig methodConfig = methodConfigProvider.apply(methodDescriptor);
checkInvocation(promiseStatusResource, promiseRequestContext, methodDescriptor, methodConfig, "GET", version, "/promisestatuses/1", null, buildPathKeys("statusID", 1L), new Callback<RestResponse>() {
@Override
public void onError(Throwable e) {
Assert.fail("Request failed unexpectedly.");
}
@Override
public void onSuccess(RestResponse result) {
Trace parseqTrace = (Trace) promiseRequestContext.getLocalAttr(ATTRIBUTE_PARSEQ_TRACE);
Assert.assertNotNull(parseqTrace);
if (timeoutTaskName != null) {
Assert.assertTrue(hasTask(timeoutTaskName, parseqTrace));
}
}
}, true, false, null, null);
}
use of com.linkedin.restli.server.config.ResourceMethodConfig in project rest.li by linkedin.
the class TestArgumentBuilder method getMockResourceMethodConfig.
private ResourceMethodConfig getMockResourceMethodConfig(boolean shouldValidateParams) {
ResourceMethodConfig mockResourceMethodConfig = EasyMock.createMock(ResourceMethodConfig.class);
EasyMock.expect(mockResourceMethodConfig.shouldValidateResourceKeys()).andReturn(shouldValidateParams).anyTimes();
EasyMock.expect(mockResourceMethodConfig.shouldValidateQueryParams()).andReturn(shouldValidateParams).anyTimes();
EasyMock.replay(mockResourceMethodConfig);
return mockResourceMethodConfig;
}
Aggregations