【问题标题】:Google App Engine: Exception while using TaskQueue with JUnit test casesGoogle App Engine:将 TaskQueue 与 JUnit 测试用例一起使用时出现异常
【发布时间】:2016-11-21 09:30:23
【问题描述】:

我想从 Junit 测试用例中调用任务队列。我的代码是:

@Test
    public void monthlyCronTest1() throws Exception {
....
       Queue queue = QueueFactory.getQueue("updateVcoCron");
       TaskOptions options = TaskOptions.Builder.withUrl(String.format("/api/v1/users/update/validation/points")).method(TaskOptions.Method.GET);
                    options.param("pageNumber", String.valueOf(pageNumber));
                    options.param("validatableBrands", validatableBrands);
          queue.add(options); // this line throw exception
......
}

这里出现错误:

 Exception:java.lang.IllegalStateException: The specified queue is unknown : updateVcoCron
    [junit] 1577867 INFO  org.quartz.impl.StdSchedulerFactory  - Quartz scheduler 'DefaultQuartzScheduler' initialized f
rom default resource file in Quartz package: 'quartz.properties'
    [junit] 1577867 INFO  org.quartz.impl.StdSchedulerFactory  - Quartz scheduler version: UNKNOWN.UNKNOWN.UNKNOWN
    [junit] 1577867 INFO  org.quartz.core.QuartzScheduler  - Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED started.

2) 如果我使用默认队列,例如:

   Queue queue = QueueFactory.getDefaultQueue();

我得到不同的错误。

    [junit] com.google.apphosting.api.ApiProxy$ApplicationException: ApplicationError: 2: Received exception executing h
ttp method GET against URL http://localhost:8080/api/v1/users/update/validation/points?pageNumber=1&validatableBrands=Vi
rgin+Trains: Connection to http://localhost:8080 refused
    [junit]     at com.google.appengine.api.urlfetch.dev.LocalURLFetchService.fetch(LocalURLFetchService.java:412)
    [junit]     at com.google.appengine.api.taskqueue.dev.LocalTaskQueue$UrlFetchServiceLocalTaskQueueCallback.execute(L
ocalTaskQueue.java:701)
    [junit]     at com.google.appengine.api.taskqueue.dev.UrlFetchJob.execute(UrlFetchJob.java:90)
    [junit]     at org.quartz.core.JobRunShell.run(JobRunShell.java:203)
    [junit]     at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
    [junit] 432275 ERROR org.quartz.core.ErrorLogger  - Job (default.task-1a8a7b8a-db49-432e-ac3d-cce784211b8a threw an
exception.

我的 queue.xml 位于以下路径:

src/main/webapp/WEB-INF.

现在我的问题是:JUnit 环境是否还有任何配置?为什么它不选择 queue.xml?请在这里帮忙。

【问题讨论】:

    标签: java google-app-engine junit task-queue


    【解决方案1】:

    我遇到了“指定的队列未知”错误。在查看了这个解决方案 https://stackoverflow.com/a/11200214/2742117 之后,我通过将它添加到我的基础测试类来修复它

    private static String dir;
    static {
      dir = System.getProperty("user.dir") + "/src/main/webapp/WEB-INF/queue.xml";
      System.out.println(dir);
    }
    
    protected final LocalServiceTestHelper helper =
      new LocalServiceTestHelper(
          //some other configurations removed for brevity...
          new LocalTaskQueueTestConfig().setQueueXmlPath(dir)
      );
    

    在此之后,我的测试能够使用我的非默认队列。

    【讨论】:

      猜你喜欢
      • 2012-05-30
      • 2015-11-20
      • 1970-01-01
      • 2018-11-22
      • 2019-02-13
      • 1970-01-01
      • 2017-09-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多