11/*
2- * Copyright 2013-2017 the original author or authors.
2+ * Copyright 2013-2019 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
4747import org .springframework .beans .factory .InitializingBean ;
4848import org .springframework .beans .factory .annotation .Autowired ;
4949import org .springframework .context .ApplicationEvent ;
50+ import org .springframework .context .Lifecycle ;
5051import org .springframework .data .redis .RedisConnectionFailureException ;
5152import org .springframework .data .redis .RedisSystemException ;
5253import org .springframework .data .redis .connection .RedisConnectionFactory ;
@@ -89,9 +90,15 @@ public class RedisQueueMessageDrivenEndpointTests extends RedisAvailableTests {
8990 @ Autowired
9091 private PollableChannel fromChannel ;
9192
93+ @ Autowired
94+ private Lifecycle fromChannelEndpoint ;
95+
9296 @ Autowired
9397 private MessageChannel symmetricalInputChannel ;
9498
99+ @ Autowired
100+ private Lifecycle symmetricalRedisChannelEndpoint ;
101+
95102 @ Autowired
96103 private PollableChannel symmetricalOutputChannel ;
97104
@@ -107,6 +114,7 @@ public void testInt3014Default() throws Exception {
107114 redisTemplate .setKeySerializer (new StringRedisSerializer ());
108115 redisTemplate .setValueSerializer (new JdkSerializationRedisSerializer ());
109116 redisTemplate .afterPropertiesSet ();
117+ redisTemplate .delete (queueName );
110118
111119 String payload = "testing" ;
112120
@@ -136,6 +144,7 @@ public void testInt3014Default() throws Exception {
136144 assertEquals (payload2 , receive .getPayload ());
137145
138146 endpoint .stop ();
147+ redisTemplate .delete (queueName );
139148 }
140149
141150 @ Test
@@ -150,6 +159,7 @@ public void testInt3014ExpectMessageTrue() throws Exception {
150159 redisTemplate .setKeySerializer (new StringRedisSerializer ());
151160 redisTemplate .setValueSerializer (new JdkSerializationRedisSerializer ());
152161 redisTemplate .afterPropertiesSet ();
162+ redisTemplate .delete (queueName );
153163
154164 Message <?> message = MessageBuilder .withPayload ("testing" ).build ();
155165
@@ -188,38 +198,53 @@ public void testInt3014ExpectMessageTrue() throws Exception {
188198 Matchers .containsString ("java.lang.String cannot be cast to org.springframework.messaging.Message" ));
189199
190200 endpoint .stop ();
201+ redisTemplate .delete (queueName );
191202 }
192203
193204 @ Test
194205 @ RedisAvailable
195206 public void testInt3017IntegrationInbound () throws Exception {
196- String payload = new Date ().toString ();
197-
207+ String queueName = "si.test.redisQueueInboundChannelAdapterTests2" ;
198208 RedisTemplate <String , String > redisTemplate = new StringRedisTemplate ();
199209 redisTemplate .setConnectionFactory (this .connectionFactory );
200210 redisTemplate .afterPropertiesSet ();
211+ redisTemplate .delete (queueName );
212+
213+ this .fromChannelEndpoint .start ();
214+ String payload = new Date ().toString ();
215+
201216
202217 redisTemplate .boundListOps ("si.test.Int3017IntegrationInbound" )
203218 .leftPush ("{\" payload\" :\" " + payload + "\" ,\" headers\" :{}}" );
204219
205220 Message <?> receive = this .fromChannel .receive (10000 );
206221 assertNotNull (receive );
207222 assertEquals (payload , receive .getPayload ());
223+ this .fromChannelEndpoint .stop ();
224+ redisTemplate .delete (queueName );
208225 }
209226
210227 @ Test
211228 @ RedisAvailable
212229 public void testInt3017IntegrationSymmetrical () throws Exception {
230+ String queueName = "si.test.Int3017IntegrationSymmetrical" ;
231+ RedisTemplate <String , String > redisTemplate = new StringRedisTemplate ();
232+ redisTemplate .setConnectionFactory (this .connectionFactory );
233+ redisTemplate .afterPropertiesSet ();
234+ redisTemplate .delete (queueName );
235+ this .symmetricalRedisChannelEndpoint .start ();
213236 UUID payload = UUID .randomUUID ();
214237 Message <UUID > message = MessageBuilder .withPayload (payload )
215- .setHeader ("redis_queue" , "si.test.Int3017IntegrationSymmetrical" )
238+ .setHeader ("redis_queue" , queueName )
216239 .build ();
217240
218241 this .symmetricalInputChannel .send (message );
219242
220243 Message <?> receive = this .symmetricalOutputChannel .receive (10000 );
221244 assertNotNull (receive );
222245 assertEquals (payload , receive .getPayload ());
246+ this .symmetricalRedisChannelEndpoint .stop ();
247+ redisTemplate .delete (queueName );
223248 }
224249
225250 @ Test
@@ -234,6 +259,7 @@ public void testInt3442ProperlyStop() throws Exception {
234259 redisTemplate .setKeySerializer (new StringRedisSerializer ());
235260 redisTemplate .setValueSerializer (new JdkSerializationRedisSerializer ());
236261 redisTemplate .afterPropertiesSet ();
262+ redisTemplate .delete (queueName );
237263
238264 while (redisTemplate .boundListOps (queueName ).rightPop () != null ) {
239265 // drain
@@ -271,6 +297,7 @@ public void testInt3442ProperlyStop() throws Exception {
271297 assertTrue (stopLatch .await (21 , TimeUnit .SECONDS ));
272298
273299 verify (boundListOperations , atLeastOnce ()).rightPush (any (byte [].class ));
300+ redisTemplate .delete (queueName );
274301 }
275302
276303
@@ -285,7 +312,8 @@ public void testInt3196Recovery() throws Exception {
285312
286313 final CountDownLatch exceptionsLatch = new CountDownLatch (2 );
287314
288- RedisQueueMessageDrivenEndpoint endpoint = new RedisQueueMessageDrivenEndpoint (queueName , this .connectionFactory );
315+ RedisQueueMessageDrivenEndpoint endpoint = new RedisQueueMessageDrivenEndpoint (queueName ,
316+ this .connectionFactory );
289317 endpoint .setBeanFactory (Mockito .mock (BeanFactory .class ));
290318 endpoint .setApplicationEventPublisher (event -> {
291319 exceptionEvents .add ((ApplicationEvent ) event );
@@ -328,6 +356,7 @@ public void testInt3196Recovery() throws Exception {
328356 assertEquals (payload , receive .getPayload ());
329357
330358 endpoint .stop ();
359+ redisTemplate .delete (queueName );
331360 }
332361
333362 @ Test
@@ -342,6 +371,7 @@ public void testInt3932ReadFromLeft() throws Exception {
342371 redisTemplate .setKeySerializer (new StringRedisSerializer ());
343372 redisTemplate .setValueSerializer (new JdkSerializationRedisSerializer ());
344373 redisTemplate .afterPropertiesSet ();
374+ redisTemplate .delete (queueName );
345375
346376 String payload = "testing" ;
347377
@@ -372,6 +402,7 @@ public void testInt3932ReadFromLeft() throws Exception {
372402 assertEquals (payload2 , receive .getPayload ());
373403
374404 endpoint .stop ();
405+ redisTemplate .delete (queueName );
375406 }
376407
377408 private void waitListening (RedisQueueMessageDrivenEndpoint endpoint ) throws InterruptedException {
0 commit comments