use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class TestScatterGather method testScatterGatherKVLoadBalancerIntegration.
@Test(dataProvider = "requestBuilderDataProvider")
public static void testScatterGatherKVLoadBalancerIntegration(RootBuilderWrapper<Long, Greeting> builders) throws Exception {
SimpleLoadBalancer loadBalancer = MockLBFactory.createLoadBalancer();
KeyMapper keyMapper = new ConsistentHashKeyMapper(loadBalancer, new TestPartitionInfoProvider());
try {
keyMapper.mapKeysV2(URI.create("http://badurischeme/"), new HashSet<String>());
Assert.fail("keyMapper should reject non-D2 URI scheme");
} catch (IllegalArgumentException e) {
//expected
}
ScatterGatherBuilder<Greeting> sg = new ScatterGatherBuilder<Greeting>(keyMapper);
final int NUM_IDS = 20;
Long[] requestIds = generateIds(NUM_IDS);
Collection<ScatterGatherBuilder.KVRequestInfo<Long, Greeting>> scatterGatherRequests = buildScatterGatherGetKVRequests(sg, requestIds);
}
use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class TestScatterGather method prepareData.
private static Long[] prepareData(List<Greeting> entities, RestliRequestOptions requestOptions) throws RemoteInvocationException {
GreetingsRequestBuilders builders = new GreetingsRequestBuilders(requestOptions);
BatchCreateIdRequest<Long, Greeting> request = builders.batchCreate().inputs(entities).build();
Response<BatchCreateIdResponse<Long>> response = REST_CLIENT.sendRequest(request).getResponse();
List<CreateIdStatus<Long>> statuses = response.getEntity().getElements();
final Long[] requestIds = new Long[entities.size()];
for (int i = 0; i < statuses.size(); ++i) {
CreateIdStatus<Long> status = statuses.get(i);
Assert.assertFalse(status.hasError());
requestIds[i] = status.getKey();
}
return requestIds;
}
use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class TestScatterGather method generateUpdates.
private static Map<Long, Greeting> generateUpdates(Long[] ids) {
Map<Long, Greeting> updates = new HashMap<Long, Greeting>();
for (long l : ids) {
Greeting greeting = new Greeting();
greeting.setId(l).setMessage("update message").setTone(Tone.SINCERE);
updates.put(l, greeting);
}
return updates;
}
use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class TestMultiplexerIntegration method twoSequentialCalls.
@Test
public void twoSequentialCalls() throws Exception {
GetRequest<Greeting> request1 = new GreetingsCallbackBuilders().get().id(1L).build();
FutureCallback<Response<Greeting>> muxCallback1 = new FutureCallback<Response<Greeting>>();
FutureCallback<Response<Greeting>> directCallback1 = new FutureCallback<Response<Greeting>>();
GetRequest<Greeting> request2 = new GreetingsCallbackBuilders().get().id(2L).build();
FutureCallback<Response<Greeting>> muxCallback2 = new FutureCallback<Response<Greeting>>();
FutureCallback<Response<Greeting>> directCallback2 = new FutureCallback<Response<Greeting>>();
MultiplexedRequest multiplexedRequest = MultiplexedRequestBuilder.createSequentialRequest().addRequest(request1, muxCallback1).addRequest(request2, muxCallback2).build();
getClient().sendRequest(multiplexedRequest);
getClient().sendRequest(request1, directCallback1);
getClient().sendRequest(request2, directCallback2);
assertEqualResponses(muxCallback1, directCallback1);
assertEqualResponses(muxCallback2, directCallback2);
}
use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class TestMultiplexerIntegration method twoSequentialCallsWithOneError.
@Test
public void twoSequentialCallsWithOneError() throws Exception {
GetRequest<Greeting> request1 = new GreetingsCallbackBuilders().get().id(1L).build();
FutureCallback<Response<Greeting>> muxCallback1 = new FutureCallback<Response<Greeting>>();
FutureCallback<Response<Greeting>> directCallback1 = new FutureCallback<Response<Greeting>>();
GetRequest<Greeting> request2 = new GreetingsCallbackBuilders().get().id(Long.MAX_VALUE).build();
FutureCallback<Response<Greeting>> muxCallback2 = new FutureCallback<Response<Greeting>>();
FutureCallback<Response<Greeting>> directCallback2 = new FutureCallback<Response<Greeting>>();
MultiplexedRequest multiplexedRequest = MultiplexedRequestBuilder.createSequentialRequest().addRequest(request1, muxCallback1).addRequest(request2, muxCallback2).build();
getClient().sendRequest(multiplexedRequest);
getClient().sendRequest(request1, directCallback1);
getClient().sendRequest(request2, directCallback2);
assertEqualResponses(muxCallback1, directCallback1);
assertEqualErrors(muxCallback2, directCallback2);
}
Aggregations