Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
JobQueueTest.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
37  class JobQueueTest extends BaseTest
38  {
39  public static function setUpBeforeClass()
40  {
41  parent::setUpBeforeClass();
42  }
43 
44  public function testAddAndGetAll()
45  {
46  $this->assertCount(0, Yii::app()->jobQueue->getAll());
47  Yii::app()->jobQueue->add('aJob', 13);
48  $queuedJobs = Yii::app()->jobQueue->getAll();
49  $this->assertCount(1, $queuedJobs[13]);
50  $this->assertEquals('aJob', $queuedJobs[13][0]['jobType']);
51  //Try to add it again
52  Yii::app()->jobQueue->add('aJob', 13);
53  $queuedJobs = Yii::app()->jobQueue->getAll();
54  $this->assertCount(1, $queuedJobs[13]);
55 
56  Yii::app()->jobQueue->add('aJob', 10);
57  $queuedJobs = Yii::app()->jobQueue->getAll();
58  $this->assertCount(1, $queuedJobs[10]);
59 
60  // And add it with tolerance
61  Yii::app()->jobQueue->add('aJob', 15);
62  $queuedJobs = Yii::app()->jobQueue->getAll();
63  $this->assertCount(1, $queuedJobs[15]);
64  $this->assertFalse(isset($queuedJobs[13]));
65  $this->assertEquals('aJob', $queuedJobs[15][0]['jobType']);
66 
67  // Now add same job, but with delay that is much higher then existing job with noise
68  Yii::app()->jobQueue->add('aJob', 100);
69  $queuedJobs = Yii::app()->jobQueue->getAll();
70  $this->assertCount(1, $queuedJobs[15]);
71  $this->assertCount(1, $queuedJobs[100]);
72  $this->assertEquals('aJob', $queuedJobs[100][0]['jobType']);
73 
74  //Try to add a new job
75  Yii::app()->jobQueue->add('bJob', 15);
76  $queuedJobs = Yii::app()->jobQueue->getAll();
77  $this->assertCount(2, $queuedJobs[15]);
78  $this->assertEquals('aJob', $queuedJobs[15][0]['jobType']);
79  $this->assertEquals('bJob', $queuedJobs[15][1]['jobType']);
80  //Add an immediate job
81  Yii::app()->jobQueue->add('cJob');
82  $queuedJobs = Yii::app()->jobQueue->getAll();
83  $this->assertCount(1, $queuedJobs[0]);
84  $this->assertEquals('cJob', $queuedJobs[0][0]['jobType']);
85  }
86 
90  public function testDeleteAll()
91  {
92  $queuedJobs = Yii::app()->jobQueue->getAll();
93  $this->assertCount(4, $queuedJobs);
94  $this->assertCount(1, $queuedJobs[10]);
95  $this->assertCount(2, $queuedJobs[15]);
96  $this->assertCount(1, $queuedJobs[100]);
97  $this->assertCount(1, $queuedJobs[0]);
98  Yii::app()->jobQueue->deleteAll();
99  $queuedJobs = Yii::app()->jobQueue->getAll();
100  $this->assertCount(0, $queuedJobs);
101  }
102  }
103 ?>
Generated on Mon Nov 30 2020 07:10:40
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.