3636import com .rabbitmq .client .GetResponse ;
3737import com .rabbitmq .client .QueueingConsumer ;
3838
39+ import com .rabbitmq .tools .Host ;
40+
3941import 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 /**
0 commit comments