app
潘志宝
2024-08-19 2563526c3fda3ae9b45aad02ed10427508a29af3
提交 | 用户 | 时间
e7c126 1 package com.xxl.job.executorbiz;
H 2
3 import com.xxl.job.core.biz.ExecutorBiz;
4 import com.xxl.job.core.biz.client.ExecutorBizClient;
5 import com.xxl.job.core.biz.model.*;
6 import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
7 import com.xxl.job.core.glue.GlueTypeEnum;
8 import org.junit.jupiter.api.Assertions;
9 import org.junit.jupiter.api.Test;
10
11 /**
12  * executor api test
13  *
14  * Created by xuxueli on 17/5/12.
15  */
16 public class ExecutorBizTest {
17
18     // admin-client
19     private static String addressUrl = "http://127.0.0.1:9999/";
20     private static String accessToken = null;
21
22     @Test
23     public void beat() throws Exception {
24         ExecutorBiz executorBiz = new ExecutorBizClient(addressUrl, accessToken);
25         // Act
26         final ReturnT<String> retval = executorBiz.beat();
27
28         // Assert result
29         Assertions.assertNotNull(retval);
30         Assertions.assertNull(((ReturnT<String>) retval).getContent());
31         Assertions.assertEquals(200, retval.getCode());
32         Assertions.assertNull(retval.getMsg());
33     }
34
35     @Test
36     public void idleBeat(){
37         ExecutorBiz executorBiz = new ExecutorBizClient(addressUrl, accessToken);
38
39         final int jobId = 0;
40
41         // Act
42         final ReturnT<String> retval = executorBiz.idleBeat(new IdleBeatParam(jobId));
43
44         // Assert result
45         Assertions.assertNotNull(retval);
46         Assertions.assertNull(((ReturnT<String>) retval).getContent());
47         Assertions.assertEquals(500, retval.getCode());
48         Assertions.assertEquals("job thread is running or has trigger queue.", retval.getMsg());
49     }
50
51     @Test
52     public void run(){
53         ExecutorBiz executorBiz = new ExecutorBizClient(addressUrl, accessToken);
54
55         // trigger data
56         final TriggerParam triggerParam = new TriggerParam();
57         triggerParam.setJobId(1);
58         triggerParam.setExecutorHandler("demoJobHandler");
59         triggerParam.setExecutorParams(null);
60         triggerParam.setExecutorBlockStrategy(ExecutorBlockStrategyEnum.COVER_EARLY.name());
61         triggerParam.setGlueType(GlueTypeEnum.BEAN.name());
62         triggerParam.setGlueSource(null);
63         triggerParam.setGlueUpdatetime(System.currentTimeMillis());
64         triggerParam.setLogId(1);
65         triggerParam.setLogDateTime(System.currentTimeMillis());
66
67         // Act
68         final ReturnT<String> retval = executorBiz.run(triggerParam);
69
70         // Assert result
71         Assertions.assertNotNull(retval);
72     }
73
74     @Test
75     public void kill(){
76         ExecutorBiz executorBiz = new ExecutorBizClient(addressUrl, accessToken);
77
78         final int jobId = 0;
79
80         // Act
81         final ReturnT<String> retval = executorBiz.kill(new KillParam(jobId));
82
83         // Assert result
84         Assertions.assertNotNull(retval);
85         Assertions.assertNull(((ReturnT<String>) retval).getContent());
86         Assertions.assertEquals(200, retval.getCode());
87         Assertions.assertNull(retval.getMsg());
88     }
89
90     @Test
91     public void log(){
92         ExecutorBiz executorBiz = new ExecutorBizClient(addressUrl, accessToken);
93
94         final long logDateTim = 0L;
95         final long logId = 0;
96         final int fromLineNum = 0;
97
98         // Act
99         final ReturnT<LogResult> retval = executorBiz.log(new LogParam(logDateTim, logId, fromLineNum));
100
101         // Assert result
102         Assertions.assertNotNull(retval);
103     }
104
105 }