@@ -93,17 +93,15 @@ public void testRejectExceedingFrameMax()
9393 {
9494 closeChannel ();
9595 closeConnection ();
96- Host . rabbitmqctl ( "eval 'application:set_env(rabbit, frame_max, 4096).'" );
97- ConnectionFactory cf = new ConnectionFactory ();
96+
97+ ConnectionFactory cf = new GenerousConnectionFactory ();
9898 connection = cf .newConnection ();
9999 openChannel ();
100100 try {
101- basicPublishVolatile (new byte [8196 ], "void" );
101+ basicPublishVolatile (new byte [connection . getFrameMax () ], "void" );
102102 channel .basicQos (0 );
103103 fail ("Expected exception when publishing" );
104104 } catch (IOException e ) {
105- } finally {
106- Host .rabbitmqctl ("eval 'application:set_env(rabbit, frame_max, 131072).'" );
107105 }
108106 }
109107
@@ -135,4 +133,55 @@ public Frame readFrame() throws IOException {
135133 return f ;
136134 }
137135 }
136+
137+ /*
138+ AMQConnection with a frame_max that is one higher than what it
139+ tells the server.
140+ */
141+ private static class GenerousAMQConnection extends AMQConnection {
142+
143+ public GenerousAMQConnection (ConnectionFactory factory ,
144+ FrameHandler handler ,
145+ ExecutorService executor ) {
146+ super (factory .getUsername (),
147+ factory .getPassword (),
148+ handler ,
149+ executor ,
150+ factory .getVirtualHost (),
151+ factory .getClientProperties (),
152+ factory .getRequestedFrameMax (),
153+ factory .getRequestedChannelMax (),
154+ factory .getRequestedHeartbeat (),
155+ factory .getSaslConfig ());
156+ }
157+
158+ @ Override public int getFrameMax () {
159+ // the RabbitMQ broker permits frames that are oversize by
160+ // up to EMPTY_FRAME_SIZE octets
161+ return super .getFrameMax () + AMQCommand .EMPTY_FRAME_SIZE + 1 ;
162+ }
163+
164+ }
165+
166+ private static class GenerousConnectionFactory extends ConnectionFactory {
167+
168+ @ Override public Connection newConnection (ExecutorService executor , Address [] addrs )
169+ throws IOException
170+ {
171+ IOException lastException = null ;
172+ for (Address addr : addrs ) {
173+ try {
174+ FrameHandler frameHandler = createFrameHandler (addr );
175+ AMQConnection conn = new GenerousAMQConnection (this , frameHandler , executor );
176+ conn .start ();
177+ return conn ;
178+ } catch (IOException e ) {
179+ lastException = e ;
180+ }
181+ }
182+ throw (lastException != null ) ? lastException
183+ : new IOException ("failed to connect" );
184+ }
185+ }
186+
138187}
0 commit comments