1
1
package com .vip .saturn .it .impl ;
2
2
3
- import ch .qos .logback .classic .Level ;
4
- import ch .qos .logback .classic .spi .ILoggingEvent ;
5
3
import com .vip .saturn .it .base .AbstractSaturnIT ;
6
- import com .vip .saturn .it .utils . LogbackListAppender ;
4
+ import com .vip .saturn .it .job . InitByGroupsJob ;
7
5
import com .vip .saturn .job .console .domain .JobConfig ;
8
6
import com .vip .saturn .job .console .domain .JobType ;
9
- import com .vip .saturn .job .executor .InitNewJobService ;
10
7
import com .vip .saturn .job .utils .SystemEnvProperties ;
11
8
import org .junit .*;
12
9
import org .junit .runners .MethodSorters ;
@@ -37,62 +34,50 @@ public void testA_ExecutorNotConfigGroups() throws Exception {
37
34
System .clearProperty (SystemEnvProperties .NAME_VIP_SATURN_INIT_JOB_BY_GROUPS );
38
35
SystemEnvProperties .loadProperties ();
39
36
40
- LogbackListAppender logbackListAppender = new LogbackListAppender ();
41
- logbackListAppender .addToLogger (InitNewJobService .class );
42
- logbackListAppender .start ();
37
+ InitByGroupsJob .inited = false ;
38
+
39
+ startOneNewExecutorList ();
40
+ Thread .sleep (1000 );
41
+ JobConfig jobConfig = new JobConfig ();
42
+ jobConfig .setJobName ("testA_ExecutorNotConfigGroups" );
43
+ jobConfig .setCron ("*/2 * * * * ?" );
44
+ jobConfig .setJobType (JobType .JAVA_JOB .toString ());
45
+ jobConfig .setJobClass (InitByGroupsJob .class .getCanonicalName ());
46
+ jobConfig .setShardingTotalCount (1 );
47
+ jobConfig .setShardingItemParameters ("0=0" );
48
+ jobConfig .setGroups ("" );
49
+ addJob (jobConfig );
50
+ Thread .sleep (1000 );
51
+
52
+ assertThat (InitByGroupsJob .inited ).isTrue ();
53
+
54
+ removeJob (jobConfig .getJobName ());
55
+ }
56
+
57
+ @ Test
58
+ public void testB_ExecutorConfigGroupsAndInitJobSuccessfully () throws Exception {
43
59
try {
60
+ System .setProperty (SystemEnvProperties .NAME_VIP_SATURN_INIT_JOB_BY_GROUPS , "group1, group2" );
61
+ SystemEnvProperties .loadProperties ();
62
+
63
+ InitByGroupsJob .inited = false ;
64
+
44
65
startOneNewExecutorList ();
45
66
Thread .sleep (1000 );
46
67
JobConfig jobConfig = new JobConfig ();
47
- jobConfig .setJobName ("testA_ExecutorNotConfigGroups " );
68
+ jobConfig .setJobName ("testB_ExecutorConfigGroupsAndInitJobSuccessfully " );
48
69
jobConfig .setCron ("*/2 * * * * ?" );
49
- jobConfig .setJobType (JobType .SHELL_JOB .toString ());
70
+ jobConfig .setJobType (JobType .JAVA_JOB .toString ());
71
+ jobConfig .setJobClass (InitByGroupsJob .class .getCanonicalName ());
50
72
jobConfig .setShardingTotalCount (1 );
51
73
jobConfig .setShardingItemParameters ("0=0" );
52
- jobConfig .setGroups ("" );
74
+ jobConfig .setGroups ("group2 " );
53
75
addJob (jobConfig );
54
76
Thread .sleep (1000 );
55
77
56
- assertThat (logbackListAppender .getLastMessage ()).isEqualTo (
57
- "[testA_ExecutorNotConfigGroups] msg=the job testA_ExecutorNotConfigGroups initialize successfully" );
78
+ assertThat (InitByGroupsJob .inited ).isTrue ();
58
79
59
80
removeJob (jobConfig .getJobName ());
60
- } finally {
61
- logbackListAppender .clearLogs ();
62
- logbackListAppender .stop ();
63
- }
64
- }
65
-
66
- @ Test
67
- public void testB_ExecutorConfigGroupsAndInitJobSuccessfully () throws Exception {
68
- try {
69
- System .setProperty (SystemEnvProperties .NAME_VIP_SATURN_INIT_JOB_BY_GROUPS , "group1, group2" );
70
- SystemEnvProperties .loadProperties ();
71
-
72
- LogbackListAppender logbackListAppender = new LogbackListAppender ();
73
- logbackListAppender .addToLogger (InitNewJobService .class );
74
- logbackListAppender .start ();
75
- try {
76
- startOneNewExecutorList ();
77
- Thread .sleep (1000 );
78
- JobConfig jobConfig = new JobConfig ();
79
- jobConfig .setJobName ("testB_ExecutorConfigGroupsAndInitJobSuccessfully" );
80
- jobConfig .setCron ("*/2 * * * * ?" );
81
- jobConfig .setJobType (JobType .SHELL_JOB .toString ());
82
- jobConfig .setShardingTotalCount (1 );
83
- jobConfig .setShardingItemParameters ("0=0" );
84
- jobConfig .setGroups ("group2" );
85
- addJob (jobConfig );
86
- Thread .sleep (1000 );
87
-
88
- assertThat (logbackListAppender .getLastMessage ()).isEqualTo (
89
- "[testB_ExecutorConfigGroupsAndInitJobSuccessfully] msg=the job testB_ExecutorConfigGroupsAndInitJobSuccessfully initialize successfully" );
90
-
91
- removeJob (jobConfig .getJobName ());
92
- } finally {
93
- logbackListAppender .clearLogs ();
94
- logbackListAppender .stop ();
95
- }
96
81
} finally {
97
82
System .clearProperty (SystemEnvProperties .NAME_VIP_SATURN_INIT_JOB_BY_GROUPS );
98
83
SystemEnvProperties .loadProperties ();
@@ -105,34 +90,24 @@ public void testC_ExecutorConfigGroupsAndInitJobFailed() throws Exception {
105
90
System .setProperty (SystemEnvProperties .NAME_VIP_SATURN_INIT_JOB_BY_GROUPS , "group1, group2" );
106
91
SystemEnvProperties .loadProperties ();
107
92
108
- LogbackListAppender logbackListAppender = new LogbackListAppender ();
109
- logbackListAppender .addToLogger (InitNewJobService .class );
110
- logbackListAppender .start ();
111
- try {
112
- startOneNewExecutorList ();
113
- Thread .sleep (1000 );
114
- JobConfig jobConfig = new JobConfig ();
115
- jobConfig .setJobName ("testC_ExecutorConfigGroupsAndInitJobFailed" );
116
- jobConfig .setCron ("*/2 * * * * ?" );
117
- jobConfig .setJobType (JobType .SHELL_JOB .toString ());
118
- jobConfig .setShardingTotalCount (1 );
119
- jobConfig .setShardingItemParameters ("0=0" );
120
- jobConfig .setGroups ("" );
121
- addJob (jobConfig );
122
- Thread .sleep (1000 );
123
-
124
- ILoggingEvent lastLog = logbackListAppender .getLastLog ();
125
- assertThat (lastLog .getLevel ()).isEqualTo (Level .INFO );
126
- // VIP_SATURN_INIT_JOB_BY_GROUPS is Set, not ArrayList
127
- assertThat (lastLog .getFormattedMessage ())
128
- .isIn ("[testC_ExecutorConfigGroupsAndInitJobFailed] msg=the job testC_ExecutorConfigGroupsAndInitJobFailed wont be initialized, because it's not in the groups [group1, group2]" ,
129
- "[testC_ExecutorConfigGroupsAndInitJobFailed] msg=the job testC_ExecutorConfigGroupsAndInitJobFailed wont be initialized, because it's not in the groups [group2, group1]" );
130
-
131
- removeJob (jobConfig .getJobName ());
132
- } finally {
133
- logbackListAppender .clearLogs ();
134
- logbackListAppender .stop ();
135
- }
93
+ InitByGroupsJob .inited = false ;
94
+
95
+ startOneNewExecutorList ();
96
+ Thread .sleep (1000 );
97
+ JobConfig jobConfig = new JobConfig ();
98
+ jobConfig .setJobName ("testC_ExecutorConfigGroupsAndInitJobFailed" );
99
+ jobConfig .setCron ("*/2 * * * * ?" );
100
+ jobConfig .setJobType (JobType .JAVA_JOB .toString ());
101
+ jobConfig .setJobClass (InitByGroupsJob .class .getCanonicalName ());
102
+ jobConfig .setShardingTotalCount (1 );
103
+ jobConfig .setShardingItemParameters ("0=0" );
104
+ jobConfig .setGroups ("" );
105
+ addJob (jobConfig );
106
+ Thread .sleep (1000 );
107
+
108
+ assertThat (InitByGroupsJob .inited ).isFalse ();
109
+
110
+ removeJob (jobConfig .getJobName ());
136
111
} finally {
137
112
System .clearProperty (SystemEnvProperties .NAME_VIP_SATURN_INIT_JOB_BY_GROUPS );
138
113
SystemEnvProperties .loadProperties ();
0 commit comments