Search in sources :

Example 11 with TaskQueueAddResponse

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

the class DevQueueTest method testAdd_NamedTask.

@Test
public void testAdd_NamedTask() throws Exception {
    TaskQueueAddRequest.Builder add = newAddRequest(1000).setTaskName(ByteString.copyFromUtf8("the name"));
    when(schedulerMock.getJobDetail("the name", "default")).thenReturn(null);
    when(schedulerMock.scheduleJob(isA(JobDetail.class), isA(SimpleTrigger.class))).thenReturn(null);
    TaskQueueAddResponse resp = queue.add(add);
    assertThat(resp.getChosenTaskName().toStringUtf8()).isEmpty();
}
Also used : TaskQueueAddResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddResponse) JobDetail(org.quartz.JobDetail) TaskQueueAddRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddRequest) SimpleTrigger(org.quartz.SimpleTrigger) Test(org.junit.Test)

Example 12 with TaskQueueAddResponse

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

the class DevPullQueueTest method testAdd_UnnamedTask.

public void testAdd_UnnamedTask() throws Exception {
    TaskQueueAddRequest.Builder add = newAddRequest(1000);
    TaskQueueAddResponse resp = queue.add(add);
    assertThat(resp.getChosenTaskName().toStringUtf8()).startsWith("task-");
}
Also used : TaskQueueAddResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddResponse) TaskQueueAddRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddRequest)

Example 13 with TaskQueueAddResponse

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

the class DevPullQueue method add.

/**
 * Adds pull tasks into the queue.
 */
@Override
synchronized TaskQueueAddResponse add(TaskQueueAddRequest.Builder addRequest) {
    if (addRequest.getMode() != Mode.PULL) {
        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;
    // If the task has no name, make one.
    if (addRequest.hasTaskName() && !addRequest.getTaskName().isEmpty()) {
        taskName = addRequest.getTaskName().toStringUtf8();
    } else {
        // Generate a unique task name if task name is not set.
        taskName = genTaskName();
    }
    if (taskMap.containsKey(taskName)) {
        throw new ApiProxy.ApplicationException(ErrorCode.TASK_ALREADY_EXISTS_VALUE);
    }
    taskMap.put(taskName, 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)

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