Skip to content

Commit 4539351

Browse files
author
Alexandru Scvortov
committed
merge bug23710 into default
2 parents f31a527 + b1d1afc commit 4539351

File tree

3 files changed

+51
-9
lines changed

3 files changed

+51
-9
lines changed

src/com/rabbitmq/client/impl/Frame.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ else if(value instanceof byte[]) {
297297
else if(value instanceof List) {
298298
acc += 4 + arraySize((List<?>)value);
299299
}
300+
else if(value instanceof Object[]) {
301+
acc += 4 + arraySize((Object[])value);
302+
}
300303
else if(value == null) {
301304
}
302305
else {
@@ -305,7 +308,7 @@ else if(value == null) {
305308
return acc;
306309
}
307310

308-
/** Computes the AMQP wire-protocol length of an encoded field-array */
311+
/** Computes the AMQP wire-protocol length of an encoded field-array of type List<?> */
309312
public static long arraySize(List<?> values)
310313
throws UnsupportedEncodingException
311314
{
@@ -315,7 +318,16 @@ public static long arraySize(List<?> values)
315318
}
316319
return acc;
317320
}
318-
321+
322+
/** Computes the AMQP wire-protocol length of an encoded field-array of type Object[] */
323+
public static long arraySize(Object[] values) throws UnsupportedEncodingException {
324+
long acc = 0;
325+
for (Object value : values) {
326+
acc += fieldValueSize(value);
327+
}
328+
return acc;
329+
}
330+
319331
/** Computes the AMQP wire-protocol length of a protocol-encoded long string. */
320332
private static int longStrSize(String str)
321333
throws UnsupportedEncodingException

src/com/rabbitmq/client/impl/ValueWriter.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ else if(value instanceof List) {
200200
writeOctet('A');
201201
writeArray((List<?>)value);
202202
}
203+
else if(value instanceof Object[]) {
204+
writeOctet('A');
205+
writeArray((Object[])value);
206+
}
203207
else {
204208
throw new IllegalArgumentException
205209
("Invalid value type: " + value.getClass().getName());
@@ -220,6 +224,20 @@ public final void writeArray(List<?> value)
220224
}
221225
}
222226

227+
public final void writeArray(Object[] value)
228+
throws IOException
229+
{
230+
if (value==null) {
231+
out.write(0);
232+
}
233+
else {
234+
out.writeInt((int)Frame.arraySize(value));
235+
for (Object item : value) {
236+
writeFieldValue(item);
237+
}
238+
}
239+
}
240+
223241
/** Public API - encodes an octet from an int. */
224242
public final void writeOctet(int octet)
225243
throws IOException

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@
1818
package com.rabbitmq.client.test.functional;
1919

2020
import java.io.IOException;
21+
import java.util.Arrays;
2122
import java.util.HashMap;
2223
import java.util.Map;
2324

2425
import com.rabbitmq.client.AMQP;
2526
import com.rabbitmq.client.QueueingConsumer;
2627
import com.rabbitmq.client.test.BrokerTestCase;
2728

28-
// Test queue auto-delete and exclusive semantics.
29+
/**
30+
* Test queue auto-delete and exclusive semantics.
31+
*/
2932
public class QueueLifecycle extends BrokerTestCase {
3033

3134
void verifyQueueExists(String name) throws IOException {
@@ -77,12 +80,13 @@ void verifyNotEquivalent(boolean durable, boolean exclusive,
7780
fail("Queue.declare should have been rejected as not equivalent");
7881
}
7982

80-
// From amqp-0-9-1.xml, for "passive" property, "equivalent" rule:
81-
// "If not set and the queue exists, the server MUST check that the
82-
// existing queue has the same values for durable, exclusive,
83-
// auto-delete, and arguments fields. The server MUST respond with
84-
// Declare-Ok if the requested queue matches these fields, and MUST
85-
// raise a channel exception if not."
83+
/** From amqp-0-9-1.xml, for "passive" property, "equivalent" rule:
84+
* "If not set and the queue exists, the server MUST check that the
85+
* existing queue has the same values for durable, exclusive,
86+
* auto-delete, and arguments fields. The server MUST respond with
87+
* Declare-Ok if the requested queue matches these fields, and MUST
88+
* raise a channel exception if not."
89+
*/
8690
public void testQueueEquivalence() throws IOException {
8791
String q = "queue";
8892
channel.queueDeclare(q, false, false, false, null);
@@ -154,4 +158,12 @@ public void testExclusiveGoesWithConnection() throws IOException {
154158
verifyQueueMissing(name);
155159
}
156160

161+
public void testArgumentArrays() throws IOException {
162+
Map<String, Object> args = new HashMap<String, Object>();
163+
String[] arr = new String[]{"foo", "bar", "baz"};
164+
args.put("my-key", arr);
165+
String queueName = "argumentArraysQueue";
166+
channel.queueDeclare(queueName, true, true, false, args);
167+
verifyQueue(queueName, true, true, false, args);
168+
}
157169
}

0 commit comments

Comments
 (0)