示例#1
0
 public function testJScan()
 {
     $p = new Producer($this->stream);
     $queue = uniqid('jscan_');
     $n = rand(0, 100);
     for ($i = 0; $i < $n; $i++) {
         $p->addJob($queue, Job::create(['body' => '23']));
     }
     $node = new Node($this->stream, $this->log);
     $it = $node->jscan(5, [$queue], [Job::STATE_QUEUED]);
     $busy = $node->jscan(0, [$queue], [Job::STATE_QUEUED]);
     $iterCount = $busyCount = 0;
     $jobs = [];
     foreach ($it as $k => $job) {
         $iterCount++;
         $jobs[] = $job;
     }
     foreach ($busy as $k => $job) {
         $busyCount++;
     }
     // cleanup
     $this->assertEquals($n, $node->del($jobs));
     $this->assertEquals($n, $iterCount);
 }