4242import com .rabbitmq .client .GetResponse ;
4343import com .rabbitmq .client .MessageProperties ;
4444import com .rabbitmq .client .ShutdownSignalException ;
45-
45+ import com .rabbitmq .client .AlreadyClosedException ;
46+ import com .rabbitmq .client .impl .ShutdownNotifierComponent ;
4647import com .rabbitmq .client .AMQP ;
4748
4849public class BrokerTestCase extends TestCase
@@ -128,6 +129,16 @@ public void closeChannel()
128129
129130 public void checkShutdownSignal (int expectedCode , IOException ioe ) {
130131 ShutdownSignalException sse = (ShutdownSignalException ) ioe .getCause ();
132+ checkShutdownSignal (expectedCode , sse );
133+ }
134+
135+ public void checkShutdownSignal (int expectedCode , AlreadyClosedException ace ) {
136+ ShutdownNotifierComponent snc = (ShutdownNotifierComponent ) ace .getReference ();
137+ ShutdownSignalException sse = snc .getCloseReason ();
138+ checkShutdownSignal (expectedCode , sse );
139+ }
140+
141+ public void checkShutdownSignal (int expectedCode , ShutdownSignalException sse ) {
131142 Command closeCommand = (Command ) sse .getReason ();
132143 channel = null ;
133144 if (sse .isHardError ()) {
@@ -140,6 +151,20 @@ public void checkShutdownSignal(int expectedCode, IOException ioe) {
140151 }
141152 }
142153
154+ public void expectChannelError (int error ) {
155+ try {
156+ channel .basicQos (0 );
157+ fail ("Expected channel error " + error );
158+ } catch (IOException ioe ) {
159+ // If we get a channel close back when flushing it with the
160+ // synchronous basicQos above.
161+ checkShutdownSignal (error , ioe );
162+ } catch (AlreadyClosedException ace ) {
163+ // If it has already closed of its own accord before we got there.
164+ checkShutdownSignal (error , ace );
165+ }
166+ }
167+
143168 protected void assertDelivered (String q , int count ) throws IOException {
144169 assertDelivered (q , count , false );
145170 }
0 commit comments