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