Skip to content

Commit 179b327

Browse files
author
Simon MacMullen
committed
Tidy up two files which didn't get merged to default and tidied there.
1 parent 0ba7617 commit 179b327

File tree

2 files changed

+74
-82
lines changed

2 files changed

+74
-82
lines changed

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

Lines changed: 58 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import com.rabbitmq.client.AMQP;
3838
import com.rabbitmq.client.MalformedFrameException;
3939
import com.rabbitmq.client.impl.Method;
40-
import com.rabbitmq.client.impl.Frame;
4140
import com.rabbitmq.client.impl.SocketFrameHandler;
4241
import com.rabbitmq.client.impl.AMQCommand;
4342
import com.rabbitmq.client.ConnectionFactory;
@@ -48,69 +47,67 @@
4847
/**
4948
* Check that protocol negotiation works
5049
*/
51-
public class ConnectionOpen extends TestCase
52-
{
53-
public void testCorrectProtocolHeader() throws IOException {
54-
ConnectionFactory factory = new ConnectionFactory();
55-
SocketFrameHandler fh = new SocketFrameHandler(factory.getSocketFactory().createSocket("localhost", AMQP.PROTOCOL.PORT));
56-
fh.sendHeader();
57-
AMQCommand.Assembler a = AMQCommand.newAssembler();
58-
AMQCommand command = null;
59-
while (command==null) {
60-
command = a.handleFrame(fh.readFrame());
50+
public class ConnectionOpen extends TestCase {
51+
public void testCorrectProtocolHeader() throws IOException {
52+
ConnectionFactory factory = new ConnectionFactory();
53+
SocketFrameHandler fh = new SocketFrameHandler(factory.getSocketFactory().createSocket("localhost", AMQP.PROTOCOL.PORT));
54+
fh.sendHeader();
55+
AMQCommand.Assembler a = AMQCommand.newAssembler();
56+
AMQCommand command = null;
57+
while (command == null) {
58+
command = a.handleFrame(fh.readFrame());
59+
}
60+
Method m = command.getMethod();
61+
// System.out.println(m.getClass());
62+
assertTrue("First command must be Connection.start",
63+
m instanceof AMQP.Connection.Start);
64+
AMQP.Connection.Start start = (AMQP.Connection.Start) m;
65+
assertTrue("Version in Connection.start is <= what we sent",
66+
start.getVersionMajor() < AMQP.PROTOCOL.MAJOR ||
67+
(start.getVersionMajor() == AMQP.PROTOCOL.MAJOR &&
68+
start.getVersionMinor() <= AMQP.PROTOCOL.MINOR));
6169
}
62-
Method m = command.getMethod();
63-
// System.out.println(m.getClass());
64-
assertTrue("First command must be Connection.start",
65-
m instanceof AMQP.Connection.Start);
66-
AMQP.Connection.Start start = (AMQP.Connection.Start) m;
67-
assertTrue("Version in Connection.start is <= what we sent",
68-
start.getVersionMajor() < AMQP.PROTOCOL.MAJOR ||
69-
(start.getVersionMajor() == AMQP.PROTOCOL.MAJOR &&
70-
start.getVersionMinor() <= AMQP.PROTOCOL.MINOR));
71-
}
7270

73-
public void testCrazyProtocolHeader() throws IOException {
74-
ConnectionFactory factory = new ConnectionFactory();
75-
SocketFrameHandler fh = new SocketFrameHandler(factory.getSocketFactory().createSocket("localhost", AMQP.PROTOCOL.PORT));
76-
fh.sendHeader(100, 3); // major, minor
77-
DataInputStream in = fh._inputStream;
78-
// we should get a valid protocol header back
79-
byte[] header = new byte[4];
80-
in.read(header);
81-
// The protocol header is "AMQP" plus a version that the server
82-
// supports. We can really only test for the first bit.
83-
assertEquals("AMQP", new String(header));
84-
in.read(header);
85-
assertEquals(in.available(), 0);
86-
// At this point the socket should have been closed. We can't
87-
// directly test for this, since Socket.isClosed isn't very
88-
// reliable, but we can test whether trying to read more bytes
89-
// gives an error.
90-
fh._socket.setSoTimeout(500);
91-
// NB the frame handler will return null if the socket times out
92-
try {
93-
fh.readFrame();
94-
fail("Expected socket read to fail due to socket being closed");
71+
public void testCrazyProtocolHeader() throws IOException {
72+
ConnectionFactory factory = new ConnectionFactory();
73+
SocketFrameHandler fh = new SocketFrameHandler(factory.getSocketFactory().createSocket("localhost", AMQP.PROTOCOL.PORT));
74+
fh.sendHeader(100, 3); // major, minor
75+
DataInputStream in = fh._inputStream;
76+
// we should get a valid protocol header back
77+
byte[] header = new byte[4];
78+
in.read(header);
79+
// The protocol header is "AMQP" plus a version that the server
80+
// supports. We can really only test for the first bit.
81+
assertEquals("AMQP", new String(header));
82+
in.read(header);
83+
assertEquals(in.available(), 0);
84+
// At this point the socket should have been closed. We can't
85+
// directly test for this, since Socket.isClosed isn't very
86+
// reliable, but we can test whether trying to read more bytes
87+
// gives an error.
88+
fh._socket.setSoTimeout(500);
89+
// NB the frame handler will return null if the socket times out
90+
try {
91+
fh.readFrame();
92+
fail("Expected socket read to fail due to socket being closed");
93+
}
94+
catch (MalformedFrameException mfe) {
95+
fail("Expected nothing, rather than a badly-formed something");
96+
}
97+
catch (IOException ioe) {
98+
return;
99+
}
95100
}
96-
catch (MalformedFrameException mfe) {
97-
fail("Expected nothing, rather than a badly-formed something");
98-
}
99-
catch (IOException ioe) {
100-
return;
101-
}
102-
}
103101

104-
public void testFrameMaxLessThanFrameMinSize() throws IOException {
105-
ConnectionFactory factory = new ConnectionFactory();
106-
factory.setRequestedFrameMax(100);
107-
try {
108-
factory.newConnection();
109-
}
110-
catch (IOException ioe) {
111-
return;
102+
public void testFrameMaxLessThanFrameMinSize() throws IOException {
103+
ConnectionFactory factory = new ConnectionFactory();
104+
factory.setRequestedFrameMax(100);
105+
try {
106+
factory.newConnection();
107+
}
108+
catch (IOException ioe) {
109+
return;
110+
}
111+
fail("Broker should have closed the connection since our frame max < frame_min_size");
112112
}
113-
fail("Broker should have closed the connection since our frame max < frame_min_size");
114-
}
115-
116113
}

test/src/com/rabbitmq/client/test/server/ExchangeEquivalence.java

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,24 @@
3535
import java.util.HashMap;
3636
import java.io.IOException;
3737

38-
import com.rabbitmq.client.AMQP;
39-
import com.rabbitmq.client.QueueingConsumer;
40-
4138
import com.rabbitmq.client.test.BrokerTestCase;
4239
import com.rabbitmq.client.test.functional.ExchangeDeclare;
4340

4441
public class ExchangeEquivalence extends BrokerTestCase {
45-
46-
static Map<String, Object> args = new HashMap<String, Object>();
47-
{
48-
args.put("alternate-exchange", "UME");
49-
}
50-
51-
public void testAlternateExchangeEquivalence() throws IOException {
52-
channel.exchangeDeclare("alternate", "direct", false, args);
53-
ExchangeDeclare.verifyEquivalent(channel, "alternate", "direct", false, args);
54-
}
55-
56-
public void testAlternateExchangeNonEquivalence() throws IOException {
57-
channel.exchangeDeclare("alternate", "direct", false, args);
58-
Map<String, Object> altargs = new HashMap<String, Object>();
59-
altargs.put("alternate-exchange", "somewhere");
60-
ExchangeDeclare.verifyNotEquivalent(channel, "alternate", "direct", false, altargs);
61-
}
62-
42+
static Map<String, Object> args = new HashMap<String, Object>();
43+
{
44+
args.put("alternate-exchange", "UME");
45+
}
46+
47+
public void testAlternateExchangeEquivalence() throws IOException {
48+
channel.exchangeDeclare("alternate", "direct", false, args);
49+
ExchangeDeclare.verifyEquivalent(channel, "alternate", "direct", false, args);
50+
}
51+
52+
public void testAlternateExchangeNonEquivalence() throws IOException {
53+
channel.exchangeDeclare("alternate", "direct", false, args);
54+
Map<String, Object> altargs = new HashMap<String, Object>();
55+
altargs.put("alternate-exchange", "somewhere");
56+
ExchangeDeclare.verifyNotEquivalent(channel, "alternate", "direct", false, altargs);
57+
}
6358
}

0 commit comments

Comments
 (0)