use of com.google.apphosting.utils.config.QueueXml 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.apphosting.utils.config.QueueXml in project appengine-java-standard by GoogleCloudPlatform.
the class LocalTaskQueueTest method makeQueueXml.
private QueueXml makeQueueXml() {
// add 2 entries not with the default name.
QueueXml queueXML = new QueueXml();
QueueXml.Entry tmpEntry = queueXML.addNewEntry();
tmpEntry.setBucketSize(1);
tmpEntry.setName("Aqueue");
tmpEntry.setRate("2/d");
tmpEntry = queueXML.addNewEntry();
tmpEntry.setBucketSize(2);
tmpEntry.setName("Bqueue");
tmpEntry.setRate("2/m");
queueXML.validateLastEntry();
return queueXML;
}
Aggregations