use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class TestScatterGather method testScatterGatherLoadBalancerIntegration.
@Test(dataProvider = "requestBuilderDataProvider")
public static void testScatterGatherLoadBalancerIntegration(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.RequestInfo<Greeting>> scatterGatherRequests = buildScatterGatherGetRequests(sg, requestIds);
}
use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class TestScatterGather method testSendSGRequests.
@Test(dataProvider = "requestBuilderDataProvider")
public static void testSendSGRequests(RootBuilderWrapper<Long, Greeting> builders) throws URISyntaxException, InterruptedException, RemoteInvocationException {
final int NUM_ENDPOINTS = 4;
ConsistentHashKeyMapper mapper = getKeyToHostMapper(NUM_ENDPOINTS);
ScatterGatherBuilder<Greeting> sg = new ScatterGatherBuilder<Greeting>(mapper);
final int NUM_IDS = 20;
List<Greeting> entities = generateCreate(NUM_IDS);
Long[] requestIds = prepareData(entities, builders.getRequestOptions());
testSendGetSGRequests(sg, requestIds);
testSendGetKVSGRequests(sg, requestIds);
Map<Long, Greeting> input = generateUpdates(requestIds);
testSendSGUpdateRequests(sg, input, builders);
testSendSGDeleteRequests(sg, requestIds, builders);
}
use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class TestGreetingsClient method testOldCookbookInBatch.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testOldCookbookInBatch(RestliRequestOptions requestOptions) throws Exception {
final GreetingsBuilders builders = new GreetingsBuilders(requestOptions);
// GET
final BatchGetRequestBuilder<Long, Greeting> batchGetBuilder = builders.batchGet();
Request<BatchResponse<Greeting>> request = batchGetBuilder.ids(1L).build();
ResponseFuture<BatchResponse<Greeting>> future = getClient().sendRequest(request);
Response<BatchResponse<Greeting>> greetingResponse = future.getResponse();
// PUT
Greeting greeting = new Greeting(greetingResponse.getEntity().getResults().get("1").data().copy());
greeting.setMessage("This is a new message!");
Request<BatchKVResponse<Long, UpdateStatus>> writeRequest = builders.batchUpdate().input(1L, greeting).build();
getClient().sendRequest(writeRequest).getResponse();
// GET again, to verify that our POST worked.
Request<BatchResponse<Greeting>> request2 = builders.batchGet().ids(1L).build();
ResponseFuture<BatchResponse<Greeting>> future2 = getClient().sendRequest(request2);
greetingResponse = future2.get();
Greeting repeatedGreeting = new Greeting();
repeatedGreeting.setMessage("Hello Hello");
repeatedGreeting.setTone(Tone.SINCERE);
Request<CollectionResponse<CreateStatus>> request3 = builders.batchCreate().inputs(Arrays.asList(repeatedGreeting, repeatedGreeting)).build();
CollectionResponse<CreateStatus> statuses = getClient().sendRequest(request3).getResponse().getEntity();
for (CreateStatus status : statuses.getElements()) {
Assert.assertEquals(status.getStatus().intValue(), HttpStatus.S_201_CREATED.getCode());
@SuppressWarnings("deprecation") String id = status.getId();
Assert.assertNotNull(id);
}
}
use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class TestGreetingsClient method testBatchUpdate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testBatchUpdate(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException, CloneNotSupportedException {
List<Greeting> greetings = generateBatchTestData(3, "BatchUpdate", Tone.FRIENDLY);
@SuppressWarnings("unchecked") List<Long> createdIds = createBatchTestDataSerially(builders, greetings);
addIdsToGeneratedGreetings(createdIds, greetings);
// Update the created greetings
List<Greeting> updatedGreetings = new ArrayList<Greeting>();
Map<Long, Greeting> updateGreetingsRequestMap = new HashMap<Long, Greeting>();
for (Greeting greeting : greetings) {
Greeting updatedGreeting = new Greeting(greeting.data().copy());
updatedGreeting.setMessage(updatedGreeting.getMessage().toUpperCase());
updatedGreeting.setTone(Tone.SINCERE);
updatedGreetings.add(updatedGreeting);
updateGreetingsRequestMap.put(updatedGreeting.getId(), updatedGreeting);
}
// Batch update
Request<BatchKVResponse<Long, UpdateStatus>> batchUpdateRequest = builders.batchUpdate().inputs(updateGreetingsRequestMap).build();
Map<Long, UpdateStatus> results = getClient().sendRequest(batchUpdateRequest).getResponse().getEntity().getResults();
Assert.assertEquals(results.size(), updatedGreetings.size());
for (UpdateStatus status : results.values()) {
Assert.assertEquals(status.getStatus().intValue(), HttpStatus.S_204_NO_CONTENT.getCode());
}
getAndVerifyBatchTestDataSerially(builders, createdIds, updatedGreetings, null);
deleteAndVerifyBatchTestDataSerially(builders, createdIds);
}
use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class TestGreetingsClient method testGetAll.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testGetAll(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
List<Greeting> greetings = generateBatchTestData(3, "GetAll", Tone.FRIENDLY);
@SuppressWarnings("unchecked") List<Long> createdIds = createBatchTestDataSerially(builders, greetings);
addIdsToGeneratedGreetings(createdIds, greetings);
Request<CollectionResponse<Greeting>> getAllRequest = builders.getAll().build();
List<Greeting> getAllReturnedGreetings = getClient().sendRequest(getAllRequest).getResponse().getEntity().getElements();
// the current implementation of getAll should return all those Greetings with the String "GetAll"
// in them. Thus, fetchedGreetings and getAllGreetings should be the same
Assert.assertEquals(getAllReturnedGreetings.size(), greetings.size());
for (int i = 0; i < greetings.size(); i++) {
Greeting getAllReturnedGreeting = getAllReturnedGreetings.get(i);
Greeting greeting = greetings.get(i);
// Make sure the types of the fetched Greeting match the types in the schema. This happens as a side effect of the
// validate method
// This is why we can't do Assert.assertEquals(getAllReturnedGreetings, greetings) directly
ValidateDataAgainstSchema.validate(getAllReturnedGreeting.data(), getAllReturnedGreeting.schema(), new ValidationOptions());
Assert.assertEquals(getAllReturnedGreeting, greeting);
}
deleteAndVerifyBatchTestDataSerially(builders, createdIds);
}
Aggregations