mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 08:43:02 +08:00
推进 ActionExecutor 下的‘行动生成与执行’部分
- 新增 RunnerClient 抽象类,并划分 SandboxRunnerClient、LocalRunnerClient两个子类(内容待完善)。前者负责对接 SandboxRunner 模块,后者直接使用本地作为执行环境(但不推荐)。
- 将 ActionWatchService 划为 LocalRunnerClient 的内部类,负责采用本地执行环境时,监听行动程序变化
- 完善 ActionRepairer 处的修复逻辑
- 调整 MetaAction 中路径获取逻辑
这提交方式真该调整一下了,这阶段推进容易攒太多,但又不好停手。或许阶段目标可以保留,但推进点应该可以细化🤔
This commit is contained in:
47
Partner-Main/src/test/java/SystemTest.java
Normal file
47
Partner-Main/src/test/java/SystemTest.java
Normal file
@@ -0,0 +1,47 @@
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import work.slhaf.partner.core.action.entity.MetaActionInfo;
|
||||
import work.slhaf.partner.core.action.runner.LocalRunnerClient;
|
||||
import work.slhaf.partner.core.action.runner.RunnerClient;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class SystemTest {
|
||||
@Test
|
||||
void execTest() {
|
||||
// exec("pwd");
|
||||
// exec("ls", "-la");
|
||||
String r = exec("pip", "st", "--format=freeze");
|
||||
System.out.println(r);
|
||||
}
|
||||
|
||||
private String exec(String... command) {
|
||||
StringBuilder s = new StringBuilder();
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(command);
|
||||
try {
|
||||
Process process = processBuilder.start();
|
||||
java.io.InputStream inputStream = process.getInputStream();
|
||||
java.util.Scanner scanner = new java.util.Scanner(inputStream).useDelimiter("\\A");
|
||||
if (scanner.hasNext()) {
|
||||
s.append(scanner.next());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
void localRunnerClientTest() {
|
||||
Map<String, MetaActionInfo> existedMetaActions = new HashMap<>();
|
||||
ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor();
|
||||
RunnerClient client = new LocalRunnerClient(existedMetaActions, executor);
|
||||
JSONObject res = client.listSysDependencies();
|
||||
System.out.println(res.toString());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user