Search in sources :

Example 6 with TaskQueueModifyTaskLeaseRequest

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

the class LocalTaskQueueTest method testExtendTaskLeaseInvalidQueueName.

@Test
public void testExtendTaskLeaseInvalidQueueName() throws Exception {
    TaskQueueModifyTaskLeaseRequest extendRequest = TaskQueueModifyTaskLeaseRequest.newBuilder().setQueueName(ByteString.copyFromUtf8("****invalid****")).setTaskName(ByteString.copyFromUtf8("foo")).setEtaUsec(0).setLeaseSeconds(30).build();
    ApiProxy.ApplicationException e = assertThrows(ApiProxy.ApplicationException.class, () -> localService.modifyTaskLease(new Status(), extendRequest));
    assertThat(e.getApplicationError()).isEqualTo(ErrorCode.INVALID_QUEUE_NAME_VALUE);
}
Also used : Status(com.google.appengine.tools.development.LocalRpcService.Status) ApiProxy(com.google.apphosting.api.ApiProxy) TaskQueueModifyTaskLeaseRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueModifyTaskLeaseRequest) Test(org.junit.Test)

Example 7 with TaskQueueModifyTaskLeaseRequest

use of com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueModifyTaskLeaseRequest 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 8 with TaskQueueModifyTaskLeaseRequest

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

the class LocalTaskQueueTest method testExtendTaskLeaseOnPushQueue.

@Test
public void testExtendTaskLeaseOnPushQueue() throws Exception {
    TaskQueueModifyTaskLeaseRequest extendRequest = TaskQueueModifyTaskLeaseRequest.newBuilder().setQueueName(ByteString.copyFromUtf8(entry.getName())).setTaskName(ByteString.copyFromUtf8("foo")).setEtaUsec(0).setLeaseSeconds(30).build();
    ApiProxy.ApplicationException e = assertThrows(ApiProxy.ApplicationException.class, () -> localService.modifyTaskLease(new Status(), extendRequest));
    assertThat(e.getApplicationError()).isEqualTo(ErrorCode.INVALID_QUEUE_MODE_VALUE);
}
Also used : Status(com.google.appengine.tools.development.LocalRpcService.Status) ApiProxy(com.google.apphosting.api.ApiProxy) TaskQueueModifyTaskLeaseRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueModifyTaskLeaseRequest) Test(org.junit.Test)

Aggregations

TaskQueueModifyTaskLeaseRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueModifyTaskLeaseRequest)8 ApiProxy (com.google.apphosting.api.ApiProxy)6 TaskQueueAddRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddRequest)4 Status (com.google.appengine.tools.development.LocalRpcService.Status)4 Test (org.junit.Test)4 TaskQueueBulkAddResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse)1 TaskQueueModifyTaskLeaseResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueModifyTaskLeaseResponse)1 TaskQueueQueryAndOwnTasksRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksRequest)1 TaskQueueQueryAndOwnTasksResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksResponse)1 Clock (com.google.appengine.tools.development.Clock)1