abstractdog commented on code in PR #3556: URL: https://github.com/apache/hive/pull/3556#discussion_r963625098
########## standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/utils/MetastoreTestUtils.java: ########## @@ -0,0 +1,65 @@ +/* + * 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.hive.metastore.utils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Common utils for metastore tests. + */ +public class MetastoreTestUtils { + + private static final Logger LOG = LoggerFactory.getLogger(MetastoreTestUtils.class); + + /** + * This method can run an assertion wrapped in to a runnable, and keep retrying it for a certain amount of time. + * It can be useful when the assertion doesn't necessarily pass immediately, and it would be hard + * to mock into production code in order to wait for some conditions properly. Instead, it just + * waits, but not like a constant time before a single attempt (which is easy, but errorprone). + * @param assertionContext + * @param runnable + * @param msBetweenAssertionAttempts + * @param msOverallTimeout + * @throws Exception + */ + public static void waitForAssertion(String assertionContext, Runnable assertionRunnable, int msBetweenAssertionAttempts, Review Comment: good point, however, there is no direct dependency on hadoop-common in metastore (only provided, optional, etc.) I like GenericTestUtils, I implemented pretty much the same, but I think mine is maybe better in a sense that the caller doesn't have to create a boolean function and handle TimeoutException and stuff, instead just write the very same assertion in a runnable which would be originally there without this timeout hack...if the code block throws assertion error, unit test fails automatically as a unit test is expected ########## standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/utils/MetastoreTestUtils.java: ########## @@ -0,0 +1,65 @@ +/* + * 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.hive.metastore.utils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Common utils for metastore tests. + */ +public class MetastoreTestUtils { + + private static final Logger LOG = LoggerFactory.getLogger(MetastoreTestUtils.class); + + /** + * This method can run an assertion wrapped in to a runnable, and keep retrying it for a certain amount of time. + * It can be useful when the assertion doesn't necessarily pass immediately, and it would be hard + * to mock into production code in order to wait for some conditions properly. Instead, it just + * waits, but not like a constant time before a single attempt (which is easy, but errorprone). + * @param assertionContext + * @param runnable + * @param msBetweenAssertionAttempts + * @param msOverallTimeout + * @throws Exception + */ + public static void waitForAssertion(String assertionContext, Runnable assertionRunnable, int msBetweenAssertionAttempts, Review Comment: good point, however, there is no direct dependency on hadoop-common in metastore (only provided, optional, etc.) I like GenericTestUtils, I implemented pretty much the same, but I think mine is maybe better in a sense that the caller doesn't have to create a boolean function and handle TimeoutException and stuff, instead just write the very same assertion in a runnable which would be originally there without this timeout hack...if the code block throws assertion error, unit test fails automatically as a unit test is expected, does this make sense to you? -- 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]
