Skip to content

Commit 082c2f9

Browse files
committed
Change queue names between test methods
To avoid collisions on slow environments like CI. (cherry picked from commit abb67a7)
1 parent 3242f7a commit 082c2f9

File tree

1 file changed

+41
-27
lines changed

1 file changed

+41
-27
lines changed

src/test/java/com/rabbitmq/client/test/functional/CcRoutes.java

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@
2222
import static org.junit.Assert.fail;
2323

2424
import java.io.IOException;
25-
import java.util.ArrayList;
26-
import java.util.Arrays;
27-
import java.util.HashMap;
28-
import java.util.List;
29-
import java.util.Map;
25+
import java.util.*;
3026
import java.util.concurrent.TimeoutException;
27+
import java.util.stream.Collectors;
28+
import java.util.stream.IntStream;
3129

3230
import org.junit.Test;
3331

@@ -38,7 +36,7 @@
3836

3937
public class CcRoutes extends BrokerTestCase {
4038

41-
static private final String[] queues = new String[]{"queue1", "queue2", "queue3"};
39+
private String[] queues;
4240
private final String exDirect = "direct_cc_exchange";
4341
private final String exTopic = "topic_cc_exchange";
4442
private BasicProperties.Builder propsBuilder;
@@ -56,6 +54,10 @@ public class CcRoutes extends BrokerTestCase {
5654

5755
@Override protected void createResources() throws IOException, TimeoutException {
5856
super.createResources();
57+
queues = IntStream.range(1, 4)
58+
.mapToObj(index -> CcRoutes.class.getSimpleName() + "." + UUID.randomUUID().toString())
59+
.collect(Collectors.toList())
60+
.toArray(new String[]{});
5961
for (String q : queues) {
6062
channel.queueDeclare(q, false, false, true, null);
6163
}
@@ -72,58 +74,58 @@ protected void releaseResources() throws IOException {
7274
}
7375

7476
@Test public void ccList() throws IOException {
75-
ccList.add("queue2");
76-
ccList.add("queue3");
77-
headerPublish("", "queue1", ccList, null);
78-
expect(new String []{"queue1", "queue2", "queue3"}, true);
77+
ccList.add(queue2());
78+
ccList.add(queue3());
79+
headerPublish("", queue1(), ccList, null);
80+
expect(new String []{queue1(), queue2(), queue3()}, true);
7981
}
8082

8183
@Test public void ccIgnoreEmptyAndInvalidRoutes() throws IOException {
8284
bccList.add("frob");
83-
headerPublish("", "queue1", ccList, bccList);
84-
expect(new String []{"queue1"}, true);
85+
headerPublish("", queue1(), ccList, bccList);
86+
expect(new String []{queue1()}, true);
8587
}
8688

8789
@Test public void bcc() throws IOException {
88-
bccList.add("queue2");
89-
headerPublish("", "queue1", null, bccList);
90-
expect(new String []{"queue1", "queue2"}, false);
90+
bccList.add(queue2());
91+
headerPublish("", queue1(), null, bccList);
92+
expect(new String []{queue1(), queue2()}, false);
9193
}
9294

9395
@Test public void noDuplicates() throws IOException {
94-
ccList.add("queue1");
95-
ccList.add("queue1");
96-
bccList.add("queue1");
97-
headerPublish("", "queue1", ccList, bccList);
98-
expect(new String[] {"queue1"}, true);
96+
ccList.add(queue1());
97+
ccList.add(queue1());
98+
bccList.add(queue1());
99+
headerPublish("", queue1(), ccList, bccList);
100+
expect(new String[] {queue1()}, true);
99101
}
100102

101103
@Test public void directExchangeWithoutBindings() throws IOException {
102-
ccList.add("queue1");
103-
headerPublish(exDirect, "queue2", ccList, null);
104+
ccList.add(queue1());
105+
headerPublish(exDirect, queue2(), ccList, null);
104106
expect(new String[] {}, true);
105107
}
106108

107109
@Test public void topicExchange() throws IOException {
108110
ccList.add("routing_key");
109-
channel.queueBind("queue2", exTopic, "routing_key");
111+
channel.queueBind(queue2(), exTopic, "routing_key");
110112
headerPublish(exTopic, "", ccList, null);
111-
expect(new String[] {"queue2"}, true);
113+
expect(new String[] {queue2()}, true);
112114
}
113115

114116
@Test public void boundExchanges() throws IOException {
115117
ccList.add("routing_key1");
116118
bccList.add("routing_key2");
117119
channel.exchangeBind(exTopic, exDirect, "routing_key1");
118-
channel.queueBind("queue2", exTopic, "routing_key2");
120+
channel.queueBind(queue2(), exTopic, "routing_key2");
119121
headerPublish(exDirect, "", ccList, bccList);
120-
expect(new String[] {"queue2"}, true);
122+
expect(new String[] {queue2()}, true);
121123
}
122124

123125
@Test public void nonArray() throws IOException {
124126
headers.put("CC", 0);
125127
propsBuilder.headers(headers);
126-
channel.basicPublish("", "queue1", propsBuilder.build(), new byte[0]);
128+
channel.basicPublish("", queue1(), propsBuilder.build(), new byte[0]);
127129
try {
128130
expect(new String[] {}, false);
129131
fail();
@@ -161,4 +163,16 @@ private void expect(String[] expectedQueues, boolean usedCc) throws IOException
161163
}
162164
}
163165
}
166+
167+
String queue1() {
168+
return queues[0];
169+
}
170+
171+
String queue2() {
172+
return queues[1];
173+
}
174+
175+
String queue3() {
176+
return queues[2];
177+
}
164178
}

0 commit comments

Comments
 (0)