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
@@ -316,7 +319,7 @@ void testConcurrentModifications() throws Exception {
316
319
executor .execute (() -> {
317
320
store2 .removeMessagesFromGroup (this .groupId , message );
318
321
MessageGroup group = store2 .getMessageGroup (this .groupId );
319
- if (group .getMessages ().size () != 0 ) {
322
+ if (! group .getMessages ().isEmpty () ) {
320
323
failures .add ("REMOVE" );
321
324
throw new AssertionFailedError ("Failed on Remove" );
322
325
}
@@ -400,11 +403,17 @@ void testJsonSerialization() {
400
403
Message <?> mutableMessage = new MutableMessage <>(UUID .randomUUID ());
401
404
Message <?> adviceMessage = new AdviceMessage <>("foo" , genericMessage );
402
405
ErrorMessage errorMessage = new ErrorMessage (new RuntimeException ("test exception" ), mutableMessage );
406
+ var delayedMessageWrapperConstructor =
407
+ BeanUtils .getResolvableConstructor (DelayHandler .DelayedMessageWrapper .class );
408
+ Message <?> delayMessage = new GenericMessage <>(
409
+ BeanUtils .instantiateClass (delayedMessageWrapperConstructor , genericMessage ,
410
+ System .currentTimeMillis ()));
403
411
404
- store .addMessagesToGroup (this .groupId , genericMessage , mutableMessage , adviceMessage , errorMessage );
412
+ store .addMessagesToGroup (this .groupId ,
413
+ genericMessage , mutableMessage , adviceMessage , errorMessage , delayMessage );
405
414
406
415
MessageGroup messageGroup = store .getMessageGroup (this .groupId );
407
- assertThat (messageGroup .size ()).isEqualTo (4 );
416
+ assertThat (messageGroup .size ()).isEqualTo (5 );
408
417
List <Message <?>> messages = new ArrayList <>(messageGroup .getMessages ());
409
418
assertThat (messages .get (0 )).isEqualTo (genericMessage );
410
419
assertThat (messages .get (0 ).getHeaders ()).containsKeys (MessageHistory .HEADER_NAME );
@@ -417,22 +426,21 @@ void testJsonSerialization() {
417
426
.isEqualTo (errorMessage .getOriginalMessage ());
418
427
assertThat (((ErrorMessage ) errorMessageResult ).getPayload ().getMessage ())
419
428
.isEqualTo (errorMessage .getPayload ().getMessage ());
429
+ assertThat (messages .get (4 )).isEqualTo (delayMessage );
420
430
421
431
Message <Foo > fooMessage = new GenericMessage <>(new Foo ("foo" ));
422
- try {
423
- store .addMessageToGroup (this .groupId , fooMessage )
424
- .getMessages ()
425
- .iterator ()
426
- .next ();
427
- fail ("SerializationException expected" );
428
- }
429
- catch (Exception e ) {
430
- assertThat (e .getCause ().getCause ()).isInstanceOf (IllegalArgumentException .class );
431
- assertThat (e .getMessage ()).contains ("The class with " +
432
- "org.springframework.integration.redis.store.RedisMessageGroupStoreTests$Foo and name of " +
433
- "org.springframework.integration.redis.store.RedisMessageGroupStoreTests$Foo " +
434
- "is not in the trusted packages:" );
435
- }
432
+
433
+ assertThatExceptionOfType (SerializationException .class )
434
+ .isThrownBy (() ->
435
+ store .addMessageToGroup (this .groupId , fooMessage )
436
+ .getMessages ()
437
+ .iterator ()
438
+ .next ())
439
+ .withRootCauseInstanceOf (IllegalArgumentException .class )
440
+ .withMessageContaining ("The class with " +
441
+ "org.springframework.integration.redis.store.RedisMessageGroupStoreTests$Foo and name of " +
442
+ "org.springframework.integration.redis.store.RedisMessageGroupStoreTests$Foo " +
443
+ "is not in the trusted packages:" );
436
444
437
445
mapper = JacksonJsonUtils .messagingAwareMapper (getClass ().getPackage ().getName ());
438
446
@@ -485,43 +493,7 @@ public void removeMessagesFromGroupDontRemoveSameMessageInOtherGroup() {
485
493
assertThat (store .messageGroupSize ("2" )).isEqualTo (1 );
486
494
}
487
495
488
- private static class Foo {
489
-
490
- private String foo ;
491
-
492
- Foo () {
493
- }
494
-
495
- Foo (String foo ) {
496
- this .foo = foo ;
497
- }
498
-
499
- public String getFoo () {
500
- return this .foo ;
501
- }
502
-
503
- public void setFoo (String foo ) {
504
- this .foo = foo ;
505
- }
506
-
507
- @ Override
508
- public boolean equals (Object o ) {
509
- if (this == o ) {
510
- return true ;
511
- }
512
- if (o == null || getClass () != o .getClass ()) {
513
- return false ;
514
- }
515
-
516
- Foo foo1 = (Foo ) o ;
517
-
518
- return this .foo != null ? this .foo .equals (foo1 .foo ) : foo1 .foo == null ;
519
- }
520
-
521
- @ Override
522
- public int hashCode () {
523
- return Objects .hashCode (this .foo );
524
- }
496
+ private record Foo (String foo ) {
525
497
526
498
}
527
499
0 commit comments