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


##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/bucket/TestOMNonS3BucketCreateRequest.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.hadoop.ozone.om.request.bucket;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.UUID;
+
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests TestOMNonS3BucketCreateRequest class,
+ * which handles CreateNonS3Bucket request.
+ */
+@RunWith(Parameterized.class)
+public class TestOMNonS3BucketCreateRequest extends TestOMBucketCreateRequest {

Review Comment:
   By extending `TestOMBucketCreateRequest` and making this `Parameterized`, 
all test cases from parent class are run for all parameters.  That's 
unnecessary, those parent test cases are independent of the parameters.
   
   ```
   [INFO] Tests run: 40, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 
11.343 s - in 
org.apache.hadoop.ozone.om.request.bucket.TestOMNonS3BucketCreateRequest
   ```
   
   If you want to keep it parameterized, the new test should either extend 
`TestBucketRequest`, or be added as nested class in `TestOMBucketCreateRequest`.
   
   I suggest getting rid of `Parameterized` run, adding test cases explicitly 
(as described in comment below).  If you follow that, the test cases can be 
moved into `TestOMBucketCreateRequest` as non-nested, top-level methods.



##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/bucket/TestOMNonS3BucketCreateRequest.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.hadoop.ozone.om.request.bucket;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.UUID;
+
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests TestOMNonS3BucketCreateRequest class,

Review Comment:
   The test doesn't test itself.



##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/bucket/TestOMNonS3BucketCreateRequest.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.hadoop.ozone.om.request.bucket;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.UUID;
+
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests TestOMNonS3BucketCreateRequest class,
+ * which handles CreateNonS3Bucket request.
+ */
+@RunWith(Parameterized.class)
+public class TestOMNonS3BucketCreateRequest extends TestOMBucketCreateRequest {
+  private String bucketName;
+  private boolean strictS3;
+  private boolean expectBucketCreated;
+
+  @Parameterized.Parameters
+  public static Collection createBucketNamesAndStrictS3() {
+    return Arrays.asList(new Object[][] {
+            {"bucket_underscore", false, true},
+            {"_bucket___multi_underscore_", false, true},
+            {"bucket", true, true},
+            {"bucket_", true, false},
+    });
+  }
+
+  public TestOMNonS3BucketCreateRequest(String bucketName, boolean strictS3,
+        boolean expectBucketCreated) {
+    this.bucketName = bucketName;
+    this.strictS3 = strictS3;
+    this.expectBucketCreated = expectBucketCreated;
+  }
+
+  @Test
+  public void testCreateBucketWithOMNamespaceS3NotStrict() throws Exception {

Review Comment:
   Please split this into three test cases:
    * accepts S3-compliant bucket name regardless of `strictS3` setting
    * rejects non-S3-compliant bucket name with `strictS3=true`
    * accepts non-S3-compliant bucket name with `strictS3=false`
   
   Extract and reuse helper methods:
    * creates bucket successfully
    * rejects bucket name
   
   You can then test multiple bucket names using a loop or individual calls to 
helper method.



##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/bucket/TestOMNonS3BucketCreateRequest.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.hadoop.ozone.om.request.bucket;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.UUID;
+
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests TestOMNonS3BucketCreateRequest class,
+ * which handles CreateNonS3Bucket request.

Review Comment:
   There is no such request: `CreateNonS3Bucket`



##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/bucket/TestOMNonS3BucketCreateRequest.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.hadoop.ozone.om.request.bucket;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.UUID;
+
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests TestOMNonS3BucketCreateRequest class,
+ * which handles CreateNonS3Bucket request.
+ */
+@RunWith(Parameterized.class)
+public class TestOMNonS3BucketCreateRequest extends TestOMBucketCreateRequest {
+  private String bucketName;
+  private boolean strictS3;
+  private boolean expectBucketCreated;
+
+  @Parameterized.Parameters
+  public static Collection createBucketNamesAndStrictS3() {
+    return Arrays.asList(new Object[][] {
+            {"bucket_underscore", false, true},
+            {"_bucket___multi_underscore_", false, true},
+            {"bucket", true, true},
+            {"bucket_", true, false},
+    });
+  }
+
+  public TestOMNonS3BucketCreateRequest(String bucketName, boolean strictS3,
+        boolean expectBucketCreated) {
+    this.bucketName = bucketName;
+    this.strictS3 = strictS3;
+    this.expectBucketCreated = expectBucketCreated;
+  }
+
+  @Test
+  public void testCreateBucketWithOMNamespaceS3NotStrict() throws Exception {
+    String volumeName = UUID.randomUUID().toString();
+    when(ozoneManager.isStrictS3()).thenReturn(strictS3);
+    OMBucketCreateRequest omBucketCreateRequest;
+    if (expectBucketCreated) {
+      omBucketCreateRequest = doPreExecute(volumeName, bucketName);
+      doValidateAndUpdateCache(volumeName, bucketName,
+            omBucketCreateRequest.getOmRequest());
+    } else {
+      Throwable e = assertThrows(OMException.class, () ->
+                doPreExecute(volumeName, bucketName));
+      assertEquals(e.getMessage(), "Invalid bucket name: bucket_");

Review Comment:
   Replace hard-coded `bucket_` with the actual `bucketName`.



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