3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 require_once 'CiviTest/CiviUnitTestCase.php';
32 * Ensure that the extended interface for SQL-backed queues
33 * work. For example, the createItem() interface supports
36 class CRM_Queue_Queue_SqlTest
extends CiviUnitTestCase
{
39 'name' => 'SQL Queue',
40 'description' => 'Test SQL-backed queue items',
45 /* ----------------------- Queue providers ----------------------- */
47 /* Define a list of queue providers which should be tested */
50 * Return a list of persistent and transient queue providers
52 function getQueueSpecs() {
53 $queueSpecs = array();
54 $queueSpecs[] = array(
57 'name' => 'test-queue',
62 /* ----------------------- Per-provider tests ----------------------- */
65 $this->queueService
= CRM_Queue_Service
::singleton(TRUE);
69 CRM_Utils_Time
::resetTime();
71 $tablesToTruncate = array('civicrm_queue_item');
72 $this->quickCleanup($tablesToTruncate);
76 * Create a few queue items; alternately enqueue and dequeue various
78 * @dataProvider getQueueSpecs
80 function testPriorities($queueSpec) {
81 $this->queue
= $this->queueService
->create($queueSpec);
82 $this->assertTrue($this->queue
instanceof CRM_Queue_Queue
);
84 $this->queue
->createItem(array(
87 $this->queue
->createItem(array(
90 $this->queue
->createItem(array(
94 $this->assertEquals(3, $this->queue
->numberOfItems());
95 $item = $this->queue
->claimItem();
96 $this->assertEquals('a', $item->data
['test-key']);
97 $this->queue
->deleteItem($item);
99 $this->assertEquals(2, $this->queue
->numberOfItems());
100 $item = $this->queue
->claimItem();
101 $this->assertEquals('b', $item->data
['test-key']);
102 $this->queue
->deleteItem($item);
104 $this->queue
->createItem(
106 'test-key' => 'start',
112 $this->queue
->createItem(
120 $this->queue
->createItem(array(
124 $this->assertEquals(4, $this->queue
->numberOfItems());
125 $item = $this->queue
->claimItem();
126 $this->assertEquals('start', $item->data
['test-key']);
127 $this->queue
->deleteItem($item);
129 $this->assertEquals(3, $this->queue
->numberOfItems());
130 $item = $this->queue
->claimItem();
131 $this->assertEquals('c', $item->data
['test-key']);
132 $this->queue
->deleteItem($item);
134 $this->assertEquals(2, $this->queue
->numberOfItems());
135 $item = $this->queue
->claimItem();
136 $this->assertEquals('d', $item->data
['test-key']);
137 $this->queue
->deleteItem($item);
139 $this->assertEquals(1, $this->queue
->numberOfItems());
140 $item = $this->queue
->claimItem();
141 $this->assertEquals('end', $item->data
['test-key']);
142 $this->queue
->deleteItem($item);
144 $this->assertEquals(0, $this->queue
->numberOfItems());