Skip to content

Commit 42e384e

Browse files
Fix MockPartialResponsePolicy to interrupt during streaming
Co-authored-by: gunjansingh-msft <[email protected]>
1 parent 3688c5f commit 42e384e

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,10 @@ public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineN
5151
return Mono.just(response);
5252
} else {
5353
this.tries -= 1;
54-
return response.getBody().collectList().flatMap(bodyBuffers -> {
55-
if (bodyBuffers.isEmpty()) {
56-
// If no body was returned, don't attempt to slice a partial response. Simply propagate
57-
// the original response to avoid test failures when the service unexpectedly returns an
58-
// empty body (for example, after a retry on the underlying transport).
59-
return Mono.just(response);
60-
}
61-
ByteBuffer firstBuffer = bodyBuffers.get(0);
62-
byte firstByte = firstBuffer.get();
63-
64-
// Simulate partial response by returning the first byte only from the requested range and timeout
65-
return Mono.just(new MockDownloadHttpResponse(response, 206,
66-
Flux.just(ByteBuffer.wrap(new byte[] { firstByte }))
67-
.concatWith(Flux.error(new IOException("Simulated timeout")))
68-
));
69-
});
54+
// Simulate partial response by taking only the first buffer from the stream and immediately
55+
// throwing an error to simulate a network interruption. This tests smart retry behavior.
56+
Flux<ByteBuffer> interruptedBody = response.getBody().take(1).concatWith(Flux.error(new IOException("Simulated timeout")));
57+
return Mono.just(new MockDownloadHttpResponse(response, 206, interruptedBody));
7058
}
7159
});
7260
}

0 commit comments

Comments
 (0)