8000 Merge branch 'rabbitmq-java-client-81' into stable · panchenko/rabbitmq-java-client@d9e8f02 · GitHub
[go: up one dir, main page]

Skip to content

Commit d9e8f02

Browse files
Merge branch 'rabbitmq-java-client-81' into stable
2 parents b93263d + 49d2911 commit d9e8f02

File tree

2 files changed

+59
-8
lines changed

2 files changed

+59
-8
lines changed

src/com/rabbitmq/client/ConnectionFactory.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,17 @@ public int getRequestedHeartbeat() {
315315

316316
/**
317317
* Set the TCP connection timeout.
318-
* @param connectionTimeout connection TCP establishment timeout in milliseconds; zero for infinite
318+
* @param timeout connection TCP establishment timeout in milliseconds; zero for infinite
319319
*/
320-
public void setConnectionTimeout(int connectionTimeout) {
321-
8000 this.connectionTimeout = connectionTimeout;
320+
public void setConnectionTimeout(int timeout) {
321+
if(timeout < 0) {
322+
throw new IllegalArgumentException("TCP connection timeout cannot be negative");
323+
}
324+
if(timeout > handshakeTimeout) {
325+
throw new IllegalArgumentException("TCP connection timeout cannot be greater than handshake timeout");
326+
} else {
327+
this.connectionTimeout = timeout;
328+
}
322329
}
323330

324331
/**
@@ -339,13 +346,16 @@ public int getHandshakeTimeout() {
339346

340347
/**
341348
* Set the AMQP0-9-1 protocol handshake timeout.
342-
* @param handshakeTimeout the AMQP0-9-1 protocol handshake timeout, in milliseconds
349+
* @param timeout the AMQP0-9-1 protocol handshake timeout, in milliseconds
343350
*/
344-
public void setHandshakeTimeout(int handshakeTimeout) {
345-
if(handshakeTimeout < connectionTimeout) {
346-
this.handshakeTimeout = handshakeTimeout;
347-
} else {
351+
public void setHandshakeTimeout(int timeout) {
352+
if(timeout < 0) {
353+
throw new IllegalArgumentException("handshake timeout cannot be negative");
354+
}
355+
if(connectionTimeout != 0 && timeout < connectionTimeout) {
348356
throw new IllegalArgumentException("handshake timeout cannot be lower than TCP connection timeout");
357+
} else {
358+
this.handshakeTimeout = timeout;
349359
}
350360
}
351361

test/src/com/rabbitmq/client/test/AMQConnectionTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,47 @@ public static TestSuite suite() {
8484
super.tearDown();
8585
}
8686

87+
public void testNegativeTCPConnectionTimeout() {
88+
ConnectionFactory cf = new ConnectionFactory();
89+
try {
90+
cf.setConnectionTimeout(-10);
91+
fail("expected an exception");
92+
} catch (IllegalArgumentException _ignored) {
93+
// expected
94+
}
95+
}
96+
97+
public void testNegativeProtocolHandshakeTimeout() {
98+
ConnectionFactory cf = new ConnectionFactory();
99+
try {
100+
cf.setHandshakeTimeout(-10);
101+
fail("expected an exception");
102+
} catch (IllegalArgumentException _ignored) {
103+
// expected
104+
}
105+
}
106+
107+
public void testTCPConnectionTimeoutGreaterThanHandShakeTimeout() {
108+
ConnectionFactory cf = new ConnectionFactory();
109+
try {
110+
cf.setHandshakeTimeout(3000);
111+ cf.setConnectionTimeout(5000);
112+
fail("expected an exception");
113+
} catch (IllegalArgumentException _ignored) {
114+
// expected
115+
}
116+
}
117+
118+
public void testProtocolHandshakeTimeoutGreaterThanTCPConnectionTimeout() {
119+
ConnectionFactory cf = new ConnectionFactory();
120+
121+
cf.setConnectionTimeout(5000);
122+
cf.setHandshakeTimeout(7000);
123+
124+
cf.setConnectionTimeout(0);
125+
cf.setHandshakeTimeout(7000);
126+
}
127+
87128
/** Check the AMQConnection does send exactly 1 initial header, and deal correctly with
88129
* the frame handler throwing an exception when we try to read data
89130
*/

0 commit comments

Comments
 (0)
0