Search in sources :

Example 1 with TaskQueueAddResponse

use of com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddResponse in project appengine-java-standard by GoogleCloudPlatform.

the class DevPushQueue method add.

@Override
TaskQueueAddResponse add(TaskQueueAddRequest.Builder addRequest) {
    if (addRequest.getMode() != Mode.PUSH) {
        throw new ApiProxy.ApplicationException(ErrorCode.INVALID_QUEUE_MODE_VALUE);
    }
    if (!addRequest.getQueueName().toStringUtf8().equals(getQueueName())) {
        throw new ApiProxy.ApplicationException(ErrorCode.INVALID_REQUEST_VALUE);
    }
    String taskName = scheduleTask(addRequest);
    TaskQueueAddResponse.Builder addResponse = TaskQueueAddResponse.newBuilder();
    if (!addRequest.hasTaskName() || addRequest.getTaskName().isEmpty()) {
        addRequest.setTaskName(ByteString.copyFromUtf8(taskName));
        addResponse.setChosenTaskName(ByteString.copyFromUtf8(taskName));
    }
    return addResponse.build();
}
Also used : TaskQueueAddResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddResponse) ByteString(com.google.protobuf.ByteString)

Example 2 with TaskQueueAddResponse

use of com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddResponse in project appengine-java-standard by GoogleCloudPlatform.

the class LocalTaskQueue method add.

@LatencyPercentiles(latency50th = 4)
public TaskQueueAddResponse add(Status status, TaskQueueAddRequest addRequest) {
    TaskQueueBulkAddRequest.Builder bulkRequest = TaskQueueBulkAddRequest.newBuilder();
    bulkRequest.addAddRequestBuilder().mergeFrom(addRequest);
    TaskQueueAddResponse.Builder addResponse = TaskQueueAddResponse.newBuilder();
    TaskQueueBulkAddResponse bulkResponse = bulkAdd(status, bulkRequest.build());
    if (bulkResponse.getTaskResultCount() != 1) {
        throw new InternalFailureException(String.format("expected 1 result from BulkAdd(), got %d", bulkResponse.getTaskResultCount()));
    }
    int result = bulkResponse.getTaskResult(0).getResult().getNumber();
    if (result != ErrorCode.OK_VALUE) {
        throw new ApiProxy.ApplicationException(result);
    } else if (bulkResponse.getTaskResult(0).hasChosenTaskName()) {
        addResponse.setChosenTaskName(bulkResponse.getTaskResult(0).getChosenTaskName());
    }
    return addResponse.build();
}
Also used : InternalFailureException(com.google.appengine.api.taskqueue.InternalFailureException) TaskQueueAddResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddResponse) TaskQueueBulkAddRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddRequest) TaskQueueBulkAddResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse) LatencyPercentiles(com.google.appengine.tools.development.LatencyPercentiles)

Example 3 with TaskQueueAddResponse

use of com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddResponse in project appengine-java-standard by GoogleCloudPlatform.

the class LocalTaskQueueTest method testAddUnNamedTask.

@Test
public void testAddUnNamedTask() throws Exception {
    TaskQueueAddRequest.Builder request = bulkAddRequest.getAddRequestBuilder(0);
    TaskQueueAddResponse.Builder expectedResponse = TaskQueueAddResponse.newBuilder();
    request.setTaskName(ByteString.copyFromUtf8(""));
    TaskQueueAddResponse response = localService.add(new Status(), request.buildPartial());
    assertThat(response.getChosenTaskName().toStringUtf8()).startsWith("task-");
    expectedResponse.setChosenTaskName(response.getChosenTaskName());
    assertThat(response).isEqualTo(expectedResponse.build());
}
Also used : Status(com.google.appengine.tools.development.LocalRpcService.Status) TaskQueueAddResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddResponse) TaskQueueAddRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddRequest) Test(org.junit.Test)

Example 4 with TaskQueueAddResponse

use of com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddResponse in project appengine-java-standard by GoogleCloudPlatform.

the class LocalTaskQueueTest method testAddNamedTask.

@Test
public void testAddNamedTask() throws Exception {
    TaskQueueAddRequest.Builder request = bulkAddRequest.getAddRequestBuilder(0);
    TaskQueueAddResponse expectedResponse = TaskQueueAddResponse.getDefaultInstance();
    TaskQueueAddResponse response = localService.add(new Status(), request.build());
    assertThat(response).isEqualTo(expectedResponse);
}
Also used : Status(com.google.appengine.tools.development.LocalRpcService.Status) TaskQueueAddResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddResponse) TaskQueueAddRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddRequest) Test(org.junit.Test)

Example 5 with TaskQueueAddResponse

use of com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddResponse in project appengine-java-standard by GoogleCloudPlatform.

the class DevPullQueueTest method testAdd_NamedTask.

public void testAdd_NamedTask() throws Exception {
    TaskQueueAddRequest.Builder add = newAddRequest(1000).setTaskName(ByteString.copyFromUtf8("the name"));
    TaskQueueAddResponse resp = queue.add(add);
    assertThat(resp.getChosenTaskName().toStringUtf8()).isEmpty();
}
Also used : TaskQueueAddResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddResponse) TaskQueueAddRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddRequest)

Aggregations

TaskQueueAddResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddResponse)13 TaskQueueAddRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddRequest)10 Test (org.junit.Test)7 ByteString (com.google.protobuf.ByteString)3 Header (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddRequest.Header)2 Status (com.google.appengine.tools.development.LocalRpcService.Status)2 JobDetail (org.quartz.JobDetail)2 SimpleTrigger (org.quartz.SimpleTrigger)2 InternalFailureException (com.google.appengine.api.taskqueue.InternalFailureException)1 TaskQueueBulkAddRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddRequest)1 TaskQueueBulkAddResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse)1 LatencyPercentiles (com.google.appengine.tools.development.LatencyPercentiles)1