Search in sources :

Example 21 with Status

use of com.google.appengine.tools.development.LocalRpcService.Status 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 22 with Status

use of com.google.appengine.tools.development.LocalRpcService.Status in project appengine-java-standard by GoogleCloudPlatform.

the class LocalTaskQueueTest method testTransactionalTasksWithAddActionsFailure.

@Test
public void testTransactionalTasksWithAddActionsFailure() throws Exception {
    DevQueue.taskNameGenerator = new AtomicInteger();
    final int tx = 321;
    final int error = 123;
    localService.stop();
    localService = LocalTaskQueueTestConfig.getLocalTaskQueue();
    initLocalTaskQueue(Clock.DEFAULT);
    QueueXml queueXml = makeQueueXml();
    localService.setQueueXml(queueXml);
    localService.start();
    addRequest1.getTransactionBuilder().setHandle(tx).setApp("foo");
    addRequest2.getTransactionBuilder().setHandle(tx).setApp("foo");
    addRequest3.getTransactionBuilder().setHandle(tx).setApp("foo");
    addRequest1.setTaskName(ByteString.copyFromUtf8(""));
    addRequest2.setTaskName(ByteString.copyFromUtf8(""));
    addRequest3.setTaskName(ByteString.copyFromUtf8(""));
    expectedTaskResult1.setChosenTaskName(ByteString.copyFromUtf8("task1"));
    expectedTaskResult2.setChosenTaskName(ByteString.copyFromUtf8("task2"));
    expectedTaskResult3.setChosenTaskName(ByteString.copyFromUtf8("task3"));
    Delegate<?> oldDelegate = ApiProxy.getDelegate();
    ApiProxy.setDelegate(mockDelegate);
    TaskQueueBulkAddRequest.Builder expectedAddActionsRequest = bulkAddRequest.clone();
    expectedAddActionsRequest.getAddRequestBuilder(0).setTaskName(ByteString.copyFromUtf8("task1"));
    expectedAddActionsRequest.getAddRequestBuilder(1).setTaskName(ByteString.copyFromUtf8("task2"));
    expectedAddActionsRequest.getAddRequestBuilder(2).setTaskName(ByteString.copyFromUtf8("task3"));
    when(mockDelegate.makeSyncCall(ApiProxy.getCurrentEnvironment(), "datastore_v3", "addActions", expectedAddActionsRequest.build().toByteArray())).thenThrow(new ApiProxy.ApplicationException(error, "mock"));
    ApiProxy.ApplicationException e = assertThrows(ApiProxy.ApplicationException.class, () -> localService.bulkAdd(new Status(), bulkAddRequest.build()));
    assertThat(e.getApplicationError()).isEqualTo(error + ErrorCode.DATASTORE_ERROR_VALUE);
    verify(mockDelegate).makeSyncCall(any(), any(), any(), any());
    Map<String, QueueStateInfo> queueInfo = localService.getQueueStateInfo();
    assertThat(queueInfo).hasSize(queueXml.getEntries().size() + 1);
    assertThat(queueInfo.get(addRequest1.getQueueName().toStringUtf8()).getCountTasks()).isEqualTo(0);
    // We have to restore the old delegate so that LocalServiceTestHelper won't break in tearDown
    ApiProxy.setDelegate(oldDelegate);
}
Also used : Status(com.google.appengine.tools.development.LocalRpcService.Status) TaskQueueBulkAddRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddRequest) ApiProxy(com.google.apphosting.api.ApiProxy) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueueXml(com.google.apphosting.utils.config.QueueXml) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 23 with Status

use of com.google.appengine.tools.development.LocalRpcService.Status in project appengine-java-standard by GoogleCloudPlatform.

the class LocalTaskQueueTest method testBulkAddPushTasksToPullQueue.

@Test
public void testBulkAddPushTasksToPullQueue() throws Exception {
    for (TaskQueueAddRequest.Builder addRequest : bulkAddRequest.getAddRequestBuilderList()) {
        addRequest.setQueueName(ByteString.copyFromUtf8("pull-queue"));
    }
    TaskQueueBulkAddResponse response = localService.bulkAdd(new Status(), bulkAddRequest.build());
    assertThat(response.getTaskResult(0).getResult().getNumber()).isEqualTo(ErrorCode.INVALID_QUEUE_MODE_VALUE);
    assertThat(response.getTaskResult(1).getResult().getNumber()).isEqualTo(ErrorCode.INVALID_QUEUE_MODE_VALUE);
    assertThat(response.getTaskResult(2).getResult().getNumber()).isEqualTo(ErrorCode.INVALID_QUEUE_MODE_VALUE);
}
Also used : Status(com.google.appengine.tools.development.LocalRpcService.Status) TaskQueueAddRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddRequest) TaskQueueBulkAddResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse) Test(org.junit.Test)

Example 24 with Status

use of com.google.appengine.tools.development.LocalRpcService.Status in project appengine-java-standard by GoogleCloudPlatform.

the class LocalTaskQueueTest method testTransactionalTasks.

@Test
public void testTransactionalTasks() throws Exception {
    DevQueue.taskNameGenerator = new AtomicInteger();
    final int tx = 321;
    localService.stop();
    localService = LocalTaskQueueTestConfig.getLocalTaskQueue();
    initLocalTaskQueue(Clock.DEFAULT);
    QueueXml queueXml = makeQueueXml();
    localService.setQueueXml(queueXml);
    localService.start();
    addRequest1.getTransactionBuilder().setHandle(tx).setApp("foo");
    addRequest2.getTransactionBuilder().setHandle(tx).setApp("foo");
    addRequest3.getTransactionBuilder().setHandle(tx).setApp("foo");
    addRequest1.setTaskName(ByteString.copyFromUtf8(""));
    addRequest2.setTaskName(ByteString.copyFromUtf8(""));
    addRequest3.setTaskName(ByteString.copyFromUtf8(""));
    expectedTaskResult1.setChosenTaskName(ByteString.copyFromUtf8("task1"));
    expectedTaskResult2.setChosenTaskName(ByteString.copyFromUtf8("task2"));
    expectedTaskResult3.setChosenTaskName(ByteString.copyFromUtf8("task3"));
    Delegate<?> oldDelegate = ApiProxy.getDelegate();
    ApiProxy.setDelegate(mockDelegate);
    TaskQueueBulkAddRequest.Builder expectedAddActionsRequest = bulkAddRequest.clone();
    expectedAddActionsRequest.getAddRequestBuilder(0).setTaskName(ByteString.copyFromUtf8("task1"));
    expectedAddActionsRequest.getAddRequestBuilder(1).setTaskName(ByteString.copyFromUtf8("task2"));
    expectedAddActionsRequest.getAddRequestBuilder(2).setTaskName(ByteString.copyFromUtf8("task3"));
    when(mockDelegate.makeSyncCall(ApiProxy.getCurrentEnvironment(), "datastore_v3", "addActions", expectedAddActionsRequest.build().toByteArray())).thenReturn(new byte[0]);
    // add an entry in the default queue, this makes sure that the default
    // queue is automagically added, but task is not (it's sent to datastore).
    TaskQueueBulkAddResponse response = localService.bulkAdd(new Status(), bulkAddRequest.build());
    assertThat(response).isEqualTo(expectedBulkAddResponse.build());
    verify(mockDelegate).makeSyncCall(any(), any(), any(), any());
    Map<String, QueueStateInfo> queueInfo = localService.getQueueStateInfo();
    assertThat(queueInfo).hasSize(queueXml.getEntries().size() + 1);
    assertThat(queueInfo.get(addRequest1.getQueueName().toStringUtf8()).getCountTasks()).isEqualTo(0);
    // We have to restore the old delegate so that LocalServiceTestHelper won't break in tearDown
    ApiProxy.setDelegate(oldDelegate);
}
Also used : Status(com.google.appengine.tools.development.LocalRpcService.Status) TaskQueueBulkAddRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueueXml(com.google.apphosting.utils.config.QueueXml) TaskQueueBulkAddResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 25 with Status

use of com.google.appengine.tools.development.LocalRpcService.Status 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)

Aggregations

Status (com.google.appengine.tools.development.LocalRpcService.Status)34 Test (org.junit.Test)31 TaskQueueBulkAddResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse)18 TaskQueueQueryAndOwnTasksRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksRequest)5 ApiProxy (com.google.apphosting.api.ApiProxy)5 ByteString (com.google.protobuf.ByteString)5 TaskQueueAddRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddRequest)4 TaskQueueModifyTaskLeaseRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueModifyTaskLeaseRequest)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)4 TaskQueueDeleteRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueDeleteRequest)3 TaskQueueDeleteResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueDeleteResponse)3 TaskQueueAddResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddResponse)2 TaskQueueBulkAddRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddRequest)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ImageData (com.google.appengine.api.images.ImagesServicePb.ImageData)1 MIME_TYPE (com.google.appengine.api.images.ImagesServicePb.OutputSettings.MIME_TYPE)1 Transform (com.google.appengine.api.images.ImagesServicePb.Transform)1 TaskQueueFetchQueueStatsRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueFetchQueueStatsRequest)1