use of com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksRequest in project appengine-java-standard by GoogleCloudPlatform.
the class LocalTaskQueueTest method testQueryAndOwnTasks.
@Test
public void testQueryAndOwnTasks() throws Exception {
class MockClock implements Clock {
@Override
public long getCurrentTime() {
// Force nowMillis of QueryAndOwnTasks is guaranteed to be bigger than task eta.
return Clock.DEFAULT.getCurrentTime() + 1000;
}
}
initLocalTaskQueue(new MockClock());
TaskQueueBulkAddResponse sbresponse = localService.bulkAdd(new Status(), bulkAddPullRequest.build());
assertThat(sbresponse).isEqualTo(expectedBulkAddResponse.build());
TaskQueueQueryAndOwnTasksRequest request = TaskQueueQueryAndOwnTasksRequest.newBuilder().setQueueName(ByteString.copyFromUtf8("pull-queue")).setLeaseSeconds(10).setMaxTasks(5).build();
TaskQueueQueryAndOwnTasksResponse response = localService.queryAndOwnTasks(new Status(), request);
assertThat(response.getTaskCount()).isEqualTo(3);
for (int i = 0; i < response.getTaskCount(); ++i) {
assertThat(response.getTask(i).getTaskName().toStringUtf8()).isEqualTo("a-task-" + i);
assertThat(response.getTask(i).getBody().toStringUtf8()).isEqualTo("payload" + i);
}
}
use of com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksRequest in project appengine-java-standard by GoogleCloudPlatform.
the class LocalTaskQueueTest method testQueryAndOwnTasksOnPushQueue.
@Test
public void testQueryAndOwnTasksOnPushQueue() throws Exception {
localService.bulkAdd(new Status(), bulkAddRequest.build());
TaskQueueQueryAndOwnTasksRequest request = TaskQueueQueryAndOwnTasksRequest.newBuilder().setQueueName(ByteString.copyFromUtf8(entry.getName())).setLeaseSeconds(10).setMaxTasks(5).build();
ApiProxy.ApplicationException e = assertThrows(ApiProxy.ApplicationException.class, () -> localService.queryAndOwnTasks(new Status(), request));
assertThat(e.getApplicationError()).isEqualTo(ErrorCode.INVALID_QUEUE_MODE_VALUE);
}
use of com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksRequest in project appengine-java-standard by GoogleCloudPlatform.
the class LocalTaskQueueTest method testExtendTaskLease.
@Test
public void testExtendTaskLease() throws Exception {
// QueryAndOwn tasks first, same as testQueryAndOwnTasks above
class MockClock implements Clock {
@Override
public long getCurrentTime() {
// So that nowMillis of QueryAndOwnTasks is guaranteed to be bigger than task eta.
return Clock.DEFAULT.getCurrentTime() + 1000;
}
}
initLocalTaskQueue(new MockClock());
TaskQueueBulkAddResponse sbresponse = localService.bulkAdd(new Status(), bulkAddPullRequest.build());
assertThat(sbresponse).isEqualTo(expectedBulkAddResponse.build());
TaskQueueQueryAndOwnTasksRequest request = TaskQueueQueryAndOwnTasksRequest.newBuilder().setQueueName(ByteString.copyFromUtf8("pull-queue")).setLeaseSeconds(60).setMaxTasks(5).build();
TaskQueueQueryAndOwnTasksResponse response = localService.queryAndOwnTasks(new Status(), request);
assertThat(response.getTaskCount()).isEqualTo(3);
for (int i = 0; i < response.getTaskCount(); ++i) {
TaskQueueModifyTaskLeaseRequest extendRequest = TaskQueueModifyTaskLeaseRequest.newBuilder().setQueueName(ByteString.copyFromUtf8("pull-queue")).setTaskName(response.getTask(i).getTaskName()).setEtaUsec(response.getTask(i).getEtaUsec()).setLeaseSeconds(300).build();
TaskQueueModifyTaskLeaseResponse extendResponse = localService.modifyTaskLease(new Status(), extendRequest);
assertThat(extendResponse.getUpdatedEtaUsec()).isGreaterThan(response.getTask(i).getEtaUsec());
}
}
use of com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksRequest in project appengine-java-standard by GoogleCloudPlatform.
the class LocalTaskQueueTest method testQueryAndOwnTasksWithUnspecifiedTag.
@Test
public void testQueryAndOwnTasksWithUnspecifiedTag() throws Exception {
class MockClock implements Clock {
@Override
public long getCurrentTime() {
// Force nowMillis of QueryAndOwnTasks is guaranteed to be bigger than task eta.
return Clock.DEFAULT.getCurrentTime() + 1000;
}
}
initLocalTaskQueue(new MockClock());
TaskQueueBulkAddResponse sbresponse = localService.bulkAdd(new Status(), bulkAddPullRequest.build());
assertThat(sbresponse).isEqualTo(expectedBulkAddResponse.build());
TaskQueueQueryAndOwnTasksRequest request = TaskQueueQueryAndOwnTasksRequest.newBuilder().setQueueName(ByteString.copyFromUtf8("pull-queue")).setLeaseSeconds(10).setMaxTasks(5).setGroupByTag(true).build();
TaskQueueQueryAndOwnTasksResponse response = localService.queryAndOwnTasks(new Status(), request);
assertThat(response.getTaskCount()).isEqualTo(2);
assertThat(response.getTask(0).getTaskName().toStringUtf8()).isEqualTo("a-task-0");
assertThat(response.getTask(0).getBody().toStringUtf8()).isEqualTo("payload0");
assertThat(response.getTask(0).getTag().toStringUtf8()).isEqualTo("tag");
assertThat(response.getTask(1).getTaskName().toStringUtf8()).isEqualTo("a-task-2");
assertThat(response.getTask(1).getBody().toStringUtf8()).isEqualTo("payload2");
assertThat(response.getTask(1).getTag().toStringUtf8()).isEqualTo("tag");
}
use of com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksRequest in project appengine-java-standard by GoogleCloudPlatform.
the class LocalTaskQueueTest method testQueryAndOwnTasksWithTags.
@Test
public void testQueryAndOwnTasksWithTags() throws Exception {
class MockClock implements Clock {
@Override
public long getCurrentTime() {
// Force nowMillis of QueryAndOwnTasks is guaranteed to be bigger than task eta.
return Clock.DEFAULT.getCurrentTime() + 1000;
}
}
initLocalTaskQueue(new MockClock());
TaskQueueBulkAddResponse sbresponse = localService.bulkAdd(new Status(), bulkAddPullRequest.build());
assertThat(sbresponse).isEqualTo(expectedBulkAddResponse.build());
TaskQueueQueryAndOwnTasksRequest request = TaskQueueQueryAndOwnTasksRequest.newBuilder().setQueueName(ByteString.copyFromUtf8("pull-queue")).setLeaseSeconds(10).setMaxTasks(5).setGroupByTag(true).setTag(ByteString.copyFromUtf8("tag")).build();
TaskQueueQueryAndOwnTasksResponse response = localService.queryAndOwnTasks(new Status(), request);
assertThat(response.getTaskCount()).isEqualTo(2);
assertThat(response.getTask(0).getTaskName().toStringUtf8()).isEqualTo("a-task-0");
assertThat(response.getTask(0).getBody().toStringUtf8()).isEqualTo("payload0");
assertThat(response.getTask(0).getTag().toStringUtf8()).isEqualTo("tag");
assertThat(response.getTask(1).getTaskName().toStringUtf8()).isEqualTo("a-task-2");
assertThat(response.getTask(1).getBody().toStringUtf8()).isEqualTo("payload2");
assertThat(response.getTask(1).getTag().toStringUtf8()).isEqualTo("tag");
}
Aggregations