Skip to content

Commit 4af4db4

Browse files
committed
1 parent 6b2f48c commit 4af4db4

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/QueueParserIntegrationTests.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -16,19 +16,22 @@
1616

1717
package org.springframework.amqp.rabbit.config;
1818

19+
import static org.hamcrest.Matchers.equalTo;
1920
import static org.junit.Assert.assertEquals;
2021
import static org.junit.Assert.assertNotNull;
22+
import static org.junit.Assert.assertThat;
23+
24+
import java.util.Properties;
2125

2226
import org.junit.Before;
23-
import org.junit.Rule;
27+
import org.junit.ClassRule;
2428
import org.junit.Test;
2529

2630
import org.springframework.amqp.core.Queue;
2731
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
2832
import org.springframework.amqp.rabbit.core.RabbitAdmin;
2933
import org.springframework.amqp.rabbit.core.RabbitTemplate;
3034
import org.springframework.amqp.rabbit.junit.BrokerRunning;
31-
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
3235
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
3336
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
3437
import org.springframework.core.io.ClassPathResource;
@@ -42,8 +45,8 @@
4245
*/
4346
public final class QueueParserIntegrationTests {
4447

45-
@Rule
46-
public BrokerRunning brokerIsRunning = BrokerRunning.isRunning();
48+
@ClassRule
49+
public static BrokerRunning brokerIsRunning = BrokerRunning.isRunning();
4750

4851
private DefaultListableBeanFactory beanFactory;
4952

@@ -59,19 +62,24 @@ public void testArgumentsQueue() throws Exception {
5962

6063
Queue queue = beanFactory.getBean("arguments", Queue.class);
6164
assertNotNull(queue);
62-
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(BrokerTestUtils.getPort());
63-
connectionFactory.setHost("localhost");
65+
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(
66+
brokerIsRunning.getConnectionFactory());
6467
RabbitTemplate template = new RabbitTemplate(connectionFactory);
65-
RabbitAdmin rabbitAdmin = new RabbitAdmin(template.getConnectionFactory());
68+
RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
6669
rabbitAdmin.deleteQueue(queue.getName());
6770
rabbitAdmin.declareQueue(queue);
6871

6972
assertEquals(100L, queue.getArguments().get("x-message-ttl"));
7073
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+
}
7583

7684
connectionFactory.destroy();
7785
brokerIsRunning.deleteQueues("arguments");

0 commit comments

Comments
 (0)