[
https://issues.apache.org/jira/browse/HIVE-26500?focusedWorklogId=806341&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-806341
]
ASF GitHub Bot logged work on HIVE-26500:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 06/Sep/22 12:11
Start Date: 06/Sep/22 12:11
Worklog Time Spent: 10m
Work Description: 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?
Issue Time Tracking
-------------------
Worklog Id: (was: 806341)
Time Spent: 1h 10m (was: 1h)
> Improve TestHiveMetastore
> -------------------------
>
> Key: HIVE-26500
> URL: https://issues.apache.org/jira/browse/HIVE-26500
> Project: Hive
> Issue Type: Improvement
> Reporter: László Bodor
> Assignee: László Bodor
> Priority: Major
> Labels: pull-request-available
> Time Spent: 1h 10m
> Remaining Estimate: 0h
>
> {code}
> Thread.sleep(5 * 1000); // give HMS time to handle close request
> int numObjectsAfterClose = getJDOPersistanceManagerCacheSize();
> assertTrue(numObjectsBeforeClose == numObjectsAfterClose);
> {code}
> 1. easy fix: assertTrue(numObjectsBeforeClose == numObjectsAfterClose);
> this tells nothing in case of assertionerror:
> {code}
> java.lang.AssertionError
> at org.junit.Assert.fail(Assert.java:87)
> at org.junit.Assert.assertTrue(Assert.java:42)
> at org.junit.Assert.assertTrue(Assert.java:53)
> at
> org.apache.hadoop.hive.metastore.TestHiveMetaStore.testJDOPersistanceManagerCleanup(TestHiveMetaStore.java:3298)
> {code}
> should tell a more informative message with particular values
> 2. harder fix, maybe do it later
> {code}
> Thread.sleep(5 * 1000); // give HMS time to handle close request
> {code}
> sleep is always dangerous, cannot make sure it handled everything that we
> expected
--
This message was sent by Atlassian Jira
(v8.20.10#820010)