Пример #1
0
 /**
  * @test
  */
 public function onChannelWaitABeforeCommandLineShouldExecuteANewProcess()
 {
     $process = $this->getMockBuilder('\\Liuggio\\Spawn\\Process\\Process')->disableOriginalConstructor()->getMock();
     $channel = Channel::createAWaiting(3, 5);
     $queue = $this->getMock('\\Liuggio\\Spawn\\Queue\\QueueInterface');
     $queue->expects($this->once())->method('dequeue')->willReturn(10);
     $processFactory = $this->getMock('\\Liuggio\\Spawn\\Process\\ProcessFactory');
     $processFactory->expects($this->once())->method('create')->with($this->equalTo($channel))->willReturn($process);
     $ed = $this->getMock('\\Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $consumer = new ConsumerListener($queue, $ed, $processFactory, CommandLine::fromString("echo 'a'"));
     $consumer->onChannelIsWaiting(new ChannelIsWaitingEvent($channel));
 }
Пример #2
0
 /**
  * @test
  */
 public function shouldCreateAProcessTests()
 {
     $assertionCommandLine = 'bin/phpunit fileA';
     $channelNumber = 2;
     $channel = Channel::createAWaiting($channelNumber, 10);
     $process = $this->getMockBuilder('\\Liuggio\\Spawn\\Process\\Process')->disableOriginalConstructor()->getMock();
     $channel = $channel->assignToAProcess($process);
     $envs = new ProcessEnvironment($channel, 'fileA', 11);
     $process = new Process(new CommandLine($assertionCommandLine), $envs);
     $this->assertInstanceOf('\\Liuggio\\Spawn\\Process\\Process', $process);
     $this->assertEquals('bin/phpunit fileA', $process->getCommandLine());
     $this->assertEquals(array(0 => 'ENV_TEST_CHANNEL=2', 1 => 'ENV_TEST_CHANNEL_READABLE=test_2', 2 => 'ENV_TEST_CHANNELS_NUMBER=10', 3 => 'ENV_TEST_ARGUMENT=fileA', 4 => 'ENV_TEST_INC_NUMBER=11', 5 => 'ENV_TEST_IS_FIRST_ON_CHANNEL=1'), $process->getenv());
 }
Пример #3
0
 /**
  * Spawns a callable into an isolated processes.
  *
  * @param array|mixed    $args
  * @param \Closure       $closure
  * @param int|float|null $timeout
  * @param string|null    $cwd
  *
  * @return ClosureProcess
  *
  * @api
  */
 public function spawn($args, \Closure $closure, $timeout = null, $cwd = null)
 {
     $factory = new ClosureProcessFactory($closure, $this->autoloadFile, $timeout);
     $process = $factory->create(Channel::createAWaiting(0, 0), $args, 1, null, $cwd);
     $process->start();
     return $process;
 }
Пример #4
0
 /**
  * Free a channel.
  *
  * @param Channel $channel
  */
 public function setEmpty(Channel $channel)
 {
     $this->channels[$channel->getId()] = $channel->setIsWaiting();
 }
Пример #5
0
 /**
  * @return bool
  */
 public function isTheFirstCommandOnChannel()
 {
     return $this->channel->getAssignedProcessesCounter() == 1;
 }