You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by pe...@apache.org on 2026/09/29 17:52:35 UTC

(ozone) branch master updated: HDDS-12950. Refactor TestBucketList to reduce duplicated declarations (#11338)

This is an automated email from the ASF dual-hosted git repository.

peterxcli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 907411afe71 HDDS-12950. Refactor TestBucketList to reduce duplicated declarations (#11338)
907411afe71 is described below

commit 907411afe71aca200712c3620f4019cc3ef37c48
Author: Arun Sarin <ar...@gmail.com>
AuthorDate: Tue Sep 29 23:22:28 2026 +0530

    HDDS-12950. Refactor TestBucketList to reduce duplicated declarations (#11338)
---
 .../hadoop/ozone/s3/endpoint/TestBucketList.java   | 389 ++++++++++-----------
 1 file changed, 177 insertions(+), 212 deletions(-)

diff --git a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketList.java b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketList.java
index 3ce9e70153a..d16ef557bff 100644
--- a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketList.java
+++ b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketList.java
@@ -50,16 +50,26 @@
  */
 public class TestBucketList {
 
+  private static final String BUCKET_NAME = "b1";
+
+  private OzoneClient client;
+  private BucketEndpoint bucketEndpoint;
+
+  private void setup(String... keys) throws IOException {
+    client = new OzoneClientStub();
+    client.getObjectStore().createS3Bucket(BUCKET_NAME);
+    createKeys(client, keys);
+    bucketEndpoint = newBucketEndpointBuilder().setClient(client).build();
+  }
+
   @Test
   public void listRoot() throws OS3Exception, IOException {
-    OzoneClient client = createClientWithKeys("file1", "dir1/file2");
-    BucketEndpoint endpoint = newBucketEndpointBuilder()
-        .setClient(client)
-        .build();
+    setup("file1", "dir1/file2");
 
-    endpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
-    endpoint.queryParamsForTest().set(QueryParams.PREFIX, "");
-    ListObjectResponse getBucketResponse = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
+    bucketEndpoint.queryParamsForTest().set(QueryParams.PREFIX, "");
+    ListObjectResponse getBucketResponse =
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertNotNull(getBucketResponse.getPrefix());
     assertEquals("", getBucketResponse.getPrefix().getName());
@@ -75,12 +85,12 @@ public void listRoot() throws OS3Exception, IOException {
 
   @Test
   public void listDir() throws OS3Exception, IOException {
-    OzoneClient client = createClientWithKeys("dir1/file2", "dir1/dir2/file2");
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(client).build();
+    setup("dir1/file2", "dir1/dir2/file2");
 
-    endpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
-    endpoint.queryParamsForTest().set(QueryParams.PREFIX, "dir1");
-    ListObjectResponse getBucketResponse = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
+    bucketEndpoint.queryParamsForTest().set(QueryParams.PREFIX, "dir1");
+    ListObjectResponse getBucketResponse =
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertEquals(1, getBucketResponse.getCommonPrefixes().size());
     assertEquals("dir1/",
@@ -91,15 +101,12 @@ public void listDir() throws OS3Exception, IOException {
 
   @Test
   public void listSubDir() throws OS3Exception, IOException {
-    OzoneClient ozoneClient =
-        createClientWithKeys("dir1/file2", "dir1/dir2/file2", "dir1bh/file",
-            "dir1bha/file2");
+    setup("dir1/file2", "dir1/dir2/file2", "dir1bh/file", "dir1bha/file2");
 
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(ozoneClient).build();
-
-    endpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
-    endpoint.queryParamsForTest().set(QueryParams.PREFIX, "dir1/");
-    ListObjectResponse getBucketResponse = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
+    bucketEndpoint.queryParamsForTest().set(QueryParams.PREFIX, "dir1/");
+    ListObjectResponse getBucketResponse =
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertEquals(1, getBucketResponse.getCommonPrefixes().size());
     assertEquals("dir1/dir2/",
@@ -117,20 +124,18 @@ public void listObjectOwner() throws OS3Exception, IOException {
     UserGroupInformation user2 = UserGroupInformation
         .createUserForTesting("user2", new String[] {"user2"});
 
-    OzoneClient client = new OzoneClientStub();
-    client.getObjectStore().createS3Bucket("b1");
-    OzoneBucket bucket = client.getObjectStore().getS3Bucket("b1");
+    setup();
+    OzoneBucket bucket = client.getObjectStore().getS3Bucket(BUCKET_NAME);
 
     UserGroupInformation.setLoginUser(user1);
     bucket.createKey("key1", 0).close();
     UserGroupInformation.setLoginUser(user2);
     bucket.createKey("key2", 0).close();
 
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(client).build();
-
-    endpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
-    endpoint.queryParamsForTest().set(QueryParams.PREFIX, "key");
-    ListObjectResponse getBucketResponse = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
+    bucketEndpoint.queryParamsForTest().set(QueryParams.PREFIX, "key");
+    ListObjectResponse getBucketResponse =
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertEquals(2, getBucketResponse.getContents().size());
     assertEquals(user1.getShortUserName(),
@@ -141,13 +146,12 @@ public void listObjectOwner() throws OS3Exception, IOException {
 
   @Test
   public void listWithDelimiterAndPrefixMatchingNoKeys() throws OS3Exception, IOException {
-    OzoneClient ozoneClient =
-        createClientWithKeys("b/a/r", "b/a/c", "b/a/g", "g");
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(ozoneClient).build();
+    setup("b/a/r", "b/a/c", "b/a/g", "g");
 
-    endpoint.queryParamsForTest().set(QueryParams.DELIMITER, "d");
-    endpoint.queryParamsForTest().set(QueryParams.PREFIX, "/");
-    ListObjectResponse response = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.DELIMITER, "d");
+    bucketEndpoint.queryParamsForTest().set(QueryParams.PREFIX, "/");
+    ListObjectResponse response =
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertEquals(0, response.getContents().size());
     assertEquals(0, response.getCommonPrefixes().size());
@@ -155,30 +159,24 @@ public void listWithDelimiterAndPrefixMatchingNoKeys() throws OS3Exception, IOEx
 
   @Test
   public void listWithPrefixAndDelimiter() throws OS3Exception, IOException {
-    OzoneClient ozoneClient =
-        createClientWithKeys("dir1/file2", "dir1/dir2/file2", "dir1bh/file",
-            "dir1bha/file2", "file2");
+    setup("dir1/file2", "dir1/dir2/file2", "dir1bh/file", "dir1bha/file2", "file2");
 
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(ozoneClient).build();
-
-    endpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
-    endpoint.queryParamsForTest().set(QueryParams.PREFIX, "dir1");
-    ListObjectResponse getBucketResponse = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
+    bucketEndpoint.queryParamsForTest().set(QueryParams.PREFIX, "dir1");
+    ListObjectResponse getBucketResponse =
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertEquals(3, getBucketResponse.getCommonPrefixes().size());
   }
 
   @Test
   public void listWithPrefixAndDelimiter1() throws OS3Exception, IOException {
-    OzoneClient ozoneClient =
-        createClientWithKeys("dir1/file2", "dir1/dir2/file2", "dir1bh/file",
-            "dir1bha/file2", "file2");
+    setup("dir1/file2", "dir1/dir2/file2", "dir1bh/file", "dir1bha/file2", "file2");
 
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(ozoneClient).build();
-
-    endpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
-    endpoint.queryParamsForTest().set(QueryParams.PREFIX, "");
-    ListObjectResponse getBucketResponse = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
+    bucketEndpoint.queryParamsForTest().set(QueryParams.PREFIX, "");
+    ListObjectResponse getBucketResponse =
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertEquals(3, getBucketResponse.getCommonPrefixes().size());
     assertEquals("file2", getBucketResponse.getContents().get(0)
@@ -187,16 +185,13 @@ public void listWithPrefixAndDelimiter1() throws OS3Exception, IOException {
 
   @Test
   public void listWithPrefixAndDelimiter2() throws OS3Exception, IOException {
-    OzoneClient ozoneClient =
-        createClientWithKeys("dir1/file2", "dir1/dir2/file2", "dir1bh/file",
-            "dir1bha/file2", "file2");
+    setup("dir1/file2", "dir1/dir2/file2", "dir1bh/file", "dir1bha/file2", "file2");
 
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(ozoneClient).build();
-
-    endpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
-    endpoint.queryParamsForTest().set(QueryParams.PREFIX, "dir1bh");
-    endpoint.queryParamsForTest().set(QueryParams.START_AFTER, "dir1/dir2/file2");
-    ListObjectResponse getBucketResponse = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
+    bucketEndpoint.queryParamsForTest().set(QueryParams.PREFIX, "dir1bh");
+    bucketEndpoint.queryParamsForTest().set(QueryParams.START_AFTER, "dir1/dir2/file2");
+    ListObjectResponse getBucketResponse =
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertEquals(2, getBucketResponse.getCommonPrefixes().size());
   }
@@ -204,16 +199,13 @@ public void listWithPrefixAndDelimiter2() throws OS3Exception, IOException {
   @Test
   public void listWithPrefixAndEmptyStrDelimiter()
       throws OS3Exception, IOException {
-    OzoneClient ozoneClient =
-        createClientWithKeys("dir1/", "dir1/dir2/", "dir1/dir2/file1",
-          "dir1/dir2/file2");
-
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(ozoneClient).build();
+    setup("dir1/", "dir1/dir2/", "dir1/dir2/file1", "dir1/dir2/file2");
 
     // Should behave the same if delimiter is null
-    endpoint.queryParamsForTest().set(QueryParams.DELIMITER, "");
-    endpoint.queryParamsForTest().set(QueryParams.PREFIX, "dir1/");
-    ListObjectResponse getBucketResponse = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.DELIMITER, "");
+    bucketEndpoint.queryParamsForTest().set(QueryParams.PREFIX, "dir1/");
+    ListObjectResponse getBucketResponse =
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertEquals(0, getBucketResponse.getCommonPrefixes().size());
     assertEquals(4, getBucketResponse.getContents().size());
@@ -230,34 +222,31 @@ public void listWithPrefixAndEmptyStrDelimiter()
 
   @Test
   public void listWithContinuationToken() throws OS3Exception, IOException {
-    OzoneClient ozoneClient =
-        createClientWithKeys("dir1/file2", "dir1/dir2/file2", "dir1bh/file",
-            "dir1bha/file2", "file2");
-
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(ozoneClient).build();
+    setup("dir1/file2", "dir1/dir2/file2", "dir1bh/file", "dir1bha/file2", "file2");
 
     int maxKeys = 2;
     // As we have 5 keys, with max keys 2 we should call list 3 times.
 
     // First time
-    endpoint.queryParamsForTest().set(QueryParams.PREFIX, "");
-    endpoint.queryParamsForTest().setInt(QueryParams.MAX_KEYS, maxKeys);
-    ListObjectResponse getBucketResponse = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.PREFIX, "");
+    bucketEndpoint.queryParamsForTest().setInt(QueryParams.MAX_KEYS, maxKeys);
+    ListObjectResponse getBucketResponse =
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertTrue(getBucketResponse.isTruncated());
     assertEquals(2, getBucketResponse.getContents().size());
 
     // 2nd time
     String value1 = getBucketResponse.getNextToken();
-    endpoint.queryParamsForTest().set(QueryParams.CONTINUATION_TOKEN, value1);
-    getBucketResponse = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.CONTINUATION_TOKEN, value1);
+    getBucketResponse = (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
     assertTrue(getBucketResponse.isTruncated());
     assertEquals(2, getBucketResponse.getContents().size());
 
     //3rd time
     String value = getBucketResponse.getNextToken();
-    endpoint.queryParamsForTest().set(QueryParams.CONTINUATION_TOKEN, value);
-    getBucketResponse = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.CONTINUATION_TOKEN, value);
+    getBucketResponse = (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertFalse(getBucketResponse.isTruncated());
     assertEquals(1, getBucketResponse.getContents().size());
@@ -266,27 +255,24 @@ public void listWithContinuationToken() throws OS3Exception, IOException {
   @Test
   public void listWithContinuationTokenDirBreak()
       throws OS3Exception, IOException {
-    OzoneClient ozoneClient =
-        createClientWithKeys(
-            "test/dir1/file1",
-            "test/dir1/file2",
-            "test/dir1/file3",
-            "test/dir2/file4",
-            "test/dir2/file5",
-            "test/dir2/file6",
-            "test/dir3/file7",
-            "test/file8");
-
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(ozoneClient).build();
+    setup(
+        "test/dir1/file1",
+        "test/dir1/file2",
+        "test/dir1/file3",
+        "test/dir2/file4",
+        "test/dir2/file5",
+        "test/dir2/file6",
+        "test/dir3/file7",
+        "test/file8");
 
     int maxKeys = 2;
 
     ListObjectResponse getBucketResponse;
 
-    endpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
-    endpoint.queryParamsForTest().set(QueryParams.PREFIX, "test/");
-    endpoint.queryParamsForTest().setInt(QueryParams.MAX_KEYS, maxKeys);
-    getBucketResponse = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
+    bucketEndpoint.queryParamsForTest().set(QueryParams.PREFIX, "test/");
+    bucketEndpoint.queryParamsForTest().setInt(QueryParams.MAX_KEYS, maxKeys);
+    getBucketResponse = (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertEquals(0, getBucketResponse.getContents().size());
     assertEquals(2, getBucketResponse.getCommonPrefixes().size());
@@ -296,8 +282,8 @@ public void listWithContinuationTokenDirBreak()
         getBucketResponse.getCommonPrefixes().get(1).getPrefix().getName());
 
     String value = getBucketResponse.getNextToken();
-    endpoint.queryParamsForTest().set(QueryParams.CONTINUATION_TOKEN, value);
-    getBucketResponse = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.CONTINUATION_TOKEN, value);
+    getBucketResponse = (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
     assertEquals(1, getBucketResponse.getContents().size());
     assertEquals(1, getBucketResponse.getCommonPrefixes().size());
     assertEquals("test/dir3/",
@@ -312,35 +298,32 @@ public void listWithContinuationTokenDirBreak()
    */
   @Test
   public void listWithContinuationToken1() throws OS3Exception, IOException {
-    OzoneClient ozoneClient =
-        createClientWithKeys("dir1/file1", "dir1bh/file1",
-            "dir1bha/file1", "dir0/file1", "dir2/file1");
-
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(ozoneClient).build();
+    setup("dir1/file1", "dir1bh/file1", "dir1bha/file1", "dir0/file1", "dir2/file1");
 
     int maxKeys = 2;
     // As we have 5 keys, with max keys 2 we should call list 3 times.
 
     // First time
-    endpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
-    endpoint.queryParamsForTest().set(QueryParams.PREFIX, "dir");
-    endpoint.queryParamsForTest().setInt(QueryParams.MAX_KEYS, maxKeys);
-    ListObjectResponse getBucketResponse = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
+    bucketEndpoint.queryParamsForTest().set(QueryParams.PREFIX, "dir");
+    bucketEndpoint.queryParamsForTest().setInt(QueryParams.MAX_KEYS, maxKeys);
+    ListObjectResponse getBucketResponse =
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertTrue(getBucketResponse.isTruncated());
     assertEquals(2, getBucketResponse.getCommonPrefixes().size());
 
     // 2nd time
     String value1 = getBucketResponse.getNextToken();
-    endpoint.queryParamsForTest().set(QueryParams.CONTINUATION_TOKEN, value1);
-    getBucketResponse = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.CONTINUATION_TOKEN, value1);
+    getBucketResponse = (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
     assertTrue(getBucketResponse.isTruncated());
     assertEquals(2, getBucketResponse.getCommonPrefixes().size());
 
     //3rd time
     String value = getBucketResponse.getNextToken();
-    endpoint.queryParamsForTest().set(QueryParams.CONTINUATION_TOKEN, value);
-    getBucketResponse = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.CONTINUATION_TOKEN, value);
+    getBucketResponse = (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertFalse(getBucketResponse.isTruncated());
     assertEquals(1, getBucketResponse.getCommonPrefixes().size());
@@ -348,31 +331,23 @@ public void listWithContinuationToken1() throws OS3Exception, IOException {
 
   @Test
   public void listWithContinuationTokenFail() throws IOException {
-    OzoneClient ozoneClient =
-        createClientWithKeys("dir1/file2", "dir1/dir2/file2", "dir1bh/file",
-            "dir1bha/file2", "dir1", "dir2", "dir3");
+    setup("dir1/file2", "dir1/dir2/file2", "dir1bh/file", "dir1bha/file2", "dir1", "dir2", "dir3");
 
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(ozoneClient).build();
-
-    endpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
-    endpoint.queryParamsForTest().set(QueryParams.PREFIX, "dir");
-    endpoint.queryParamsForTest().set(QueryParams.CONTINUATION_TOKEN, "random");
-    endpoint.queryParamsForTest().setInt(QueryParams.MAX_KEYS, 2);
-    OS3Exception e = assertThrows(OS3Exception.class, () -> endpoint.get("b1").getEntity());
+    bucketEndpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
+    bucketEndpoint.queryParamsForTest().set(QueryParams.PREFIX, "dir");
+    bucketEndpoint.queryParamsForTest().set(QueryParams.CONTINUATION_TOKEN, "random");
+    bucketEndpoint.queryParamsForTest().setInt(QueryParams.MAX_KEYS, 2);
+    OS3Exception e = assertThrows(OS3Exception.class, () -> bucketEndpoint.get(BUCKET_NAME).getEntity());
     assertEquals("random", e.getResource());
     assertEquals("Invalid Argument", e.getErrorMessage());
   }
 
   @Test
   public void testStartAfter() throws IOException, OS3Exception {
-    OzoneClient ozoneClient =
-        createClientWithKeys("dir1/file1", "dir1bh/file1",
-            "dir1bha/file1", "dir0/file1", "dir2/file1");
-
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(ozoneClient).build();
+    setup("dir1/file1", "dir1bh/file1", "dir1bha/file1", "dir0/file1", "dir2/file1");
 
     ListObjectResponse getBucketResponse =
-        (ListObjectResponse) endpoint.get("b1").getEntity();
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertFalse(getBucketResponse.isTruncated());
     assertEquals(5, getBucketResponse.getContents().size());
@@ -381,16 +356,16 @@ public void testStartAfter() throws IOException, OS3Exception {
     // have 4 keys.
     String startAfter = "dir0/file1";
 
-    endpoint.queryParamsForTest().set(QueryParams.START_AFTER, startAfter);
+    bucketEndpoint.queryParamsForTest().set(QueryParams.START_AFTER, startAfter);
     getBucketResponse =
-        (ListObjectResponse) endpoint.get("b1").getEntity();
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertFalse(getBucketResponse.isTruncated());
     assertEquals(4, getBucketResponse.getContents().size());
 
-    endpoint.queryParamsForTest().set(QueryParams.START_AFTER, "random");
+    bucketEndpoint.queryParamsForTest().set(QueryParams.START_AFTER, "random");
     getBucketResponse =
-        (ListObjectResponse) endpoint.get("b1").getEntity();
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertFalse(getBucketResponse.isTruncated());
     assertEquals(0, getBucketResponse.getContents().size());
@@ -422,20 +397,19 @@ public void testEncodingType() throws IOException, OS3Exception {
       if encodingType == null , the = will not be encoded to "%3D
     * */
 
-    OzoneClient ozoneClient =
-        createClientWithKeys("data=1970", "data==1970");
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(ozoneClient).build();
+    setup("data=1970", "data==1970");
 
     String delimiter = "=";
     String prefix = "data=";
     String startAfter = "data=";
     String encodingType = ENCODING_TYPE;
 
-    endpoint.queryParamsForTest().set(QueryParams.DELIMITER, delimiter);
-    endpoint.queryParamsForTest().set(QueryParams.PREFIX, prefix);
-    endpoint.queryParamsForTest().set(QueryParams.ENCODING_TYPE, encodingType);
-    endpoint.queryParamsForTest().set(QueryParams.START_AFTER, startAfter);
-    ListObjectResponse response = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.DELIMITER, delimiter);
+    bucketEndpoint.queryParamsForTest().set(QueryParams.PREFIX, prefix);
+    bucketEndpoint.queryParamsForTest().set(QueryParams.ENCODING_TYPE, encodingType);
+    bucketEndpoint.queryParamsForTest().set(QueryParams.START_AFTER, startAfter);
+    ListObjectResponse response =
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     // Assert encodingType == url.
     // The Object name will be encoded by ObjectKeyNameAdapter
@@ -451,8 +425,8 @@ public void testEncodingType() throws IOException, OS3Exception {
     assertEquals(encodingType,
         response.getContents().get(0).getKey().getEncodingType());
 
-    endpoint.queryParamsForTest().unset(QueryParams.ENCODING_TYPE);
-    response = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().unset(QueryParams.ENCODING_TYPE);
+    response = (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     // Assert encodingType == null.
     // The Object name will not be encoded by ObjectKeyNameAdapter
@@ -469,20 +443,18 @@ public void testEncodingType() throws IOException, OS3Exception {
 
   @Test
   public void testEncodingTypeException() throws IOException {
-    OzoneClient client = new OzoneClientStub();
-    client.getObjectStore().createS3Bucket("b1");
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(client).build();
+    setup();
 
-    endpoint.queryParamsForTest().set(QueryParams.ENCODING_TYPE, "unSupportType");
-    OS3Exception e = assertThrows(OS3Exception.class, () -> endpoint.get("b1").getEntity());
+    bucketEndpoint.queryParamsForTest().set(QueryParams.ENCODING_TYPE, "unSupportType");
+    OS3Exception e = assertThrows(OS3Exception.class, () -> bucketEndpoint.get(BUCKET_NAME).getEntity());
     assertEquals(S3ErrorTable.INVALID_ARGUMENT.getCode(), e.getCode());
   }
 
   @Test
   public void testListObjectsWithNonIntegerMaxKeys() throws Exception {
-    OzoneClient client = new OzoneClientStub();
+    client = new OzoneClientStub();
     client.getObjectStore().createS3Bucket("bucket");
-    BucketEndpoint bucketEndpoint = newBucketEndpointBuilder()
+    bucketEndpoint = newBucketEndpointBuilder()
         .setClient(client)
         .build();
 
@@ -493,9 +465,9 @@ public void testListObjectsWithNonIntegerMaxKeys() throws Exception {
 
   @Test
   public void testListObjectsWithNegativeMaxKeys() throws Exception {
-    OzoneClient client = new OzoneClientStub();
+    client = new OzoneClientStub();
     client.getObjectStore().createS3Bucket("bucket");
-    BucketEndpoint bucketEndpoint = newBucketEndpointBuilder()
+    bucketEndpoint = newBucketEndpointBuilder()
         .setClient(client)
         .build();
 
@@ -507,9 +479,9 @@ public void testListObjectsWithNegativeMaxKeys() throws Exception {
 
   @Test
   public void testListObjectsWithZeroMaxKeys() throws Exception {
-    OzoneClient client = new OzoneClientStub();
+    client = new OzoneClientStub();
     client.getObjectStore().createS3Bucket("bucket");
-    BucketEndpoint bucketEndpoint = newBucketEndpointBuilder()
+    bucketEndpoint = newBucketEndpointBuilder()
         .setClient(client)
         .build();
 
@@ -523,20 +495,19 @@ public void testListObjectsWithZeroMaxKeys() throws Exception {
 
   @Test
   public void testListObjectsWithZeroMaxKeysInNonEmptyBucket() throws Exception {
-    OzoneClient client = createClientWithKeys("file1", "file2", "file3", "file4", "file5");
-    BucketEndpoint bucketEndpoint = newBucketEndpointBuilder()
-        .setClient(client)
-        .build();
+    setup("file1", "file2", "file3", "file4", "file5");
 
     bucketEndpoint.queryParamsForTest().setInt(QueryParams.MAX_KEYS, 0);
-    ListObjectResponse response = (ListObjectResponse) bucketEndpoint.get("b1").getEntity();
+    ListObjectResponse response =
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     // Should return empty list and not throw.
     assertEquals(0, response.getContents().size());
     assertFalse(response.isTruncated());
 
     bucketEndpoint.queryParamsForTest().unset(QueryParams.MAX_KEYS);
-    ListObjectResponse fullResponse = (ListObjectResponse) bucketEndpoint.get("b1").getEntity();
+    ListObjectResponse fullResponse =
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
     assertEquals(5, fullResponse.getContents().size());
   }
 
@@ -544,7 +515,7 @@ public void testListObjectsWithZeroMaxKeysInNonEmptyBucket() throws Exception {
   public void testListObjectsRespectsConfiguredMaxKeysLimit() throws Exception {
     // Arrange: Create a bucket with 1001 keys
     String[] keys = IntStream.range(0, 1001).mapToObj(i -> "file" + i).toArray(String[]::new);
-    OzoneClient client = createClientWithKeys(keys);
+    setup(keys);
 
     // Arrange: Set the max-keys limit in the configuration
     OzoneConfiguration config = new OzoneConfiguration();
@@ -552,7 +523,7 @@ public void testListObjectsRespectsConfiguredMaxKeysLimit() throws Exception {
     config.set(OZONE_S3G_LIST_MAX_KEYS_LIMIT, configuredMaxKeysLimit);
 
     // Arrange: Build and initialize the BucketEndpoint with the config
-    BucketEndpoint bucketEndpoint = newBucketEndpointBuilder()
+    bucketEndpoint = newBucketEndpointBuilder()
         .setClient(client)
         .setConfig(config)
         .build();
@@ -564,7 +535,8 @@ public void testListObjectsRespectsConfiguredMaxKeysLimit() throws Exception {
     // Act: Request more keys than the configured max-keys limit
     final int requestedMaxKeys = Integer.parseInt(configuredMaxKeysLimit) + 1;
     bucketEndpoint.queryParamsForTest().setInt(QueryParams.MAX_KEYS, requestedMaxKeys);
-    ListObjectResponse response = (ListObjectResponse) bucketEndpoint.get("b1").getEntity();
+    ListObjectResponse response =
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     // Assert: The number of returned keys should be capped at the configured limit
     assertEquals(Integer.parseInt(configuredMaxKeysLimit), response.getContents().size());
@@ -573,13 +545,12 @@ public void testListObjectsRespectsConfiguredMaxKeysLimit() throws Exception {
   @Test
   public void testListObjectsUrlEncodingUsesPercentTwentyForSpaces()
       throws Exception {
-    OzoneClient client = createClientWithKeys(
-        "foo+1/bar", "foo/bar/xyzzy", "quux ab/thud", "asdf+b");
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(client).build();
+    setup("foo+1/bar", "foo/bar/xyzzy", "quux ab/thud", "asdf+b");
 
-    endpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
-    endpoint.queryParamsForTest().set(QueryParams.ENCODING_TYPE, ENCODING_TYPE);
-    ListObjectResponse response = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.DELIMITER, "/");
+    bucketEndpoint.queryParamsForTest().set(QueryParams.ENCODING_TYPE, ENCODING_TYPE);
+    ListObjectResponse response =
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     ObjectKeyNameAdapter adapter = new ObjectKeyNameAdapter();
     assertEquals("asdf%2Bb", adapter.marshal(response.getContents().get(0).getKey()));
@@ -591,11 +562,11 @@ public void testListObjectsUrlEncodingUsesPercentTwentyForSpaces()
 
   @Test
   public void testListObjectsOmitsDelimiterWhenEmpty() throws Exception {
-    OzoneClient client = createClientWithKeys("bar", "baz", "cab", "foo");
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(client).build();
+    setup("bar", "baz", "cab", "foo");
 
-    endpoint.queryParamsForTest().set(QueryParams.DELIMITER, "");
-    ListObjectResponse response = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.DELIMITER, "");
+    ListObjectResponse response =
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertNull(response.getDelimiter());
     assertEquals(4, response.getContents().size());
@@ -614,12 +585,12 @@ private void assertEncodingTypeObject(
    */
   @Test
   public void listWithEmptyContinuationToken() throws OS3Exception, IOException {
-    OzoneClient ozoneClient = createClientWithKeys("bar", "baz", "foo", "quxx");
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(ozoneClient).build();
+    setup("bar", "baz", "foo", "quxx");
 
-    endpoint.queryParamsForTest().set(QueryParams.PREFIX, "");
-    endpoint.queryParamsForTest().set(QueryParams.CONTINUATION_TOKEN, "");
-    ListObjectResponse response = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.PREFIX, "");
+    bucketEndpoint.queryParamsForTest().set(QueryParams.CONTINUATION_TOKEN, "");
+    ListObjectResponse response =
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertFalse(response.isTruncated());
     assertEquals(4, response.getContents().size());
@@ -633,19 +604,18 @@ public void listWithEmptyContinuationToken() throws OS3Exception, IOException {
    */
   @Test
   public void listEchoesContinuationToken() throws OS3Exception, IOException {
-    OzoneClient ozoneClient = createClientWithKeys("bar", "baz", "foo", "quxx");
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(ozoneClient).build();
+    setup("bar", "baz", "foo", "quxx");
 
-    endpoint.queryParamsForTest().set(QueryParams.PREFIX, "");
-    endpoint.queryParamsForTest().setInt(QueryParams.MAX_KEYS, 1);
-    ListObjectResponse first = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.PREFIX, "");
+    bucketEndpoint.queryParamsForTest().setInt(QueryParams.MAX_KEYS, 1);
+    ListObjectResponse first = (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
     assertTrue(first.isTruncated());
     String token = first.getNextToken();
     assertNotNull(token);
 
-    endpoint.queryParamsForTest().unset(QueryParams.MAX_KEYS);
-    endpoint.queryParamsForTest().set(QueryParams.CONTINUATION_TOKEN, token);
-    ListObjectResponse second = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().unset(QueryParams.MAX_KEYS);
+    bucketEndpoint.queryParamsForTest().set(QueryParams.CONTINUATION_TOKEN, token);
+    ListObjectResponse second = (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertFalse(second.isTruncated());
     // The request continuation token is echoed back verbatim.
@@ -660,20 +630,19 @@ public void listEchoesContinuationToken() throws OS3Exception, IOException {
   @Test
   public void listContinuationTokenWithStartAfter()
       throws OS3Exception, IOException {
-    OzoneClient ozoneClient = createClientWithKeys("bar", "baz", "foo", "quxx");
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(ozoneClient).build();
+    setup("bar", "baz", "foo", "quxx");
 
-    endpoint.queryParamsForTest().set(QueryParams.PREFIX, "");
-    endpoint.queryParamsForTest().set(QueryParams.START_AFTER, "bar");
-    endpoint.queryParamsForTest().setInt(QueryParams.MAX_KEYS, 1);
-    ListObjectResponse first = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().set(QueryParams.PREFIX, "");
+    bucketEndpoint.queryParamsForTest().set(QueryParams.START_AFTER, "bar");
+    bucketEndpoint.queryParamsForTest().setInt(QueryParams.MAX_KEYS, 1);
+    ListObjectResponse first = (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
     assertTrue(first.isTruncated());
     String token = first.getNextToken();
     assertNotNull(token);
 
-    endpoint.queryParamsForTest().unset(QueryParams.MAX_KEYS);
-    endpoint.queryParamsForTest().set(QueryParams.CONTINUATION_TOKEN, token);
-    ListObjectResponse second = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().unset(QueryParams.MAX_KEYS);
+    bucketEndpoint.queryParamsForTest().set(QueryParams.CONTINUATION_TOKEN, token);
+    ListObjectResponse second = (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertFalse(second.isTruncated());
     assertEquals(token, second.getContinueToken());
@@ -702,11 +671,11 @@ public void continuationTokenXmlElementName() throws Exception {
 
   @Test
   public void listObjectOwnerOmittedForListV2ByDefault() throws OS3Exception, IOException {
-    OzoneClient client = createClientWithKeys("key1", "key2");
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(client).build();
+    setup("key1", "key2");
 
-    endpoint.queryParamsForTest().setInt(QueryParams.LIST_TYPE, 2);
-    ListObjectResponse response = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().setInt(QueryParams.LIST_TYPE, 2);
+    ListObjectResponse response =
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertEquals(2, response.getContents().size());
     assertNull(response.getContents().get(0).getOwner());
@@ -715,36 +684,32 @@ public void listObjectOwnerOmittedForListV2ByDefault() throws OS3Exception, IOEx
 
   @Test
   public void listObjectOwnerOmittedForListV2WhenFetchOwnerFalse() throws OS3Exception, IOException {
-    OzoneClient client = createClientWithKeys("key1");
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(client).build();
+    setup("key1");
 
-    endpoint.queryParamsForTest().setInt(QueryParams.LIST_TYPE, 2);
-    endpoint.queryParamsForTest().set(QueryParams.FETCH_OWNER, "false");
-    ListObjectResponse response = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().setInt(QueryParams.LIST_TYPE, 2);
+    bucketEndpoint.queryParamsForTest().set(QueryParams.FETCH_OWNER, "false");
+    ListObjectResponse response =
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertNull(response.getContents().get(0).getOwner());
   }
 
   @Test
   public void listObjectOwnerIncludedForListV2WhenFetchOwnerTrue() throws OS3Exception, IOException {
-    OzoneClient client = createClientWithKeys("key1");
-    BucketEndpoint endpoint = newBucketEndpointBuilder().setClient(client).build();
+    setup("key1");
 
-    endpoint.queryParamsForTest().setInt(QueryParams.LIST_TYPE, 2);
-    endpoint.queryParamsForTest().set(QueryParams.FETCH_OWNER, "true");
-    ListObjectResponse response = (ListObjectResponse) endpoint.get("b1").getEntity();
+    bucketEndpoint.queryParamsForTest().setInt(QueryParams.LIST_TYPE, 2);
+    bucketEndpoint.queryParamsForTest().set(QueryParams.FETCH_OWNER, "true");
+    ListObjectResponse response =
+        (ListObjectResponse) bucketEndpoint.get(BUCKET_NAME).getEntity();
 
     assertNotNull(response.getContents().get(0).getOwner());
   }
 
-  private OzoneClient createClientWithKeys(String... keys) throws IOException {
-    OzoneClient client = new OzoneClientStub();
-
-    client.getObjectStore().createS3Bucket("b1");
-    OzoneBucket bucket = client.getObjectStore().getS3Bucket("b1");
+  private void createKeys(OzoneClient ozoneClient, String... keys) throws IOException {
+    OzoneBucket bucket = ozoneClient.getObjectStore().getS3Bucket(BUCKET_NAME);
     for (String key : keys) {
       bucket.createKey(key, 0).close();
     }
-    return client;
   }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@ozone.apache.org
For additional commands, e-mail: commits-help@ozone.apache.org