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