Search in sources :

Example 6 with ResourceMethodConfig

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);
}
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 7 with ResourceMethodConfig

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());
    }
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RestLiSyntaxException(com.linkedin.restli.internal.server.util.RestLiSyntaxException) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) PathKeysImpl(com.linkedin.restli.internal.server.PathKeysImpl) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceMethodConfig(com.linkedin.restli.server.config.ResourceMethodConfig) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl)

Example 8 with ResourceMethodConfig

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);
}
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)

Example 9 with ResourceMethodConfig

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;
}
Also used : ResourceMethodConfig(com.linkedin.restli.server.config.ResourceMethodConfig)

Aggregations

ResourceMethodConfig (com.linkedin.restli.server.config.ResourceMethodConfig)9 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)5 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)4 Test (org.testng.annotations.Test)3 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 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)2 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)2 RestLiSyntaxException (com.linkedin.restli.internal.server.util.RestLiSyntaxException)2 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)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