Testing non-default App Engine task queues

前端 未结 2 1981
天涯浪人
天涯浪人 2021-01-03 08:45

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\'

相关标签:
2条回答
  • 2021-01-03 09:34

    When using the gradle plugin, make sure to include:

    testCompile 'com.google.appengine:appengine-tools-sdk:1.9.9'
    
    0 讨论(0)
  • 2021-01-03 09:41

    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 讨论(0)
提交回复
热议问题