Search in sources :

Example 61 with Greeting

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

the class TestMultiplexerIntegration method twoParallelCalls.

@Test
public void twoParallelCalls() 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.createParallelRequest().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 62 with Greeting

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

the class TestScatterGather method checkInput.

// TODO modify this method to accept a CollectionRequest as it's first parameter once our server code has been
//      updated to work with the new representation of BatchUpdateRequests and BatchPartialUpdateRequests. As of now
//      we are still converting to the old representation using CollectionRequestUtil.convertToBatchRequest
private static void checkInput(DataMap dataMap, Map<Long, Greeting> inputMap, Set<String> uriIds) {
    Assert.assertEquals(dataMap.size(), uriIds.size());
    for (String key : dataMap.keySet()) {
        DataMap inputDM = dataMap.getDataMap(key);
        Greeting expectedGreeting = inputMap.get(Long.parseLong(key));
        Assert.assertTrue(uriIds.contains(key));
        Assert.assertTrue(inputDM.equals(expectedGreeting.data()));
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) DataMap(com.linkedin.data.DataMap)

Example 63 with Greeting

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

the class NullGreetingsResourceImpl method batchUpdate.

@RestMethod.BatchPartialUpdate
public BatchUpdateResult<Long, Greeting> batchUpdate(BatchPatchRequest<Long, Greeting> entityUpdates) {
    final Map<Long, UpdateResponse> responseMap = new HashMap<Long, UpdateResponse>();
    responseMap.put(3l, new UpdateResponse(HttpStatus.S_201_CREATED));
    if (entityUpdates.getData().containsKey(1l)) {
        //Return a null BatchUpdateResult
        return null;
    } else if (entityUpdates.getData().containsKey(2l)) {
        //Return a BatchUpdateResult with a null results Map
        return new BatchUpdateResult<Long, Greeting>(null);
    } else if (entityUpdates.getData().containsKey(3l)) {
        //Return a BatchUpdateResult with a null errors Map
        return new BatchUpdateResult<Long, Greeting>(responseMap, null);
    } else {
        //Return a BatchUpdateResult with a map that has a null key in it
        responseMap.put(null, new UpdateResponse(HttpStatus.S_201_CREATED));
        return new BatchUpdateResult<Long, Greeting>(responseMap);
    }
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) BatchUpdateResult(com.linkedin.restli.server.BatchUpdateResult) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 64 with Greeting

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

the class SimpleResourceUnderCollectionResource method update.

/**
   * Updates the greeting.
   */
@Override
public UpdateResponse update(PatchRequest<Greeting> patchRequest) {
    Long key = this.getContext().getPathKeys().get("subgreetingsId");
    if (TONES.containsKey(key)) {
        try {
            Greeting patched = new Greeting();
            PatchApplier.applyPatch(patched, patchRequest);
            TONES.put(key, patched.getTone());
            return new UpdateResponse(HttpStatus.S_204_NO_CONTENT);
        } catch (DataProcessingException e) {
            return new UpdateResponse((HttpStatus.S_400_BAD_REQUEST));
        }
    } else {
        return new UpdateResponse(HttpStatus.S_404_NOT_FOUND);
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) UpdateResponse(com.linkedin.restli.server.UpdateResponse) DataProcessingException(com.linkedin.data.transform.DataProcessingException)

Example 65 with Greeting

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

the class StreamingGreetings method get.

@Override
public void get(Long key, @CallbackParam Callback<Greeting> callback) {
    if (getContext().responseAttachmentsSupported()) {
        final GreetingWriter greetingWriter = new GreetingWriter(ByteString.copy(greetingBytes));
        final RestLiResponseAttachments streamingAttachments = new RestLiResponseAttachments.Builder().appendSingleAttachment(greetingWriter).build();
        getContext().setResponseAttachments(streamingAttachments);
        final String headerValue = getContext().getRequestHeaders().get("getHeader");
        getContext().setResponseHeader("getHeader", headerValue);
        callback.onSuccess(new Greeting().setMessage("Your greeting has an attachment since you were kind and " + "decided you wanted to read it!").setId(key));
    }
    callback.onError(new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "You must be able to receive attachments!"));
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) ByteString(com.linkedin.data.ByteString) RestLiResponseAttachments(com.linkedin.restli.server.RestLiResponseAttachments)

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