use of com.linkedin.restli.server.config.ResourceMethodConfigProvider 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.ResourceMethodConfigProvider 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);
}
Aggregations