Search in sources :

Example 51 with Greeting

use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.

the class TestAsyncExceptions method testTask.

@Test(dataProvider = "exceptionProvider")
public void testTask(String key, int expectedStatus) throws RemoteInvocationException {
    AsyncErrorsBuilders builder = new AsyncErrorsBuilders();
    Request<Greeting> request = builder.actionTask().paramId(key).build();
    try {
        getClient().sendRequest(request).getResponse();
        Assert.fail("This request should have failed.");
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getStatus(), expectedStatus);
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) AsyncErrorsBuilders(com.linkedin.restli.examples.greetings.client.AsyncErrorsBuilders) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 52 with Greeting

use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.

the class TestAsyncExceptions method testCallback.

@Test(dataProvider = "exceptionProvider")
public void testCallback(String key, int expectedStatus) throws RemoteInvocationException {
    AsyncErrorsBuilders builder = new AsyncErrorsBuilders();
    Request<Greeting> request = builder.actionCallback().paramId(key).build();
    try {
        getClient().sendRequest(request).getResponse();
        Assert.fail("This request should have failed.");
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getStatus(), expectedStatus);
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) AsyncErrorsBuilders(com.linkedin.restli.examples.greetings.client.AsyncErrorsBuilders) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 53 with Greeting

use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.

the class TestComplexArrayResource method testGet.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testGet(RootBuilderWrapper<ComplexResourceKey<ComplexArray, ComplexArray>, Greeting> builders) throws RemoteInvocationException, CloneNotSupportedException {
    // all array are singletons with single element
    LongArray singleton = new LongArray();
    singleton.add(1L);
    ComplexArray next = new ComplexArray().setArray(singleton);
    ComplexArray key = new ComplexArray().setArray(singleton).setNext(next);
    ComplexArray params = new ComplexArray().setArray(singleton).setNext(next);
    ComplexResourceKey<ComplexArray, ComplexArray> complexKey = new ComplexResourceKey<ComplexArray, ComplexArray>(key, params);
    Request<Greeting> request = builders.get().id(complexKey).build();
    getClient().sendRequest(request).getResponse().getEntity();
}
Also used : LongArray(com.linkedin.data.template.LongArray) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) ComplexArray(com.linkedin.restli.examples.greetings.api.ComplexArray) Test(org.testng.annotations.Test)

Example 54 with Greeting

use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.

the class TestScatterGather method testBuildSGRequests.

public static void testBuildSGRequests(int endPointsNum, int partitionNum, RootBuilderWrapper<Long, Greeting> builders) throws URISyntaxException, RestException, ServiceUnavailableException {
    final int NUM_ENDPOINTS = endPointsNum;
    ConsistentHashKeyMapper mapper;
    if (partitionNum > 0) {
        mapper = getKeyToHostMapper(endPointsNum, partitionNum);
    } else {
        mapper = getKeyToHostMapper(endPointsNum);
    }
    ScatterGatherBuilder<Greeting> sg = new ScatterGatherBuilder<Greeting>(mapper);
    final int NUM_IDS = 100;
    Long[] ids = generateIds(NUM_IDS);
    Map<Long, Greeting> updates = generateUpdates(ids);
    testBuildSGGetRequests(NUM_ENDPOINTS, sg, ids);
    testBuildSGDeleteRequests(NUM_ENDPOINTS, sg, ids, builders);
    testBuildSGUpdateRequests(NUM_ENDPOINTS, sg, updates, builders);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) ConsistentHashKeyMapper(com.linkedin.d2.balancer.util.hashing.ConsistentHashKeyMapper)

Example 55 with Greeting

use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.

the class TestScatterGather method testBuildSGGetKVRequests.

private static void testBuildSGGetKVRequests(int numEndpoints, ScatterGatherBuilder<Greeting> sg, Long[] ids) throws ServiceUnavailableException {
    Collection<ScatterGatherBuilder.KVRequestInfo<Long, Greeting>> requests = buildScatterGatherGetKVRequests(sg, ids);
    Assert.assertEquals(requests.size(), numEndpoints);
    Set<Set<String>> requestIdSets = new HashSet<Set<String>>();
    Set<Long> requestIds = new HashSet<Long>();
    for (ScatterGatherBuilder.KVRequestInfo<Long, Greeting> requestInfo : requests) {
        //URI will be something like "greetings/?ids=21&ids=4&ids=53&ids=60&ids=66&ids=88&ids=93&foo=bar"
        BatchRequest<BatchKVResponse<Long, Greeting>> request = requestInfo.getRequest();
        Set<String> expectedParams = new HashSet<String>();
        expectedParams.add(RestConstants.QUERY_BATCH_IDS_PARAM);
        expectedParams.add("foo");
        expectedParams.add(RestConstants.FIELDS_PARAM);
        Set<PathSpec> expectedFields = Collections.singleton(new PathSpec("message"));
        testRequest(request, expectedParams, expectedFields, null, requestIdSets, requestIds);
    }
    Assert.assertTrue(requestIds.containsAll(Arrays.asList(ids)));
    Assert.assertEquals(requestIds.size(), ids.length);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) Set(java.util.Set) HashSet(java.util.HashSet) PathSpec(com.linkedin.data.schema.PathSpec) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) HashSet(java.util.HashSet)

Aggregations

Greeting (com.linkedin.restli.examples.greetings.api.Greeting)250 Test (org.testng.annotations.Test)195 CollectionResponse (com.linkedin.restli.common.CollectionResponse)59 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)33 EmptyRecord (com.linkedin.restli.common.EmptyRecord)33 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)20 CustomLong (com.linkedin.restli.examples.custom.types.CustomLong)20 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)18 BatchCreateIdResponse (com.linkedin.restli.common.BatchCreateIdResponse)12 EntityResponse (com.linkedin.restli.common.EntityResponse)12 BatchResponse (com.linkedin.restli.common.BatchResponse)11 RestLiIntegrationTest (com.linkedin.restli.examples.RestLiIntegrationTest)11 IdResponse (com.linkedin.restli.common.IdResponse)10 GreetingsRequestBuilders (com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders)10 GreetingsBuilders (com.linkedin.restli.examples.greetings.client.GreetingsBuilders)9 ConsistentHashKeyMapper (com.linkedin.d2.balancer.util.hashing.ConsistentHashKeyMapper)8 Response (com.linkedin.restli.client.Response)8 CreateIdStatus (com.linkedin.restli.common.CreateIdStatus)8 ErrorResponse (com.linkedin.restli.common.ErrorResponse)8