Beispiel #1
0
 /**
  * @inheritdoc
  */
 public function sendToOne($command, array $arguments = [])
 {
     $e = null;
     $keysAvailable = array_keys($this->connections);
     $keysUsed = [];
     $keysExhausted = false;
     while (!$keysExhausted && ($key = $this->strategy->pickOne($keysAvailable)) !== false) {
         try {
             return $this->sendToExact($key, $command, $arguments);
         } catch (RuntimeException $e) {
             // ignore
         }
         $keysUsed[$key] = true;
         if (count($keysUsed) == count($keysAvailable)) {
             $keysExhausted = true;
         }
     }
     $message = "Failed to send command '{$command}' to one of the connections.";
     if ($e instanceof \Exception) {
         $final = new RuntimeException($message, 0, $e);
     } else {
         $final = new RuntimeException($message);
     }
     throw $final;
 }
Beispiel #2
0
 /**
  * @expectedException \Phlib\Beanstalk\Exception\RuntimeException
  */
 public function testSendToOneThrowsTheLastError()
 {
     $command = 'stats';
     $identifier1 = 'id-123';
     $connection1 = $this->getMockConnection($identifier1);
     $connection1->expects($this->any())->method($command)->will($this->throwException(new RuntimeException()));
     $identifier2 = 'id-456';
     $connection2 = $this->getMockConnection($identifier2);
     $connection2->expects($this->once())->method($command)->will($this->throwException(new RuntimeException()));
     $this->strategy->expects($this->any())->method('pickOne')->will($this->onConsecutiveCalls($identifier1, $identifier2));
     $collection = new Collection([$connection1, $connection2], $this->strategy);
     $collection->sendToOne($command);
 }