You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by xx...@apache.org on 2023/02/07 07:09:35 UTC

[kylin] 06/15: KYLIN-5411 Add check-env for zstd native lib loading test

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

xxyu pushed a commit to branch kylin5
in repository https://gitbox.apache.org/repos/asf/kylin.git

commit a3e33dd13cf1b263fefef3c3cd5890a916a602be
Author: Yinghao Lin <39...@users.noreply.github.com>
AuthorDate: Fri Nov 18 22:46:38 2022 +0800

    KYLIN-5411 Add check-env for zstd native lib loading test
---
 pom.xml                                            |  8 ++++
 src/tool/pom.xml                                   |  5 +++
 .../kylin/tool/setup/ZstdLibLoadableTestTool.java  | 45 ++++++++++++++++++++++
 .../tool/setup/ZstdLibLoadableTestToolTest.java    | 45 ++++++++++++++++++++++
 4 files changed, 103 insertions(+)

diff --git a/pom.xml b/pom.xml
index 85479cfcf5..5b85bc60bf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -308,6 +308,7 @@
         <validation.api.version>2.0.1.Final</validation.api.version>
         <jackson-databind.version>2.13.4.2</jackson-databind.version>
         <nimbus-jose-jwt.version>9.23</nimbus-jose-jwt.version>
+        <system-lambda.version>1.2.1</system-lambda.version>
     </properties>
 
     <modules>
@@ -2852,6 +2853,13 @@
                 <artifactId>snakeyaml</artifactId>
                 <version>${snakeyaml.version}</version>
             </dependency>
+
+            <dependency>
+                <groupId>com.github.stefanbirkner</groupId>
+                <artifactId>system-lambda</artifactId>
+                <version>${system-lambda.version}</version>
+                <scope>test</scope>
+            </dependency>
         </dependencies>
     </dependencyManagement>
 
diff --git a/src/tool/pom.xml b/src/tool/pom.xml
index e4174d46d1..3edecd48e4 100644
--- a/src/tool/pom.xml
+++ b/src/tool/pom.xml
@@ -199,5 +199,10 @@
             <artifactId>hadoop-yarn-client</artifactId>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>com.github.stefanbirkner</groupId>
+            <artifactId>system-lambda</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
diff --git a/src/tool/src/main/java/org/apache/kylin/tool/setup/ZstdLibLoadableTestTool.java b/src/tool/src/main/java/org/apache/kylin/tool/setup/ZstdLibLoadableTestTool.java
new file mode 100644
index 0000000000..0f2f1a2d39
--- /dev/null
+++ b/src/tool/src/main/java/org/apache/kylin/tool/setup/ZstdLibLoadableTestTool.java
@@ -0,0 +1,45 @@
+/*
+ * 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.kylin.tool.setup;
+
+import java.io.File;
+
+import org.apache.kylin.common.util.Unsafe;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.github.luben.zstd.util.Native;
+
+public class ZstdLibLoadableTestTool {
+
+    public static final Logger logger = LoggerFactory.getLogger(ZstdLibLoadableTestTool.class);
+
+    public static void main(String[] args) {
+        logger.info("Start ZstdLibLoadableTestTool");
+        File tmpDir = args.length == 1 ? new File(args[0]) : null;
+        try {
+            Native.load(tmpDir);
+            logger.info("zstd lib loading succeed.");
+        } catch (Throwable t) {
+            logger.error("zstd lib loading failed", t);
+            Unsafe.systemExit(1);
+        }
+        Unsafe.systemExit(0);
+    }
+}
diff --git a/src/tool/src/test/java/org/apache/kylin/tool/setup/ZstdLibLoadableTestToolTest.java b/src/tool/src/test/java/org/apache/kylin/tool/setup/ZstdLibLoadableTestToolTest.java
new file mode 100644
index 0000000000..056d7b7e14
--- /dev/null
+++ b/src/tool/src/test/java/org/apache/kylin/tool/setup/ZstdLibLoadableTestToolTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.kylin.tool.setup;
+
+import com.github.stefanbirkner.systemlambda.SystemLambda;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+class ZstdLibLoadableTestToolTest {
+
+    @Test
+    public void testLoadSuccess() throws Exception {
+        int code = SystemLambda.catchSystemExit(() -> {
+            ZstdLibLoadableTestTool.main(new String[0]);
+        });
+        Assertions.assertEquals(0, code);
+    }
+
+    @Test
+    public void testLoadFailed() throws Exception {
+        int code = SystemLambda.catchSystemExit(() -> {
+            ZstdLibLoadableTestTool.main(new String[] {"/some/non-exists/path"});
+        });
+        Assertions.assertEquals(1, code);
+    }
+}