adoroszlai commented on code in PR #3263:
URL: https://github.com/apache/ozone/pull/3263#discussion_r846624871


##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/metrics/TestS3GatewayMetrics.java:
##########
@@ -110,4 +123,146 @@ public void testHeadObject() throws Exception {
     long curMetric = metrics.getHeadKeySuccess();
     assertEquals(1L, curMetric - oriMetric);
   }
-}
+
+  @Test
+  public void testGetBucketEndpointMetric() throws Exception {
+    long oriMetric = metrics.getGetBucketSuccess();
+
+    clientStub = createClientWithKeys("file1");
+    bucketEndpoint.setClient(clientStub);
+    bucketEndpoint.get(bucketName, null,
+        null, null, 1000, null,
+        null, null, "random", null,
+        null, null).getEntity();
+
+    long curMetric = metrics.getGetBucketSuccess();
+    assertEquals(1L, curMetric - oriMetric);
+
+
+    oriMetric = metrics.getGetBucketFailure();
+
+    try {
+      // Searching for a bucket that does not exist
+      bucketEndpoint.get("newBucket", null,
+          null, null, 1000, null,
+          null, null, "random", null,
+          null, null);
+      fail();
+    } catch (OS3Exception e) {
+    }
+
+    curMetric = metrics.getGetBucketFailure();
+    assertEquals(1L, curMetric - oriMetric);
+  }

Review Comment:
   > Each method is associated with a single S3 Endpoint and there are 2 
metrics associated with each endpoint, hence we are measuring the number of 
times a method succeeds and fails, and once an object is initialised we can 
reuse it for both the metrics
   
   Currently each test method is associated with a method on one of the 
endpoints.  E.g. `testCreateBucket` tests `bucketEndpoint.put()`, while 
`testDeleteBucket` tests `bucketEndpoint.delete()`.  If object reuse is so 
important, why not merge all these together in a huge `testBucketEndpoint` 
method?
   
   The reasons for separating these are at least:
   
    1. Small, self-contained test methods are easier to understand.
    2. Independence: test cases may pass or fail regardless of the result of 
other test cases.  If multiple cases are bundled in the same method, failure of 
one case may hide the result of the subsequent case.
   
   We can apply the same reasons to testing different metrics on the same 
endpoint and method pairs.



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