Search in sources :

Example 56 with Greeting

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

the class TestScatterGather method testScatterGatherKVLoadBalancerIntegration.

@Test(dataProvider = "requestBuilderDataProvider")
public static void testScatterGatherKVLoadBalancerIntegration(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.KVRequestInfo<Long, Greeting>> scatterGatherRequests = buildScatterGatherGetKVRequests(sg, requestIds);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) SimpleLoadBalancer(com.linkedin.d2.balancer.simple.SimpleLoadBalancer) HostToKeyMapper(com.linkedin.d2.balancer.util.HostToKeyMapper) KeyMapper(com.linkedin.d2.balancer.KeyMapper) ConsistentHashKeyMapper(com.linkedin.d2.balancer.util.hashing.ConsistentHashKeyMapper) ConsistentHashKeyMapper(com.linkedin.d2.balancer.util.hashing.ConsistentHashKeyMapper) Test(org.testng.annotations.Test) RestLiIntegrationTest(com.linkedin.restli.examples.RestLiIntegrationTest)

Example 57 with Greeting

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

the class TestScatterGather method prepareData.

private static Long[] prepareData(List<Greeting> entities, RestliRequestOptions requestOptions) throws RemoteInvocationException {
    GreetingsRequestBuilders builders = new GreetingsRequestBuilders(requestOptions);
    BatchCreateIdRequest<Long, Greeting> request = builders.batchCreate().inputs(entities).build();
    Response<BatchCreateIdResponse<Long>> response = REST_CLIENT.sendRequest(request).getResponse();
    List<CreateIdStatus<Long>> statuses = response.getEntity().getElements();
    final Long[] requestIds = new Long[entities.size()];
    for (int i = 0; i < statuses.size(); ++i) {
        CreateIdStatus<Long> status = statuses.get(i);
        Assert.assertFalse(status.hasError());
        requestIds[i] = status.getKey();
    }
    return requestIds;
}
Also used : BatchCreateIdResponse(com.linkedin.restli.common.BatchCreateIdResponse) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CreateIdStatus(com.linkedin.restli.common.CreateIdStatus) GreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders)

Example 58 with Greeting

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

the class TestScatterGather method generateUpdates.

private static Map<Long, Greeting> generateUpdates(Long[] ids) {
    Map<Long, Greeting> updates = new HashMap<Long, Greeting>();
    for (long l : ids) {
        Greeting greeting = new Greeting();
        greeting.setId(l).setMessage("update message").setTone(Tone.SINCERE);
        updates.put(l, greeting);
    }
    return updates;
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 59 with Greeting

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

the class TestMultiplexerIntegration method twoSequentialCalls.

@Test
public void twoSequentialCalls() throws Exception {
    GetRequest<Greeting> request1 = new GreetingsCallbackBuilders().get().id(1L).build();
    FutureCallback<Response<Greeting>> muxCallback1 = new FutureCallback<Response<Greeting>>();
    FutureCallback<Response<Greeting>> directCallback1 = new FutureCallback<Response<Greeting>>();
    GetRequest<Greeting> request2 = new GreetingsCallbackBuilders().get().id(2L).build();
    FutureCallback<Response<Greeting>> muxCallback2 = new FutureCallback<Response<Greeting>>();
    FutureCallback<Response<Greeting>> directCallback2 = new FutureCallback<Response<Greeting>>();
    MultiplexedRequest multiplexedRequest = MultiplexedRequestBuilder.createSequentialRequest().addRequest(request1, muxCallback1).addRequest(request2, muxCallback2).build();
    getClient().sendRequest(multiplexedRequest);
    getClient().sendRequest(request1, directCallback1);
    getClient().sendRequest(request2, directCallback2);
    assertEqualResponses(muxCallback1, directCallback1);
    assertEqualResponses(muxCallback2, directCallback2);
}
Also used : Response(com.linkedin.restli.client.Response) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) FutureCallback(com.linkedin.common.callback.FutureCallback) GreetingsCallbackBuilders(com.linkedin.restli.examples.greetings.client.GreetingsCallbackBuilders) RestLiIntegrationTest(com.linkedin.restli.examples.RestLiIntegrationTest) Test(org.testng.annotations.Test)

Example 60 with Greeting

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

the class TestMultiplexerIntegration method twoSequentialCallsWithOneError.

@Test
public void twoSequentialCallsWithOneError() throws Exception {
    GetRequest<Greeting> request1 = new GreetingsCallbackBuilders().get().id(1L).build();
    FutureCallback<Response<Greeting>> muxCallback1 = new FutureCallback<Response<Greeting>>();
    FutureCallback<Response<Greeting>> directCallback1 = new FutureCallback<Response<Greeting>>();
    GetRequest<Greeting> request2 = new GreetingsCallbackBuilders().get().id(Long.MAX_VALUE).build();
    FutureCallback<Response<Greeting>> muxCallback2 = new FutureCallback<Response<Greeting>>();
    FutureCallback<Response<Greeting>> directCallback2 = new FutureCallback<Response<Greeting>>();
    MultiplexedRequest multiplexedRequest = MultiplexedRequestBuilder.createSequentialRequest().addRequest(request1, muxCallback1).addRequest(request2, muxCallback2).build();
    getClient().sendRequest(multiplexedRequest);
    getClient().sendRequest(request1, directCallback1);
    getClient().sendRequest(request2, directCallback2);
    assertEqualResponses(muxCallback1, directCallback1);
    assertEqualErrors(muxCallback2, directCallback2);
}
Also used : Response(com.linkedin.restli.client.Response) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) FutureCallback(com.linkedin.common.callback.FutureCallback) GreetingsCallbackBuilders(com.linkedin.restli.examples.greetings.client.GreetingsCallbackBuilders) RestLiIntegrationTest(com.linkedin.restli.examples.RestLiIntegrationTest) Test(org.testng.annotations.Test)

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