Skip to content

Commit e93ea3e

Browse files
author
Matthew Sackman
committed
Reflect the current value of the heartbeat interval in the connection state; after conn.close_ok, call setHeartbeat(0) rather than just setting _heartbeat = 0; and improve the heartbeat tests
1 parent f8199c5 commit e93ea3e

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ public int getHeartbeat() {
351351
public void setHeartbeat(int heartbeat) {
352352
try {
353353
_heartbeatSender.setHeartbeat(heartbeat);
354+
_heartbeat = heartbeat;
354355

355356
// Divide by four to make the maximum unwanted delay in
356357
// sending a timeout be less than a quarter of the
@@ -540,7 +541,7 @@ public void handleConnectionClose(Command closeCommand) {
540541
} catch (IOException ioe) {
541542
Utility.emptyStatement();
542543
}
543-
_heartbeat = 0; // Do not try to send heartbeats after CloseOk
544+
setHeartbeat(0); // Do not try to send heartbeats after CloseOk
544545
_brokerInitiatedShutdown = true;
545546
Thread scw = new SocketCloseWait(sse);
546547
scw.setName("AMQP Connection Closing Monitor " +

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ public Heartbeat()
4747
public void testHeartbeat()
4848
throws IOException, InterruptedException
4949
{
50+
assertEquals(1, connection.getHeartbeat());
5051
Thread.sleep(3100);
5152
assertTrue(connection.isOpen());
5253
((AMQConnection)connection).setHeartbeat(0);
54+
assertEquals(0, connection.getHeartbeat());
5355
Thread.sleep(3100);
5456
assertFalse(connection.isOpen());
5557

0 commit comments

Comments
 (0)