3535import com .rabbitmq .client .ConnectionFactory ;
3636import com .rabbitmq .client .Consumer ;
3737import com .rabbitmq .client .impl .AMQConnection ;
38- import com .rabbitmq .client .impl . ExceptionHandler ;
38+ import com .rabbitmq .client .ExceptionHandler ;
3939import com .rabbitmq .client .impl .Frame ;
4040import com .rabbitmq .client .impl .FrameHandler ;
4141
@@ -59,6 +59,7 @@ public static TestSuite suite() {
5959 /** The mock frame handler used to test connection behaviour. */
6060 private MockFrameHandler _mockFrameHandler ;
6161 private ConnectionFactory factory ;
62+ private MyExceptionHandler exceptionHandler ;
6263
6364 /** Setup the environment for this test
6465 * @see junit.framework.TestCase#setUp()
@@ -68,6 +69,8 @@ public static TestSuite suite() {
6869 super .setUp ();
6970 _mockFrameHandler = new MockFrameHandler ();
7071 factory = new ConnectionFactory ();
72+ exceptionHandler = new MyExceptionHandler ();
73+ factory .setExceptionHandler (exceptionHandler );
7174 }
7275
7376 /** Tear down the environment for this test
@@ -86,19 +89,17 @@ public static TestSuite suite() {
8689 public void testConnectionSendsSingleHeaderAndTimesOut () {
8790 IOException exception = new SocketTimeoutException ();
8891 _mockFrameHandler .setExceptionOnReadingFrames (exception );
89- MyExceptionHandler handler = new MyExceptionHandler ();
9092 assertEquals (0 , _mockFrameHandler .countHeadersSent ());
9193 try {
9294 ConnectionParams params = factory .params (Executors .newFixedThreadPool (1 ));
93- params .setExceptionHandler (handler );
9495 new AMQConnection (params , _mockFrameHandler ).start ();
9596 fail ("Connection should have thrown exception" );
9697 } catch (IOException signal ) {
9798 // As expected
9899 }
99100 assertEquals (1 , _mockFrameHandler .countHeadersSent ());
100101 // _connection.close(0, CLOSE_MESSAGE);
101- List <Throwable > exceptionList = handler .getHandledExceptions ();
102+ List <Throwable > exceptionList = exceptionHandler .getHandledExceptions ();
102103 assertEquals (Collections .<Throwable >singletonList (exception ), exceptionList );
103104 }
104105
@@ -120,19 +121,17 @@ public void testConnectionSendsSingleHeaderAndTimesOut() {
120121 */
121122 public void testConnectionHangInNegotiation () {
122123 this ._mockFrameHandler .setTimeoutCount (10 ); // to limit hang
123- MyExceptionHandler handler = new MyExceptionHandler ();
124124 assertEquals (0 , this ._mockFrameHandler .countHeadersSent ());
125125 try {
126126 ConnectionParams params = factory .params (Executors .newFixedThreadPool (1 ));
127- params .setExceptionHandler (handler );
128127 new AMQConnection (params , this ._mockFrameHandler ).start ();
129128 fail ("Connection should have thrown exception" );
130129 } catch (IOException signal ) {
131130 // As expected
132131 }
133132 assertEquals (1 , this ._mockFrameHandler .countHeadersSent ());
134133 // _connection.close(0, CLOSE_MESSAGE);
135- List <Throwable > exceptionList = handler .getHandledExceptions ();
134+ List <Throwable > exceptionList = exceptionHandler .getHandledExceptions ();
136135 assertEquals ("Only one exception expected" , 1 , exceptionList .size ());
137136 assertEquals ("Wrong type of exception returned." , SocketTimeoutException .class , exceptionList .get (0 ).getClass ());
138137 }
0 commit comments