aloyszhang commented on code in PR #9916:
URL: https://github.com/apache/inlong/pull/9916#discussion_r1547194661


##########
inlong-agent/agent-installer/src/test/java/installer/BaseTestsHelper.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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 installer;
+
+import org.apache.inlong.agent.conf.TaskProfile;
+import org.apache.inlong.agent.constant.AgentConstants;
+import org.apache.inlong.agent.constant.FetcherConstants;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.pojo.FileTask.FileTaskConfig;
+import org.apache.inlong.common.enums.TaskStateEnum;
+import org.apache.inlong.common.pojo.agent.DataConfig;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import org.apache.commons.io.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+/**
+ * common environment setting up for test cases.
+ */
+public class BaseTestsHelper {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(BaseTestsHelper.class);
+    private static final GsonBuilder gsonBuilder = new 
GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss");
+    private static final Gson GSON = gsonBuilder.create();
+    private final String className;
+    private Path testRootDir;
+
+    public BaseTestsHelper(String className) {
+        this.className = className;
+    }
+
+    public BaseTestsHelper setupAgentHome() {
+        testRootDir = Paths
+                .get("/tmp", BaseTestsHelper.class.getSimpleName(), className);
+        teardownAgentHome();
+        boolean result = testRootDir.toFile().mkdirs();
+        LOGGER.info("try to create {}, result is {}", testRootDir, result);
+        
InstallerConfiguration.getInstallerConf().set(AgentConstants.AGENT_HOME, 
testRootDir.toString());
+        
InstallerConfiguration.getInstallerConf().set(FetcherConstants.AGENT_MANAGER_ADDR,
 "");
+        return this;
+    }
+
+    public Path getTestRootDir() {
+        return testRootDir;
+    }
+
+    public void teardownAgentHome() {
+        if (testRootDir != null) {
+            try {
+                FileUtils.deleteDirectory(testRootDir.toFile());
+            } catch (Exception ignored) {
+                LOGGER.warn("deleteDirectory error ", ignored);
+            }
+        }
+    }
+
+    public TaskProfile getTaskProfile(int taskId, String pattern, boolean 
retry, Long startTime, Long endTime,
+            TaskStateEnum state, String timeZone) {
+        DataConfig dataConfig = getDataConfig(taskId, pattern, retry, 
startTime, endTime, state, timeZone);
+        TaskProfile profile = TaskProfile.convertToTaskProfile(dataConfig);
+        return profile;

Review Comment:
   ```suggestion
           return TaskProfile.convertToTaskProfile(dataConfig);
   ```



##########
inlong-agent/agent-installer/src/test/java/installer/BaseTestsHelper.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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 installer;
+
+import org.apache.inlong.agent.conf.TaskProfile;
+import org.apache.inlong.agent.constant.AgentConstants;
+import org.apache.inlong.agent.constant.FetcherConstants;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.pojo.FileTask.FileTaskConfig;
+import org.apache.inlong.common.enums.TaskStateEnum;
+import org.apache.inlong.common.pojo.agent.DataConfig;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import org.apache.commons.io.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+/**
+ * common environment setting up for test cases.
+ */
+public class BaseTestsHelper {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(BaseTestsHelper.class);
+    private static final GsonBuilder gsonBuilder = new 
GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss");
+    private static final Gson GSON = gsonBuilder.create();
+    private final String className;
+    private Path testRootDir;
+
+    public BaseTestsHelper(String className) {
+        this.className = className;
+    }
+
+    public BaseTestsHelper setupAgentHome() {
+        testRootDir = Paths
+                .get("/tmp", BaseTestsHelper.class.getSimpleName(), className);
+        teardownAgentHome();
+        boolean result = testRootDir.toFile().mkdirs();
+        LOGGER.info("try to create {}, result is {}", testRootDir, result);
+        
InstallerConfiguration.getInstallerConf().set(AgentConstants.AGENT_HOME, 
testRootDir.toString());
+        
InstallerConfiguration.getInstallerConf().set(FetcherConstants.AGENT_MANAGER_ADDR,
 "");
+        return this;
+    }
+
+    public Path getTestRootDir() {
+        return testRootDir;
+    }
+
+    public void teardownAgentHome() {
+        if (testRootDir != null) {
+            try {
+                FileUtils.deleteDirectory(testRootDir.toFile());
+            } catch (Exception ignored) {
+                LOGGER.warn("deleteDirectory error ", ignored);
+            }
+        }
+    }
+
+    public TaskProfile getTaskProfile(int taskId, String pattern, boolean 
retry, Long startTime, Long endTime,

Review Comment:
   Not used



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to