-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INLONG-9909][Agent] Add unit test for installer (#9916)
- Loading branch information
1 parent
73c9350
commit 30dd38f
Showing
9 changed files
with
419 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
inlong-agent/agent-installer/src/test/java/installer/BaseTestsHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* 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.constant.AgentConstants; | ||
import org.apache.inlong.agent.constant.FetcherConstants; | ||
import org.apache.inlong.agent.installer.conf.InstallerConfiguration; | ||
|
||
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 Gson GSON = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").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 void teardownAgentHome() { | ||
if (testRootDir != null) { | ||
try { | ||
FileUtils.deleteDirectory(testRootDir.toFile()); | ||
} catch (Exception ignored) { | ||
LOGGER.warn("deleteDirectory error ", ignored); | ||
} | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
inlong-agent/agent-installer/src/test/java/installer/ModuleActionTypeEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* Enum of module action. | ||
*/ | ||
public enum ModuleActionTypeEnum { | ||
|
||
DOWNLOAD(0), | ||
INSTALL(1), | ||
UNINSTALL(2), | ||
START(3), | ||
STOP(4); | ||
|
||
private final int type; | ||
|
||
ModuleActionTypeEnum(int state) { | ||
this.type = state; | ||
} | ||
|
||
public static ModuleActionTypeEnum getTaskState(int state) { | ||
switch (state) { | ||
case 0: | ||
return DOWNLOAD; | ||
case 1: | ||
return INSTALL; | ||
case 2: | ||
return UNINSTALL; | ||
case 3: | ||
return START; | ||
case 4: | ||
return STOP; | ||
default: | ||
throw new RuntimeException("Unsupported module action " + state); | ||
} | ||
} | ||
|
||
public int getType() { | ||
return type; | ||
} | ||
} |
Oops, something went wrong.