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(); }
/** * @param Operation $operation */ public function run(Operation $operation) { $this->buffer->add($operation); while (null !== ($operation = $this->buffer->current())) { $this->runner->run($operation); $this->buffer->pop(); } }
/** * {@inheritdoc} */ public function patch(Log $log, array $patch) { $operation = new Callback(function () use($log, $patch) { return $this->client->patch($log, $patch); }); $this->operationRunner->run($operation); return $operation->getResult(); }
function it_should_throw_the_original_exception_if_the_wait_fails(OperationRunner $runner, WaitStrategy $waitStrategy, Operation $operation) { $runner->run($operation)->will(function () use($operation) { throw new \RuntimeException('Operation failed'); }); $waitStrategy->wait()->willThrow(new WaiterException('Retried to many times')); $this->shouldThrow(\RuntimeException::class)->duringRun($operation); }
/** * {@inheritdoc} */ public function run(Operation $operation) { try { return $this->runner->run($operation); } catch (\Exception $e) { try { $this->waitStrategy->wait(); } catch (WaiterException $waiterException) { throw $e; } return $this->run($operation); } }