Search in sources :

Example 1 with ResourceMethodConfigProvider

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);
}
Also used : Status(com.linkedin.restli.server.twitter.TwitterTestDataModels.Status) HttpStatus(com.linkedin.restli.common.HttpStatus) TaskStatusCollectionResource(com.linkedin.restli.server.twitter.TaskStatusCollectionResource) RestResponse(com.linkedin.r2.message.rest.RestResponse) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ByteString(com.linkedin.data.ByteString) CustomString(com.linkedin.restli.server.custom.types.CustomString) RestException(com.linkedin.r2.message.rest.RestException) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) RoutingException(com.linkedin.restli.server.RoutingException) RestLiSyntaxException(com.linkedin.restli.internal.server.util.RestLiSyntaxException) ResourceMethodConfigProvider(com.linkedin.restli.server.config.ResourceMethodConfigProvider) Trace(com.linkedin.parseq.trace.Trace) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) ResourceMethodConfig(com.linkedin.restli.server.config.ResourceMethodConfig) FilterRequestContext(com.linkedin.restli.server.filter.FilterRequestContext) RequestContext(com.linkedin.r2.message.RequestContext) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 2 with ResourceMethodConfigProvider

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);
}
Also used : Status(com.linkedin.restli.server.twitter.TwitterTestDataModels.Status) HttpStatus(com.linkedin.restli.common.HttpStatus) PromiseStatusCollectionResource(com.linkedin.restli.server.twitter.PromiseStatusCollectionResource) RestResponse(com.linkedin.r2.message.rest.RestResponse) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ByteString(com.linkedin.data.ByteString) CustomString(com.linkedin.restli.server.custom.types.CustomString) ResourceMethodConfigProvider(com.linkedin.restli.server.config.ResourceMethodConfigProvider) Trace(com.linkedin.parseq.trace.Trace) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) ResourceMethodConfig(com.linkedin.restli.server.config.ResourceMethodConfig) FilterRequestContext(com.linkedin.restli.server.filter.FilterRequestContext) RequestContext(com.linkedin.r2.message.RequestContext) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

ByteString (com.linkedin.data.ByteString)2 Trace (com.linkedin.parseq.trace.Trace)2 RequestContext (com.linkedin.r2.message.RequestContext)2 RestResponse (com.linkedin.r2.message.rest.RestResponse)2 HttpStatus (com.linkedin.restli.common.HttpStatus)2 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)2 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)2 ResourceMethodConfig (com.linkedin.restli.server.config.ResourceMethodConfig)2 ResourceMethodConfigProvider (com.linkedin.restli.server.config.ResourceMethodConfigProvider)2 CustomString (com.linkedin.restli.server.custom.types.CustomString)2 FilterRequestContext (com.linkedin.restli.server.filter.FilterRequestContext)2 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)2 Status (com.linkedin.restli.server.twitter.TwitterTestDataModels.Status)2 AfterTest (org.testng.annotations.AfterTest)2 BeforeTest (org.testng.annotations.BeforeTest)2 Test (org.testng.annotations.Test)2 RestException (com.linkedin.r2.message.rest.RestException)1 RestLiSyntaxException (com.linkedin.restli.internal.server.util.RestLiSyntaxException)1 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)1 RoutingException (com.linkedin.restli.server.RoutingException)1