Skip to content

Commit bfb1030

Browse files
authored
Handle eventual consistency test case to make sure to wait for some time so that item is eventually available (#6303)
1 parent b4fd74e commit bfb1030

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

services-custom/dynamodb-enhanced/src/it/java/software/amazon/awssdk/enhanced/dynamodb/CrudWithResponseIntegrationTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public void getItem_set_requestedMetadataNull() {
275275
}
276276

277277
@Test
278-
public void getItem_set_eventualConsistent() {
278+
public void getItem_set_eventualConsistent() throws InterruptedException {
279279
Record record = new Record().setId("101").setSort(102).setStringAttribute(getStringAttrValue(80 * 1024));
280280
Key key = Key.builder()
281281
.partitionValue(record.getId())
@@ -286,6 +286,18 @@ public void getItem_set_eventualConsistent() {
286286
GetItemEnhancedResponse<Record> response = mappedTable.getItemWithResponse(
287287
req -> req.key(key).returnConsumedCapacity(ReturnConsumedCapacity.TOTAL)
288288
);
289+
290+
// Handle eventual consistency: DynamoDB's eventually consistent reads may not immediately
291+
// reflect recent writes. Retry once with a delay to ensure item propagation.
292+
if(response.attributes() == null){
293+
Thread.sleep(200);
294+
response = mappedTable.getItemWithResponse(
295+
req -> req.key(key).returnConsumedCapacity(ReturnConsumedCapacity.TOTAL));
296+
}
297+
assertThat(response.attributes())
298+
.withFailMessage("Item not propagated to DynamoDB after retry - eventual consistency delay exceeded")
299+
.isNotNull();
300+
289301
ConsumedCapacity consumedCapacity = response.consumedCapacity();
290302
assertThat(consumedCapacity).isNotNull();
291303
// An eventually consistent read request of an item up to 4 KB requires one-half read request unit.

0 commit comments

Comments
 (0)