/** * Retry succeeds on third attempt (second/final retry) */ public function testRetryReturn() { $count = 0; $callFn = function () use(&$count) { $count++; if ($count == 3) { return 'response'; } throw new Exception('fail ' . $count); }; $response = \Packaged\Helpers\RetryHelper::retry(2, $callFn); $this->assertEquals('response', $response); $this->assertEquals(3, $count); }
/** * Run a query without preparing it and without retries * * @param string $query * @param int $consistency * @param int $retries * * @return array The query results */ public function runRawQuery($query, $consistency = ConsistencyLevel::QUORUM, $retries = null) { if ($retries === null) { $retries = (int) $this->_config()->getItem('retries', 2); } return RetryHelper::retry($retries, function () use($query, $consistency) { $this->connect()->_switchDatabase(); $result = $this->_client->execute_cql3_query($query, Compression::NONE, $consistency); /** * @var $result CqlResult */ if ($result->type == CqlResultType::VOID) { return true; } $return = []; foreach ($result->rows as $row) { /** * @var $row CqlRow */ $resultRow = []; foreach ($row->columns as $column) { /** * @var $column Column */ $resultRow[$column->name] = CqlDataType::unpack($result->schema->value_types[$column->name], $column->value); } $return[] = $resultRow; } return $return; }); }