Skip to content

Commit 82cd530

Browse files
author
Michael Bridgen
committed
Merge from default to get josn name changes
2 parents ac55105 + fe6e87f commit 82cd530

File tree

5 files changed

+186
-1
lines changed

5 files changed

+186
-1
lines changed

build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<pathelement path="${test.javac.out}"/>
2727
</path>
2828

29-
<property name="AMQP_SPEC_JSON_PATH" value="${codegen.dir}/amqp-${spec.version}.json ${codegen.dir}/rabbitmq-0.8-extensions.json"/>
29+
<property name="AMQP_SPEC_JSON_PATH" value="${codegen.dir}/amqp-rabbitmq-${spec.version}.json"/>
3030

3131
<target name="amqp-generate-check" description="check if codegen needs to be run">
3232
<uptodate property="amqp.generate.notRequired">

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
public class FunctionalTests extends TestCase {
3939
public static TestSuite suite() {
4040
TestSuite suite = new TestSuite("functional");
41+
suite.addTestSuite(Heartbeat.class);
4142
suite.addTestSuite(Tables.class);
4243
suite.addTestSuite(DoubleDeletion.class);
4344
suite.addTestSuite(Routing.class);
@@ -65,6 +66,7 @@ public static TestSuite suite() {
6566
suite.addTestSuite(BindToDefaultExchange.class);
6667
suite.addTestSuite(UnbindAutoDeleteExchange.class);
6768
suite.addTestSuite(RecoverAfterCancel.class);
69+
suite.addTestSuite(UnexpectedFrames.class);
6870
return suite;
6971
}
7072
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 at
4+
// 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 the
8+
// License for the specific language governing rights and limitations
9+
// under the License.
10+
//
11+
// The Original Code is RabbitMQ.
12+
//
13+
// The Initial Developers of the Original Code are LShift Ltd,
14+
// Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd.
15+
//
16+
// Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd,
17+
// Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd
18+
// are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial
19+
// Technologies LLC, and Rabbit Technologies Ltd.
20+
//
21+
// Portions created by LShift Ltd are Copyright (C) 2007-2010 LShift
22+
// Ltd. Portions created by Cohesive Financial Technologies LLC are
23+
// Copyright (C) 2007-2010 Cohesive Financial Technologies
24+
// LLC. Portions created by Rabbit Technologies Ltd are Copyright
25+
// (C) 2007-2010 Rabbit Technologies Ltd.
26+
//
27+
// All Rights Reserved.
28+
//
29+
// Contributor(s): ______________________________________.
30+
//
31+
32+
package com.rabbitmq.client.test.functional;
33+
34+
import java.io.IOException;
35+
36+
import com.rabbitmq.client.impl.AMQConnection;
37+
import com.rabbitmq.client.test.BrokerTestCase;
38+
39+
public class Heartbeat extends BrokerTestCase {
40+
41+
public Heartbeat()
42+
{
43+
super();
44+
connectionFactory.setRequestedHeartbeat(1);
45+
}
46+
47+
public void testHeartbeat()
48+
throws IOException, InterruptedException
49+
{
50+
Thread.sleep(3100);
51+
assertTrue(connection.isOpen());
52+
((AMQConnection)connection).setHeartbeat(0);
53+
Thread.sleep(3100);
54+
assertFalse(connection.isOpen());
55+
56+
}
57+
58+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package com.rabbitmq.client.test.functional;
2+
3+
import com.rabbitmq.client.*;
4+
import com.rabbitmq.client.impl.*;
5+
import com.rabbitmq.client.test.BrokerTestCase;
6+
7+
import java.io.ByteArrayOutputStream;
8+
import java.io.DataInputStream;
9+
import java.io.IOException;
10+
import java.net.Socket;
11+
12+
/**
13+
* Test that the server correctly handles us when we send it bad frames
14+
*/
15+
public class UnexpectedFrames extends BrokerTestCase {
16+
private interface Confuser {
17+
public Frame confuse(Frame frame) throws IOException;
18+
}
19+
20+
public void testMissingHeader() throws IOException {
21+
expectUnexpectedFrameError(new Confuser() {
22+
public Frame confuse(Frame frame) {
23+
if (frame.type == AMQP.FRAME_HEADER) {
24+
return null;
25+
}
26+
return frame;
27+
}
28+
});
29+
}
30+
31+
public void testMissingMethod() throws IOException {
32+
expectUnexpectedFrameError(new Confuser() {
33+
public Frame confuse(Frame frame) {
34+
if (frame.type == AMQP.FRAME_METHOD) {
35+
// We can't just skip the method as that will lead us to
36+
// send 0 bytes and hang waiting for a response.
37+
frame.type = AMQP.FRAME_HEADER;
38+
}
39+
return frame;
40+
}
41+
});
42+
}
43+
44+
public void testMissingBody() throws IOException {
45+
expectUnexpectedFrameError(new Confuser() {
46+
public Frame confuse(Frame frame) {
47+
if (frame.type == AMQP.FRAME_BODY) {
48+
return null;
49+
}
50+
return frame;
51+
}
52+
});
53+
}
54+
55+
public void testWrongClassInHeader() throws IOException {
56+
expectUnexpectedFrameError(new Confuser() {
57+
public Frame confuse(Frame frame) throws IOException {
58+
if (frame.type == AMQP.FRAME_HEADER) {
59+
byte[] payload = frame.accumulator.toByteArray();
60+
// First two bytes = class ID, must match class ID from
61+
// method.
62+
payload[0] = 12;
63+
payload[1] = 34;
64+
frame.accumulator = new ByteArrayOutputStream();
65+
frame.accumulator.write(payload, 0, payload.length);
66+
}
67+
return frame;
68+
}
69+
});
70+
}
71+
72+
private void expectUnexpectedFrameError(Confuser confuser) throws IOException {
73+
ConnectionFactory factory = new ConnectionFactory();
74+
Socket socket = factory.getSocketFactory().createSocket("localhost",
75+
AMQP.PROTOCOL.PORT);
76+
ConfusedFrameHandler handler = new ConfusedFrameHandler(socket);
77+
AMQConnection connection = new AMQConnection(factory, handler);
78+
try {
79+
connection.start(false);
80+
} catch (RedirectException e) {}
81+
Channel channel = connection.createChannel();
82+
83+
handler.confuser = confuser;
84+
85+
try {
86+
String queue = channel.queueDeclare().getQueue();
87+
channel.basicPublish("", queue, null, "Hello".getBytes());
88+
GetResponse result = channel.basicGet(queue, false);
89+
channel.basicAck(result.getEnvelope().getDeliveryTag(), false);
90+
fail("We should have seen an UNEXPECTED_FRAME by now");
91+
}
92+
catch (IOException e) {
93+
checkShutdownSignal(AMQP.UNEXPECTED_FRAME, e);
94+
}
95+
}
96+
97+
private static class ConfusedFrameHandler extends SocketFrameHandler {
98+
public ConfusedFrameHandler(Socket socket) throws IOException {
99+
super(socket);
100+
}
101+
102+
@Override
103+
public void writeFrame(Frame frame) throws IOException {
104+
Frame confusedFrame = new Frame();
105+
confusedFrame.accumulator = frame.accumulator;
106+
confusedFrame.channel = frame.channel;
107+
confusedFrame.type = frame.type;
108+
109+
confusedFrame = confuser.confuse(confusedFrame);
110+
if (confusedFrame != null) {
111+
super.writeFrame(confusedFrame);
112+
}
113+
}
114+
115+
public Confuser confuser = new Confuser() {
116+
public Frame confuse(Frame frame) {
117+
// Do nothing to start with, we need to negotiate before the
118+
// server will send us unexpected_frame errors
119+
return frame;
120+
}
121+
};
122+
}
123+
}

test/src/com/rabbitmq/examples/TestMain.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ public static void runConnectionNegotiationTest(final String hostName, final int
122122

123123
//should succeed IF the highest version supported by the
124124
//server is a version supported by this client
125+
/* TODO: re-enable this test once the client speaks 0-9-1
125126
conn = new TestConnectionFactory(100, 0, hostName, portNumber).newConnection();
126127
conn.close();
128+
*/
127129

128130
ConnectionFactory factory;
129131
factory = new ConnectionFactory();

0 commit comments

Comments
 (0)