16
16
*/
17
17
package org .apache .seatunnel .e2e .connector .redis ;
18
18
19
+ import org .apache .seatunnel .shade .com .fasterxml .jackson .databind .node .ObjectNode ;
20
+
19
21
import org .apache .seatunnel .api .table .type .ArrayType ;
20
22
import org .apache .seatunnel .api .table .type .BasicType ;
21
23
import org .apache .seatunnel .api .table .type .DecimalType ;
25
27
import org .apache .seatunnel .api .table .type .SeaTunnelDataType ;
26
28
import org .apache .seatunnel .api .table .type .SeaTunnelRow ;
27
29
import org .apache .seatunnel .api .table .type .SeaTunnelRowType ;
30
+ import org .apache .seatunnel .common .utils .JsonUtils ;
28
31
import org .apache .seatunnel .e2e .common .TestResource ;
29
32
import org .apache .seatunnel .e2e .common .TestSuiteBase ;
33
+ import org .apache .seatunnel .e2e .common .container .EngineType ;
30
34
import org .apache .seatunnel .e2e .common .container .TestContainer ;
35
+ import org .apache .seatunnel .e2e .common .junit .DisabledOnContainer ;
31
36
import org .apache .seatunnel .format .json .JsonSerializationSchema ;
32
37
33
38
import org .junit .jupiter .api .AfterAll ;
34
39
import org .junit .jupiter .api .Assertions ;
35
40
import org .junit .jupiter .api .BeforeAll ;
36
41
import org .junit .jupiter .api .TestTemplate ;
42
+ import org .junit .jupiter .api .condition .DisabledOnOs ;
43
+ import org .junit .jupiter .api .condition .OS ;
37
44
import org .testcontainers .containers .Container ;
38
45
import org .testcontainers .containers .GenericContainer ;
39
46
import org .testcontainers .containers .output .Slf4jLogConsumer ;
52
59
import java .time .LocalDate ;
53
60
import java .time .LocalDateTime ;
54
61
import java .util .ArrayList ;
62
+ import java .util .Arrays ;
55
63
import java .util .Collections ;
56
64
import java .util .HashMap ;
57
65
import java .util .List ;
58
66
import java .util .Map ;
59
67
import java .util .Objects ;
68
+ import java .util .concurrent .CompletableFuture ;
69
+ import java .util .concurrent .TimeUnit ;
70
+ import java .util .regex .Matcher ;
71
+ import java .util .regex .Pattern ;
72
+ import java .util .stream .Collectors ;
60
73
import java .util .stream .Stream ;
61
74
75
+ import static org .awaitility .Awaitility .await ;
76
+
62
77
@ Slf4j
63
78
public abstract class RedisTestCaseTemplateIT extends TestSuiteBase implements TestResource {
64
79
@@ -492,7 +507,7 @@ public void testFakeToRedisDeleteSetTest(TestContainer container)
492
507
}
493
508
494
509
@ TestTemplate
495
- public void testMysqlCdcToRedisDeleteZSetTest (TestContainer container )
510
+ public void testFakeToToRedisDeleteZSetTest (TestContainer container )
496
511
throws IOException , InterruptedException {
497
512
Container .ExecResult execResult =
498
513
container .executeJob ("/fake-to-redis-test-delete-zset.conf" );
@@ -501,6 +516,69 @@ public void testMysqlCdcToRedisDeleteZSetTest(TestContainer container)
501
516
jedis .del ("zset_check" );
502
517
}
503
518
519
+ @ TestTemplate
520
+ @ DisabledOnContainer (
521
+ value = {},
522
+ type = {EngineType .SPARK , EngineType .FLINK },
523
+ disabledReason = "Only support for seatunnel" )
524
+ @ DisabledOnOs (OS .WINDOWS )
525
+ public void testFakeToRedisInRealTimeTest (TestContainer container )
526
+ throws IOException , InterruptedException {
527
+ CompletableFuture .supplyAsync (
528
+ () -> {
529
+ try {
530
+ container .executeJob ("/fake-to-redis-test-in-real-time.conf" );
531
+ } catch (Exception e ) {
532
+ log .error ("Commit task exception :" + e .getMessage ());
533
+ throw new RuntimeException (e );
534
+ }
535
+ return null ;
536
+ });
537
+ await ().atMost (60000 , TimeUnit .MILLISECONDS )
538
+ .untilAsserted (
539
+ () -> {
540
+ Assertions .assertEquals (3 , jedis .llen ("list_check" ));
541
+ });
542
+ jedis .del ("list_check" );
543
+ // Get the task id
544
+ Container .ExecResult execResult = container .executeBaseCommand (new String [] {"-l" });
545
+ String regex = "(\\ d+)\\ s+" ;
546
+ Pattern pattern = Pattern .compile (regex );
547
+ List <String > runningJobId =
548
+ Arrays .stream (execResult .getStdout ().toString ().split ("\n " ))
549
+ .filter (s -> s .contains ("fake-to-redis-test-in-real-time" ))
550
+ .map (
551
+ s -> {
552
+ Matcher matcher = pattern .matcher (s );
553
+ return matcher .find () ? matcher .group (1 ) : null ;
554
+ })
555
+ .filter (jobId -> jobId != null )
556
+ .collect (Collectors .toList ());
557
+ Assertions .assertEquals (1 , runningJobId .size ());
558
+ // Verify that the status is Running
559
+ for (String jobId : runningJobId ) {
560
+ Container .ExecResult execResult1 =
561
+ container .executeBaseCommand (new String [] {"-j" , jobId });
562
+ String stdout = execResult1 .getStdout ();
563
+ ObjectNode jsonNodes = JsonUtils .parseObject (stdout );
564
+ Assertions .assertEquals (jsonNodes .get ("jobStatus" ).asText (), "RUNNING" );
565
+ }
566
+ // Execute cancellation task
567
+ String [] batchCancelCommand =
568
+ Stream .concat (Arrays .stream (new String [] {"-can" }), runningJobId .stream ())
569
+ .toArray (String []::new );
570
+ Assertions .assertEquals (0 , container .executeBaseCommand (batchCancelCommand ).getExitCode ());
571
+
572
+ // Verify whether the cancellation is successful
573
+ for (String jobId : runningJobId ) {
574
+ Container .ExecResult execResult1 =
575
+ container .executeBaseCommand (new String [] {"-j" , jobId });
576
+ String stdout = execResult1 .getStdout ();
577
+ ObjectNode jsonNodes = JsonUtils .parseObject (stdout );
578
+ Assertions .assertEquals (jsonNodes .get ("jobStatus" ).asText (), "CANCELED" );
579
+ }
580
+ }
581
+
504
582
@ TestTemplate
505
583
public void testFakeToRedisNormalKeyIsNullTest (TestContainer container )
506
584
throws IOException , InterruptedException {
0 commit comments