use of com.linkedin.restli.examples.greetings.client.GreetingsBuilders 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.examples.greetings.client.GreetingsBuilders 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.examples.greetings.client.GreetingsBuilders in project rest.li by linkedin.
the class TestCompressionServer method clientsCompressedResponsesBuilderDataProvider.
//Returns a combination of all possible request/response compression combinations
@DataProvider(name = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientsCompressedResponsesBuilderDataProvider")
public Object[][] clientsCompressedResponsesBuilderDataProvider() {
// sample compression operation config
String[] compressionOperations = { "*", "action:*", "finder:*", "finder:search", "get, batch_get, get_all", "get, batch_get, get_all, batch_create, batch_update, batch_partial_update" };
int entries = compressionOperations.length;
Object[][] result = new Object[entries * 4][];
int index = entries * 4 - 1;
for (String operation : compressionOperations) {
Map<String, String> clientProperties = new HashMap<String, String>();
clientProperties.put(HttpClientFactory.HTTP_RESPONSE_COMPRESSION_OPERATIONS, operation);
RestClient client = new RestClient(newTransportClient(clientProperties), URI_PREFIX);
result[index--] = new Object[] { client, operation, new RootBuilderWrapper<Long, Greeting>(new GreetingsBuilders()), AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion() };
result[index--] = new Object[] { client, operation, new RootBuilderWrapper<Long, Greeting>(new GreetingsBuilders(TestConstants.FORCE_USE_NEXT_OPTIONS)), AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion() };
result[index--] = new Object[] { client, operation, new RootBuilderWrapper<Long, Greeting>(new GreetingsRequestBuilders()), AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion() };
result[index--] = new Object[] { client, operation, new RootBuilderWrapper<Long, Greeting>(new GreetingsRequestBuilders(TestConstants.FORCE_USE_NEXT_OPTIONS)), AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion() };
}
return result;
}
use of com.linkedin.restli.examples.greetings.client.GreetingsBuilders in project rest.li by linkedin.
the class TestCompressionServer method getOldCookbookBatchGetResult.
private Greeting getOldCookbookBatchGetResult(RestClient client, RestliRequestOptions requestOptions) throws RemoteInvocationException {
Request<BatchResponse<Greeting>> request = new GreetingsBuilders(requestOptions).batchGet().ids(1L).build();
ResponseFuture<BatchResponse<Greeting>> future = client.sendRequest(request);
Response<BatchResponse<Greeting>> greetingResponse = future.getResponse();
checkContentEncodingHeaderIsAbsent(greetingResponse);
return greetingResponse.getEntity().getResults().get("1");
}
use of com.linkedin.restli.examples.greetings.client.GreetingsBuilders in project rest.li by linkedin.
the class TestGreetingClientContentTypes method testCreate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "buildersClientDataDataProvider")
public void testCreate(RestClient restClient, RestliRequestOptions requestOptions) throws RemoteInvocationException {
Greeting greeting = new Greeting();
greeting.setMessage("Hello there!");
greeting.setTone(Tone.FRIENDLY);
final GreetingsBuilders builders = new GreetingsBuilders(requestOptions);
Request<EmptyRecord> createRequest = builders.create().input(greeting).build();
Response<EmptyRecord> response = restClient.sendRequest(createRequest).getResponse();
Assert.assertNull(response.getHeader(RestConstants.HEADER_CONTENT_TYPE));
@SuppressWarnings("unchecked") CreateResponse<Long> createResponse = (CreateResponse<Long>) response.getEntity();
long id = createResponse.getId();
@SuppressWarnings("deprecation") String stringId = response.getId();
Assert.assertEquals(id, Long.parseLong(stringId));
Request<Greeting> getRequest = builders.get().id(id).build();
Response<Greeting> getResponse = restClient.sendRequest(getRequest).getResponse();
Greeting responseGreeting = getResponse.getEntity();
Assert.assertEquals(responseGreeting.getMessage(), greeting.getMessage());
Assert.assertEquals(responseGreeting.getTone(), greeting.getTone());
}
Aggregations