Skip to content

Commit 0d7acfc

Browse files
author
Matthew Sackman
committed
merge bug 20729
2 parents c214a04 + bb24503 commit 0d7acfc

File tree

2 files changed

+54
-18
lines changed

2 files changed

+54
-18
lines changed

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

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,18 @@
3636
import com.rabbitmq.client.GetResponse;
3737
import com.rabbitmq.client.QueueingConsumer;
3838

39+
import com.rabbitmq.tools.Host;
40+
3941
import java.io.IOException;
4042

4143
/**
4244
* This tests whether bindings are created and nuked properly.
4345
*
46+
* The tests attempt to declare durable queues on a secondary node, if
47+
* present, and that node is restarted as part of the tests while the
48+
* primary node is still running. That way we exercise any node-down
49+
* handler code in the server.
50+
*
4451
* TODO: Adjust this test when Queue.Unbind is implemented in the
4552
* server
4653
*/
@@ -55,27 +62,56 @@ public class BindingLifecycle extends PersisterRestartBase {
5562
protected static final String X = "X-" + System.currentTimeMillis();
5663
protected static final String K = "K-" + System.currentTimeMillis();
5764

58-
/**
59-
* Create a durable queue on secondary node, if possible, falling
60-
* back on the primary node if necessary.
61-
*/
62-
@Override protected void declareDurableQueue(String q)
63-
throws IOException
64-
{
65-
Connection connection;
66-
try {
67-
connection = connectionFactory.newConnection("localhost", 5673);
68-
} catch (IOException e) {
69-
super.declareDurableQueue(q);
70-
return;
65+
public Connection secondaryConnection;
66+
public Channel secondaryChannel;
67+
68+
@Override public void openConnection() throws IOException {
69+
super.openConnection();
70+
if (secondaryConnection == null) {
71+
try {
72+
secondaryConnection = connectionFactory.newConnection("localhost", 5673);
73+
} catch (IOException e) {
74+
// just use a single node
75+
}
7176
}
77+
}
7278

73-
Channel channel = connection.createChannel();
79+
@Override public void closeConnection() throws IOException {
80+
if (secondaryConnection != null) {
81+
secondaryConnection.abort();
82+
secondaryConnection = null;
83+
}
84+
super.closeConnection();
85+
}
7486

75-
channel.queueDeclare(q, true);
87+
@Override public void openChannel() throws IOException {
88+
if (secondaryConnection != null) {
89+
secondaryChannel = secondaryConnection.createChannel();
90+
}
91+
super.openChannel();
92+
}
93+
94+
@Override public void closeChannel() throws IOException {
95+
if (secondaryChannel != null) {
96+
secondaryChannel.abort();
97+
secondaryChannel = null;
98+
}
99+
super.closeChannel();
100+
}
101+
102+
@Override protected void restart() throws IOException {
103+
if (secondaryConnection != null) {
104+
secondaryConnection.abort();
105+
secondaryConnection = null;
106+
secondaryChannel = null;
107+
Host.executeCommand("cd ../rabbitmq-test; make restart-secondary-node");
108+
}
109+
super.restart();
110+
}
76111

77-
channel.abort();
78-
connection.abort();
112+
@Override protected void declareDurableQueue(String q) throws IOException {
113+
(secondaryChannel == null ? channel : secondaryChannel).
114+
queueDeclare(q, true);
79115
}
80116

81117
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected void restart()
5858
throws IOException
5959
{
6060
tearDown();
61-
Host.executeCommand("cd ../rabbitmq-test; make restart-on-node");
61+
Host.executeCommand("cd ../rabbitmq-test; make restart-app");
6262
setUp();
6363
}
6464

0 commit comments

Comments
 (0)