Exemplo n.º 1
0
 /**
  * Check we can use the getters and setters appropriately
  * 
  * @return void
  * 
  * @test
  */
 public function testGettersSetters()
 {
     //Get a task
     $_task = $this->_getTask();
     //test priority
     $_priority = 123;
     $_task->setPriority($_priority);
     $this->assertEquals($_priority, $_task->getPriority(), 'Check that priority was set correctly');
     //test ttr
     $_ttr = 62;
     $_task->setTtr($_ttr);
     $this->assertEquals($_ttr, $_task->getTtr(), 'Check that ttr was set correctly');
     //test delay
     $_delay = 10;
     $_task->setDelay($_delay);
     $this->assertEquals($_delay, $_task->getDelay(), 'Check that delay was set correctly');
     //test status
     $_status = 'testing';
     $_task->setStatus($_status);
     $this->assertEquals($_status, $_task->getStatus(), 'Check that status was set correctly');
     //set the task to the queue
     $this->_adapter->addTask($this->_queue, $_task);
     //peek at queue task
     $_task2 = $this->_adapter->getUnreservedDelayedTask($this->_queue);
     //check that the data is as expected
     $this->assertEquals(array('queue' => 'unit_tests', 'state' => 'delayed', 'priority' => (string) $_priority, 'age' => '0', 'delay' => (string) $_delay, 'ttr' => (string) $_ttr, 'expiration' => (string) ($_delay - 1), 'reserves' => '0', 'timeouts' => '0', 'releases' => '0', 'holds' => '0', 'unholds' => '0'), $this->_adapter->getInformation($_task2)->getData(), 'Check that the task information is as we expected');
     //kick the delayed tasks
     $this->_adapter->unholdMultiple(10);
     //delete the task that was set
     $this->_adapter->remove($this->_queue, $_task2);
 }
Exemplo n.º 2
0
 /**
  * Check that we can queue multiple tasks, hold them, and then unhold them all
  * 
  * @return void
  * 
  * @test
  */
 public function testMultipleUnhold()
 {
     //number of tasks to work with
     $_taskCount = 5;
     $_tasks = array();
     //create and queue the tasks
     for ($i = 0; $i < $_taskCount; $i++) {
         //add and then retrieve the task
         $this->_queue->addTask($this->_getTask(self::DEFAULT_TASK_DATA, 'test_error'));
         $_tasks[$i] = $this->_queue->getNextUnreservedTask();
         //run the tasks
         $this->_queue->runNextTask();
         //check it's been held
         $this->assertEquals(Lilmuckers_Queue_Model_Queue_Task_State::HELD, $_tasks[$i]->getInfo(true)->getState(), 'Check that the task was held');
     }
     // multiple unholds
     $this->_adapter->unholdMultiple(10);
     //create and queue the tasks
     for ($i = 0; $i < $_taskCount; $i++) {
         //check it's been held
         $this->assertEquals(Lilmuckers_Queue_Model_Queue_Task_State::QUEUED, $_tasks[$i]->getInfo(true)->getState(), 'Check that the task was unheld');
         //remove the task
         $this->_queue->remove($_tasks[$i]);
     }
 }
 /**
  * Test that a task can be held and unheld
  * 
  * @return void
  * 
  * @test
  */
 public function testHoldTask()
 {
     //generate a random value to verify
     $_testValue = mt_rand();
     //create a task and check it's instantiated
     $_task = $this->_getTask($_testValue);
     //add task to queue
     $this->_adapter->addTask($this->_queue, $_task);
     //reserve a queue task
     $_task2 = $this->_adapter->getTask($this->_queue->getName());
     //put the task on hold
     $this->_adapter->hold($this->_queue, $_task2);
     //get the info on the task
     $this->assertEquals(Lilmuckers_Queue_Model_Queue_Task_State::HELD, $_task2->getInfo(true)->getState(), 'Check that the task was held');
     //unhold the task - this doesn't cover standard hold
     $this->_adapter->unholdMultiple(10, $this->_queue);
     //get the info on the task
     $this->assertEquals(Lilmuckers_Queue_Model_Queue_Task_State::QUEUED, $_task2->getInfo(true)->getState(), 'Check that the task was requeued');
     //delete the task that was set
     $this->_adapter->remove($this->_queue, $_task2);
 }