Search in sources :

Example 16 with TaskQueueBulkAddResponse

use of com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse 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());
    }
}
Also used : Status(com.google.appengine.tools.development.LocalRpcService.Status) TaskQueueModifyTaskLeaseResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueModifyTaskLeaseResponse) TaskQueueBulkAddResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse) TaskQueueQueryAndOwnTasksRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksRequest) Clock(com.google.appengine.tools.development.Clock) TaskQueueModifyTaskLeaseRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueModifyTaskLeaseRequest) TaskQueueQueryAndOwnTasksResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksResponse) Test(org.junit.Test)

Example 17 with TaskQueueBulkAddResponse

use of com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse 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");
}
Also used : Status(com.google.appengine.tools.development.LocalRpcService.Status) TaskQueueBulkAddResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse) TaskQueueQueryAndOwnTasksRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksRequest) Clock(com.google.appengine.tools.development.Clock) TaskQueueQueryAndOwnTasksResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksResponse) Test(org.junit.Test)

Example 18 with TaskQueueBulkAddResponse

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

the class LocalTaskQueueTest method testBulkAddNoName.

@Test
public void testBulkAddNoName() throws Exception {
    addRequest1.setTaskName(ByteString.copyFromUtf8(""));
    addRequest2.setTaskName(ByteString.copyFromUtf8(""));
    addRequest3.setTaskName(ByteString.copyFromUtf8(""));
    TaskQueueBulkAddResponse response = localService.bulkAdd(new Status(), bulkAddRequest.build());
    assertThat(response.getTaskResult(0).getChosenTaskName().toStringUtf8()).startsWith("task-");
    assertThat(response.getTaskResult(1).getChosenTaskName().toStringUtf8()).startsWith("task-");
    assertThat(response.getTaskResult(2).getChosenTaskName().toStringUtf8()).startsWith("task-");
    expectedTaskResult1.setChosenTaskName(response.getTaskResult(0).getChosenTaskName());
    expectedTaskResult2.setChosenTaskName(response.getTaskResult(1).getChosenTaskName());
    expectedTaskResult3.setChosenTaskName(response.getTaskResult(2).getChosenTaskName());
    assertThat(response).isEqualTo(expectedBulkAddResponse.build());
}
Also used : Status(com.google.appengine.tools.development.LocalRpcService.Status) TaskQueueBulkAddResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse) Test(org.junit.Test)

Example 19 with TaskQueueBulkAddResponse

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

the class LocalTaskQueueTest method assertValidationExceptionPull.

private void assertValidationExceptionPull(ErrorCode ec) {
    expectedTaskResult1.setResult(ErrorCode.SKIPPED);
    expectedTaskResult2.setResult(ec);
    expectedTaskResult3.setResult(ErrorCode.SKIPPED);
    TaskQueueBulkAddResponse response = localService.bulkAdd(new Status(), bulkAddPullRequest.build());
    assertThat(response).isEqualTo(expectedBulkAddResponse.buildPartial());
}
Also used : Status(com.google.appengine.tools.development.LocalRpcService.Status) TaskQueueBulkAddResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse)

Example 20 with TaskQueueBulkAddResponse

use of com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse 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");
}
Also used : Status(com.google.appengine.tools.development.LocalRpcService.Status) TaskQueueBulkAddResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse) TaskQueueQueryAndOwnTasksRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksRequest) Clock(com.google.appengine.tools.development.Clock) TaskQueueQueryAndOwnTasksResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksResponse) Test(org.junit.Test)

Aggregations

TaskQueueBulkAddResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse)21 Status (com.google.appengine.tools.development.LocalRpcService.Status)18 Test (org.junit.Test)16 ByteString (com.google.protobuf.ByteString)5 TaskQueueAddRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddRequest)4 TaskQueueBulkAddRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddRequest)4 TaskQueueQueryAndOwnTasksRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksRequest)4 TaskQueueQueryAndOwnTasksResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksResponse)4 Clock (com.google.appengine.tools.development.Clock)4 QueueXml (com.google.apphosting.utils.config.QueueXml)3 LatencyPercentiles (com.google.appengine.tools.development.LatencyPercentiles)2 InternalFailureException (com.google.appengine.api.taskqueue.InternalFailureException)1 TaskQueueAddResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddResponse)1 TaskQueueModifyTaskLeaseRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueModifyTaskLeaseRequest)1 TaskQueueModifyTaskLeaseResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueModifyTaskLeaseResponse)1 ErrorCode (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueServiceError.ErrorCode)1 ApiProxy (com.google.apphosting.api.ApiProxy)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 IdentityHashMap (java.util.IdentityHashMap)1