Search in sources :

Example 1 with RestLiClientConfig

use of com.linkedin.restli.client.util.RestLiClientConfig in project rest.li by linkedin.

the class RestLiIntegrationTest method initClient.

private void initClient(String uriPrefix, Map<String, String> transportProperties) {
    _clientFactory = new HttpClientFactory.Builder().setUsePipelineV2(false).build();
    _transportClients = new ArrayList<>();
    Client client = newTransportClient(transportProperties);
    RestLiClientConfig restLiClientConfig = new RestLiClientConfig();
    restLiClientConfig.setUseStreaming(Boolean.parseBoolean(System.getProperty("test.useStreamCodecClient", "false")));
    _restClient = new RestClient(client, uriPrefix, restLiClientConfig);
}
Also used : RestLiClientConfig(com.linkedin.restli.client.util.RestLiClientConfig) RestClient(com.linkedin.restli.client.RestClient) RestClient(com.linkedin.restli.client.RestClient) Client(com.linkedin.r2.transport.common.Client) HttpClientFactory(com.linkedin.r2.transport.http.client.HttpClientFactory)

Example 2 with RestLiClientConfig

use of com.linkedin.restli.client.util.RestLiClientConfig in project rest.li by linkedin.

the class TestRestLiScatterGather method testSendScatterGatherRequest.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "scatterGatherDataProvider", // Known to be flaky in CI
retryAnalyzer = SingleRetry.class)
public static void testSendScatterGatherRequest(URIMapper mapper, RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    RestLiClientConfig config = new RestLiClientConfig();
    config.setScatterGatherStrategy(new DefaultScatterGatherStrategy(mapper));
    RestClient restClient = new AlwaysD2RestClient(CLIENT, URI_PREFIX, config);
    final int NUM_IDS = 20;
    List<Greeting> entities = generateCreate(NUM_IDS);
    Long[] requestIds = prepareData(restClient, entities);
    // BATCH_GET
    testSendSGGetRequests(restClient, requestIds);
    testSendSGGetEntityRequests(restClient, requestIds);
    testSendSGGetKVRequests(restClient, requestIds);
    // BATCH_UPDATE
    Map<Long, Greeting> input = generateUpdates(requestIds);
    testSendSGUpdateRequests(restClient, input, builders);
    // BATCH_PATIAL_UPDATE
    Map<Long, PatchRequest<Greeting>> patch = generatePartialUpdates(requestIds);
    testSendSGPartialUpdateRequests(restClient, patch, builders);
    // BATCH_DELETE
    testSendSGDeleteRequests(restClient, requestIds, builders);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) RestLiClientConfig(com.linkedin.restli.client.util.RestLiClientConfig) PatchRequest(com.linkedin.restli.common.PatchRequest) RestLiIntegrationTest(com.linkedin.restli.examples.RestLiIntegrationTest) Test(org.testng.annotations.Test)

Example 3 with RestLiClientConfig

use of com.linkedin.restli.client.util.RestLiClientConfig in project rest.li by linkedin.

the class LatencyInstrumentationResource method create.

/**
 * This is the "upstream endpoint" which is queried directly by the integration test.
 * This endpoint makes a call to {@link #batchPartialUpdate(BatchPatchRequest)} (the "downstream endpoint"),
 * then packs all the client-side timing data into the original server-side request context.
 */
@ReturnEntity
@RestMethod.Create
public CreateKVResponse<Long, InstrumentationControl> create(InstrumentationControl control) {
    final boolean forceException = control.isForceException();
    final boolean useScatterGather = control.isUseScatterGather();
    final String uriPrefix = control.getServiceUriPrefix();
    // Build the downstream request
    final BatchPartialUpdateEntityRequestBuilder<Long, InstrumentationControl> builder = new LatencyInstrumentationBuilders().batchPartialUpdateAndGet();
    final PatchRequest<InstrumentationControl> patch = PatchGenerator.diffEmpty(control);
    for (long i = 0; i < DOWNSTREAM_BATCH_SIZE; i++) {
        builder.input(i, patch);
    }
    final BatchPartialUpdateEntityRequest<Long, InstrumentationControl> request = builder.build();
    // Set up the Rest.li client config
    final RestLiClientConfig clientConfig = new RestLiClientConfig();
    clientConfig.setUseStreaming(control.isUseStreaming());
    if (useScatterGather) {
        clientConfig.setScatterGatherStrategy(new DefaultScatterGatherStrategy(new DummyUriMapper()));
    }
    final TransportClient transportClient = new HttpClientFactory.Builder().build().getClient(Collections.emptyMap());
    final RestClient restClient = new ForceScatterGatherRestClient(new TransportClientAdapter(transportClient), uriPrefix, clientConfig);
    final RequestContext serverRequestContext = getContext().getRawRequestContext();
    final RequestContext clientRequestContext = new RequestContext();
    // Load the timing importance threshold from the server context into the client context
    clientRequestContext.putLocalAttr(TimingContextUtil.TIMING_IMPORTANCE_THRESHOLD_KEY_NAME, serverRequestContext.getLocalAttr(TimingContextUtil.TIMING_IMPORTANCE_THRESHOLD_KEY_NAME));
    try {
        // Make the request, then assert that the returned errors (if any) are as expected
        BatchKVResponse<Long, UpdateEntityStatus<InstrumentationControl>> response = restClient.sendRequest(request, clientRequestContext).getResponseEntity();
        final Map<Long, ErrorResponse> errors = response.getErrors();
        if (forceException && errors.isEmpty()) {
            throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "Expected failures for the downstream batch request, but found none.");
        }
        if (!forceException && !errors.isEmpty()) {
            throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "Expected no failures for the downstream batch request, but found some.");
        }
        for (ErrorResponse errorResponse : errors.values()) {
            if (!DOWNSTREAM_ERROR_CODE.equals(errorResponse.getCode())) {
                throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "Encountered a downstream failure with an unexpected or missing error code.");
            }
        }
    } catch (RemoteInvocationException e) {
        throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "Downstream failures should be batch entry failures, but encountered a top-level request failure.", e);
    }
    Map<TimingKey, TimingContextUtil.TimingContext> clientTimingsMap = TimingContextUtil.getTimingsMap(clientRequestContext);
    Map<TimingKey, TimingContextUtil.TimingContext> serverTimingsMap = TimingContextUtil.getTimingsMap(serverRequestContext);
    // Load all client timings into the server timings map
    serverTimingsMap.putAll(clientTimingsMap);
    getContext().setResponseHeader(HAS_CLIENT_TIMINGS_HEADER, Boolean.TRUE.toString());
    if (forceException) {
        throw new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "You wanted me to fail, so I failed.").setCode(UPSTREAM_ERROR_CODE);
    }
    return new CreateKVResponse<>(1L, control);
}
Also used : RestLiClientConfig(com.linkedin.restli.client.util.RestLiClientConfig) BatchPartialUpdateEntityRequestBuilder(com.linkedin.restli.client.BatchPartialUpdateEntityRequestBuilder) InstrumentationControl(com.linkedin.restli.examples.instrumentation.api.InstrumentationControl) DefaultScatterGatherStrategy(com.linkedin.restli.client.DefaultScatterGatherStrategy) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) TimingKey(com.linkedin.r2.message.timing.TimingKey) TransportClientAdapter(com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter) RequestContext(com.linkedin.r2.message.RequestContext) RemoteInvocationException(com.linkedin.r2.RemoteInvocationException) UpdateEntityStatus(com.linkedin.restli.common.UpdateEntityStatus) TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) RestClient(com.linkedin.restli.client.RestClient) LatencyInstrumentationBuilders(com.linkedin.restli.examples.instrumentation.client.LatencyInstrumentationBuilders) ErrorResponse(com.linkedin.restli.common.ErrorResponse) CreateKVResponse(com.linkedin.restli.server.CreateKVResponse) ReturnEntity(com.linkedin.restli.server.annotations.ReturnEntity)

Example 4 with RestLiClientConfig

use of com.linkedin.restli.client.util.RestLiClientConfig in project rest.li by linkedin.

the class TestRestLiScatterGather method testSendScatterGatherPartialUpdateEntityRequest.

@Test(dataProvider = "scatterGatherPartialUpdateEntityDataProvider")
public static void testSendScatterGatherPartialUpdateEntityRequest(URIMapper mapper) throws RemoteInvocationException {
    RestLiClientConfig config = new RestLiClientConfig();
    config.setScatterGatherStrategy(new DefaultScatterGatherStrategy(mapper));
    RestClient restClient = new AlwaysD2RestClient(CLIENT, URI_PREFIX, config);
    // Note that PartialUpdateGreeting resource only supports ids up to 20.
    Long[] requestIds = new Long[] { 0L, 1L, 2L, 3L, 4L, 5L };
    Map<Long, PatchRequest<Greeting>> patch = generatePartialUpdates(requestIds);
    testSendSGPartialUpdateEntityRequests(restClient, patch);
}
Also used : RestLiClientConfig(com.linkedin.restli.client.util.RestLiClientConfig) PatchRequest(com.linkedin.restli.common.PatchRequest) RestLiIntegrationTest(com.linkedin.restli.examples.RestLiIntegrationTest) Test(org.testng.annotations.Test)

Example 5 with RestLiClientConfig

use of com.linkedin.restli.client.util.RestLiClientConfig in project rest.li by linkedin.

the class TestCompressionServer method getClientConfig.

private RestLiClientConfig getClientConfig() {
    RestLiClientConfig restLiClientConfig = new RestLiClientConfig();
    restLiClientConfig.setUseStreaming(Boolean.parseBoolean(System.getProperty("test.useStreamCodecClient", "false")));
    return restLiClientConfig;
}
Also used : RestLiClientConfig(com.linkedin.restli.client.util.RestLiClientConfig)

Aggregations

RestLiClientConfig (com.linkedin.restli.client.util.RestLiClientConfig)5 RestClient (com.linkedin.restli.client.RestClient)2 PatchRequest (com.linkedin.restli.common.PatchRequest)2 RestLiIntegrationTest (com.linkedin.restli.examples.RestLiIntegrationTest)2 Test (org.testng.annotations.Test)2 RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)1 RequestContext (com.linkedin.r2.message.RequestContext)1 TimingKey (com.linkedin.r2.message.timing.TimingKey)1 Client (com.linkedin.r2.transport.common.Client)1 TransportClient (com.linkedin.r2.transport.common.bridge.client.TransportClient)1 TransportClientAdapter (com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter)1 HttpClientFactory (com.linkedin.r2.transport.http.client.HttpClientFactory)1 BatchPartialUpdateEntityRequestBuilder (com.linkedin.restli.client.BatchPartialUpdateEntityRequestBuilder)1 DefaultScatterGatherStrategy (com.linkedin.restli.client.DefaultScatterGatherStrategy)1 ErrorResponse (com.linkedin.restli.common.ErrorResponse)1 UpdateEntityStatus (com.linkedin.restli.common.UpdateEntityStatus)1 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)1 InstrumentationControl (com.linkedin.restli.examples.instrumentation.api.InstrumentationControl)1 LatencyInstrumentationBuilders (com.linkedin.restli.examples.instrumentation.client.LatencyInstrumentationBuilders)1 CreateKVResponse (com.linkedin.restli.server.CreateKVResponse)1