use of com.linkedin.restli.common.BatchResponse in project rest.li by linkedin.
the class TestBatchUpdateResponseBuilder method testBuilder.
@Test(dataProvider = "testData")
@SuppressWarnings("unchecked")
public void testBuilder(Object results, ProtocolVersion protocolVersion, String altKeyName, Map<String, AlternativeKey<?, ?>> alternativeKeyMap, Map<String, UpdateStatus> expectedResults, Map<String, ErrorResponse> expectedErrors) {
ResourceContext mockContext = getMockResourceContext(protocolVersion, altKeyName);
ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor(alternativeKeyMap);
RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
Map<String, String> headers = ResponseBuilderUtil.getHeaders();
BatchUpdateResponseBuilder batchUpdateResponseBuilder = new BatchUpdateResponseBuilder(new ErrorResponseBuilder());
RestLiResponseData responseData = batchUpdateResponseBuilder.buildRestLiResponseData(null, routingResult, results, headers, Collections.<HttpCookie>emptyList());
PartialRestResponse restResponse = batchUpdateResponseBuilder.buildResponse(routingResult, responseData);
BatchResponse<UpdateStatus> batchResponse = (BatchResponse<UpdateStatus>) restResponse.getEntity();
EasyMock.verify(mockContext, mockDescriptor);
ResponseBuilderUtil.validateHeaders(restResponse, headers);
Assert.assertEquals(batchResponse.getResults(), expectedResults);
Assert.assertEquals(batchResponse.getErrors().size(), expectedErrors.size());
for (Map.Entry<String, ErrorResponse> entry : batchResponse.getErrors().entrySet()) {
String key = entry.getKey();
ErrorResponse value = entry.getValue();
Assert.assertEquals(value.getStatus(), expectedErrors.get(key).getStatus());
}
}
use of com.linkedin.restli.common.BatchResponse in project rest.li by linkedin.
the class TestResponseCompression method testAcceptEncodingConfiguration.
@Test(dataProvider = "encodingsData")
public void testAcceptEncodingConfiguration(String responseContentEncodings, String expectedAcceptEncoding, String expectedContentEncoding) throws RemoteInvocationException {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(HttpClientFactory.HTTP_RESPONSE_CONTENT_ENCODINGS, responseContentEncodings);
properties.put(HttpClientFactory.HTTP_USE_RESPONSE_COMPRESSION, "true");
Client client = newTransportClient(properties);
Long[] ids = new Long[100];
for (int i = 0; i < ids.length; i++) {
ids[i] = (long) i;
}
Request<BatchResponse<Greeting>> request = new GreetingsBuilders().batchGet().ids(Arrays.asList(ids)).setHeader(EXPECTED_ACCEPT_ENCODING, expectedAcceptEncoding).build();
RestClient restClient = new RestClient(client, FILTERS_URI_PREFIX);
Response<BatchResponse<Greeting>> response = restClient.sendRequest(request).getResponse();
Assert.assertEquals(response.getHeader(TestCompressionServer.CONTENT_ENCODING_SAVED), expectedContentEncoding);
}
use of com.linkedin.restli.common.BatchResponse in project rest.li by linkedin.
the class TestResponseCompression method testResponseCompression.
@Test(dataProvider = "requestData")
public void testResponseCompression(Boolean useResponseCompression, CompressionConfig responseCompressionConfig, RestliRequestOptions restliRequestOptions, int idCount, String expectedAcceptEncoding, String expectedCompressionThreshold, boolean responseShouldBeCompressed) throws RemoteInvocationException, CloneNotSupportedException {
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("R2 Netty Scheduler"));
Map<String, CompressionConfig> responseCompressionConfigs = new HashMap<String, CompressionConfig>();
if (responseCompressionConfig != null) {
responseCompressionConfigs.put(SERVICE_NAME, responseCompressionConfig);
}
HttpClientFactory httpClientFactory = new HttpClientFactory(FilterChains.empty(), new NioEventLoopGroup(0, /* use default settings */
new NamedThreadFactory("R2 Nio Event Loop")), true, executor, true, executor, false, AbstractJmxManager.NULL_JMX_MANAGER, Integer.MAX_VALUE, Collections.<String, CompressionConfig>emptyMap(), responseCompressionConfigs, true);
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(HttpClientFactory.HTTP_SERVICE_NAME, SERVICE_NAME);
if (useResponseCompression != null) {
properties.put(HttpClientFactory.HTTP_USE_RESPONSE_COMPRESSION, String.valueOf(useResponseCompression));
}
TransportClientAdapter clientAdapter1 = new TransportClientAdapter(httpClientFactory.getClient(properties));
RestClient client = new RestClient(clientAdapter1, FILTERS_URI_PREFIX);
Long[] ids = new Long[idCount];
for (int i = 0; i < ids.length; i++) {
ids[i] = (long) i;
}
BatchGetRequestBuilder<Long, Greeting> builder = new GreetingsBuilders(restliRequestOptions).batchGet().ids(Arrays.asList(ids)).setHeader(EXPECTED_ACCEPT_ENCODING, expectedAcceptEncoding);
if (expectedCompressionThreshold != null) {
builder.setHeader(EXPECTED_COMPRESSION_THRESHOLD, expectedCompressionThreshold);
}
Request<BatchResponse<Greeting>> request = builder.build();
Response<BatchResponse<Greeting>> response = client.sendRequest(request).getResponse();
if (responseShouldBeCompressed) {
Assert.assertEquals(response.getHeader(TestCompressionServer.CONTENT_ENCODING_SAVED), EncodingType.GZIP.getHttpName());
} else {
Assert.assertNull(response.getHeader(TestCompressionServer.CONTENT_ENCODING_SAVED));
}
}
use of com.linkedin.restli.common.BatchResponse in project rest.li by linkedin.
the class TestRestLiValidation method testBatchGet.
@Test
public void testBatchGet() throws RemoteInvocationException {
BatchGetRequest<ValidationDemo> request = new ValidationDemosBuilders().batchGet().ids(1, 2, 3).build();
Response<BatchResponse<ValidationDemo>> response = _restClientManual.sendRequest(request).getResponse();
Assert.assertEquals(response.getStatus(), HttpStatus.S_200_OK.getCode());
BatchGetEntityRequest<Integer, ValidationDemo> request2 = new ValidationDemosRequestBuilders().batchGet().ids(1, 2, 3).build();
Response<BatchKVResponse<Integer, EntityResponse<ValidationDemo>>> response2 = _restClientManual.sendRequest(request2).getResponse();
Assert.assertEquals(response2.getStatus(), HttpStatus.S_200_OK.getCode());
}
use of com.linkedin.restli.common.BatchResponse in project rest.li by linkedin.
the class TestTyperefKeysResource method testBatchGet.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testBatchGet(RestliRequestOptions requestOptions) throws RemoteInvocationException {
BatchGetRequest<Greeting> req = new TyperefKeysBuilders(requestOptions).batchGet().ids(1L, 2L).build();
Response<BatchResponse<Greeting>> resp = getClient().sendRequest(req).getResponse();
Map<String, Greeting> results = resp.getEntity().getResults();
Assert.assertEquals(results.get("1").getId(), new Long(1L));
Assert.assertEquals(results.get("2").getId(), new Long(2L));
}
Aggregations