Copilot commented on code in PR #10461:
URL: https://github.com/apache/ozone/pull/10461#discussion_r3376698031
##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestCompleteMultipartUploadRequestUnmarshaller.java:
##########
@@ -58,6 +63,44 @@ public void fromStreamWithNamespace() throws IOException {
checkContent(completeMultipartUploadRequest);
}
+ @Test
+ public void fromStreamWhereAvailableReturnsZero() throws IOException {
+ // Simulates a request body stream (e.g. with Expect: 100-continue) where
+ // InputStream#available() returns 0 even though the body has not been
+ // fully buffered yet. See HDDS-14760.
+ InputStream inputBody = new FilterInputStream(new ByteArrayInputStream(
+ ("<CompleteMultipartUpload xmlns=\"" + S3Consts.S3_XML_NAMESPACE +
"\">" +
+ "<Part><ETag>" + part1 + "</ETag><PartNumber>1" +
+ "</PartNumber></Part><Part><ETag>" + part2 +
+ "</ETag><PartNumber>2</PartNumber></Part>" +
+ "</CompleteMultipartUpload>").getBytes(UTF_8))) {
+ @Override
+ public int available() {
+ return 0;
+ }
+ };
+
+ //WHEN
+ CompleteMultipartUploadRequest completeMultipartUploadRequest =
+ new CompleteMultipartUploadRequestUnmarshaller()
+ .readFrom(null, null, null, null, null, inputBody);
+
+ //THEN
+ checkContent(completeMultipartUploadRequest);
+ }
+
+ @Test
+ public void emptyBodyThrowsMustSpecifyAtLeastOnePart() {
+ InputStream emptyBody = new ByteArrayInputStream(new byte[0]);
+
+ WebApplicationException ex = assertThrows(WebApplicationException.class,
+ () -> new CompleteMultipartUploadRequestUnmarshaller()
+ .readFrom(null, null, null, null, null, emptyBody));
+
+ assertTrue(ex.getMessage().contains("must specify at least one part"),
+ "Unexpected message: " + ex.getMessage());
Review Comment:
This test asserts on `WebApplicationException#getMessage()`, which is more
fragile than asserting on the underlying `OS3Exception` returned as the cause
(that’s what `wrapOS3Exception` sets). Asserting on the cause makes the test
resilient to changes in how the JAX-RS exception formats its message.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]