This is an automated email from the ASF dual-hosted git repository.

kerwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new b6d9c92e1 [hive] Remove redundant test class 'CommonTestUtils' (#2071)
b6d9c92e1 is described below

commit b6d9c92e125759c80fa760061fa8d3260ca647f8
Author: yuzelin <[email protected]>
AuthorDate: Tue Sep 26 12:58:45 2023 +0800

    [hive] Remove redundant test class 'CommonTestUtils' (#2071)
---
 paimon-hive/paimon-hive-catalog/pom.xml            |   8 ++
 .../org/apache/paimon/hive/HiveCatalogTest.java    |   2 +-
 .../apache/paimon/hive/utils/CommonTestUtils.java  | 117 ---------------------
 3 files changed, 9 insertions(+), 118 deletions(-)

diff --git a/paimon-hive/paimon-hive-catalog/pom.xml 
b/paimon-hive/paimon-hive-catalog/pom.xml
index 5cb71c0bc..4c3d46194 100644
--- a/paimon-hive/paimon-hive-catalog/pom.xml
+++ b/paimon-hive/paimon-hive-catalog/pom.xml
@@ -139,6 +139,14 @@ under the License.
             <type>test-jar</type>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.paimon</groupId>
+            <artifactId>paimon-common</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+            <type>test-jar</type>
+        </dependency>
+
         <dependency>
             <groupId>org.apache.paimon</groupId>
             <artifactId>paimon-format</artifactId>
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 a45130735..d3e3ca0c7 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 @@ package org.apache.paimon.hive;
 
 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 6196e9e74..000000000
--- 
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<String, String> 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<String, String> newenv, boolean 
clearExisting) {
-        try {
-            Map<String, String> env = System.getenv();
-            Class<?> clazz = env.getClass();
-            Field field = clazz.getDeclaredField("m");
-            field.setAccessible(true);
-            Map<String, String> map = (Map<String, String>) 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<String, String> cienv =
-                        (Map<String, String>) 
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<? extends Exception> expected, Callable<?> code) 
{
-        
assertThatThrownBy(code::call).isInstanceOf(expected).hasMessageContaining(msg);
-    }
-
-    public static void waitUtil(Supplier<Boolean> 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 
<code>TimeoutException</code> 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<Boolean> 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);
-        }
-    }
-}

Reply via email to