Skip to content

Instantly share code, notes, and snippets.

@alejandrogr
Last active November 17, 2018 13:06
Show Gist options
  • Save alejandrogr/fba129f0eadce6b13c1f to your computer and use it in GitHub Desktop.
Save alejandrogr/fba129f0eadce6b13c1f to your computer and use it in GitHub Desktop.
Appengine JunitTest TaskLauncher
public static void executeTasksInQueue(String p_queue) throws InterruptedException, ServletException, IOException{
LocalTaskQueue ltq = LocalTaskQueueTestConfig.getLocalTaskQueue();
QueueStateInfo qsi = ltq.getQueueStateInfo().get(QueueFactory.getQueue(p_queue).getQueueName());
System.out.println("tasks in queue " + qsi.getTaskInfo().size());
int i, I = qsi.getTaskInfo().size();
for (i = 0; i < I; i++) {
QueueStateInfo.TaskStateInfo tsi = qsi.getTaskInfo().get(i);
String body = tsi.getBody();
System.out.println("body -> " + body);
Map<String, String> queryMap = getQueryMap(body);
HttpServletRequest req = mock(HttpServletRequest.class);
HttpServletResponse res = mock(HttpServletResponse.class);
Set<String> keys = queryMap.keySet();
for (String key : keys) {
Mockito.when(req.getParameter(key)).thenReturn(queryMap.get(key));
}
Task task = new TaskFactory().getTask(tsi.getUrl());
task.executeTask(req, res);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment