public function test_getAllAcquiredLockKeys_shouldReturnUsedKeysThatAreLocked() { $this->assertSame(array(), $this->lock->getAllAcquiredLockKeys()); $this->lock->acquireLock(0); $this->assertSame(array('QueuedTrackingLock0'), $this->lock->getAllAcquiredLockKeys()); $this->lock->acquireLock(4); $this->lock->acquireLock(5); $locks = $this->lock->getAllAcquiredLockKeys(); sort($locks); $this->assertSame(array('QueuedTrackingLock0', 'QueuedTrackingLock4', 'QueuedTrackingLock5'), $locks); }
/** * @return Queue */ public function lockNext() { $this->unlock(); if ($this->currentQueueId < 0) { // we just want to avoid to always start looking for the queue at position 0 $this->currentQueueId = $this->getRandomQueueId(); } // here we look for all available queues whether at least one should and can be processed $start = $this->currentQueueId + 1; // this way we make sure to rotate through all queues $end = $start + $this->numQueuesAvailable; for (; $start < $end; $start++) { $this->currentQueueId = $start % $this->numQueuesAvailable; $queue = $this->createQueue($this->currentQueueId); if ($queue->shouldProcess() && $this->lock->acquireLock($this->currentQueueId)) { return $queue; } } }
public function test_process_ShouldNotDirectlyProcessQueue_IfAlreadyLocked() { Queue\Factory::getSettings()->numQueueWorkers->setValue(1); $this->handler->enableProcessingInTrackerMode(); $this->queue->setNumberOfRequestsToProcessAtSameTime(1); // there is only one worker, so make sure that queue is locked $lock = new Queue\Lock($this->backend); $lock->acquireLock(0); $this->assertSame(0, $this->queue->getNumberOfRequestSetsInAllQueues()); $this->processDummyRequests(); $this->assertSame(1, $this->queue->getNumberOfRequestSetsInAllQueues()); $this->processDummyRequests(); $this->assertSame(2, $this->queue->getNumberOfRequestSetsInAllQueues()); $this->queue->unlock(); }
private function acquireAllQueueLocks() { for ($queueId = 0; $queueId < $this->queue->getNumberOfAvailableQueues(); $queueId++) { $this->lock->acquireLock($queueId); } }