use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testBatchCreate.
@Test
public void testBatchCreate() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
CompletionStage<List<CreateIdStatus<Long>>> result = greetings.batchCreate(Arrays.asList(getGreeting(), getGreeting()));
CompletableFuture<List<CreateIdStatus<Long>>> future = result.toCompletableFuture();
List<CreateIdStatus<Long>> ids = future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(ids.size(), 2);
}
use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testGetAll.
@Test
public void testGetAll() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
// Create some greetings with "GetAll" in message so they will be returned by getAll test method..
CompletionStage<List<CreateIdStatus<Long>>> createResult = greetings.batchCreate(Arrays.asList(getGreeting("GetAll"), getGreeting("GetAll")));
CompletionStage<CollectionResponse<Greeting>> result = createResult.thenCompose(ids -> greetings.getAll());
CompletableFuture<CollectionResponse<Greeting>> future = result.toCompletableFuture();
List<Greeting> greetingList = future.get(5000, TimeUnit.MILLISECONDS).getElements();
Assert.assertTrue(greetingList.size() >= 2);
for (Greeting greeting : greetingList) {
Assert.assertTrue(greeting.getMessage().contains("GetAll"));
}
}
use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testCollectionActionWithException.
@Test(expectedExceptions = { RestLiResponseException.class })
public void testCollectionActionWithException() throws Throwable {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
CompletableFuture<Void> stage = greetings.exceptionTest().toCompletableFuture();
try {
stage.get(5000, TimeUnit.MILLISECONDS);
Assert.fail("expected exception");
} catch (Exception e) {
assert (stage.isCompletedExceptionally());
throw e.getCause();
}
}
use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testBatchUpdate.
@Test
public void testBatchUpdate() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
CompletionStage<List<CreateIdStatus<Long>>> createResult = greetings.batchCreate(Arrays.asList(getGreeting(), getGreeting()));
final Map<Long, Greeting> inputs = new HashMap<>();
CompletionStage<Map<Long, UpdateStatus>> result = createResult.thenCompose(idStatuses -> {
for (CreateIdStatus<Long> idStatus : idStatuses) {
inputs.put(idStatus.getKey(), getGreeting("Batch update test"));
}
return greetings.batchUpdate(inputs);
});
CompletableFuture<Map<Long, UpdateStatus>> future = result.toCompletableFuture();
Map<Long, UpdateStatus> ids = future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(ids.size(), 2);
for (Long id : inputs.keySet()) {
Assert.assertEquals(ids.get(id).getStatus().intValue(), 204);
}
}
use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testBatchGetRequestWithPartialErrors.
@Test
public void testBatchGetRequestWithPartialErrors() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
Set<Long> ids = Sets.newHashSet(Arrays.asList(-1L, -2L, 1L, 2L, 3L));
CompletionStage<Map<Long, EntityResponse<Greeting>>> result = greetings.batchGet(ids);
CompletableFuture<Map<Long, EntityResponse<Greeting>>> future = result.toCompletableFuture();
Map<Long, EntityResponse<Greeting>> resultMap = future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(resultMap.size(), ids.size());
for (Long id : ids) {
EntityResponse<Greeting> g = resultMap.get(id);
Assert.assertNotNull(g);
if (id > 0) {
Assert.assertTrue(g.hasEntry());
Assert.assertEquals(id, g.getEntity().getId());
} else {
Assert.assertTrue(g.hasError());
}
}
}
Aggregations