Пример #1
0
 public function get_get_stack_size()
 {
     $this->given($group = new SUT('foo'), $exception1 = new SUT('bar'), $exception2 = new SUT('baz'), $group['bar'] = $exception1, $group->beginTransaction(), $group['baz'] = $exception2)->when($result = $group->getStackSize())->then->integer($result)->isEqualTo(2);
 }
Пример #2
0
 /**
  * Broadcast a message to a subset of nodes that fulfill a predicate.
  *
  * @param   \Closure  $predicate    Predicate. Take a node in argument.
  * @param   string    $message      Message.
  * @param   …         …             …
  * @return  void
  * @throws  \Hoa\Exception\Group
  */
 public function broadcastIf(\Closure $predicate, $message)
 {
     $connection = $this->getConnection();
     $currentSocket = $this->getOriginalConnection()->getSocket();
     $arguments = array_slice(func_get_args(), 2);
     array_unshift($arguments, $message, null);
     $callable = [$this, 'send'];
     $exceptions = new HoaException\Group('Message cannot be sent to some nodes.');
     foreach ($connection->getNodes() as $node) {
         if (true === $predicate($node) && $node->getConnection()->getSocket() === $currentSocket) {
             $arguments[1] = $node;
             try {
                 call_user_func_array($callable, $arguments);
             } catch (Socket\Exception $e) {
                 $exceptions[$node->getId()] = $e;
             }
         }
     }
     if (0 < $exceptions->count()) {
         throw $exceptions;
     }
     return;
 }