Class EnvSettingTaskqueueCallback

java.lang.Object
com.google.appengine.tools.development.testing.EnvSettingTaskqueueCallback
All Implemented Interfaces:
LocalTaskQueueCallback, Serializable

public class EnvSettingTaskqueueCallback extends Object implements LocalTaskQueueCallback
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 Details

    • EnvSettingTaskqueueCallback

      public EnvSettingTaskqueueCallback()
  • Method Details

    • setProxyProperties

      public static void setProxyProperties(ApiProxyLocal proxy, Class<? extends LocalTaskQueueCallback> delegateClass, boolean shouldCopyApiProxyEnvironment)
      A helper method invoked from LocalTaskQueueTestConfig which sets the above two properties.
      Parameters:
      proxy - The instance of ApiProxyLocal in which the properties should be set.
      delegateClass - the name of the delegate class.
      shouldCopyApiProxyEnvironment - should we copy the Environment to the task threads.
    • setTaskExecutionLatch

      public static void setTaskExecutionLatch(CountDownLatch latch)
      A helper method invoked from LocalTaskQueueTestConfig which sets the provided latch on the current environment.
      Parameters:
      latch - the latch
    • initialize

      public void initialize(Map<String,String> properties)
      This is invoked during initialization of the LocalTaskQueue service. The thread that invokes this has access to the ApiProxy.Environment that was set by the testing thread. We retrieve the two properties that were set above.
      Specified by:
      initialize in interface LocalTaskQueueCallback
    • execute

      public int execute(com.google.appengine.api.urlfetch.URLFetchServicePb.URLFetchRequest req)
      This method is invoked from the task execution threads.
      Specified by:
      execute in interface LocalTaskQueueCallback
      Parameters:
      req - The url fetch request
      Returns:
      The HTTP status code of the fetch.