Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demonstrates bug in remote api transactional task handling
package com.remoteapi.bug;
import com.google.appengine.api.datastore.*;
import com.google.appengine.api.taskqueue.Queue;
import com.google.appengine.api.taskqueue.QueueFactory;
import com.google.appengine.api.taskqueue.TaskOptions;
import com.google.appengine.tools.remoteapi.RemoteApiInstaller;
import com.google.appengine.tools.remoteapi.RemoteApiOptions;
import java.io.IOException;
public class RemoteApiExample {
public static void main(String[] args) throws IOException, EntityNotFoundException {
RemoteApiOptions options = new RemoteApiOptions()
.server("remoteapi-transaction-bug.appspot.com", 443)
.useApplicationDefaultCredential();
RemoteApiInstaller installer = new RemoteApiInstaller();
installer.install(options);
try {
insertIntoDatasore();
} finally {
installer.uninstall();
}
}
private static void insertIntoDatasore() throws EntityNotFoundException {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
final Queue defaultQueue = QueueFactory.getDefaultQueue();
Transaction txn = datastore.beginTransaction();
try {
Entity employee = new Entity(KeyFactory.createKey("Employee", "Joe"));
datastore.put(txn,employee);
defaultQueue.add(txn, TaskOptions.Builder.withUrl("/"));
txn.commit();
} finally {
if (txn.isActive()) {
txn.rollback();
}
}
}
}
Exception in thread "main" com.google.appengine.api.taskqueue.TransactionalTaskException
at com.google.appengine.api.taskqueue.QueueApiHelper.translateError(QueueApiHelper.java:102)
at com.google.appengine.api.taskqueue.QueueApiHelper.translateError(QueueApiHelper.java:159)
at com.google.appengine.api.taskqueue.QueueApiHelper$1.convertException(QueueApiHelper.java:55)
at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:96)
at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:88)
at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:88)
at com.google.appengine.api.taskqueue.QueueApiHelper.getInternal(QueueApiHelper.java:78)
at com.google.appengine.api.taskqueue.QueueImpl.add(QueueImpl.java:433)
at com.remoteapi.bug.RemoteApiExample.insertIntoDatasore(RemoteApiExample.java:33)
at com.remoteapi.bug.RemoteApiExample.main(RemoteApiExample.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.IllegalArgumentException:
at com.google.appengine.api.datastore.DatastoreApiHelper.translateError(DatastoreApiHelper.java:54)
at com.google.appengine.api.taskqueue.QueueApiHelper.translateError(QueueApiHelper.java:104)
... 14 more
Process finished with exit code 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment