Search in sources :

Example 6 with BatchKVResponse

use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.

the class TestComplexKeysResource method testBatchDeleteMain.

private void testBatchDeleteMain(RootBuilderWrapper.MethodBuilderWrapper<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message, BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus>> requestBuilder, RootBuilderWrapper.MethodBuilderWrapper<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message, EmptyRecord> createRequestBuilder, BatchGetEntityRequestBuilder<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchGetRequestBuilder) throws RemoteInvocationException {
    String messageText = "m1";
    Message message = new Message();
    message.setMessage(messageText);
    Request<EmptyRecord> createRequest = createRequestBuilder.input(message).build();
    ResponseFuture<EmptyRecord> createFuture = getClient().sendRequest(createRequest);
    Response<EmptyRecord> createResponse = createFuture.getResponse();
    Assert.assertEquals(createResponse.getStatus(), 201);
    String messageText2 = "m2";
    message.setMessage(messageText2);
    createRequest = createRequestBuilder.input(message).build();
    createFuture = getClient().sendRequest(createRequest);
    createResponse = createFuture.getResponse();
    Assert.assertEquals(createResponse.getStatus(), 201);
    ComplexResourceKey<TwoPartKey, TwoPartKey> key1 = getComplexKey(messageText, messageText);
    ComplexResourceKey<TwoPartKey, TwoPartKey> key2 = getComplexKey(messageText2, messageText2);
    ArrayList<ComplexResourceKey<TwoPartKey, TwoPartKey>> ids = new ArrayList<ComplexResourceKey<TwoPartKey, TwoPartKey>>();
    ids.add(key1);
    ids.add(key2);
    final Request<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus>> request = requestBuilder.ids(ids).build();
    final ResponseFuture<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus>> future = getClient().sendRequest(request);
    final BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus> response = future.getResponse().getEntity();
    for (Map.Entry<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus> resp : response.getResults().entrySet()) {
        Assert.assertEquals(resp.getValue().getStatus().intValue(), 204);
    }
    Assert.assertNotNull(response.getResults().get(key1));
    Assert.assertNotNull(response.getResults().get(key2));
    Request<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>>> batchGetRequest = batchGetRequestBuilder.ids(ids).build();
    ResponseFuture<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>>> batchGetFuture = getClient().sendRequest(batchGetRequest);
    BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>> batchGetResponse = batchGetFuture.getResponse().getEntity();
    Assert.assertEquals(batchGetResponse.getResults().size(), batchGetResponse.getErrors().size());
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) EmptyRecord(com.linkedin.restli.common.EmptyRecord) UpdateStatus(com.linkedin.restli.common.UpdateStatus) Message(com.linkedin.restli.examples.greetings.api.Message) ArrayList(java.util.ArrayList) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) EntityResponse(com.linkedin.restli.common.EntityResponse) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Map(java.util.Map) HashMap(java.util.HashMap) DataMap(com.linkedin.data.DataMap)

Example 7 with BatchKVResponse

use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.

the class TestComplexKeysResource method testBatchPartialUpdateMain.

private void testBatchPartialUpdateMain(RootBuilderWrapper.MethodBuilderWrapper<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message, BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus>> requestBuilder, BatchGetEntityRequestBuilder<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchGetRequestBuilder) throws RemoteInvocationException {
    Message message = new Message();
    message.setTone(Tone.FRIENDLY);
    PatchRequest<Message> patch = PatchGenerator.diffEmpty(message);
    final Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, PatchRequest<Message>> inputs = new HashMap<ComplexResourceKey<TwoPartKey, TwoPartKey>, PatchRequest<Message>>();
    ComplexResourceKey<TwoPartKey, TwoPartKey> key1 = getComplexKey(StringTestKeys.SIMPLEKEY, StringTestKeys.SIMPLEKEY2);
    ComplexResourceKey<TwoPartKey, TwoPartKey> key2 = getComplexKey(StringTestKeys.URL, StringTestKeys.URL2);
    inputs.put(key1, patch);
    inputs.put(key2, patch);
    final Request<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus>> request = requestBuilder.patchInputs(inputs).build();
    final ResponseFuture<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus>> future = getClient().sendRequest(request);
    final BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus> response = future.getResponse().getEntity();
    for (Map.Entry<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus> resp : response.getResults().entrySet()) {
        Assert.assertTrue(inputs.containsKey(resp.getKey()));
        Assert.assertEquals(resp.getValue().getStatus().intValue(), 204);
    }
    Assert.assertNotNull(response.getResults().get(key1));
    Assert.assertNotNull(response.getResults().get(key2));
    Assert.assertTrue(response.getErrors().isEmpty());
    ArrayList<ComplexResourceKey<TwoPartKey, TwoPartKey>> ids = new ArrayList<ComplexResourceKey<TwoPartKey, TwoPartKey>>();
    ids.add(key1);
    ids.add(key2);
    Request<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>>> batchGetRequest = batchGetRequestBuilder.ids(ids).build();
    ResponseFuture<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>>> batchGetFuture = getClient().sendRequest(batchGetRequest);
    BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>> batchGetResponse = batchGetFuture.getResponse().getEntity();
    Assert.assertEquals(batchGetResponse.getResults().get(key1).getEntity().getTone(), Tone.FRIENDLY);
    Assert.assertEquals(batchGetResponse.getResults().get(key2).getEntity().getTone(), Tone.FRIENDLY);
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) UpdateStatus(com.linkedin.restli.common.UpdateStatus) Message(com.linkedin.restli.examples.greetings.api.Message) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PatchRequest(com.linkedin.restli.common.PatchRequest) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) EntityResponse(com.linkedin.restli.common.EntityResponse) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Map(java.util.Map) HashMap(java.util.HashMap) DataMap(com.linkedin.data.DataMap)

Example 8 with BatchKVResponse

use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.

the class TestGreetingClientContentTypes method testBatchGetEntity.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientDataBatchDataProvider")
public void testBatchGetEntity(RestClient restClient, RestliRequestOptions requestOptions) throws RemoteInvocationException {
    List<Long> ids = Arrays.asList(1L, 2L, 3L, 4L);
    Request<BatchKVResponse<Long, EntityResponse<Greeting>>> request = new GreetingsRequestBuilders(requestOptions).batchGet().ids(ids).build();
    Response<BatchKVResponse<Long, EntityResponse<Greeting>>> response = restClient.sendRequest(request).getResponse();
    BatchKVResponse<Long, EntityResponse<Greeting>> batchResponse = response.getEntity();
    Assert.assertEquals(batchResponse.getResults().size(), ids.size());
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EntityResponse(com.linkedin.restli.common.EntityResponse) GreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) Test(org.testng.annotations.Test)

Example 9 with BatchKVResponse

use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.

the class TestCustomTypesClient method testBatchUpdate.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "request3BuilderDataProvider")
public void testBatchUpdate(RootBuilderWrapper<CompoundKey, Greeting> builders) throws RemoteInvocationException {
    Long lo = 5L;
    Long date = 13L;
    CustomTypes3Builders.Key key = new CustomTypes3Builders.Key().setLongId(new CustomLong(lo)).setDateId(new Date(date));
    RequestBuilder<? extends Request<BatchKVResponse<CompoundKey, UpdateStatus>>> batchUpdateRequest = builders.batchUpdate().input(key, new Greeting().setId(1).setMessage("foo")).getBuilder();
    BatchKVResponse<CompoundKey, UpdateStatus> response = getClient().sendRequest(batchUpdateRequest).getResponse().getEntity();
    Assert.assertEquals(response.getResults().keySet().size(), 1);
    CompoundKey expected = new CompoundKey();
    expected.append("dateId", new Date(date));
    expected.append("longId", new CustomLong(lo));
    Assert.assertEquals(response.getResults().keySet().iterator().next(), expected);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CustomTypes3Builders(com.linkedin.restli.examples.greetings.client.CustomTypes3Builders) UpdateStatus(com.linkedin.restli.common.UpdateStatus) CompoundKey(com.linkedin.restli.common.CompoundKey) CustomNonNegativeLong(com.linkedin.restli.examples.custom.types.CustomNonNegativeLong) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) CompoundKey(com.linkedin.restli.common.CompoundKey) Date(java.util.Date) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) Test(org.testng.annotations.Test)

Example 10 with BatchKVResponse

use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.

the class TestCustomTypesClient method testCollectionBatchGetEntity.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testCollectionBatchGetEntity(RestliRequestOptions requestOptions) throws RemoteInvocationException {
    Request<BatchKVResponse<CustomLong, EntityResponse<Greeting>>> request = new CustomTypes2RequestBuilders(requestOptions).batchGet().ids(new CustomLong(1L), new CustomLong(2L), new CustomLong(3L)).build();
    Map<CustomLong, EntityResponse<Greeting>> greetings = getClient().sendRequest(request).getResponse().getEntity().getResults();
    Assert.assertEquals(greetings.size(), 3);
    Assert.assertEquals(greetings.get(new CustomLong(1L)).getEntity().getId().longValue(), 1L);
    Assert.assertEquals(greetings.get(new CustomLong(2L)).getEntity().getId().longValue(), 2L);
    Assert.assertEquals(greetings.get(new CustomLong(3L)).getEntity().getId().longValue(), 3L);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EntityResponse(com.linkedin.restli.common.EntityResponse) CustomTypes2RequestBuilders(com.linkedin.restli.examples.greetings.client.CustomTypes2RequestBuilders) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) Test(org.testng.annotations.Test)

Aggregations

BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)57 Test (org.testng.annotations.Test)40 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)31 EntityResponse (com.linkedin.restli.common.EntityResponse)18 UpdateStatus (com.linkedin.restli.common.UpdateStatus)15 HashSet (java.util.HashSet)13 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)11 Message (com.linkedin.restli.examples.greetings.api.Message)11 ArrayList (java.util.ArrayList)11 CompoundKey (com.linkedin.restli.common.CompoundKey)10 DataMap (com.linkedin.data.DataMap)8 HashMap (java.util.HashMap)8 CustomLong (com.linkedin.restli.examples.custom.types.CustomLong)7 TwoPartKey (com.linkedin.restli.examples.greetings.api.TwoPartKey)6 BatchCreateIdResponse (com.linkedin.restli.common.BatchCreateIdResponse)5 BatchResponse (com.linkedin.restli.common.BatchResponse)5 CollectionResponse (com.linkedin.restli.common.CollectionResponse)5 PatchRequest (com.linkedin.restli.common.PatchRequest)4 GreetingsRequestBuilders (com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders)4 RequestContext (com.linkedin.r2.message.RequestContext)3