use of com.linkedin.restli.common.CreateIdStatus in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testCreateAndThenBatchDelete.
@Test
public void testCreateAndThenBatchDelete() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
// Create entities first so we don't delete those used by other tests.
CompletionStage<List<CreateIdStatus<Long>>> createResult = greetings.batchCreate(Arrays.asList(getGreeting(), getGreeting()));
CompletionStage<Map<Long, UpdateStatus>> result = createResult.thenCompose(ids -> greetings.batchDelete(Sets.newHashSet(ids.stream().map(CreateIdStatus::getKey).collect(Collectors.toList()))));
CompletableFuture<Map<Long, UpdateStatus>> future = result.toCompletableFuture();
Map<Long, UpdateStatus> ids = future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(ids.size(), 2);
for (UpdateStatus status : ids.values()) {
Assert.assertEquals(status.getStatus().intValue(), 204);
}
}
use of com.linkedin.restli.common.CreateIdStatus in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testCreateAndThenBatchDeleteWithFailures.
@Test
public void testCreateAndThenBatchDeleteWithFailures() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
// Create entities first so we don't delete those used by other tests.
CompletionStage<List<CreateIdStatus<Long>>> createResult = greetings.batchCreate(Arrays.asList(getGreeting(), getGreeting()));
CompletionStage<Map<Long, UpdateStatus>> result = createResult.thenCompose(ids -> {
Set<Long> deleteIds = Sets.newHashSet(ids.stream().map(CreateIdStatus::getKey).collect(Collectors.toList()));
deleteIds.add(-1L);
return greetings.batchDelete(deleteIds);
});
CompletableFuture<Map<Long, UpdateStatus>> future = result.toCompletableFuture();
Map<Long, UpdateStatus> ids = future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(ids.size(), 3);
Assert.assertEquals(ids.remove(-1L).getStatus().intValue(), 404);
for (UpdateStatus status : ids.values()) {
Assert.assertEquals(status.getStatus().intValue(), 204);
}
}
use of com.linkedin.restli.common.CreateIdStatus in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testBatchCreateReturnEntityDisabled.
@Test
public void testBatchCreateReturnEntityDisabled() throws Exception {
CreateGreeting greetings = new CreateGreetingFluentClient(_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.common.CreateIdStatus in project rest.li by linkedin.
the class TestParseqBasedFluentClientApiWithProjections method testGetAllWithFieldProjection.
@Test
public void testGetAllWithFieldProjection() 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").setId(200L), getGreeting("GetAll").setId(201L)));
CompletionStage<CollectionResponse<Greeting>> result = createResult.thenCompose(ids -> greetings.getAll(optionalParams -> optionalParams.withMask(mask -> mask.withMessage())));
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.assertFalse(greeting.hasId());
Assert.assertTrue(greeting.getMessage().contains("GetAll"));
}
}
use of com.linkedin.restli.common.CreateIdStatus in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testSubResource_noPathKey.
/**
* Test {@link com.linkedin.restli.examples.greetings.server.CollectionUnderSimpleResource}
* A complete set of request tests were tested in {@link TestSimpleResourceHierarchy}
*/
@Test
public void testSubResource_noPathKey() throws Exception {
SubgreetingsFluentClient subgreetingsFluentClient = new SubgreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
CompletableFuture<Greeting> future = subgreetingsFluentClient.get(1L).toCompletableFuture();
Greeting greeting = future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertTrue(greeting.hasId());
Assert.assertEquals((Long) 1L, greeting.getId());
List<Long> ids = Arrays.asList(1L, 2L, 3L, 4L);
Map<Long, EntityResponse<Greeting>> response = subgreetingsFluentClient.batchGet(new HashSet<>(ids)).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(response.size(), ids.size());
// Update
String updatedMessage = "updated";
greeting.setMessage(updatedMessage);
CompletionStage<Void> updateStage = subgreetingsFluentClient.update(1L, greeting).thenRun(() -> {
try {
Assert.assertEquals(subgreetingsFluentClient.get(1L).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS), greeting);
} catch (Exception e) {
Assert.fail("Unexpected error");
}
});
updateStage.toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
Assert.assertFalse(updateStage.toCompletableFuture().isCompletedExceptionally());
// Partial update
Greeting update = greeting.copy();
String partialUpdateMessage = "Partial update message";
update.setMessage(partialUpdateMessage);
CompletionStage<Void> partialUpdateResult = subgreetingsFluentClient.partialUpdate(1L, PatchGenerator.diff(greeting, update));
partialUpdateResult.toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(subgreetingsFluentClient.get(1L).toCompletableFuture().get(500, TimeUnit.MILLISECONDS).getMessage(), partialUpdateMessage);
Assert.assertFalse(partialUpdateResult.toCompletableFuture().isCompletedExceptionally());
// create
String msg = Double.toString(Math.random());
CompletionStage<Long> result = subgreetingsFluentClient.create(getGreeting(msg));
CompletableFuture<Long> createFuture = result.toCompletableFuture();
Long createdId = createFuture.get(5000, TimeUnit.MILLISECONDS);
Assert.assertTrue(subgreetingsFluentClient.get(createdId).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS).getMessage().equals(msg));
// batch create
String msg1 = Double.toString(Math.random());
String msg2 = Double.toString(Math.random());
CompletionStage<List<CreateIdStatus<Long>>> batchCreateStage = subgreetingsFluentClient.batchCreate(Arrays.asList(getGreeting(msg1), getGreeting(msg2)));
CompletableFuture<List<CreateIdStatus<Long>>> batchCreateFuture = batchCreateStage.toCompletableFuture();
List<CreateIdStatus<Long>> createdList = batchCreateFuture.get(5000, TimeUnit.MILLISECONDS);
CompletionStage<Map<Long, EntityResponse<Greeting>>> batchGetStage = subgreetingsFluentClient.batchGet(createdList.stream().map(CreateIdStatus::getKey).collect(Collectors.toSet()));
Map<Long, EntityResponse<Greeting>> entities = batchGetStage.toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(entities.size(), 2);
}
Aggregations