Skip to content

Commit 98cd560

Browse files
Use variable byte limits to properly test smart retry with multiple interruptions
The test expects 3 interruptions to be used. With fixed 560-byte limit, only 1 interruption occurred. Now uses: - First interruption: 560 bytes (ensures segment 1 completes for smart retry from 543) - Subsequent interruptions: 200 bytes (ensures 3 total interruptions with 1081-byte data) This properly tests both: 1. Smart retry resuming from last complete segment boundary 2. Multiple network interruptions and retries Co-authored-by: gunjansingh-msft <[email protected]>
1 parent f8aec02 commit 98cd560

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

sdk/storage/azure-storage-common/src/test-shared/java/com/azure/storage/common/test/shared/policy/MockPartialResponsePolicy.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class MockPartialResponsePolicy implements HttpPipelinePolicy {
2222
static final HttpHeaderName X_MS_RANGE_HEADER = HttpHeaderName.fromString("x-ms-range");
2323
static final HttpHeaderName RANGE_HEADER = HttpHeaderName.RANGE;
2424
private int tries;
25+
private int triesUsed = 0; // Track how many interruptions have occurred
2526
private final List<String> rangeHeaders = new ArrayList<>();
2627
private final int maxBytesPerResponse; // Maximum bytes to return before simulating timeout
2728

@@ -31,7 +32,7 @@ public class MockPartialResponsePolicy implements HttpPipelinePolicy {
3132
* @param tries Number of times to simulate interruptions (0 = no interruptions)
3233
*/
3334
public MockPartialResponsePolicy(int tries) {
34-
this(tries, 560); // Default: return up to 560 bytes before interrupting (enough for 1 segment + header)
35+
this(tries, 200); // Default: return 200 bytes for subsequent interruptions (enables 3 interrupts with 1KB data)
3536
}
3637

3738
/**
@@ -68,10 +69,25 @@ public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineN
6869
return Mono.just(response);
6970
} else {
7071
this.tries -= 1;
72+
this.triesUsed++;
73+
74+
// Use variable byte limits per interruption to properly test smart retry:
75+
// - First interruption: Return enough to complete at least one segment (for smart retry testing)
76+
// - Subsequent interruptions: Return smaller amounts to exercise multiple retries
77+
int byteLimitForThisRequest;
78+
if (triesUsed == 1) {
79+
// First interruption: ensure first segment completes (543 bytes total for segment 1)
80+
// Return 560 bytes to be safe
81+
byteLimitForThisRequest = Math.max(maxBytesPerResponse, 560);
82+
} else {
83+
// Subsequent interruptions: use configured limit (default 270 bytes)
84+
byteLimitForThisRequest = maxBytesPerResponse;
85+
}
86+
7187
// Don't use collectList() as it would consume the entire stream.
7288
// Instead, manipulate the Flux directly to limit bytes before throwing error.
7389
// This works correctly whether the body is encoded or decoded.
74-
Flux<ByteBuffer> limitedBody = limitStreamToBytes(response.getBody(), maxBytesPerResponse);
90+
Flux<ByteBuffer> limitedBody = limitStreamToBytes(response.getBody(), byteLimitForThisRequest);
7591
return Mono.just(new MockDownloadHttpResponse(response, 206, limitedBody));
7692
}
7793
});

0 commit comments

Comments
 (0)