@@ -66,6 +66,8 @@ public class ClusterSeaTunnelContainer extends SeaTunnelContainer {
66
66
private static final Path hadoopJar =
67
67
Paths .get (SEATUNNEL_HOME , "lib/seatunnel-hadoop3-3.1.4-uber.jar" );
68
68
69
+ private static final long CUSTOM_JOB_ID = 123456789 ;
70
+
69
71
@ Override
70
72
@ BeforeEach
71
73
public void startUp () throws Exception {
@@ -101,106 +103,24 @@ public void tearDown() throws Exception {
101
103
}
102
104
103
105
@ Test
104
- public void testSubmitJob () {
106
+ public void testSubmitJobWithCustomJobId () {
105
107
AtomicInteger i = new AtomicInteger ();
106
-
107
108
Arrays .asList (server , secondServer )
108
109
.forEach (
109
- container -> {
110
- Response response =
111
- i .get () == 0
112
- ? submitJob (container , "BATCH" , jobName , paramJobName )
113
- : submitJob (container , "BATCH" , jobName , null );
114
- if (i .get () == 0 ) {
115
- response .then ()
116
- .statusCode (200 )
117
- .body ("jobName" , equalTo (paramJobName ));
118
- } else {
119
- response .then ().statusCode (200 ).body ("jobName" , equalTo (jobName ));
120
- }
121
- String jobId = response .getBody ().jsonPath ().getString ("jobId" );
110
+ container ->
111
+ submitJobAndAssertResponse (
112
+ container ,
113
+ i ,
114
+ paramJobName + "&jobId=" + CUSTOM_JOB_ID ,
115
+ true ));
116
+ }
122
117
123
- Awaitility .await ()
124
- .atMost (2 , TimeUnit .MINUTES )
125
- .untilAsserted (
126
- () -> {
127
- given ().get (
128
- http
129
- + container .getHost ()
130
- + colon
131
- + container
132
- .getFirstMappedPort ()
133
- + RestConstant
134
- .FINISHED_JOBS_INFO
135
- + "/FINISHED" )
136
- .then ()
137
- .statusCode (200 )
138
- .body (
139
- "[" + i .get () + "].jobName" ,
140
- equalTo (
141
- i .get () == 0
142
- ? paramJobName
143
- : jobName ))
144
- .body (
145
- "[" + i .get () + "].errorMsg" ,
146
- equalTo (null ))
147
- .body (
148
- "[" + i .get () + "].jobDag.jobId" ,
149
- equalTo (Long .parseLong (jobId )))
150
- .body (
151
- "["
152
- + i .get ()
153
- + "].metrics.SourceReceivedCount" ,
154
- equalTo ("100" ))
155
- .body (
156
- "["
157
- + i .get ()
158
- + "].metrics.SinkWriteCount" ,
159
- equalTo ("100" ))
160
- .body (
161
- "[" + i .get () + "].jobStatus" ,
162
- equalTo ("FINISHED" ));
163
-
164
- // test for without status parameter.
165
- given ().get (
166
- http
167
- + container .getHost ()
168
- + colon
169
- + container
170
- .getFirstMappedPort ()
171
- + RestConstant
172
- .FINISHED_JOBS_INFO )
173
- .then ()
174
- .statusCode (200 )
175
- .body (
176
- "[" + i .get () + "].jobName" ,
177
- equalTo (
178
- i .get () == 0
179
- ? paramJobName
180
- : jobName ))
181
- .body (
182
- "[" + i .get () + "].errorMsg" ,
183
- equalTo (null ))
184
- .body (
185
- "[" + i .get () + "].jobDag.jobId" ,
186
- equalTo (Long .parseLong (jobId )))
187
- .body (
188
- "["
189
- + i .get ()
190
- + "].metrics.SourceReceivedCount" ,
191
- equalTo ("100" ))
192
- .body (
193
- "["
194
- + i .get ()
195
- + "].metrics.SinkWriteCount" ,
196
- equalTo ("100" ))
197
- .body (
198
- "[" + i .get () + "].jobStatus" ,
199
- equalTo ("FINISHED" ));
200
- });
201
-
202
- i .getAndIncrement ();
203
- });
118
+ @ Test
119
+ public void testSubmitJobWithoutCustomJobId () {
120
+ AtomicInteger i = new AtomicInteger ();
121
+ Arrays .asList (server , secondServer )
122
+ .forEach (
123
+ container -> submitJobAndAssertResponse (container , i , paramJobName , false ));
204
124
}
205
125
206
126
@ Test
@@ -459,4 +379,81 @@ private GenericContainer<?> createServer(String networkAlias)
459
379
460
380
return server ;
461
381
}
382
+
383
+ private void submitJobAndAssertResponse (
384
+ GenericContainer <? extends GenericContainer <?>> container ,
385
+ AtomicInteger i ,
386
+ String customParam ,
387
+ boolean isCustomJobId ) {
388
+ Response response = submitJobAndResponse (container , i , customParam );
389
+ String jobId = response .getBody ().jsonPath ().getString ("jobId" );
390
+ assertResponse (container , i , jobId , isCustomJobId );
391
+ i .getAndIncrement ();
392
+ }
393
+
394
+ private Response submitJobAndResponse (
395
+ GenericContainer <? extends GenericContainer <?>> container ,
396
+ AtomicInteger i ,
397
+ String customParam ) {
398
+ Response response =
399
+ i .get () == 0
400
+ ? submitJob (container , "BATCH" , jobName , customParam )
401
+ : submitJob (container , "BATCH" , jobName , null );
402
+ if (i .get () == 0 ) {
403
+ response .then ().statusCode (200 ).body ("jobName" , equalTo (paramJobName ));
404
+ } else {
405
+ response .then ().statusCode (200 ).body ("jobName" , equalTo (jobName ));
406
+ }
407
+ return response ;
408
+ }
409
+
410
+ private void assertResponse (
411
+ GenericContainer <? extends GenericContainer <?>> container ,
412
+ AtomicInteger i ,
413
+ String jobId ,
414
+ boolean isCustomJobId ) {
415
+ Awaitility .await ()
416
+ .atMost (2 , TimeUnit .MINUTES )
417
+ .untilAsserted (
418
+ () -> {
419
+ assertWithStatusParameterOrNot (
420
+ container , i , jobId , isCustomJobId , true );
421
+
422
+ // test for without status parameter.
423
+ assertWithStatusParameterOrNot (
424
+ container , i , jobId , isCustomJobId , false );
425
+ });
426
+ }
427
+
428
+ private void assertWithStatusParameterOrNot (
429
+ GenericContainer <? extends GenericContainer <?>> container ,
430
+ AtomicInteger i ,
431
+ String jobId ,
432
+ boolean isCustomJobId ,
433
+ boolean isStatusWithSubmitJob ) {
434
+ String baseRestUrl = getBaseRestUrl (container );
435
+ String restUrl = isStatusWithSubmitJob ? baseRestUrl + "/FINISHED" : baseRestUrl ;
436
+ given ().get (restUrl )
437
+ .then ()
438
+ .statusCode (200 )
439
+ .body ("[" + i .get () + "].jobName" , equalTo (i .get () == 0 ? paramJobName : jobName ))
440
+ .body ("[" + i .get () + "].errorMsg" , equalTo (null ))
441
+ .body (
442
+ "[" + i .get () + "].jobId" ,
443
+ equalTo (
444
+ i .get () == 0 && isCustomJobId
445
+ ? Long .toString (CUSTOM_JOB_ID )
446
+ : jobId ))
447
+ .body ("[" + i .get () + "].metrics.SourceReceivedCount" , equalTo ("100" ))
448
+ .body ("[" + i .get () + "].metrics.SinkWriteCount" , equalTo ("100" ))
449
+ .body ("[" + i .get () + "].jobStatus" , equalTo ("FINISHED" ));
450
+ }
451
+
452
+ private String getBaseRestUrl (GenericContainer <? extends GenericContainer <?>> container ) {
453
+ return http
454
+ + container .getHost ()
455
+ + colon
456
+ + container .getFirstMappedPort ()
457
+ + RestConstant .FINISHED_JOBS_INFO ;
458
+ }
462
459
}
0 commit comments