Reputation: 1517
I want to call task queue from Junit Test cases. my code is:
@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
......
}
here I am getting error:
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) If I use default Queue like:
Queue queue = QueueFactory.getDefaultQueue();
I get different error.
[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.
src/main/webapp/WEB-INF.
Now my question: is there any configuration left for JUnit environment? why it is not picking queue.xml? Please help here.
Upvotes: 3
Views: 964
Reputation: 2263
I was getting this issue not in my unit tests, but in actuality. In the end I had to actually add the new queue in my queue.xml
<queue>
<name>myNewQueue</name>
<rate>100/s</rate>
<max-concurrent-requests>100</max-concurrent-requests>
<retry-parameters>
<task-age-limit>300h</task-age-limit>
<min-backoff-seconds>10</min-backoff-seconds>
<max-backoff-seconds>200</max-backoff-seconds>
<max-doublings>0</max-doublings>
</retry-parameters>
<target>my-queue-service</target>
</queue>
Upvotes: 0
Reputation: 504
I was experiencing the "The specified queue is unknown" error. After looking at this solution https://stackoverflow.com/a/11200214/2742117, I fixed it by adding this to my base test class
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)
);
After this my tests were able to work with my non default queue.
Upvotes: 3