Skip to content

Commit 78cae1b

Browse files
author
Rob Harrop
committed
Merge with default
2 parents f1eea1e + 2a258cb commit 78cae1b

File tree

8 files changed

+187
-32
lines changed

8 files changed

+187
-32
lines changed

codegen.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def printClassInterfaces():
138138
print " %s %s();" % (java_field_type(spec, a.domain), java_getter_name(a.name))
139139
print " }"
140140
print " }"
141-
141+
142142
def printReadProperties(c):
143143
print
144144
print """ public void readPropertiesFrom(ContentHeaderPropertyReader reader)
@@ -150,7 +150,7 @@ def printReadProperties(c):
150150
for f in c.fields:
151151
print " this.%s = %s_present ? reader.read%s() : null;" % (java_field_name(f.name), java_field_name(f.name), java_class_name(f.domain))
152152
print " }"
153-
153+
154154
def printWriteProperties(c):
155155
print
156156
print """ public void writePropertiesTo(ContentHeaderPropertyWriter writer)
@@ -162,7 +162,7 @@ def printWriteProperties(c):
162162
for f in c.fields:
163163
print " if (this.%s != null) { writer.write%s(this.%s); } " % (java_field_name(f.name), java_class_name(f.domain), java_field_name(f.name))
164164
print " }"
165-
165+
166166
def printPropertyDebug(c):
167167
print
168168
print " public void appendPropertyDebugStringTo(StringBuffer acc) {"
@@ -175,7 +175,7 @@ def printPropertyDebug(c):
175175

176176
print " acc.append(\")\");"
177177
print " }"
178-
178+
179179
def printClassProperties(c):
180180
print
181181
print " public static class %(className)s extends %(parentClass)s {" % {'className' : java_class_name(c.name) + 'Properties', 'parentClass' : 'com.rabbitmq.client.impl.AMQ' + java_class_name(c.name) + 'Properties'}
@@ -191,7 +191,7 @@ def printClassProperties(c):
191191
sys.stdout.write( " %s %s" % (java_property_type(spec,f.domain),java_field_name(f.name)))
192192
if not index == len(c.fields) - 1:
193193
print ","
194-
194+
195195
print ")"
196196
print " {"
197197
for f in c.fields:
@@ -203,7 +203,7 @@ def printClassProperties(c):
203203
print " public %sProperties() {}" % (java_class_name(c.name))
204204
print " public int getClassId() { return %i; }" % (c.index)
205205
print " public java.lang.String getClassName() { return \"%s\"; }" % (c.name)
206-
206+
207207
#access functions
208208
print
209209
for f in c.fields:
@@ -310,15 +310,15 @@ def read_arguments():
310310
for a in m.arguments:
311311
print " this.%s = reader.read%s();" % (java_field_name(a.name), java_class_name(spec.resolveDomain(a.domain)))
312312
print " }"
313-
313+
314314
def write_arguments():
315315
print
316316
print " public void writeArgumentsTo(MethodArgumentWriter writer)"
317317
print " throws IOException"
318318
print " {"
319319
for a in m.arguments:
320320
print " writer.write%s(this.%s);" % (java_class_name(spec.resolveDomain(a.domain)), java_field_name(a.name))
321-
print " }"
321+
print " }"
322322

323323
#start
324324
print
@@ -339,6 +339,7 @@ def write_arguments():
339339
argument_debug_string()
340340
read_arguments()
341341
write_arguments()
342+
342343
print " }"
343344
print " }"
344345

@@ -357,7 +358,7 @@ def printMethodVisitor():
357358
for m in c.allMethods():
358359
print " public Object visit(%s.%s x) throws IOException { throw new UnexpectedMethodError(x); } " % (java_class_name(c.name), java_class_name(m.name))
359360
print " }"
360-
361+
361362
def printMethodArgumentReader():
362363
print
363364
print " public static Method readMethodFrom(DataInputStream in) throws IOException { "
@@ -380,7 +381,7 @@ def printMethodArgumentReader():
380381
print
381382
print " throw new UnknownClassOrMethodId(classId, methodId);"
382383
print " }"
383-
384+
384385
def printContentHeaderReader(c):
385386
print
386387
print """ public static AMQContentHeader readContentHeaderFrom(DataInputStream in)
@@ -397,14 +398,14 @@ def printContentHeaderReader(c):
397398
print
398399
print " throw new UnknownClassOrMethodId(classId, -1);"
399400
print " }"
400-
401+
401402
printHeader()
402403
for c in spec.allClasses(): printClassMethods(c)
403404
printMethodVisitor()
404405
printMethodArgumentReader()
405406
printContentHeaderReader(c)
406407
print "}"
407-
408+
408409
#--------------------------------------------------------------------------------
409410

410411
def generateJavaApi(specPath):

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public final void writeShortstr(String str)
5050
if (length > 255) {
5151
throw new IllegalArgumentException(
5252
"Short string too long; utf-8 encoded length = " + length +
53-
", max = 255.");
53+
", max = 255.");
5454
}
5555
out.writeByte(bytes.length);
5656
out.write(bytes);
@@ -205,7 +205,7 @@ public void writeArray(List value)
205205
}
206206
}
207207
}
208-
208+
209209
/** Public API - encodes an octet from an int. */
210210
public final void writeOctet(int octet)
211211
throws IOException

src/com/rabbitmq/tools/jsonrpc/JsonRpcClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public Object call(String method, Object[] params)
112112
} catch(ShutdownSignalException ex) {
113113
throw new IOException(ex.getMessage()); // wrap, re-throw
114114
}
115-
115+
116116
//System.out.println(requestStr + " --->\n---> " + replyStr);
117117
Map<String, Object> map = (Map) (new JSONReader().read(replyStr));
118118
return checkReply(map);

src/com/rabbitmq/tools/jsonrpc/JsonRpcException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class JsonRpcException extends Exception {
3939
public Object error;
4040

4141
public JsonRpcException() {
42-
// no work needed in default no-argconstructor
42+
// no work needed in default no-arg constructor
4343
}
4444

4545
public JsonRpcException(Map<String, Object> errorMap) {

src/com/rabbitmq/utility/BlockingCell.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public class BlockingCell<T> {
2828

2929
/** Will be null until a value is supplied, and possibly still then. */
3030
private T _value;
31-
31+
3232
private static final long NANOS_IN_MILLI = 1000 * 1000;
33-
33+
3434
private static final long INFINITY = -1;
3535

3636
/** Instantiate a new BlockingCell waiting for a value of the specified type. */
@@ -75,10 +75,10 @@ public synchronized T get(long timeout) throws InterruptedException, TimeoutExce
7575

7676
if (!_filled)
7777
throw new TimeoutException();
78-
78+
7979
return _value;
8080
}
81-
81+
8282
/**
8383
* As get(), but catches and ignores InterruptedException, retrying until a value appears.
8484
* @return the waited-for value
@@ -92,7 +92,7 @@ public synchronized T uninterruptibleGet() {
9292
}
9393
}
9494
}
95-
95+
9696
/**
9797
* As get(long timeout), but catches and ignores InterruptedException, retrying until
9898
* a value appears or until specified timeout is reached. If timeout is reached,
@@ -105,15 +105,15 @@ public synchronized T uninterruptibleGet() {
105105
public synchronized T uninterruptibleGet(int timeout) throws TimeoutException {
106106
long now = System.nanoTime() / NANOS_IN_MILLI;
107107
long runTime = now + timeout;
108-
108+
109109
do {
110110
try {
111111
return get(runTime - now);
112112
} catch (InterruptedException e) {
113113
// Ignore.
114114
}
115115
} while ((timeout == INFINITY) || ((now = System.nanoTime() / NANOS_IN_MILLI) < runTime));
116-
116+
117117
throw new TimeoutException();
118118
}
119119

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
// The contents of this file are subject to the Mozilla Public License
2+
// Version 1.1 (the "License"); you may not use this file except in
3+
// compliance with the License. You may obtain a copy of the License
4+
// at http://www.mozilla.org/MPL/
5+
//
6+
// Software distributed under the License is distributed on an "AS IS"
7+
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
8+
// the License for the specific language governing rights and
9+
// limitations under the License.
10+
//
11+
// The Original Code is RabbitMQ.
12+
//
13+
// The Initial Developer of the Original Code is VMware, Inc.
14+
// Copyright (c) 2007-2011 VMware, Inc. All rights reserved.
15+
//
16+
17+
package com.rabbitmq.client.test.functional;
18+
19+
import com.rabbitmq.client.AMQP;
20+
import com.rabbitmq.client.AMQP.BasicProperties;
21+
import com.rabbitmq.client.GetResponse;
22+
import com.rabbitmq.client.test.BrokerTestCase;
23+
24+
import java.io.IOException;
25+
import java.util.ArrayList;
26+
import java.util.HashMap;
27+
import java.util.Arrays;
28+
import java.util.List;
29+
import java.util.Map;
30+
31+
public class CcRoutes extends BrokerTestCase {
32+
33+
static private String[] queues = new String[]{"queue1", "queue2", "queue3"};
34+
protected String exDirect = "direct_cc_exchange";
35+
protected String exTopic = "topic_cc_exchange";
36+
protected BasicProperties props;
37+
protected Map<String, Object> headers;
38+
protected List<String> ccList;
39+
protected List<String> bccList;
40+
41+
@Override protected void setUp() throws IOException {
42+
super.setUp();
43+
props = new BasicProperties();
44+
headers = new HashMap<String, Object>();
45+
ccList = new ArrayList<String>();
46+
bccList = new ArrayList<String>();
47+
}
48+
49+
@Override protected void createResources() throws IOException {
50+
super.createResources();
51+
for (String q : queues) {
52+
channel.queueDeclare(q, false, true, true, null);
53+
}
54+
channel.exchangeDeclare(exDirect, "direct", false, true, null);
55+
channel.exchangeDeclare(exTopic, "topic", false, true, null);
56+
}
57+
58+
public void testCcList() throws IOException {
59+
ccList.add("queue2");
60+
ccList.add("queue3");
61+
headerPublish("", "queue1", ccList, null);
62+
expect(new String []{"queue1", "queue2", "queue3"}, true);
63+
}
64+
65+
public void testCcIgnoreEmptyAndInvalidRoutes() throws IOException {
66+
bccList.add("frob");
67+
headerPublish("", "queue1", ccList, bccList);
68+
expect(new String []{"queue1"}, true);
69+
}
70+
71+
public void testBcc() throws IOException {
72+
bccList.add("queue2");
73+
headerPublish("", "queue1", null, bccList);
74+
expect(new String []{"queue1", "queue2"}, false);
75+
}
76+
77+
public void testNoDuplicates() throws IOException {
78+
ccList.add("queue1");
79+
ccList.add("queue1");
80+
bccList.add("queue1");
81+
headerPublish("", "queue1", ccList, bccList);
82+
expect(new String[] {"queue1"}, true);
83+
}
84+
85+
public void testDirectExchangeWithoutBindings() throws IOException {
86+
ccList.add("queue1");
87+
headerPublish(exDirect, "queue2", ccList, null);
88+
expect(new String[] {}, true);
89+
}
90+
91+
public void testTopicExchange() throws IOException {
92+
ccList.add("routing_key");
93+
channel.queueBind("queue2", exTopic, "routing_key");
94+
headerPublish(exTopic, "", ccList, null);
95+
expect(new String[] {"queue2"}, true);
96+
}
97+
98+
public void testBoundExchanges() throws IOException {
99+
ccList.add("routing_key1");
100+
bccList.add("routing_key2");
101+
channel.exchangeBind(exTopic, exDirect, "routing_key1");
102+
channel.queueBind("queue2", exTopic, "routing_key2");
103+
headerPublish(exDirect, "", ccList, bccList);
104+
expect(new String[] {"queue2"}, true);
105+
}
106+
107+
public void testNonArray() throws IOException {
108+
headers.put("CC", 0);
109+
props.setHeaders(headers);
110+
channel.basicPublish("", "queue1", props, new byte[0]);
111+
try {
112+
expect(new String[] {}, false);
113+
fail();
114+
} catch (IOException e) {
115+
checkShutdownSignal(AMQP.PRECONDITION_FAILED, e);
116+
}
117+
}
118+
119+
private void headerPublish(String ex, String to, List<String> cc, List<String> bcc) throws IOException {
120+
if (cc != null) {
121+
headers.put("CC", ccList);
122+
}
123+
if (bcc != null) {
124+
headers.put("BCC", bccList);
125+
}
126+
props.setHeaders(headers);
127+
channel.basicPublish(ex, to, props, new byte[0]);
128+
}
129+
130+
private void expect(String[] expectedQueues, boolean usedCc) throws IOException {
131+
GetResponse getResponse;
132+
List<String> expectedList = Arrays.asList(expectedQueues);
133+
for (String q : queues) {
134+
getResponse = basicGet(q);
135+
if (expectedList.contains(q)) {
136+
assertNotNull(getResponse);
137+
assertEquals(0, getResponse.getMessageCount());
138+
Map headers = getResponse.getProps().getHeaders();
139+
if (headers != null){
140+
assertEquals(usedCc, headers.containsKey("CC"));
141+
assertFalse(headers.containsKey("BCC"));
142+
}
143+
} else {
144+
assertNull(getResponse);
145+
}
146+
}
147+
}
148+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public static TestSuite suite() {
5959
suite.addTestSuite(SaslMechanisms.class);
6060
suite.addTestSuite(UserIDHeader.class);
6161
suite.addTestSuite(InternalExchange.class);
62+
suite.addTestSuite(CcRoutes.class);
6263
return suite;
6364
}
6465
}

0 commit comments

Comments
 (0)