Class EnvSettingTaskqueueCallback
java.lang.Object
com.google.appengine.tools.development.testing.EnvSettingTaskqueueCallback
- All Implemented Interfaces:
LocalTaskQueueCallback,Serializable
An implementation of
LocalTaskQueueCallback that wraps a delegate and invokes ApiProxy.setEnvironmentForCurrentThread(com.google.apphosting.api.ApiProxy.Environment) prior to
invoking the delegate.
There are two types of threads that may interact with this class. Class 1 consists of threads
used to initialize data relevant to this class. These are the main thread of a unit test, which
will invoke setProxyProperties(ApiProxyLocal, Class, boolean) and the threads started by
ApiProxyLocalImpl.makeAsyncCall() which will invoke initialize(Map).
Class 2 consists of automatic task hanlding threads which will invoke execute(com.google.appengine.api.urlfetch.URLFetchServicePb.URLFetchRequest).
The goal of this class is to be able to get data about an ApiProxy.Environment from
class 1 threads to class 2 threads. We want the class 2 threads to have an Environment so
that they can interact with App Engine APIs such as the datastore.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintThis method is invoked from the task execution threads.voidinitialize(Map<String, String> properties) This is invoked during initialization of theLocalTaskQueueservice.static voidsetProxyProperties(ApiProxyLocal proxy, Class<? extends LocalTaskQueueCallback> delegateClass, boolean shouldCopyApiProxyEnvironment) A helper method invoked fromLocalTaskQueueTestConfigwhich sets the above two properties.static voidA helper method invoked fromLocalTaskQueueTestConfigwhich sets the provided latch on the current environment.
-
Constructor Details
-
EnvSettingTaskqueueCallback
public EnvSettingTaskqueueCallback()
-
-
Method Details
-
setProxyProperties
public static void setProxyProperties(ApiProxyLocal proxy, Class<? extends LocalTaskQueueCallback> delegateClass, boolean shouldCopyApiProxyEnvironment) A helper method invoked fromLocalTaskQueueTestConfigwhich sets the above two properties.- Parameters:
proxy- The instance ofApiProxyLocalin which the properties should be set.delegateClass- the name of the delegate class.shouldCopyApiProxyEnvironment- should we copy theEnvironmentto the task threads.
-
setTaskExecutionLatch
A helper method invoked fromLocalTaskQueueTestConfigwhich sets the provided latch on the current environment.- Parameters:
latch- the latch
-
initialize
This is invoked during initialization of theLocalTaskQueueservice. The thread that invokes this has access to theApiProxy.Environmentthat was set by the testing thread. We retrieve the two properties that were set above.- Specified by:
initializein interfaceLocalTaskQueueCallback
-
execute
This method is invoked from the task execution threads.- Specified by:
executein interfaceLocalTaskQueueCallback- Parameters:
req- The url fetch request- Returns:
- The HTTP status code of the fetch.
-