20
20
import java .util .Date ;
21
21
import java .util .Iterator ;
22
22
import java .util .List ;
23
- import java .util .Objects ;
24
23
import java .util .Properties ;
25
24
import java .util .UUID ;
26
25
import java .util .concurrent .ExecutorService ;
35
34
import org .junit .jupiter .api .Disabled ;
36
35
import org .junit .jupiter .api .Test ;
37
36
37
+ import org .springframework .beans .BeanUtils ;
38
38
import org .springframework .context .support .ClassPathXmlApplicationContext ;
39
39
import org .springframework .data .redis .connection .RedisConnectionFactory ;
40
40
import org .springframework .data .redis .core .StringRedisTemplate ;
41
41
import org .springframework .data .redis .serializer .GenericJackson2JsonRedisSerializer ;
42
+ import org .springframework .data .redis .serializer .SerializationException ;
42
43
import org .springframework .integration .channel .DirectChannel ;
43
44
import org .springframework .integration .channel .NullChannel ;
44
45
import org .springframework .integration .channel .QueueChannel ;
46
+ import org .springframework .integration .handler .DelayHandler ;
45
47
import org .springframework .integration .history .MessageHistory ;
46
48
import org .springframework .integration .message .AdviceMessage ;
47
49
import org .springframework .integration .redis .RedisContainerTest ;
56
58
import org .springframework .messaging .support .GenericMessage ;
57
59
58
60
import static org .assertj .core .api .Assertions .assertThat ;
61
+ import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
59
62
import static org .assertj .core .api .Assertions .assertThatNoException ;
60
- import static org .assertj .core .api .Assertions .fail ;
61
63
62
64
/**
63
65
* @author Oleg Zhurakousky
64
66
* @author Artem Bilan
65
67
* @author Gary Russell
66
68
* @author Artem Vozhdayenko
69
+ * @author Youbin Wu
67
70
*/
68
71
class RedisMessageGroupStoreTests implements RedisContainerTest {
69
72
@@ -317,7 +320,7 @@ void testConcurrentModifications() throws Exception {
317
320
executor .execute (() -> {
318
321
store2 .removeMessagesFromGroup (this .groupId , message );
319
322
MessageGroup group = store2 .getMessageGroup (this .groupId );
320
- if (group .getMessages ().size () != 0 ) {
323
+ if (! group .getMessages ().isEmpty () ) {
321
324
failures .add ("REMOVE" );
322
325
throw new AssertionFailedError ("Failed on Remove" );
323
326
}
@@ -401,11 +404,17 @@ void testJsonSerialization() {
401
404
Message <?> mutableMessage = new MutableMessage <>(UUID .randomUUID ());
402
405
Message <?> adviceMessage = new AdviceMessage <>("foo" , genericMessage );
403
406
ErrorMessage errorMessage = new ErrorMessage (new RuntimeException ("test exception" ), mutableMessage );
407
+ var delayedMessageWrapperConstructor =
408
+ BeanUtils .getResolvableConstructor (DelayHandler .DelayedMessageWrapper .class );
409
+ Message <?> delayMessage = new GenericMessage <>(
410
+ BeanUtils .instantiateClass (delayedMessageWrapperConstructor , genericMessage ,
411
+ System .currentTimeMillis ()));
404
412
405
- store .addMessagesToGroup (this .groupId , genericMessage , mutableMessage , adviceMessage , errorMessage );
413
+ store .addMessagesToGroup (this .groupId ,
414
+ genericMessage , mutableMessage , adviceMessage , errorMessage , delayMessage );
406
415
407
416
MessageGroup messageGroup = store .getMessageGroup (this .groupId );
408
- assertThat (messageGroup .size ()).isEqualTo (4 );
417
+ assertThat (messageGroup .size ()).isEqualTo (5 );
409
418
List <Message <?>> messages = new ArrayList <>(messageGroup .getMessages ());
410
419
assertThat (messages .get (0 )).isEqualTo (genericMessage );
411
420
assertThat (messages .get (0 ).getHeaders ()).containsKeys (MessageHistory .HEADER_NAME );
@@ -418,22 +427,21 @@ void testJsonSerialization() {
418
427
.isEqualTo (errorMessage .getOriginalMessage ());
419
428
assertThat (((ErrorMessage ) errorMessageResult ).getPayload ().getMessage ())
420
429
.isEqualTo (errorMessage .getPayload ().getMessage ());
430
+ assertThat (messages .get (4 )).isEqualTo (delayMessage );
421
431
422
432
Message <Foo > fooMessage = new GenericMessage <>(new Foo ("foo" ));
423
- try {
424
- store .addMessageToGroup (this .groupId , fooMessage )
425
- .getMessages ()
426
- .iterator ()
427
- .next ();
428
- fail ("SerializationException expected" );
429
- }
430
- catch (Exception e ) {
431
- assertThat (e .getCause ().getCause ()).isInstanceOf (IllegalArgumentException .class );
432
- assertThat (e .getMessage ()).contains ("The class with " +
433
- "org.springframework.integration.redis.store.RedisMessageGroupStoreTests$Foo and name of " +
434
- "org.springframework.integration.redis.store.RedisMessageGroupStoreTests$Foo " +
435
- "is not in the trusted packages:" );
436
- }
433
+
434
+ assertThatExceptionOfType (SerializationException .class )
435
+ .isThrownBy (() ->
436
+ store .addMessageToGroup (this .groupId , fooMessage )
437
+ .getMessages ()
438
+ .iterator ()
439
+ .next ())
440
+ .withRootCauseInstanceOf (IllegalArgumentException .class )
441
+ .withMessageContaining ("The class with " +
442
+ "org.springframework.integration.redis.store.RedisMessageGroupStoreTests$Foo and name of " +
443
+ "org.springframework.integration.redis.store.RedisMessageGroupStoreTests$Foo " +
444
+ "is not in the trusted packages:" );
437
445
438
446
mapper = JacksonJsonUtils .messagingAwareMapper (getClass ().getPackage ().getName ());
439
447
@@ -486,43 +494,7 @@ public void removeMessagesFromGroupDontRemoveSameMessageInOtherGroup() {
486
494
assertThat (store .messageGroupSize ("2" )).isEqualTo (1 );
487
495
}
488
496
489
- private static class Foo {
490
-
491
- private String foo ;
492
-
493
- Foo () {
494
- }
495
-
496
- Foo (String foo ) {
497
- this .foo = foo ;
498
- }
499
-
500
- public String getFoo () {
501
- return this .foo ;
502
- }
503
-
504
- public void setFoo (String foo ) {
505
- this .foo = foo ;
506
- }
507
-
508
- @ Override
509
- public boolean equals (Object o ) {
510
- if (this == o ) {
511
- return true ;
512
- }
513
- if (o == null || getClass () != o .getClass ()) {
514
- return false ;
515
- }
516
-
517
- Foo foo1 = (Foo ) o ;
518
-
519
- return this .foo != null ? this .foo .equals (foo1 .foo ) : foo1 .foo == null ;
520
- }
521
-
522
- @ Override
523
- public int hashCode () {
524
- return Objects .hashCode (this .foo );
525
- }
497
+ private record Foo (String foo ) {
526
498
527
499
}
528
500
0 commit comments