reswqa commented on code in PR #7906:
URL: https://github.com/apache/iceberg/pull/7906#discussion_r1244732356


##########
common/src/main/java/org/apache/iceberg/common/testutils/PerTestCallbackWrapper.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.iceberg.common.testutils;
+
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+/**
+ * This class is used to wrap a specific {@link CustomExtension} to junit5 
extension with test-level
+ * callbacks {@link BeforeEachCallback} and {@link AfterEachCallback}. It can 
be used as a
+ * substitute for @Rule in junit4.
+ */
+public class PerTestCallbackWrapper<C extends CustomExtension>

Review Comment:
   If the `EcsS3MockExtension` implements both `BeforeEachCallback ` and 
`BeforeAllCallback `, then the lifecycle method like `initialize` of 
`EcsS3MockRule ` will be invoked double times.  Junit4 `TestRule` can take care 
of this by annotation with `@Rule` or `@ClassRule` respectively. As for Junit5, 
we can only register extension with single annotation `@RegisterExtension`. 
`PerTestCallbackWrapper ` and `PerClassCallbackWrapper ` is used to control the 
lifecycle of `initialize`(`before all` or `before each`).
   
   The core is to implement an `CustomExtension` similar to `TestRule`, and 
then select the appropriate `PerTest/PerClassCallBackWrapper` to wrap it based 
on the actual life cycle required for testing.
   
   The reason for introducing `CustomExtension` is for future extends. Of 
course, we may only need to migrate this `EcsS3TestRule` to Junit5 temporarily, 
but I think it is worth it. 🤔 
   
   
   



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