private void executeTasksUntilEmpty(String queueName) throws Exception {
   while (true) {
     // We have to reacquire task list every time, because local implementation returns a copy.
     List<TaskStateInfo> taskInfo = taskQueue.getQueueStateInfo().get(queueName).getTaskInfo();
     if (taskInfo.isEmpty()) {
       break;
     }
     TaskStateInfo taskStateInfo = taskInfo.get(0);
     taskQueue.deleteTask(queueName, taskStateInfo.getTaskName());
     executeTask(queueName, taskStateInfo);
   }
 }
  private void executeTask(String queueName, TaskStateInfo taskStateInfo) throws Exception {
    logger.info("Executing " + taskStateInfo.getTaskName());

    HttpServletRequest request = createMock(HttpServletRequest.class);
    HttpServletResponse response = createMock(HttpServletResponse.class);

    expect(request.getRequestURI()).andReturn(taskStateInfo.getUrl()).anyTimes();
    expect(request.getHeader("X-AppEngine-QueueName")).andReturn(queueName).anyTimes();

    Map<String, String> parameters = decodeParameters(taskStateInfo.getBody());
    for (String name : parameters.keySet()) {
      expect(request.getParameter(name)).andReturn(parameters.get(name)).anyTimes();
    }

    replay(request, response);

    if (taskStateInfo.getMethod().equals("POST")) {
      servlet.doPost(request, response);
    } else {
      throw new UnsupportedOperationException();
    }
  }