Skip to content

Commit fb57269

Browse files
author
Simon MacMullen
committed
Don't use Deque, and thus become compatible with Java 1.5. This changeset can be reversed once we drop Java 1.5 support.
1 parent e8d353c commit fb57269

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import java.io.IOException;
99
import java.util.Arrays;
10-
import java.util.Deque;
10+
import java.util.List;
1111

1212
import static com.rabbitmq.client.test.functional.QosTests.drain;
1313

@@ -20,12 +20,12 @@ protected void createResources() throws IOException {
2020
}
2121

2222
private interface Closure {
23-
public void makeMore(Deque<Delivery> deliveries) throws IOException;
23+
public void makeMore(List<Delivery> deliveries) throws IOException;
2424
}
2525

2626
public void testSingleAck() throws IOException {
2727
testPrefetch(new Closure() {
28-
public void makeMore(Deque<Delivery> deliveries) throws IOException {
28+
public void makeMore(List<Delivery> deliveries) throws IOException {
2929
for (Delivery del : deliveries) {
3030
ack(del, false);
3131
}
@@ -35,16 +35,16 @@ public void makeMore(Deque<Delivery> deliveries) throws IOException {
3535

3636
public void testMultiAck() throws IOException {
3737
testPrefetch(new Closure() {
38-
public void makeMore(Deque<Delivery> deliveries) throws IOException {
39-
ack(deliveries.getLast(), true);
38+
public void makeMore(List<Delivery> deliveries) throws IOException {
39+
ack(deliveries.get(deliveries.size() - 1), true);
4040
}
4141
});
4242
}
4343

4444
public void testSingleNack() throws IOException {
4545
for (final boolean requeue: Arrays.asList(false, true)) {
4646
testPrefetch(new Closure() {
47-
public void makeMore(Deque<Delivery> deliveries) throws IOException {
47+
public void makeMore(List<Delivery> deliveries) throws IOException {
4848
for (Delivery del : deliveries) {
4949
nack(del, false, requeue);
5050
}
@@ -56,16 +56,16 @@ public void makeMore(Deque<Delivery> deliveries) throws IOException {
5656
public void testMultiNack() throws IOException {
5757
for (final boolean requeue: Arrays.asList(false, true)) {
5858
testPrefetch(new Closure() {
59-
public void makeMore(Deque<Delivery> deliveries) throws IOException {
60-
nack(deliveries.getLast(), true, requeue);
59+
public void makeMore(List<Delivery> deliveries) throws IOException {
60+
nack(deliveries.get(deliveries.size() - 1), true, requeue);
6161
}
6262
});
6363
}
6464
}
6565

6666
public void testRecover() throws IOException {
6767
testPrefetch(new Closure() {
68-
public void makeMore(Deque<Delivery> deliveries) throws IOException {
68+
public void makeMore(List<Delivery> deliveries) throws IOException {
6969
channel.basicRecover();
7070
}
7171
});
@@ -75,7 +75,7 @@ private void testPrefetch(Closure closure) throws IOException {
7575
QueueingConsumer c = new QueueingConsumer(channel);
7676
publish(q, 15);
7777
consume(c, 5, false);
78-
Deque<Delivery> deliveries = drain(c, 5);
78+
List<Delivery> deliveries = drain(c, 5);
7979

8080
ack(channel.basicGet(q, false), false);
8181
drain(c, 0);

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@
2222
import java.util.ArrayList;
2323
import java.util.Arrays;
2424
import java.util.Collections;
25-
import java.util.Deque;
2625
import java.util.HashMap;
2726
import java.util.LinkedList;
2827
import java.util.List;
2928
import java.util.Map;
30-
import java.util.Queue;
3129

3230
import com.rabbitmq.client.AMQP;
3331
import com.rabbitmq.client.Channel;
@@ -66,16 +64,16 @@ public void fill(int n)
6664
* receive n messages - check that we receive no fewer and cannot
6765
* receive more
6866
**/
69-
public static Deque<Delivery> drain(QueueingConsumer c, int n)
67+
public static List<Delivery> drain(QueueingConsumer c, int n)
7068
throws IOException
7169
{
72-
Deque<Delivery> res = new LinkedList<Delivery>();
70+
List<Delivery> res = new LinkedList<Delivery>();
7371
try {
7472
long start = System.currentTimeMillis();
7573
for (int i = 0; i < n; i++) {
7674
Delivery d = c.nextDelivery(1000);
7775
assertNotNull(d);
78-
res.offer(d);
76+
res.add(d);
7977
}
8078
long finish = System.currentTimeMillis();
8179
Thread.sleep( (n == 0 ? 0 : (finish - start) / n) + 10 );
@@ -131,7 +129,7 @@ public void testNoAckObeysLimit()
131129
} catch (InterruptedException ie) {
132130
fail("interrupted");
133131
}
134-
Queue<Delivery> d = drain(c1, 1);
132+
List<Delivery> d = drain(c1, 1);
135133
ack(d, false); // must ack before the next one appears
136134
d = drain(c1, 1);
137135
ack(d, false);
@@ -164,7 +162,7 @@ public void testFairness()
164162
List<String> queues = configure(c, 1, queueCount, messageCount);
165163

166164
for (int i = 0; i < messageCount - 1; i++) {
167-
Queue<Delivery> d = drain(c, 1);
165+
List<Delivery> d = drain(c, 1);
168166
ack(d, false);
169167
}
170168

@@ -245,7 +243,7 @@ public void testConsumerLifecycle()
245243
String tag;
246244
for (int i = 0; i < 2; i++) {
247245
tag = channel.basicConsume(queue, false, c);
248-
Queue<Delivery> d = drain(c, 1);
246+
List<Delivery> d = drain(c, 1);
249247
channel.basicCancel(tag);
250248
drain(c, 0);
251249
ack(d, true);
@@ -264,7 +262,7 @@ public void testSetLimitAfterConsume()
264262
//We actually only guarantee that the limit takes effect
265263
//*eventually*, so this can in fact fail. It's pretty unlikely
266264
//though.
267-
Queue<Delivery> d = drain(c, 1);
265+
List<Delivery> d = drain(c, 1);
268266
ack(d, true);
269267
drain(c, 1);
270268
}
@@ -282,7 +280,7 @@ public void testLimitDecrease()
282280
throws IOException
283281
{
284282
QueueingConsumer c = new QueueingConsumer(channel);
285-
Queue<Delivery> d = configure(c, 2, 4);
283+
List<Delivery> d = configure(c, 2, 4);
286284
channel.basicQos(1, true);
287285
drain(c, 0);
288286
ack(d, true);
@@ -312,10 +310,10 @@ public void testLimitingMultipleChannels()
312310
ch1.basicQos(1, true);
313311
ch2.basicQos(1, true);
314312
fill(5);
315-
Queue<Delivery> d1 = drain(c1, 1);
316-
Queue<Delivery> d2 = drain(c2, 1);
317-
ackDelivery(ch1, d1.remove(), true);
318-
ackDelivery(ch2, d2.remove(), true);
313+
List<Delivery> d1 = drain(c1, 1);
314+
List<Delivery> d2 = drain(c2, 1);
315+
ackDelivery(ch1, d1.remove(0), true);
316+
ackDelivery(ch2, d2.remove(0), true);
319317
drain(c1, 1);
320318
drain(c2, 1);
321319
ch1.close();
@@ -364,7 +362,7 @@ protected void runLimitTests(int limit,
364362
}
365363

366364
//is limit enforced?
367-
Queue<Delivery> d = drain(c, limit);
365+
List<Delivery> d = drain(c, limit);
368366

369367
//is basic.get not limited?
370368
List<Long> tags = new ArrayList<Long>();
@@ -396,7 +394,7 @@ protected void runLimitTests(int limit,
396394
drain(c, 0);
397395
}
398396

399-
protected Delivery ack(Queue<Delivery> d, boolean multiAck)
397+
protected Delivery ack(List<Delivery> d, boolean multiAck)
400398
throws IOException
401399
{
402400
Delivery last = null;
@@ -430,7 +428,7 @@ protected List<String> configure(QueueingConsumer c,
430428
return queues;
431429
}
432430

433-
protected Queue<Delivery> configure(QueueingConsumer c,
431+
protected List<Delivery> configure(QueueingConsumer c,
434432
int limit,
435433
int messages)
436434
throws IOException

0 commit comments

Comments
 (0)