Exemplo n.º 1
0
 /**
  * @return void
  */
 public function testRun()
 {
     /** @var $worker PHPUnit_Framework_MockObject_MockObject|jp_worker_Interface */
     $worker = $this->getMock('jp_worker_Interface');
     $worker->expects($this->exactly(5))->method('processItem')->with($this->stringContains('foo'))->will($this->returnValue(true));
     /** @var $client PHPUnit_Framework_MockObject_MockObject|JobPoolIf */
     $client = $this->getMock('JobPoolIf');
     $client->expects($this->exactly(6))->method('acquire')->will($this->returnCallback(array($this, 'mockAcquire')));
     // Fill a mock queue backend
     for ($i = 0; $i < 5; $i++) {
         /** @var $job PHPUnit_Framework_MockObject_MockObject|Job */
         $job = $this->getMock('Job');
         $job->message = 'foo-' . $i;
         $job->id = $i;
         $this->addToQueueBackend($job);
     }
     $consumer = new jp_consumer_Text('foo', array('client' => $client, 'poll_interval' => 0), $worker);
     $this->assertEquals(5, $consumer->run());
 }
Exemplo n.º 2
0
#!/usr/bin/php
<?php 
set_time_limit(0);
$jpRoot = dirname(__FILE__) . '/../../';
set_include_path(get_include_path() . PATH_SEPARATOR . $jpRoot . 'lib/php' . PATH_SEPARATOR . $jpRoot . 'gen-php/jp');
require_once 'jp/consumer/Text.php';
require_once 'jp/worker/Interface.php';
class TextQueueWorker implements jp_worker_Interface
{
    public function processItem($item)
    {
        echo 'I consumed a ' . $item . PHP_EOL;
        return true;
    }
}
$consumer = new jp_consumer_Text('text', array('poll_interval' => 200), new TextQueueWorker());
$consumer->run();