Skip to content

Commit 2840fb2

Browse files
committed
Add agent system info test
1 parent da7f53a commit 2840fb2

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

platform-agent/src/main/java/com/flow/platform/agent/CmdManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ public void run() {
212212
log.setCategory(Category.SYSTEM_INFO);
213213
logListener.onLog(log);
214214
logListener.onFinish();
215+
cmd.setStatus(CmdStatus.EXECUTED);
215216
}
216217

217218
// kill current running proc

platform-agent/src/test/java/com/flow/platform/agent/test/CmdManagerTest.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.flow.platform.cmd.ProcListener;
2222
import com.flow.platform.domain.Cmd;
2323
import com.flow.platform.domain.CmdResult;
24+
import com.flow.platform.domain.CmdStatus;
2425
import com.flow.platform.domain.CmdType;
2526
import java.io.IOException;
2627
import java.util.Map;
@@ -213,4 +214,56 @@ public void onException(CmdResult result) {
213214
Assert.assertNotNull(result.getExitValue());
214215
Assert.assertEquals(CmdResult.EXIT_VALUE_FOR_KILL, result.getExitValue());
215216
}
217+
218+
219+
@Test
220+
public void should_success_run_sys_cmd() throws InterruptedException {
221+
222+
Cmd cmd = new Cmd("zone1", "agent1", CmdType.RUN_SHELL, resourcePath);
223+
cmd.setId(UUID.randomUUID().toString());
224+
CountDownLatch finishCountDownLatch = new CountDownLatch(1);
225+
CountDownLatch startCountDownLatch = new CountDownLatch(1);
226+
227+
cmdManager.getExtraProcEventListeners().add(new ProcListener() {
228+
@Override
229+
public void onStarted(CmdResult result) {
230+
startCountDownLatch.countDown();
231+
try {
232+
Thread.sleep(3000);
233+
} catch (Throwable e) {
234+
}
235+
}
236+
237+
@Override
238+
public void onLogged(CmdResult result) {
239+
finishCountDownLatch.countDown();
240+
}
241+
242+
@Override
243+
public void onExecuted(CmdResult result) {
244+
245+
}
246+
247+
@Override
248+
public void onException(CmdResult result) {
249+
250+
}
251+
});
252+
253+
// when: start and kill task immediately
254+
cmdManager.execute(cmd);
255+
256+
startCountDownLatch.await();
257+
Assert.assertEquals(1, cmdManager.getRunning().size());
258+
259+
Cmd cmdSys = new Cmd("zone1", "agent1", CmdType.SYSTEM_INFO, "");
260+
cmdSys.setId(UUID.randomUUID().toString());
261+
262+
cmdManager.execute(cmdSys);
263+
Assert.assertEquals(CmdStatus.EXECUTED, cmdSys.getStatus());
264+
265+
finishCountDownLatch.await();
266+
Assert.assertEquals(1, cmdManager.getFinished().size());
267+
268+
}
216269
}

0 commit comments

Comments
 (0)