Java Code Examples for com.google.appengine.api.taskqueue.Queue#leaseTasks()
The following examples show how to use
com.google.appengine.api.taskqueue.Queue#leaseTasks() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskQueueServlet.java From appengine-java-vm-runtime with Apache License 2.0 | 6 votes |
private void leaseAndDeleteTasks(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { int numTasks = Integer.parseInt(req.getParameter("numTasks")); Double lease = Double.parseDouble(req.getParameter("lease")); String queue = req.getParameter("queue"); Queue q = QueueFactory.getQueue(queue); Boolean doDelete = Boolean.parseBoolean(req.getParameter("doDelete")); List<TaskHandle> tasks = q.leaseTasks(lease.intValue() * 1000, TimeUnit.MILLISECONDS, numTasks); for (TaskHandle task : tasks) { if (doDelete) { q.deleteTask(task.getName()); } } resp.getWriter().print(queue + "," + tasks.size()); }
Example 2
Source File: SmokeTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test public void testBasics() throws Exception { final Queue queue = QueueFactory.getQueue("pull-queue"); sync(2000L); TaskHandle th = queue.add(TaskOptions.Builder.withMethod(TaskOptions.Method.PULL).param("foo", "bar".getBytes())); try { List<TaskHandle> handles = queue.leaseTasks(30, TimeUnit.MINUTES, 100); Assert.assertFalse(handles.isEmpty()); Assert.assertEquals(1, handles.size()); TaskHandle lh = handles.get(0); Assert.assertEquals(th.getName(), lh.getName()); sync(5000L); } finally { queue.deleteTask(th); } }
Example 3
Source File: PullTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testPullParams() throws Exception { final Queue queue = QueueFactory.getQueue("pull-queue"); TaskHandle th = queue.add(withMethod(PULL).param("foo", "bar").etaMillis(15000)); sync(); try { List<TaskHandle> handles = queue.leaseTasks(30, TimeUnit.MINUTES, 100); assertFalse(handles.isEmpty()); TaskHandle lh = handles.get(0); assertEquals(th.getName(), lh.getName()); } finally { queue.deleteTask(th); } }
Example 4
Source File: PullTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testPullPayload() throws Exception { final Queue queue = QueueFactory.getQueue("pull-queue"); TaskHandle th = queue.add(withMethod(PULL).payload("foobar".getBytes()).etaMillis(15000)); sync(); try { List<TaskHandle> handles = queue.leaseTasks(30, TimeUnit.MINUTES, 100); assertFalse(handles.isEmpty()); TaskHandle lh = handles.get(0); assertEquals(th.getName(), lh.getName()); } finally { queue.deleteTask(th); } }
Example 5
Source File: PullTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testLeaseTasksOnlyReturnsSpecifiedNumberOfTasks() { Queue queue = QueueFactory.getQueue("pull-queue"); TaskHandle th1 = queue.add(withMethod(PULL)); TaskHandle th2 = queue.add(withMethod(PULL)); sync(); try { int countLimit = 1; List<TaskHandle> handles = queue.leaseTasks(10, TimeUnit.SECONDS, countLimit); assertEquals(countLimit, handles.size()); } finally { queue.deleteTask(th1); queue.deleteTask(th2); } }
Example 6
Source File: PullQueueTest.java From appengine-tck with Apache License 2.0 | 4 votes |
@Test(expected = InvalidQueueModeException.class) public void testLeaseFromNonPullQueue() { Queue remoteQueue = QueueFactory.getQueue(E2E_TESTING_REMOTE); remoteQueue.leaseTasks(1, TimeUnit.MILLISECONDS, 1); }
Example 7
Source File: PullQueueTest.java From appengine-tck with Apache License 2.0 | 4 votes |
@Test(expected = IllegalStateException.class) public void testLeaseNonExistQueue() { Queue nonExistQueue = QueueFactory.getQueue("nonExistQueue"); nonExistQueue.leaseTasks(1, TimeUnit.MILLISECONDS, 1); }
Example 8
Source File: TasksTest.java From appengine-tck with Apache License 2.0 | 4 votes |
@Test(expected = InvalidQueueModeException.class) public void testLeaseTaskFromPushQueueThrowsException() { Queue pushQueue = QueueFactory.getDefaultQueue(); pushQueue.leaseTasks(1000, TimeUnit.SECONDS, 1); }