From b6d9c92e125759c80fa760061fa8d3260ca647f8 Mon Sep 17 00:00:00 2001 From: yuzelin <33053040+yuzelin@users.noreply.github.com> Date: Tue, 26 Sep 2023 12:58:45 +0800 Subject: [PATCH] [hive] Remove redundant test class 'CommonTestUtils' (#2071) --- paimon-hive/paimon-hive-catalog/pom.xml | 8 ++ .../apache/paimon/hive/HiveCatalogTest.java | 2 +- .../paimon/hive/utils/CommonTestUtils.java | 117 ------------------ 3 files changed, 9 insertions(+), 118 deletions(-) delete mode 100644 paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/utils/CommonTestUtils.java diff --git a/paimon-hive/paimon-hive-catalog/pom.xml b/paimon-hive/paimon-hive-catalog/pom.xml index 5cb71c0bc4b2..4c3d46194c56 100644 --- a/paimon-hive/paimon-hive-catalog/pom.xml +++ b/paimon-hive/paimon-hive-catalog/pom.xml @@ -139,6 +139,14 @@ under the License. test-jar + + org.apache.paimon + paimon-common + ${project.version} + test + test-jar + + org.apache.paimon paimon-format diff --git a/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/HiveCatalogTest.java b/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/HiveCatalogTest.java index a4513073564a..d3e3ca0c7dea 100644 --- a/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/HiveCatalogTest.java +++ b/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/HiveCatalogTest.java @@ -20,10 +20,10 @@ import org.apache.paimon.catalog.CatalogTestBase; import org.apache.paimon.catalog.Identifier; -import org.apache.paimon.hive.utils.CommonTestUtils; import org.apache.paimon.schema.Schema; import org.apache.paimon.types.DataField; import org.apache.paimon.types.DataTypes; +import org.apache.paimon.utils.CommonTestUtils; import org.apache.paimon.shade.guava30.com.google.common.collect.Lists; diff --git a/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/utils/CommonTestUtils.java b/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/utils/CommonTestUtils.java deleted file mode 100644 index 6196e9e74ab9..000000000000 --- a/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/utils/CommonTestUtils.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 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.paimon.hive.utils; - -import java.lang.reflect.Field; -import java.time.Duration; -import java.util.Map; -import java.util.concurrent.Callable; -import java.util.concurrent.TimeoutException; -import java.util.function.Supplier; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -/** This class contains reusable utility methods for unit tests. */ -public class CommonTestUtils { - - // ------------------------------------------------------------------------ - // Manipulation of environment - // ------------------------------------------------------------------------ - - public static void setEnv(Map newenv) { - setEnv(newenv, true); - } - - // This code is taken slightly modified from: http://stackoverflow.com/a/7201825/568695 - // it changes the environment variables of this JVM. Use only for testing purposes! - @SuppressWarnings("unchecked") - public static void setEnv(Map newenv, boolean clearExisting) { - try { - Map env = System.getenv(); - Class clazz = env.getClass(); - Field field = clazz.getDeclaredField("m"); - field.setAccessible(true); - Map map = (Map) field.get(env); - if (clearExisting) { - map.clear(); - } - map.putAll(newenv); - - // only for Windows - Class processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment"); - try { - @SuppressWarnings("JavaReflectionMemberAccess") - Field theCaseInsensitiveEnvironmentField = - processEnvironmentClass.getDeclaredField("theCaseInsensitiveEnvironment"); - theCaseInsensitiveEnvironmentField.setAccessible(true); - Map cienv = - (Map) theCaseInsensitiveEnvironmentField.get(null); - if (clearExisting) { - cienv.clear(); - } - cienv.putAll(newenv); - } catch (NoSuchFieldException ignored) { - } - - } catch (Exception e1) { - throw new RuntimeException(e1); - } - } - - /** Checks whether an exception with a message occurs when running a piece of code. */ - public static void assertThrows( - String msg, Class expected, Callable code) { - assertThatThrownBy(code::call).isInstanceOf(expected).hasMessageContaining(msg); - } - - public static void waitUtil(Supplier condition, Duration timeout, Duration pause) - throws TimeoutException, InterruptedException { - waitUtil(condition, timeout, pause, "Failed to wait for condition to be true."); - } - - /** - * Wait util the given condition is met or timeout. - * - * @param condition the condition to wait for. - * @param timeout the maximum time to wait for the condition to become true. - * @param pause delay between condition checks. - * @param errorMsg the error message to include in the TimeoutException if the - * condition was not met before timeout. - * @throws TimeoutException if the condition is not met before timeout. - * @throws InterruptedException if the thread is interrupted. - */ - @SuppressWarnings("BusyWait") - public static void waitUtil( - Supplier condition, Duration timeout, Duration pause, String errorMsg) - throws TimeoutException, InterruptedException { - long timeoutMs = timeout.toMillis(); - if (timeoutMs <= 0) { - throw new IllegalArgumentException("The timeout must be positive."); - } - long startingTime = System.currentTimeMillis(); - boolean conditionResult = condition.get(); - while (!conditionResult && System.currentTimeMillis() - startingTime < timeoutMs) { - conditionResult = condition.get(); - Thread.sleep(pause.toMillis()); - } - if (!conditionResult) { - throw new TimeoutException(errorMsg); - } - } -}