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();
}
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-");
}
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();
}
Aggregations