Skip to content

Commit

Permalink
Merge pull request aws#888 from jeskew/fix/correctly-requeue-write-re…
Browse files Browse the repository at this point in the history
…quest-batch-items

Correctly requeue throttled WriteRequestBatch items
  • Loading branch information
jeskew committed Jan 29, 2016
2 parents 752b58b + 6644791 commit 553e7ef
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/DynamoDb/WriteRequestBatch.php
Expand Up @@ -227,9 +227,7 @@ private function retryUnprocessed(array $unprocessed)
foreach ($requests as $request) {
$this->queue[] = [
'table' => $table,
'data' => isset($request['PutRequest'])
? $request['PutRequest']
: $request['DeleteRequest']
'data' => $request,
];
}
}
Expand Down
19 changes: 18 additions & 1 deletion tests/DynamoDb/WriteRequestBatchTest.php
Expand Up @@ -114,6 +114,7 @@ public function testUnprocessedItemsAreRequeued()
$this->addMockResults($client, [
new Result(['UnprocessedItems' => ['foo' => [
['PutRequest' => ['Item' => ['id' => ['S' => 'b']]]],
['DeleteRequest' => ['Key' => ['id' => ['S' => 'c']]]],
]]]),
new Result([])
]);
Expand All @@ -122,8 +123,24 @@ public function testUnprocessedItemsAreRequeued()

$batch->put(['id' => ['S' => 'a']]);
$batch->put(['id' => ['S' => 'b']]);
$batch->flush();
$batch->delete(['id' => ['S' => 'c']]);

$batch->flush(false);
$this->assertEquals(
[
[
'table' => 'foo',
'data' => ['PutRequest' => ['Item' => ['id' => ['S' => 'b']]]],
],
[
'table' => 'foo',
'data' => ['DeleteRequest' => ['Key' => ['id' => ['S' => 'c']]]],
]
],
$this->readAttribute($batch, 'queue')
);

$batch->flush();
$this->assertCount(0, $this->readAttribute($batch, 'queue'));
}

Expand Down

0 comments on commit 553e7ef

Please sign in to comment.