/**
  * @expectedException \Phloppy\Exception\CommandException
  * @expectedExceptionMessage MAXLEN Queue is already longer than the specified MAXLEN count
  */
 public function testAddJobMaxlen()
 {
     $queue = 'test-' . substr(sha1(mt_rand()), 0, 6);
     $producer = new Producer($this->stream);
     $producer->addJob($queue, Job::create(['body' => 'job-maxlen-1']));
     $producer->addJob($queue, Job::create(['body' => 'job-maxlen-2']));
     $producer->addJob($queue, Job::create(['body' => 'job-maxlen-3']), 1);
 }
Exemple #2
0
 /**
  * @expectedException \Phloppy\Exception\CommandException
  * @expectedExceptionMessage ERR Foo
  */
 public function testAddJobWithInvalidReplicate()
 {
     $mock = $this->getMock('\\Phloppy\\Stream\\StreamInterface');
     $mock->expects($this->any())->method('write')->willReturn($mock);
     $mock->expects($this->any())->method('readLine')->willReturn("-ERR Foo");
     $p = new Producer($mock);
     $p->addJob('test', Job::create(['body' => 42]));
 }
 public function testWorking()
 {
     $retry = rand(30, 60);
     $queue = 'test-' . substr(sha1(mt_rand()), 0, 6);
     $consumer = new Consumer($this->stream);
     $producer = new Producer($this->stream);
     $producer->addJob($queue, Job::create(['body' => __METHOD__, 'retry' => $retry, 'ttl' => 600]));
     $job = $consumer->getJob($queue);
     $this->assertEquals($retry, $consumer->working($job));
 }
 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);
 }
 public function testEnqueueDequeue()
 {
     $queueName = 'test-' . substr(sha1(mt_rand()), 0, 6);
     $queue = new Queue($this->stream);
     $producer = new Producer($this->stream);
     $node = new Node($this->stream);
     $this->assertEquals(0, $queue->len($queueName));
     $job1 = $producer->addJob($queueName, Job::create(['body' => 'test-enq-deq-1']));
     $job2 = $producer->addJob($queueName, Job::create(['body' => 'test-enq-deq-2']));
     $this->assertEquals(2, $queue->len($queueName));
     // dequeue one of the jobs
     $this->assertEquals(1, $queue->dequeue([$job1->getId()]));
     // now only one job left in queue
     $this->assertEquals(1, $queue->len($queueName));
     // job2 still enqueued, so none should be enqueued
     $this->assertEquals(0, $queue->enqueue([$job2->getId()]));
     // job1 is enqueued again, so 1 should be returned
     $this->assertEquals(1, $queue->enqueue([$job1->getId()]));
     // and the queue has len 2 again
     $this->assertEquals(2, $queue->len($queueName));
     // cleanup
     $this->assertEquals(2, $node->del([$job1->getId(), $job2->getId()]));
 }