测试非默认App Engine任务队列

时间:2020-11-27 02:16:38

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.

App Engine文档提供了单元测试任务队列的示例,它适用于“默认”队列,但我需要对非默认队列进行单元测试。

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.

我假设我需要在我的测试环境中配置非默认队列,就像需要配置非默认生产队列一样(通过queue.xml),但我不知道如何解决这个问题。

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

我的测试环境中是否需要某个queue.xml文件?如果是的话,在哪里。

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

我在资源目录中使用queue.xml文件尝试了以下操作,但它抱怨没有找到org / mortbay / xml / XmlParser

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

2 个解决方案

#1


5  

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)

是的,您将其配置为与其他单元测试工具类一样,并将其传递给测试队列文件的路径,我的恰好位于/ src / test / resources(maven项目的常用位置)

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

这是我的基础junit测试类的片段...

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:

有关Rick Mangi评论的更多细节。如果您收到如下错误:

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

add this to your pom.xml:

将其添加到您的pom.xml:

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

#2


0  

When using the gradle plugin, make sure to include:

使用gradle插件时,请确保包括:

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

#1


5  

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)

是的,您将其配置为与其他单元测试工具类一样,并将其传递给测试队列文件的路径,我的恰好位于/ src / test / resources(maven项目的常用位置)

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

这是我的基础junit测试类的片段...

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:

有关Rick Mangi评论的更多细节。如果您收到如下错误:

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

add this to your pom.xml:

将其添加到您的pom.xml:

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

#2


0  

When using the gradle plugin, make sure to include:

使用gradle插件时,请确保包括:

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