use of com.linkedin.restli.common.IdEntityResponse in project rest.li by linkedin.
the class TestLatencyInstrumentation method makeUpstreamRequest.
/**
* Make the "upstream" request (as opposed to the "downstream" request made from the resource method) using a set of
* test parameters. Waits for the timing keys to be recorded by the {@link InstrumentationTrackingFilter} before
* returning.
* @param useStreaming parameter from the test method
* @param forceException parameter from the test method
*/
private void makeUpstreamRequest(boolean useStreaming, boolean forceException, boolean useScatterGather) throws RemoteInvocationException, InterruptedException {
InstrumentationControl instrumentationControl = new InstrumentationControl().setServiceUriPrefix(FILTERS_URI_PREFIX).setUseStreaming(useStreaming).setForceException(forceException).setUseScatterGather(useScatterGather);
CreateIdEntityRequest<Long, InstrumentationControl> createRequest = new LatencyInstrumentationBuilders().createAndGet().input(instrumentationControl).build();
ResponseFuture<IdEntityResponse<Long, InstrumentationControl>> response = getClient().sendRequest(createRequest);
try {
response.getResponseEntity();
if (forceException) {
Assert.fail("Forcing exception, should've failed.");
}
} catch (RestLiResponseException e) {
if (e.getStatus() != 400) {
Assert.fail("Server responded with a non-400 error: " + e.getServiceErrorStackTrace());
}
if (!forceException) {
Assert.fail("Not forcing exception, didn't expect failure.");
}
}
// Wait for the server to send the response and save the timings
final boolean success = _countDownLatch.await(10, TimeUnit.SECONDS);
if (!success) {
Assert.fail("Request timed out!");
}
}
use of com.linkedin.restli.common.IdEntityResponse in project rest.li by linkedin.
the class TestParseqBasedFluentClientApiWithProjections method testCreateAndGetWithProjection.
@Test
public void testCreateAndGetWithProjection() throws Exception {
CreateGreeting greetings = new CreateGreetingFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
String msg = Double.toString(Math.random());
CompletionStage<IdEntityResponse<Long, Greeting>> result = greetings.createAndGet(getGreeting(msg), optionalParams -> optionalParams.withMask(mask -> mask.withMessage()));
CompletableFuture<IdEntityResponse<Long, Greeting>> future = result.toCompletableFuture();
Assert.assertNotNull(future.get(5000, TimeUnit.MILLISECONDS));
Assert.assertFalse(future.get().getEntity().hasId());
Assert.assertFalse(future.get().getEntity().hasTone());
Assert.assertEquals(msg, future.get().getEntity().getMessage());
}
use of com.linkedin.restli.common.IdEntityResponse in project rest.li by linkedin.
the class TestRestLiValidationWithProjection method provideProjectionWithValidFieldsBuilders.
@DataProvider
private Object[][] provideProjectionWithValidFieldsBuilders() throws DataProcessingException {
List<PathSpec> spec = Arrays.asList(ValidationDemo.fields().stringB(), ValidationDemo.fields().includedB(), ValidationDemo.fields().UnionFieldWithInlineRecord().MyRecord().foo2(), // Add a wildcard for projecting the rest of the union members
new PathSpec(ValidationDemo.fields().UnionFieldWithInlineRecord().getPathComponents(), PathSpec.WILDCARD), ValidationDemo.fields().ArrayWithInlineRecord().items().bar1(), ValidationDemo.fields().MapWithTyperefs().values().id(), ValidationDemo.fields().validationDemoNext().intB());
RootBuilderWrapper<Integer, ValidationDemo> wrapper = new RootBuilderWrapper<>(new AutoValidationWithProjectionBuilders());
Request<CollectionResponse<ValidationDemo>> findRequest = wrapper.findBy("searchWithProjection").fields(spec.toArray(new PathSpec[spec.size()])).build();
Request<ValidationDemo> getRequest = wrapper.get().id(1).fields(spec.toArray(new PathSpec[spec.size()])).build();
Request<ValidationDemo> getRequestWithArrayRange = wrapper.get().id(1).fields(ValidationDemo.fields().ArrayWithInlineRecord(10, 20)).build();
Request<CollectionResponse<ValidationDemo>> getAllRequest = wrapper.getAll().fields(spec.toArray(new PathSpec[spec.size()])).build();
// Valid input for CreateAndGet
ValidationDemo.UnionFieldWithInlineRecord unionField = new ValidationDemo.UnionFieldWithInlineRecord();
unionField.setMyEnum(myEnum.FOOFOO);
ValidationDemo validDemo = new ValidationDemo().setStringB("b").setUnionFieldWithInlineRecord(unionField);
Request<IdEntityResponse<Integer, ValidationDemo>> createAndGetRequest = wrapper.createAndGet().input(validDemo).fields(spec.toArray(new PathSpec[spec.size()])).build();
Request<BatchCreateIdEntityResponse<Integer, ValidationDemo>> batchCreateAndGetRequest = wrapper.batchCreateAndGet().inputs(Arrays.asList(validDemo)).fields(spec.toArray(new PathSpec[spec.size()])).build();
return new Object[][] { { findRequest, HttpStatus.S_200_OK }, { getRequest, HttpStatus.S_200_OK }, { getRequestWithArrayRange, HttpStatus.S_200_OK }, { getAllRequest, HttpStatus.S_200_OK }, { createAndGetRequest, HttpStatus.S_201_CREATED }, { batchCreateAndGetRequest, HttpStatus.S_200_OK } };
}
use of com.linkedin.restli.common.IdEntityResponse in project rest.li by linkedin.
the class TestReturnEntityWithCreate method testEntityWithProjection.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "newBuildersClientDataDataProvider")
public void testEntityWithProjection(RestClient restClient, String expectedContentType, CreateGreetingRequestBuilders builders) throws RemoteInvocationException {
Greeting greeting = new Greeting();
greeting.setMessage("second time!");
greeting.setTone(Tone.FRIENDLY);
CreateIdEntityRequest<Long, Greeting> createIdEntityRequest = builders.createAndGet().fields(Greeting.fields().tone(), Greeting.fields().id()).input(greeting).build();
Response<IdEntityResponse<Long, Greeting>> response = restClient.sendRequest(createIdEntityRequest).getResponse();
long id = response.getEntity().getId();
@SuppressWarnings("deprecation") String stringId = response.getId();
Assert.assertEquals(response.getHeader(RestConstants.HEADER_CONTENT_TYPE), expectedContentType);
Assert.assertEquals(response.getHeader(RestConstants.HEADER_LOCATION), "/" + builders.getPrimaryResource() + "/" + id);
Assert.assertEquals(id, Long.parseLong(stringId));
Assert.assertEquals(false, response.getEntity().getEntity().hasMessage());
Assert.assertEquals(Tone.FRIENDLY, response.getEntity().getEntity().getTone());
}
Aggregations