1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .amqp .rabbit .config ;
18
18
19
+ import static org .hamcrest .Matchers .equalTo ;
19
20
import static org .junit .Assert .assertEquals ;
20
21
import static org .junit .Assert .assertNotNull ;
22
+ import static org .junit .Assert .assertThat ;
23
+
24
+ import java .util .Properties ;
21
25
22
26
import org .junit .Before ;
23
- import org .junit .Rule ;
27
+ import org .junit .ClassRule ;
24
28
import org .junit .Test ;
25
29
26
30
import org .springframework .amqp .core .Queue ;
27
31
import org .springframework .amqp .rabbit .connection .CachingConnectionFactory ;
28
32
import org .springframework .amqp .rabbit .core .RabbitAdmin ;
29
33
import org .springframework .amqp .rabbit .core .RabbitTemplate ;
30
34
import org .springframework .amqp .rabbit .junit .BrokerRunning ;
31
- import org .springframework .amqp .rabbit .junit .BrokerTestUtils ;
32
35
import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
33
36
import org .springframework .beans .factory .xml .XmlBeanDefinitionReader ;
34
37
import org .springframework .core .io .ClassPathResource ;
42
45
*/
43
46
public final class QueueParserIntegrationTests {
44
47
45
- @ Rule
46
- public BrokerRunning brokerIsRunning = BrokerRunning .isRunning ();
48
+ @ ClassRule
49
+ public static BrokerRunning brokerIsRunning = BrokerRunning .isRunning ();
47
50
48
51
private DefaultListableBeanFactory beanFactory ;
49
52
@@ -59,19 +62,24 @@ public void testArgumentsQueue() throws Exception {
59
62
60
63
Queue queue = beanFactory .getBean ("arguments" , Queue .class );
61
64
assertNotNull (queue );
62
- CachingConnectionFactory connectionFactory = new CachingConnectionFactory (BrokerTestUtils . getPort ());
63
- connectionFactory . setHost ( "localhost" );
65
+ CachingConnectionFactory connectionFactory = new CachingConnectionFactory (
66
+ brokerIsRunning . getConnectionFactory () );
64
67
RabbitTemplate template = new RabbitTemplate (connectionFactory );
65
- RabbitAdmin rabbitAdmin = new RabbitAdmin (template . getConnectionFactory () );
68
+ RabbitAdmin rabbitAdmin = new RabbitAdmin (connectionFactory );
66
69
rabbitAdmin .deleteQueue (queue .getName ());
67
70
rabbitAdmin .declareQueue (queue );
68
71
69
72
assertEquals (100L , queue .getArguments ().get ("x-message-ttl" ));
70
73
template .convertAndSend (queue .getName (), "message" );
71
-
72
- Thread .sleep (200 );
73
- String result = (String ) template .receiveAndConvert (queue .getName ());
74
- assertEquals (null , result );
74
+ Properties props = rabbitAdmin .getQueueProperties ("arguments" );
75
+ if (props != null ) {
76
+ int n = 0 ;
77
+ while (n ++ < 200 && (Integer ) props .get (RabbitAdmin .QUEUE_MESSAGE_COUNT ) > 0 ) {
78
+ Thread .sleep (50 );
79
+ props = rabbitAdmin .getQueueProperties ("arguments" );
80
+ }
81
+ assertThat ((Integer ) props .get (RabbitAdmin .QUEUE_MESSAGE_COUNT ), equalTo (0 ));
82
+ }
75
83
76
84
connectionFactory .destroy ();
77
85
brokerIsRunning .deleteQueues ("arguments" );
0 commit comments