Class LocalTaskQueueTestConfig
java.lang.Object
com.google.appengine.tools.development.testing.LocalTaskQueueTestConfig
- All Implemented Interfaces:
LocalServiceTestConfig
Config for accessing the local task queue in tests. Default behavior is to
configure the local task queue to not automatically execute any tasks.
tearDown() wipes out all in-memory state so all queues are empty at
the end of every test. LocalTaskQueue configuration are not restored.
tearDown() does not restore default configuration values modified
using:
-
invalid reference
#setDisableAutoTaskExecution() -
invalid reference
#setQueueXmlPath() -
invalid reference
#setCallbackClass() -
invalid reference
#setShouldCopyApiProxyEnvironment() -
invalid reference
#setTaskExecutionLatch()
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classALocalTaskQueueCallbackimplementation that automatically detects and runs tasks with aDeferredTaskpayload.static classA class to delegate incoming task queue callbacks to HttpServlets based on a provided mapping.static final classACountDownLatchextension that can be reset. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic LocalTaskQueuesetCallbackClass(Class<? extends LocalTaskQueueCallback> callbackClass) Overrides the callback implementation used by the local task queue for async task execution.setDisableAutoTaskExecution(boolean disableAutoTaskExecution) Disables/enables automatic task execution.setQueueXmlPath(String queueXmlPath) Overrides the location of queue.xml.setQueueYamlPath(String queueYamlPath) Overrides the location of queue.yaml.setShouldCopyApiProxyEnvironment(boolean b) Enables copying of theApiProxy.Environmentto task handler threads.Sets aCountDownLatchthat the thread executing the task will decrement after aLocalTaskQueueCallbackfinishes execution.voidsetUp()Set up the local service.voidtearDown()Tear down the local service.
-
Constructor Details
-
LocalTaskQueueTestConfig
public LocalTaskQueueTestConfig()
-
-
Method Details
-
setDisableAutoTaskExecution
Disables/enables automatic task execution. If you enable automatic task execution, keep in mind that the default behavior is to hit the url that was provided when theTaskOptionswas constructed. If you do not have a servlet engine running, this will fail. As an alternative to launching a servlet engine, instead consider providing aLocalTaskQueueCallbackviasetCallbackClass(Class)so that you can assert on the properties of the URLFetchServicePb.URLFetchRequest. Once set, this value is persistent across tests. If this value needs to be set for any one test, it should be appropriately configured in the setup stage for all tests.- Parameters:
disableAutoTaskExecution-- Returns:
this(for chaining)
-
setQueueXmlPath
Overrides the location of queue.xml. Must be a full path, e.g. /usr/local/dev/myapp/test/queue.xml Once set, this value is persistent across tests. If this value needs to be set for an operation specific to any one test, it should appropriately configured in the setup stage for all tests.- Parameters:
queueXmlPath-- Returns:
this(for chaining)
-
setQueueYamlPath
Overrides the location of queue.yaml. Must be a full path, e.g. /usr/local/dev/myapp/test/queue.yamlOnce set, this value is persistent across tests. If this value needs to be set for an operation specific to any one test, it should appropriately configured in the setup stage for all tests.
- Returns:
this(for chaining)
-
setCallbackClass
public LocalTaskQueueTestConfig setCallbackClass(Class<? extends LocalTaskQueueCallback> callbackClass) Overrides the callback implementation used by the local task queue for async task execution. Once set, this value is persistent across tests. If this value needs to be set for any one test, it should be appropriately configured in the setup stage for all tests.- Parameters:
callbackClass- fully-qualified name of a class with a public, default constructor that implementsLocalTaskQueueCallback.- Returns:
this(for chaining)
-
setShouldCopyApiProxyEnvironment
Enables copying of theApiProxy.Environmentto task handler threads. This setting is ignored unless both In this case tasks will be handled locally by new threads and it may be useful for those threads to use the same environment data as the main test thread. Properties such as theappID, and the useremailwill be copied into the environment of the task threads. Be aware thatattribute mapwill be shallow-copied to the task thread environents, so that any mutable objects used as values of the map should be thread safe. If this property isfalsethen the task handler threads will have an emptyApiProxy.Environment. This property isfalseby default. Once set, this value is persistent across tests. If this value needs to be set for any one test, it should be appropriately configured in the setup stage for all tests.- Parameters:
b- should theApiProxy.Environmentbe pushed to task handler threads- Returns:
this(for chaining)
-
setTaskExecutionLatch
Sets aCountDownLatchthat the thread executing the task will decrement after aLocalTaskQueueCallbackfinishes execution. This makes it easy for tests to block until a task queue task runs. Note that the latch is only used when a callback class is provided (viasetCallbackClass(Class)) and when automatic task execution is enabled (viasetDisableAutoTaskExecution(boolean)). Also note that aCountDownLatchcannot be reused, so if you have a test that requires the ability to "reset" a CountDownLatch you can pass an instance ofLocalTaskQueueTestConfig.TaskCountDownLatch, which exposes additional methods that help with this. Once set, this value is persistent across tests. If this value needs to be set for any one test, it should be appropriately configured in the setup stage for all tests.- Parameters:
latch- The latch.- Returns:
this(for chaining)
-
setUp
public void setUp()Description copied from interface:LocalServiceTestConfigSet up the local service.- Specified by:
setUpin interfaceLocalServiceTestConfig
-
tearDown
public void tearDown()Description copied from interface:LocalServiceTestConfigTear down the local service.- Specified by:
tearDownin interfaceLocalServiceTestConfig
-
getLocalTaskQueue
-