use of com.linkedin.restli.client.ActionRequestBuilder in project rest.li by linkedin.
the class TestAllPartitionsRequestBuilder method testSendAllPartitionsRequests.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "restliRequestOptions")
public void testSendAllPartitionsRequests(RestliRequestOptions options, RingFactory<URI> ringFactory) throws ServiceUnavailableException, URISyntaxException, RestException, InterruptedException {
final int PARTITION_NUM = 5;
List<URI> expectedUris = new ArrayList<URI>();
ConsistentHashKeyMapper mapper = getKeyToHostMapper(PARTITION_NUM, expectedUris, ringFactory);
AllPartitionsRequestBuilder<Greeting> searchRB = new AllPartitionsRequestBuilder<Greeting>(mapper);
ActionRequestBuilder<Long, Greeting> builder = new ActionRequestBuilder<Long, Greeting>(TEST_URI, Greeting.class, _COLL_SPEC, options);
ActionRequest<Greeting> request = builder.name("updateTone").id(1L).setParam(new FieldDef<Tone>("newTone", Tone.class, DataTemplateUtil.getSchema(Tone.class)), Tone.FRIENDLY).build();
final Map<String, Greeting> results = new ConcurrentHashMap<String, Greeting>();
final CountDownLatch latch = new CountDownLatch(PARTITION_NUM);
final List<Throwable> errors = new ArrayList<Throwable>();
final List<Greeting> responses = new ArrayList<Greeting>();
Callback<Response<Greeting>> cb = new Callback<Response<Greeting>>() {
@Override
public void onError(Throwable e) {
synchronized (errors) {
errors.add(e);
}
latch.countDown();
}
@Override
public void onSuccess(Response<Greeting> response) {
results.put(response.getEntity().toString(), response.getEntity());
synchronized (responses) {
responses.add(response.getEntity());
}
latch.countDown();
}
};
HostSet hostsResult = searchRB.sendRequests(getClient(), request, new RequestContext(), cb);
List<URI> uris = hostsResult.getAllHosts();
Assert.assertTrue(uris.containsAll(expectedUris));
Assert.assertTrue(expectedUris.containsAll(uris));
latch.await();
if (!errors.isEmpty()) {
Assert.fail("I knew it: " + errors.toString());
}
Assert.assertEquals(PARTITION_NUM, responses.size());
}
use of com.linkedin.restli.client.ActionRequestBuilder in project rest.li by linkedin.
the class ExampleRequestResponseGenerator method buildActionRequest.
@SuppressWarnings("unchecked")
private ActionRequest<?> buildActionRequest(ActionSchema action, ResourceLevel resourceLevel) {
DynamicRecordMetadata requestParamsMetadata = _resourceSpec.getRequestMetadata(action.getName());
DynamicRecordMetadata responseMetadata = _resourceSpec.getActionResponseMetadata(action.getName());
TypeSpec<RecordTemplatePlaceholder> responseType = null;
if (responseMetadata != null) {
FieldDef<?> fieldDef = responseMetadata.getFieldDef("value");
if (fieldDef != null && fieldDef.getDataClass() != null) {
responseType = new TypeSpec<RecordTemplatePlaceholder>((Class<RecordTemplatePlaceholder>) fieldDef.getDataClass(), responseMetadata.getRecordDataSchema());
}
}
ActionRequestBuilder<Object, RecordTemplatePlaceholder> request = new ActionRequestBuilder<Object, RecordTemplatePlaceholder>(_uriTemplate, responseType, _resourceSpec, _requestOptions);
request.name(action.getName());
if (resourceLevel == ResourceLevel.ENTITY && !_resourceSpec.isKeylessResource()) {
request.id(generateKey());
}
if (requestParamsMetadata != null) {
addParams(request, requestParamsMetadata, action.getParameters());
}
addPathKeys(request);
return request.build();
}
Aggregations