4
votes

App Engine documentation gives an example of unit testing task queues, which works fine for the "default" queue, but I need a unit test for non-default queues.

I'm getting an exception from the following line:

val qsi = ltq.getQueueStateInfo.get("non-default");

I assume that I need to configure the non-default queue in my testing environment in much the same way that non-default production queues need to be configured (via queue.xml), but I'm not sure how to go about this.

Do I need a queue.xml file somewhere in my testing environment? And if so, where.

I've tried the following with a queue.xml file in my resources directory, but it complains about not finding org/mortbay/xml/XmlParser

 val ltqtc = new LocalTaskQueueTestConfig
 ltqtc.setQueueXmlPath(this.getClass.getResource("queue.xml").getPath)
 val helper = new LocalServiceTestHelper(ltqtc)
2

2 Answers

6
votes

Yes, you configure it just like the other unit test harness classes and pass it the path to your test queue.xml, mine happens to be in /src/test/resources (the usual place for a maven project)

Here's a snippet from my base junit test class...

static {
    dir = System.getProperty("user.dir") + "/src/test/resources/queue.xml";

}
private final LocalServiceTestHelper helper = new LocalServiceTestHelper(
        new LocalDatastoreServiceTestConfig(),
        new LocalTaskQueueTestConfig().setQueueXmlPath(dir));

And then you can do things like (and sorry if this is out of context, but it should give you the idea.. and it's groovy so it might look odd)

//do something that might trigger a queue to run...
    NotificationService.getInstance().doNotification(interaction)

    LocalTaskQueue taskQueue = LocalTaskQueueTestConfig.getLocalTaskQueue()
    Map allQueues = taskQueue.getQueueStateInfo()
    QueueStateInfo mailQueue = allQueues.get(EmailTaskQueue.MAIL_QUEUE)
    assert mailQueue.getCountTasks() == 1

More details on Rick Mangi's comment. If you get an error like:

 java.lang.NoClassDefFoundError: org/mortbay/xml/XmlParser

add this to your pom.xml:

<dependency>
  <groupId>com.google.appengine</groupId>
  <artifactId>appengine-tools-sdk</artifactId>
  <version>${gae.version}</version>
</dependency>
0
votes

When using the gradle plugin, make sure to include:

testCompile 'com.google.appengine:appengine-tools-sdk:1.9.9'