function it_keeps_the_operation_in_the_buffer_if_it_fails(OperationBuffer $buffer, OperationRunner $runner, Operation $operation)
 {
     $runner->run($operation)->willThrow(new \RuntimeException('Unable to run the operation'));
     $buffer->current()->willReturn($operation);
     $this->shouldThrow(\RuntimeException::class)->duringRun($operation);
     $buffer->pop()->shouldNotBeCalled();
 }
 function it_publish_a_failure_metric_and_rethrow_an_exception(OperationRunner $runner, MetricPublisher $publisher, Operation $operation)
 {
     $e = new \InvalidArgumentException();
     $runner->run($operation)->willThrow($e);
     $publisher->publish([new Metric('my_namespace.failure', 1, Metric::TYPE_INCREMENT)])->shouldBeCalled();
     $this->shouldThrow($e)->during('run', [$operation]);
 }
 function it_returns_a_placeholder_response_if_it_fails(OperationRunner $decoratedRunner, Operation $operation, PlaceholderResponseResolver $placeholderResponseResolver)
 {
     $exception = new \Exception();
     $decoratedRunner->run($operation)->willThrow($exception);
     $placeholderResponseResolver->createResponse($operation, $exception)->shouldBeCalled()->willReturn('');
     $this->run($operation)->shouldBe('');
 }
예제 #4
0
 function it_should_throw_the_original_exception_if_the_wait_fails(OperationRunner $runner, Waiter $waiter, Operation $operation)
 {
     $runner->run($operation)->will(function () use($operation) {
         throw new \RuntimeException('Operation failed');
     });
     $waiter->wait()->willThrow(new WaiterException('Retried to many times'));
     $this->shouldThrow(\RuntimeException::class)->duringRun($operation);
 }
 function it_waits_the_number_of_required_tick_if_the_rate_limit_is_reached(OperationRunner $runner, RateLimit $rateLimit, Waiter $waiter, Operation $operation)
 {
     $rateLimit->hasReachedLimit(Argument::any())->willReturn(true);
     $rateLimit->getTicksBeforeUnderLimit(Argument::any())->willReturn(10);
     $waiter->wait(10)->shouldBeCalled();
     $runner->run($operation)->shouldBeCalled();
     $rateLimit->tick(Argument::any())->shouldBeCalled();
     $this->run($operation);
 }
예제 #6
0
 /**
  * Runs the buffered operations.
  *
  * It returns an array of results.
  *
  * @return mixed[]
  */
 public function runBufferedOperations()
 {
     $results = [];
     while (null !== ($operation = $this->buffer->current())) {
         $results[] = $this->runner->run($operation);
         $this->buffer->pop();
     }
     return $results;
 }
 function it_runs_the_publish_via_a_callback_operation(MetricPublisher $decoratedPublisher, OperationRunner $operationRunner)
 {
     $operationRunner->run(Argument::that(function ($operation) {
         if (!$operation instanceof Callback) {
             return false;
         }
         $operation->call();
         return true;
     }))->shouldBeCalled();
     $metrics = [new Metric('name', 'foo')];
     $decoratedPublisher->publish($metrics)->shouldBeCalled();
     $this->publish($metrics);
 }
 /**
  * {@inheritdoc}
  */
 public function supports(Operation $operation)
 {
     return $this->decoratedRunner->supports($operation);
 }
 /**
  * {@inheritdoc}
  */
 public function publish(array $metrics)
 {
     return $this->operationRunner->run(new Callback(function () use($metrics) {
         return $this->decoratedPublisher->publish($metrics);
     }));
 }