3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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
{
38 /* ----------------------- Queue providers ----------------------- */
40 /* Define a list of queue providers which should be tested */
43 * Return a list of persistent and transient queue providers.
45 public function getQueueSpecs() {
46 $queueSpecs = array();
47 $queueSpecs[] = array(
50 'name' => 'test-queue',
60 public function setUp() {
62 $this->queueService
= CRM_Queue_Service
::singleton(TRUE);
65 public function tearDown() {
66 CRM_Utils_Time
::resetTime();
68 $tablesToTruncate = array('civicrm_queue_item');
69 $this->quickCleanup($tablesToTruncate);
73 * Create a few queue items; alternately enqueue and dequeue various
75 * @dataProvider getQueueSpecs
78 public function testPriorities($queueSpec) {
79 $this->queue
= $this->queueService
->create($queueSpec);
80 $this->assertTrue($this->queue
instanceof CRM_Queue_Queue
);
82 $this->queue
->createItem(array(
85 $this->queue
->createItem(array(
88 $this->queue
->createItem(array(
92 $this->assertEquals(3, $this->queue
->numberOfItems());
93 $item = $this->queue
->claimItem();
94 $this->assertEquals('a', $item->data
['test-key']);
95 $this->queue
->deleteItem($item);
97 $this->assertEquals(2, $this->queue
->numberOfItems());
98 $item = $this->queue
->claimItem();
99 $this->assertEquals('b', $item->data
['test-key']);
100 $this->queue
->deleteItem($item);
102 $this->queue
->createItem(
104 'test-key' => 'start',
110 $this->queue
->createItem(
118 $this->queue
->createItem(array(
122 $this->assertEquals(4, $this->queue
->numberOfItems());
123 $item = $this->queue
->claimItem();
124 $this->assertEquals('start', $item->data
['test-key']);
125 $this->queue
->deleteItem($item);
127 $this->assertEquals(3, $this->queue
->numberOfItems());
128 $item = $this->queue
->claimItem();
129 $this->assertEquals('c', $item->data
['test-key']);
130 $this->queue
->deleteItem($item);
132 $this->assertEquals(2, $this->queue
->numberOfItems());
133 $item = $this->queue
->claimItem();
134 $this->assertEquals('d', $item->data
['test-key']);
135 $this->queue
->deleteItem($item);
137 $this->assertEquals(1, $this->queue
->numberOfItems());
138 $item = $this->queue
->claimItem();
139 $this->assertEquals('end', $item->data
['test-key']);
140 $this->queue
->deleteItem($item);
142 $this->assertEquals(0, $this->queue
->numberOfItems());