|
21 | 21 | import com.flow.platform.cmd.ProcListener; |
22 | 22 | import com.flow.platform.domain.Cmd; |
23 | 23 | import com.flow.platform.domain.CmdResult; |
| 24 | +import com.flow.platform.domain.CmdStatus; |
24 | 25 | import com.flow.platform.domain.CmdType; |
25 | 26 | import java.io.IOException; |
26 | 27 | import java.util.Map; |
@@ -213,4 +214,56 @@ public void onException(CmdResult result) { |
213 | 214 | Assert.assertNotNull(result.getExitValue()); |
214 | 215 | Assert.assertEquals(CmdResult.EXIT_VALUE_FOR_KILL, result.getExitValue()); |
215 | 216 | } |
| 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 | + } |
216 | 269 | } |
0 commit comments