36
36
import com .rabbitmq .client .GetResponse ;
37
37
import com .rabbitmq .client .QueueingConsumer ;
38
38
39
+ import com .rabbitmq .tools .Host ;
40
+
39
41
import java .io .IOException ;
40
42
41
43
/**
42
44
* This tests whether bindings are created and nuked properly.
43
45
*
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
+ *
44
51
* TODO: Adjust this test when Queue.Unbind is implemented in the
45
52
* server
46
53
*/
@@ -55,27 +62,56 @@ public class BindingLifecycle extends PersisterRestartBase {
55
62
protected static final String X = "X-" + System .currentTimeMillis ();
56
63
protected static final String K = "K-" + System .currentTimeMillis ();
57
64
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
+ }
71
76
}
77
+ }
72
78
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
+ }
74
86
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
+ }
76
111
77
- channel .abort ();
78
- connection .abort ();
112
+ @ Override protected void declareDurableQueue (String q ) throws IOException {
113
+ (secondaryChannel == null ? channel : secondaryChannel ).
114
+ queueDeclare (q , true );
79
115
}
80
116
81
117
/**
0 commit comments