Skip to content

Commit

Permalink
Do not reset Retry if already set + Update BulkTest
Browse files Browse the repository at this point in the history
  • Loading branch information
csabavirag committed Jan 17, 2024
1 parent f8a20e1 commit b8963c7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Backward Compatibility Breaks
### Added
* If not expicitly set, use `retry_on_conflict` from Client configuration in Bulk updates [#2184](https://github.com/ruflin/Elastica/pull/2184)
### Changed
### Deprecated
### Removed
Expand Down
8 changes: 6 additions & 2 deletions src/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ public function getActions(): array
*/
public function addDocument(Document $document, ?string $opType = null): self
{
if ($this->_client->getConnection()->hasParam('retryOnConflict')) {
$document->setRetryOnConflict($this->_client->getConnection()->getParam('retryOnConflict'));
if (!$document->hasRetryOnConflict() && $this->_client->hasConnection() && ($retry = $this->_client->getConnection()->getParam('retryOnConflict')) > 0) {
$document->setRetryOnConflict($retry);
}

$action = AbstractDocumentAction::create($document, $opType);
Expand All @@ -159,6 +159,10 @@ public function addDocuments(array $documents, ?string $opType = null): self
*/
public function addScript(AbstractScript $script, ?string $opType = null): self
{
if (!$script->hasRetryOnConflict() && $this->_client->hasConnection() && ($retry = $this->_client->getConnection()->getParam('retryOnConflict')) > 0) {
$script->setRetryOnConflict($retry);
}

$action = AbstractDocumentAction::create($script, $opType);

return $this->addAction($action);
Expand Down
24 changes: 24 additions & 0 deletions tests/BulkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,30 @@ public function testRetry(): void

$metadata = $actions[0]->getMetadata();
$this->assertEquals(5, $metadata['retry_on_conflict']);

// Test retry via client
$client->getConnection()->setParam('retryOnConflict', 5);
$doc2 = new Document('2', ['name' => 'Invisible Woman']);
$doc2->setOpType(Action::OP_TYPE_UPDATE);

$bulk = new Bulk($client);
$bulk->addDocument($doc2);

$actions = $bulk->getActions();

$metadata = $actions[0]->getMetadata();
$this->assertEquals(5, $metadata['retry_on_conflict']);

$script = new Script('');

$bulk = new Bulk($client);
$bulk->addScript($script);

$actions = $bulk->getActions();

$metadata = $actions[0]->getMetadata();
$this->assertEquals(5, $metadata['retry_on_conflict']);

}

/**
Expand Down

0 comments on commit b8963c7

Please sign in to comment.