测试非默认App Engine任务队列 [英] Testing non-default App Engine task queues
问题描述
App Engine文档给出了一个例如单元测试任务的队列,对于默认队列工作正常,但我需要对非默认队列进行单元测试。
我从以下行中得到一个异常:
val qsi = ltq.getQueueStateInfo.get(non-default);
我假设我需要在测试环境中以非常相似的方式配置非默认队列非默认生产队列需要配置(通过queue.xml),但我不知道如何去做这件事。
我需要一个队列吗? xml文件在我的测试环境中的某处?如果是这样,在哪里。
我已经在我的资源目录中用一个queue.xml文件尝试了以下内容,但它抱怨没有找到组织/ mortbay / XML / XmlParser的
VAL ltqtc =新LocalTaskQueueTestConfig
ltqtc.setQueueXmlPath (this.getClass.getResource(queue.xml)。getPath)
val helper = new LocalServiceTestHelper(ltqtc)
是的,你像配置其他单元测试用具类一样配置它,并将它传递到测试queue.xml的路径,我恰好在/ src / 测试/资源(Maven项目的常用地点)
这是我的junit测试类的一个片段...
static {
dir = System.getProperty(user.dir)+/src/test/resources/queue.xml;
}
私人最终LocalServiceTestHelper帮手=新LocalServiceTestHelper(
新LocalDatastoreServiceTestConfig(),
新LocalTaskQueueTestConfig()setQueueXmlPath(目录)。);
然后你可以做这样的事情(并且对不起,如果这不符合上下文,但它应该给你的想法..它的常规,所以它可能看起来很奇怪)
//做一些可能会触发队列运行的事情。 ..
NotificationService.getInstance()。doNotification(相互作用)
LocalTaskQueue TASKQUEUE = LocalTaskQueueTestConfig.getLocalTaskQueue()
地图allQueues = taskQueue.getQueueStateInfo()
QueueStateInfo mailQueue = allQueues.get(EmailTaskQueue.MAIL_QUEUE)
断言mailQueue.getCountTasks()== 1个
更多关于瑞克·姬吉的评论的细节。如果出现如下错误:
java.lang.NoClassDefFoundError:org / mortbay / xml / XmlParser
code>
将其添加到您的pom.xml中:
<依赖性>
< groupId> com.google.appengine< / groupId>
< artifactId> appengine-tools-sdk< / artifactId>
< version> $ {gae.version}< / version>
< /依赖关系>
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)
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>
这篇关于测试非默认App Engine任务队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!