コード例 #1
0
ファイル: BeanstalkTest.php プロジェクト: zwilias/beanie
 public function setUp()
 {
     $host = getenv('BEANSTALK_HOST') ?: 'localhost';
     $port = getenv('BEANSTALK_PORT') ?: 11300;
     $this->serverName = sprintf('%s:%s', $host, $port);
     $this->beanie = \Beanie\Beanie::pool([$this->serverName]);
 }
コード例 #2
0
ファイル: BeanieTest.php プロジェクト: zwilias/beanie
 public function testPool_createsInstanceWithPool()
 {
     $servers = ['test1', 'test2'];
     $poolMock = $this->getMockBuilder(Pool::class)->disableOriginalConstructor()->getMock();
     $poolFactoryMock = $this->getMockBuilder(PoolFactory::class)->setMethods(['create'])->getMock();
     $poolFactoryMock->expects($this->once())->method('create')->with($servers)->willReturn($poolMock);
     $beanie = Beanie::pool($servers, $poolFactoryMock);
     $this->assertInstanceOf(Beanie::class, $beanie);
 }
コード例 #3
0
 public function testWorker_reserve_receivesJob()
 {
     $jobData = 'test';
     $response = sprintf('%s %s %s', \Beanie\Command\Response::RESPONSE_RESERVED, 1, strlen($jobData));
     $worker = \Beanie\Beanie::pool([$this->serverName])->worker();
     $worker->getServer()->connect();
     $acceptedConnection = socket_accept($this->socket);
     socket_set_nonblock($acceptedConnection);
     socket_write($acceptedConnection, $response . "\r\n");
     socket_write($acceptedConnection, $jobData . "\r\n");
     $job = $worker->reserve();
     $command = socket_read($acceptedConnection, 1024);
     $this->assertEquals(sprintf('%s' . "\r\n", \Beanie\Command\CommandInterface::COMMAND_RESERVE), $command);
     $this->assertInstanceOf(\Beanie\Job\Job::class, $job);
     $this->assertEquals(1, $job->getId());
     $this->assertEquals($jobData, $job->getData());
     $this->assertEquals(\Beanie\Job\Job::STATE_RESERVED, $job->getState());
     socket_close($acceptedConnection);
 }
コード例 #4
0
ファイル: QMan.php プロジェクト: zwilias/qman
 /**
  * @param string[] $servers
  * @param CommandSerializerInterface $serializer
  * @param LoggerInterface $logger
  * @return static
  */
 public static function create(array $servers, CommandSerializerInterface $serializer = null, LoggerInterface $logger = null)
 {
     return new static(Beanie::pool($servers)->producer(), $serializer, $logger);
 }