2020import  java .util .Date ;
2121import  java .util .Iterator ;
2222import  java .util .List ;
23- import  java .util .Objects ;
2423import  java .util .Properties ;
2524import  java .util .UUID ;
2625import  java .util .concurrent .ExecutorService ;
3534import  org .junit .jupiter .api .Disabled ;
3635import  org .junit .jupiter .api .Test ;
3736
37+ import  org .springframework .beans .BeanUtils ;
3838import  org .springframework .context .support .ClassPathXmlApplicationContext ;
3939import  org .springframework .data .redis .connection .RedisConnectionFactory ;
4040import  org .springframework .data .redis .core .StringRedisTemplate ;
4141import  org .springframework .data .redis .serializer .GenericJackson2JsonRedisSerializer ;
42+ import  org .springframework .data .redis .serializer .SerializationException ;
4243import  org .springframework .integration .channel .DirectChannel ;
4344import  org .springframework .integration .channel .NullChannel ;
4445import  org .springframework .integration .channel .QueueChannel ;
46+ import  org .springframework .integration .handler .DelayHandler ;
4547import  org .springframework .integration .history .MessageHistory ;
4648import  org .springframework .integration .message .AdviceMessage ;
4749import  org .springframework .integration .redis .RedisContainerTest ;
5658import  org .springframework .messaging .support .GenericMessage ;
5759
5860import  static  org .assertj .core .api .Assertions .assertThat ;
61+ import  static  org .assertj .core .api .Assertions .assertThatExceptionOfType ;
5962import  static  org .assertj .core .api .Assertions .assertThatNoException ;
60- import  static  org .assertj .core .api .Assertions .fail ;
6163
6264/** 
6365 * @author Oleg Zhurakousky 
6466 * @author Artem Bilan 
6567 * @author Gary Russell 
6668 * @author Artem Vozhdayenko 
69+  * @author Youbin Wu 
6770 */ 
6871class  RedisMessageGroupStoreTests  implements  RedisContainerTest  {
6972
@@ -317,7 +320,7 @@ void testConcurrentModifications() throws Exception {
317320			executor .execute (() -> {
318321				store2 .removeMessagesFromGroup (this .groupId , message );
319322				MessageGroup  group  = store2 .getMessageGroup (this .groupId );
320- 				if  (group .getMessages ().size () !=  0 ) {
323+ 				if  (! group .getMessages ().isEmpty () ) {
321324					failures .add ("REMOVE" );
322325					throw  new  AssertionFailedError ("Failed on Remove" );
323326				}
@@ -401,11 +404,17 @@ void testJsonSerialization() {
401404		Message <?> mutableMessage  = new  MutableMessage <>(UUID .randomUUID ());
402405		Message <?> adviceMessage  = new  AdviceMessage <>("foo" , genericMessage );
403406		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 ()));
404412
405- 		store .addMessagesToGroup (this .groupId , genericMessage , mutableMessage , adviceMessage , errorMessage );
413+ 		store .addMessagesToGroup (this .groupId ,
414+ 				genericMessage , mutableMessage , adviceMessage , errorMessage , delayMessage );
406415
407416		MessageGroup  messageGroup  = store .getMessageGroup (this .groupId );
408- 		assertThat (messageGroup .size ()).isEqualTo (4 );
417+ 		assertThat (messageGroup .size ()).isEqualTo (5 );
409418		List <Message <?>> messages  = new  ArrayList <>(messageGroup .getMessages ());
410419		assertThat (messages .get (0 )).isEqualTo (genericMessage );
411420		assertThat (messages .get (0 ).getHeaders ()).containsKeys (MessageHistory .HEADER_NAME );
@@ -418,22 +427,21 @@ void testJsonSerialization() {
418427				.isEqualTo (errorMessage .getOriginalMessage ());
419428		assertThat (((ErrorMessage ) errorMessageResult ).getPayload ().getMessage ())
420429				.isEqualTo (errorMessage .getPayload ().getMessage ());
430+ 		assertThat (messages .get (4 )).isEqualTo (delayMessage );
421431
422432		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:" );
437445
438446		mapper  = JacksonJsonUtils .messagingAwareMapper (getClass ().getPackage ().getName ());
439447
@@ -486,43 +494,7 @@ public void removeMessagesFromGroupDontRemoveSameMessageInOtherGroup() {
486494		assertThat (store .messageGroupSize ("2" )).isEqualTo (1 );
487495	}
488496
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 ) {
526498
527499	}
528500
0 commit comments