예제 #1
0
파일: Manager.php 프로젝트: zwilias/beanie
 /**
  * @return Tube[]
  * @throws Exception\InvalidArgumentException
  */
 public function tubes()
 {
     $tubes = [];
     foreach ($this->server->dispatchCommand($this->commandFactory->create(CommandInterface::COMMAND_LIST_TUBES))->invoke()->getData() as $tubeName) {
         $tubes[] = new Tube($tubeName, $this->server);
     }
     return $tubes;
 }
예제 #2
0
 /**
  * @param string[] $tubes
  * @param string[] $otherTubes
  * @param string $command
  * @return CommandInterface[]
  * @throws \Beanie\Exception\InvalidArgumentException
  */
 protected function calculateDiffTubes($tubes, $otherTubes, $command)
 {
     $commands = [];
     foreach (array_diff($tubes, $otherTubes) as $tube) {
         $commands[] = $this->commandFactory->create($command, [$tube]);
     }
     return $commands;
 }
예제 #3
0
 public function testWatchCommand_ParseResponse_returnsResponse()
 {
     $responseLine = sprintf('%s %s', Response::RESPONSE_WATCHING, 1);
     $watchCommand = $this->commandFactory->create(CommandInterface::COMMAND_WATCH, [Beanie::DEFAULT_TUBE]);
     $response = $watchCommand->parseResponse($responseLine, $this->getServerMock());
     $this->assertEquals(Response::RESPONSE_WATCHING, $response->getName());
     $this->assertEquals(1, $response->getData());
     $this->assertEquals($this->getServerMock(), $response->getServer());
 }
예제 #4
0
 public function testCreateFromCommand_createsJob()
 {
     $serverMock = $this->getServerMock(['dispatchCommand']);
     $command = CommandFactory::instance()->create(CommandInterface::COMMAND_PEEK, [self::TEST_ID]);
     $response = new Response(Response::RESPONSE_FOUND, ['id' => self::TEST_ID, 'data' => self::TEST_DATA], $serverMock);
     $serverMock->expects($this->once())->method('dispatchCommand')->with($this->callback(function (CommandInterface $command) {
         return $command->getCommandLine() == sprintf('%s %s', CommandInterface::COMMAND_PEEK, self::TEST_ID);
     }))->willReturn($this->oath($response));
     $JobFactory = new JobFactory();
     $job = $JobFactory->createFromCommand($command, $serverMock)->invoke();
     $this->assertEquals(Job::STATE_UNKNOWN, $job->getState());
     $this->assertEquals(self::TEST_ID, $job->getId());
     $this->assertEquals(self::TEST_DATA, $job->getData());
 }
예제 #5
0
파일: Tube.php 프로젝트: zwilias/beanie
 /**
  * @param string $command
  * @param array $arguments
  * @return Response
  */
 private function executeCommand($command, $arguments = [])
 {
     return $this->server->dispatchCommand($this->commandFactory->create($command, $arguments))->invoke();
 }
예제 #6
0
파일: Worker.php 프로젝트: zwilias/beanie
 /**
  * @return JobOath
  * @throws Exception\InvalidArgumentException
  */
 public function reserveOath()
 {
     return $this->jobFactory->createFromCommand($this->commandFactory->create(CommandInterface::COMMAND_RESERVE), $this->server->transformTubeStatusTo($this->getTubeStatus(), TubeStatus::TRANSFORM_WATCHED));
 }
예제 #7
0
 public function transformCommandsProvider()
 {
     $commandFactory = CommandFactory::instance();
     return ['identical' => [Beanie::DEFAULT_TUBE, [Beanie::DEFAULT_TUBE], Beanie::DEFAULT_TUBE, [Beanie::DEFAULT_TUBE], TubeStatus::TRANSFORM_BOTH, []], 'overlapping-watch' => [Beanie::DEFAULT_TUBE, ['1only1', '1only2', 'shared1', 'shared2', '1only3'], Beanie::DEFAULT_TUBE, ['2only1', 'shared1', 'shared2', '2only2'], TubeStatus::TRANSFORM_BOTH, [$commandFactory->create(CommandInterface::COMMAND_IGNORE, ['1only1']), $commandFactory->create(CommandInterface::COMMAND_IGNORE, ['1only2']), $commandFactory->create(CommandInterface::COMMAND_IGNORE, ['1only3']), $commandFactory->create(CommandInterface::COMMAND_WATCH, ['2only1']), $commandFactory->create(CommandInterface::COMMAND_WATCH, ['2only2'])]], 'only-additions' => [Beanie::DEFAULT_TUBE, ['shared1', 'shared2'], Beanie::DEFAULT_TUBE, ['2only1', 'shared1', 'shared2', '2only2'], TubeStatus::TRANSFORM_BOTH, [$commandFactory->create(CommandInterface::COMMAND_WATCH, ['2only1']), $commandFactory->create(CommandInterface::COMMAND_WATCH, ['2only2'])]], 'only-removals' => [Beanie::DEFAULT_TUBE, ['1only1', '1only2', 'shared1', 'shared2', '1only3'], Beanie::DEFAULT_TUBE, ['shared1', 'shared2'], TubeStatus::TRANSFORM_BOTH, [$commandFactory->create(CommandInterface::COMMAND_IGNORE, ['1only1']), $commandFactory->create(CommandInterface::COMMAND_IGNORE, ['1only2']), $commandFactory->create(CommandInterface::COMMAND_IGNORE, ['1only3'])]], 'different-use' => [self::TEST_TUBE, [Beanie::DEFAULT_TUBE], Beanie::DEFAULT_TUBE, [Beanie::DEFAULT_TUBE], TubeStatus::TRANSFORM_BOTH, [$commandFactory->create(CommandInterface::COMMAND_USE, [Beanie::DEFAULT_TUBE])]], 'different-use-ignored' => [self::TEST_TUBE, [Beanie::DEFAULT_TUBE], Beanie::DEFAULT_TUBE, [Beanie::DEFAULT_TUBE], TubeStatus::TRANSFORM_WATCHED, []], 'different-watch-ignored' => [Beanie::DEFAULT_TUBE, ['shared1', 'shared2'], Beanie::DEFAULT_TUBE, ['2only1', 'shared1', 'shared2', '2only2'], TubeStatus::TRANSFORM_USE, []], 'all-different' => [self::TEST_TUBE, ['shared1', 'shared2'], Beanie::DEFAULT_TUBE, ['2only1', 'shared1', 'shared2', '2only2'], TubeStatus::TRANSFORM_BOTH, [$commandFactory->create(CommandInterface::COMMAND_USE, [Beanie::DEFAULT_TUBE]), $commandFactory->create(CommandInterface::COMMAND_WATCH, ['2only1']), $commandFactory->create(CommandInterface::COMMAND_WATCH, ['2only2'])]], 'all-different-only-use' => [self::TEST_TUBE, ['shared1', 'shared2'], Beanie::DEFAULT_TUBE, ['2only1', 'shared1', 'shared2', '2only2'], TubeStatus::TRANSFORM_USE, [$commandFactory->create(CommandInterface::COMMAND_USE, [Beanie::DEFAULT_TUBE])]], 'all-different-only-watched' => [self::TEST_TUBE, ['shared1', 'shared2'], Beanie::DEFAULT_TUBE, ['2only1', 'shared1', 'shared2', '2only2'], TubeStatus::TRANSFORM_WATCHED, [$commandFactory->create(CommandInterface::COMMAND_WATCH, ['2only1']), $commandFactory->create(CommandInterface::COMMAND_WATCH, ['2only2'])]]];
 }
예제 #8
0
 public function testInstance_returnsSame()
 {
     CommandFactory::unsetInstance();
     $firstInstance = CommandFactory::instance();
     $this->assertSame($firstInstance, CommandFactory::instance());
 }
예제 #9
0
파일: Producer.php 프로젝트: zwilias/beanie
 /**
  * @param string $jobData
  * @param int $priority
  * @param int $delay
  * @param int $timeToRun
  * @return Job
  * @throws Exception\InvalidArgumentException
  */
 public function put($jobData, $priority = Beanie::DEFAULT_PRIORITY, $delay = Beanie::DEFAULT_DELAY, $timeToRun = Beanie::DEFAULT_TIME_TO_RUN)
 {
     return $this->createJob($jobData, $this->pool->transformTubeStatusTo($this->tubeStatus)->dispatchCommand($this->commandFactory->create(CommandInterface::COMMAND_PUT, [$jobData, $priority, $delay, $timeToRun]))->invoke());
 }