Search in sources :

Example 1 with R2RestRequestBuilder

use of org.apache.gobblin.r2.R2RestRequestBuilder in project incubator-gobblin by apache.

the class R2RestRequestBuilderTest method testBuildWriteRequest.

/**
 * Build a {@link RestRequest} from a {@link GenericRecord}
 */
public void testBuildWriteRequest() throws URISyntaxException, IOException {
    String urlTemplate = "http://www.test.com/a/part1:${part1}/a/part2:${part2}";
    String verb = "update";
    String protocolVersion = "2.0.0";
    R2RestRequestBuilder builder = spy(new R2RestRequestBuilder(urlTemplate, verb, protocolVersion));
    ArgumentCaptor<RestRequestBuilder> requestBuilderArgument = ArgumentCaptor.forClass(RestRequestBuilder.class);
    Queue<BufferedRecord<GenericRecord>> queue = HttpTestUtils.createQueue(1, false);
    AsyncRequest<GenericRecord, RestRequest> request = builder.buildRequest(queue);
    verify(builder).build(requestBuilderArgument.capture());
    RestRequestBuilder expected = new RestRequestBuilder(new URI("http://www.test.com/a/part1:01/a/part2:02?param1=01"));
    expected.setMethod("PUT");
    expected.setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion);
    expected.setHeader(RestConstants.HEADER_RESTLI_REQUEST_METHOD, verb.toLowerCase());
    expected.setHeader(RestConstants.HEADER_CONTENT_TYPE, RestConstants.HEADER_VALUE_APPLICATION_JSON);
    DataMap data = new DataMap();
    data.put("id", "id0");
    expected.setEntity(JACKSON_DATA_CODEC.mapToBytes(data));
    HttpTestUtils.assertEqual(requestBuilderArgument.getValue(), expected);
    Assert.assertEquals(request.getRecordCount(), 1);
    Assert.assertEquals(queue.size(), 0);
}
Also used : RestRequest(com.linkedin.r2.message.rest.RestRequest) R2RestRequestBuilder(org.apache.gobblin.r2.R2RestRequestBuilder) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) R2RestRequestBuilder(org.apache.gobblin.r2.R2RestRequestBuilder) BufferedRecord(org.apache.gobblin.async.BufferedRecord) GenericRecord(org.apache.avro.generic.GenericRecord) URI(java.net.URI) DataMap(com.linkedin.data.DataMap)

Example 2 with R2RestRequestBuilder

use of org.apache.gobblin.r2.R2RestRequestBuilder in project incubator-gobblin by apache.

the class R2RestWriterBuilder method fromConfig.

@Override
public R2RestWriterBuilder fromConfig(Config config) {
    config = config.withFallback(FALLBACK);
    this.client = createClient(config);
    String urlTemplate = config.getString(HttpConstants.URL_TEMPLATE);
    String verb = config.getString(HttpConstants.VERB);
    String protocolVersion = config.getString(HttpConstants.PROTOCOL_VERSION);
    asyncRequestBuilder = new R2RestRequestBuilder(urlTemplate, verb, protocolVersion);
    Set<String> errorCodeWhitelist = HttpUtils.getErrorCodeWhitelist(config);
    responseHandler = new R2RestResponseHandler(errorCodeWhitelist, metricContext);
    return this;
}
Also used : R2RestResponseHandler(org.apache.gobblin.r2.R2RestResponseHandler) R2RestRequestBuilder(org.apache.gobblin.r2.R2RestRequestBuilder)

Aggregations

R2RestRequestBuilder (org.apache.gobblin.r2.R2RestRequestBuilder)2 DataMap (com.linkedin.data.DataMap)1 RestRequest (com.linkedin.r2.message.rest.RestRequest)1 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)1 URI (java.net.URI)1 GenericRecord (org.apache.avro.generic.GenericRecord)1 BufferedRecord (org.apache.gobblin.async.BufferedRecord)1 R2RestResponseHandler (org.apache.gobblin.r2.R2RestResponseHandler)1