3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 * Ensure that the extended interface for SQL-backed queues
30 * work. For example, the createItem() interface supports
34 class CRM_Queue_Queue_SqlTest
extends CiviUnitTestCase
{
36 /* ----------------------- Queue providers ----------------------- */
38 /* Define a list of queue providers which should be tested */
41 * Return a list of persistent and transient queue providers.
43 public function getQueueSpecs() {
44 $queueSpecs = array();
45 $queueSpecs[] = array(
48 'name' => 'test-queue',
58 public function setUp() {
60 $this->queueService
= CRM_Queue_Service
::singleton(TRUE);
63 public function tearDown() {
64 CRM_Utils_Time
::resetTime();
66 $tablesToTruncate = array('civicrm_queue_item');
67 $this->quickCleanup($tablesToTruncate);
71 * Create a few queue items; alternately enqueue and dequeue various
73 * @dataProvider getQueueSpecs
76 public function testPriorities($queueSpec) {
77 $this->queue
= $this->queueService
->create($queueSpec);
78 $this->assertTrue($this->queue
instanceof CRM_Queue_Queue
);
80 $this->queue
->createItem(array(
83 $this->queue
->createItem(array(
86 $this->queue
->createItem(array(
90 $this->assertEquals(3, $this->queue
->numberOfItems());
91 $item = $this->queue
->claimItem();
92 $this->assertEquals('a', $item->data
['test-key']);
93 $this->queue
->deleteItem($item);
95 $this->assertEquals(2, $this->queue
->numberOfItems());
96 $item = $this->queue
->claimItem();
97 $this->assertEquals('b', $item->data
['test-key']);
98 $this->queue
->deleteItem($item);
100 $this->queue
->createItem(
102 'test-key' => 'start',
108 $this->queue
->createItem(
116 $this->queue
->createItem(array(
120 $this->assertEquals(4, $this->queue
->numberOfItems());
121 $item = $this->queue
->claimItem();
122 $this->assertEquals('start', $item->data
['test-key']);
123 $this->queue
->deleteItem($item);
125 $this->assertEquals(3, $this->queue
->numberOfItems());
126 $item = $this->queue
->claimItem();
127 $this->assertEquals('c', $item->data
['test-key']);
128 $this->queue
->deleteItem($item);
130 $this->assertEquals(2, $this->queue
->numberOfItems());
131 $item = $this->queue
->claimItem();
132 $this->assertEquals('d', $item->data
['test-key']);
133 $this->queue
->deleteItem($item);
135 $this->assertEquals(1, $this->queue
->numberOfItems());
136 $item = $this->queue
->claimItem();
137 $this->assertEquals('end', $item->data
['test-key']);
138 $this->queue
->deleteItem($item);
140 $this->assertEquals(0, $this->queue
->numberOfItems());