You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by xy...@apache.org on 2023/04/27 20:36:13 UTC
[helix] 04/37: Setup testng for meta-client module (#2326)
This is an automated email from the ASF dual-hosted git repository.
xyuanlu pushed a commit to branch metaclient
in repository https://gitbox.apache.org/repos/asf/helix.git
commit 22b892fedc984476d4ec29fc7ec458e0d6ae26ad
Author: Qi (Quincy) Qu <qq...@linkedin.com>
AuthorDate: Tue Dec 20 15:12:19 2022 -0500
Setup testng for meta-client module (#2326)
---
meta-client/pom.xml | 22 +++++++
meta-client/src/test/conf/testng.xml | 27 +++++++++
.../helix/metaclient/impl/zk/TestZkMetaClient.java | 70 ++++++++++++++++++++++
3 files changed, 119 insertions(+)
diff --git a/meta-client/pom.xml b/meta-client/pom.xml
index 24e07ebb8..9763220fa 100644
--- a/meta-client/pom.xml
+++ b/meta-client/pom.xml
@@ -43,6 +43,28 @@ under the License.
<artifactId>zookeeper-api</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.11.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.xerial.snappy</groupId>
+ <artifactId>snappy-java</artifactId>
+ <version>1.1.7</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<resources>
diff --git a/meta-client/src/test/conf/testng.xml b/meta-client/src/test/conf/testng.xml
new file mode 100644
index 000000000..b5e3518d1
--- /dev/null
+++ b/meta-client/src/test/conf/testng.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
+<suite name="Suite" parallel="false">
+ <test name="Test" preserve-order="true">
+ <packages>
+ <package name="org.apache.helix.metaclient.*"/>
+ </packages>
+ </test>
+</suite>
diff --git a/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestZkMetaClient.java b/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestZkMetaClient.java
new file mode 100644
index 000000000..4c74fe847
--- /dev/null
+++ b/meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestZkMetaClient.java
@@ -0,0 +1,70 @@
+package org.apache.helix.metaclient.impl.zk;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import org.apache.commons.io.FileUtils;
+import org.apache.helix.zookeeper.zkclient.IDefaultNameSpace;
+import org.apache.helix.zookeeper.zkclient.ZkServer;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+
+public class TestZkMetaClient {
+
+ private static final String ZK_ADDR = "localhost:2183";
+ private ZkServer _zkServer;
+
+ @BeforeClass
+ public void prepare() {
+ // start local zookeeper server
+ _zkServer = startZkServer(ZK_ADDR);
+ }
+
+ @Test
+ public void dummyTest() {
+ Assert.assertEquals(1+1, 2);
+ }
+
+ private static ZkServer startZkServer(final String zkAddress) {
+ String zkDir = zkAddress.replace(':', '_');
+ final String logDir = "/tmp/" + zkDir + "/logs";
+ final String dataDir = "/tmp/" + zkDir + "/dataDir";
+
+ // Clean up local directory
+ try {
+ FileUtils.deleteDirectory(new File(dataDir));
+ FileUtils.deleteDirectory(new File(logDir));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ IDefaultNameSpace defaultNameSpace = zkClient -> {
+ };
+
+ int port = Integer.parseInt(zkAddress.substring(zkAddress.lastIndexOf(':') + 1));
+ ZkServer zkServer = new ZkServer(dataDir, logDir, defaultNameSpace, port);
+ System.out.println("Starting ZK server at " + zkAddress);
+ zkServer.start();
+ return zkServer;
+ }
+}