Beispiel #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->isInstanceOf('ExampleData'))->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')));
     $protocolFactory = new TBinaryProtocolFactory();
     $transport = new TMemoryBuffer();
     $protocol = $protocolFactory->getProtocol($transport);
     // Fill a mock queue backend
     for ($i = 0; $i < 5; $i++) {
         /** @var $job PHPUnit_Framework_MockObject_MockObject|Job */
         $job = $this->getMock('Job');
         $doc = new ExampleData();
         $doc->language = 'php';
         $doc->api = 'simple' . $i;
         $doc->format = 'thrift';
         $doc->write($protocol);
         $message = $transport->read($transport->available());
         $job->message = $message;
         $job->id = $i;
         $this->addToQueueBackend($job);
     }
     $consumer = new jp_consumer_Thrift('foo', array('client' => $client, 'poll_interval' => 0), $worker, 'ExampleData');
     $this->assertEquals(5, $consumer->run());
 }
Beispiel #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');
$GLOBALS['THRIFT_ROOT'] = 'Thrift';
require_once 'jp/consumer/Thrift.php';
require_once 'jp/worker/Interface.php';
require_once dirname(__FILE__) . '/../gen-php/example/example_types.php';
class ThriftQueueWorker implements jp_worker_Interface
{
    public function processItem($message)
    {
        echo 'I consumed: ' . print_r($message, true);
        return true;
    }
}
$processor = new jp_consumer_Thrift('thrift', array('poll_interval' => 200), new ThriftQueueWorker(), 'ExampleData');
$processor->run();