chihsuan commented on code in PR #10752:
URL: https://github.com/apache/ozone/pull/10752#discussion_r3587567261


##########
hadoop-ozone/integration-test-s3/src/test/java/org/apache/hadoop/ozone/s3/awssdk/v2/AbstractS3SDKV2Tests.java:
##########
@@ -1204,6 +1206,63 @@ public void testCopyObject() {
     assertEquals("\"37b51d194a7513e45b56f6524f2d51f2\"", 
copyObjectResponse.copyObjectResult().eTag());
   }
 
+  @Test
+  public void testCopyObjectToSelfWithMetadataReplace() {
+    final String bucketName = getBucketName();
+    final String key = getKeyName();
+    final String content = "bar";
+    s3Client.createBucket(b -> b.bucket(bucketName));
+    s3Client.putObject(b -> 
b.bucket(bucketName).key(key).metadata(Collections.singletonMap("meta1", "v1")),
+        RequestBody.fromString(content));
+
+    // Copying an object onto itself is allowed when the metadata is replaced.
+    CopyObjectRequest copyReq = CopyObjectRequest.builder()
+        .sourceBucket(bucketName)
+        .sourceKey(key)
+        .destinationBucket(bucketName)
+        .destinationKey(key)
+        .metadataDirective(MetadataDirective.REPLACE)
+        .metadata(Collections.singletonMap("meta2", "v2"))
+        .build();
+
+    CopyObjectResponse copyObjectResponse = assertDoesNotThrow(() -> 
s3Client.copyObject(copyReq));
+    assertNotNull(copyObjectResponse.copyObjectResult().eTag());
+
+    // The object is still readable with its original content after the 
in-place copy.
+    ResponseBytes<GetObjectResponse> objectBytes = s3Client.getObjectAsBytes(
+        b -> b.bucket(bucketName).key(key));
+    assertEquals(content, objectBytes.asUtf8String());

Review Comment:
   Should we also verify the resulting metadata through `HeadObject` here?
   
   This test currently confirms that the self-copy succeeds and that the object 
content is preserved, but it would still pass if Ozone accepted the request 
without replacing the metadata. Since metadata replacement is the behavior this 
PR fixes, it would be useful to assert both that `meta2=v2` is present and that 
`meta1` is absent.
   
   For example:
   
   ```java
       HeadObjectResponse head = s3Client.headObject(
           b -> b.bucket(bucketName).key(key));
       assertEquals("v2", head.metadata().get("meta2"));
       assertFalse(head.metadata().containsKey("meta1"));
   ```
   
   The unit test verifies the internal `OzoneKeyDetails`; this assertion would 
additionally cover the complete AWS SDK → S3 Gateway → OM → `HeadObject` path. 
Thanks!



-- 
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]

Reply via email to