Example #1
0
 public function test_blocking_dequeue_2_items_from_a_queue_that_will_be_filled_only_by_1_item()
 {
     $pid = $this->fork();
     if ($pid) {
         $start = time();
         $this->assertEquals(['foo bar'], $this->queue->dequeue(2, 100));
         $this->assertGreaterThanOrEqual($start + $this->childSleep, time());
     } else {
         sleep($this->childSleep);
         $this->queue->push(['foo bar']);
         exit(0);
     }
 }
 public function test_shifted_items_are_consecutive_when_using_blpop()
 {
     $messageQueue = new Queue($this->redis, 'fifo:message_queue');
     for ($i = 0; $i < 2; $i++) {
         if (!$this->fork()) {
             $items = $this->queue->shift(2, 100);
             if (is_array($items) && count($items) == 2 && $items[1] == $items[0] - 1) {
                 $messageQueue->push(['OK']);
             } else {
                 $messageQueue->push(['ERROR']);
             }
             exit(0);
         }
     }
     sleep($this->childSleep);
     $this->queue->unShift([1, 2, 3, 4]);
     $this->assertEquals(['OK'], $messageQueue->dequeue(1, 100));
     $this->assertEquals(['OK'], $messageQueue->dequeue(1, 100));
 }
 /**
  * @param PriorityItem[] $items
  * @return int the number of elements added
  * The ids of items will be set on return
  */
 public function enqueue(array $items)
 {
     $n = parent::enqueue($items);
     $this->list->push(array_fill(0, $n, ''));
     return $n;
 }
Example #4
0
 public function push(array $items)
 {
     $this->mainQueue->push($items);
     return $this->safeQueue->push(array_fill(0, count($items), ''));
 }
 public function test_many_child_processes_can_multipop_from_a_queue_that_will_get_filled_gradually()
 {
     $messageQueue = new Queue($this->redis, 'fifo:message_queue');
     for ($i = 0; $i < 10; $i++) {
         if (!$this->fork()) {
             $items = $this->queue->dequeue(2, 100);
             if (count($items) == 2) {
                 $messageQueue->push([$items[0]->value, $items[1]->value]);
             }
             exit(0);
         }
     }
     sleep($this->childSleep);
     $items = [];
     $now = time();
     for ($i = 0; $i < 10; $i++) {
         $items[] = new PriorityItem($i, $now + $i);
         $items[] = new PriorityItem($i, $now + $i);
     }
     $this->queue->enqueue($items);
     for ($i = 0; $i < 10; $i++) {
         $this->assertCount(2, $messageQueue->dequeue(2, 100));
     }
 }