@@ -67,42 +67,42 @@ public void testNativeTransformation() throws Exception {
6767 startBrokerWithAmqpTransport (String .format (AMQP_URL , "?transport.transformer=native" ));
6868
6969 // send "text message" with AMQP JMS API
70- Connection amqpConnection = JMSClientContext .INSTANCE .createConnection (amqpConnectionURI );
71- amqpConnection .start ();
70+ try ( Connection amqpConnection = JMSClientContext .INSTANCE .createConnection (amqpConnectionURI )) {
71+ amqpConnection .start ();
7272
73- Session amqpSession = amqpConnection .createSession (false , Session .AUTO_ACKNOWLEDGE );
74- Queue queue = amqpSession .createQueue (TEST_QUEUE );
75- MessageProducer p = amqpSession .createProducer (queue );
76- p .setPriority (7 );
73+ Session amqpSession = amqpConnection .createSession (false , Session .AUTO_ACKNOWLEDGE );
74+ Queue queue = amqpSession .createQueue (TEST_QUEUE );
75+ MessageProducer p = amqpSession .createProducer (queue );
76+ p .setPriority (7 );
7777
78- TextMessage amqpMessage = amqpSession .createTextMessage ();
79- amqpMessage .setText ("hello" );
80- p .send (amqpMessage );
78+ TextMessage amqpMessage = amqpSession .createTextMessage ();
79+ amqpMessage .setText ("hello" );
80+ p .send (amqpMessage );
8181
82- p .close ();
83- amqpSession .close ();
84- amqpConnection . close ();
82+ p .close ();
83+ amqpSession .close ();
84+ }
8585
8686 // receive with openwire JMS
8787 ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory (openwireConnectionURI );
88- Connection openwireConn = factory .createConnection ();
89- openwireConn .start ();
90- Session session = openwireConn .createSession (false , Session .AUTO_ACKNOWLEDGE );
91- Queue jmsDest = session .createQueue (TEST_QUEUE );
88+ try ( Connection openwireConn = factory .createConnection ()) {
89+ openwireConn .start ();
90+ Session session = openwireConn .createSession (false , Session .AUTO_ACKNOWLEDGE );
91+ Queue jmsDest = session .createQueue (TEST_QUEUE );
9292
93- MessageConsumer c = session .createConsumer (jmsDest );
93+ MessageConsumer c = session .createConsumer (jmsDest );
9494
95- Message message = c .receive (1000 );
95+ Message message = c .receive (1000 );
9696
97- assertTrue (message instanceof BytesMessage );
98- Boolean nativeTransformationUsed = message .getBooleanProperty ("JMS_AMQP_NATIVE" );
99- assertTrue ("Didn't use the correct transformation, expected NATIVE" , nativeTransformationUsed );
100- assertEquals (DeliveryMode .PERSISTENT , message .getJMSDeliveryMode ());
101- assertEquals (7 , message .getJMSPriority ());
97+ assertTrue (message instanceof BytesMessage );
98+ Boolean nativeTransformationUsed = message .getBooleanProperty ("JMS_AMQP_NATIVE" );
99+ assertTrue ("Didn't use the correct transformation, expected NATIVE" , nativeTransformationUsed );
100+ assertEquals (DeliveryMode .PERSISTENT , message .getJMSDeliveryMode ());
101+ assertEquals (7 , message .getJMSPriority ());
102102
103- c .close ();
104- session .close ();
105- openwireConn . close ();
103+ c .close ();
104+ session .close ();
105+ }
106106 }
107107
108108 @ Test (timeout = 30000 )
@@ -112,46 +112,46 @@ public void testRawTransformation() throws Exception {
112112 startBrokerWithAmqpTransport (String .format (AMQP_URL , "?transport.transformer=raw" ));
113113
114114 // send "text message" with AMQP JMS API
115- Connection amqpConnection = JMSClientContext .INSTANCE .createConnection (amqpConnectionURI );
116- amqpConnection .start ();
115+ try ( Connection amqpConnection = JMSClientContext .INSTANCE .createConnection (amqpConnectionURI )) {
116+ amqpConnection .start ();
117117
118- Session amqpSession = amqpConnection .createSession (false , Session .AUTO_ACKNOWLEDGE );
119- Queue queue = amqpSession .createQueue (TEST_QUEUE );
120- MessageProducer p = amqpSession .createProducer (queue );
121- p .setPriority (7 );
118+ Session amqpSession = amqpConnection .createSession (false , Session .AUTO_ACKNOWLEDGE );
119+ Queue queue = amqpSession .createQueue (TEST_QUEUE );
120+ MessageProducer p = amqpSession .createProducer (queue );
121+ p .setPriority (7 );
122122
123- TextMessage amqpMessage = amqpSession .createTextMessage ();
124- amqpMessage .setText ("hello" );
125- p .send (amqpMessage );
123+ TextMessage amqpMessage = amqpSession .createTextMessage ();
124+ amqpMessage .setText ("hello" );
125+ p .send (amqpMessage );
126126
127- p .close ();
128- amqpSession .close ();
129- amqpConnection . close ();
127+ p .close ();
128+ amqpSession .close ();
129+ }
130130
131131 // receive with openwire JMS
132132 ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory (openwireConnectionURI );
133- Connection openwireConn = factory .createConnection ();
134- openwireConn .start ();
135- Session session = openwireConn .createSession (false , Session .AUTO_ACKNOWLEDGE );
136- Queue jmsDest = session .createQueue (TEST_QUEUE );
133+ try ( Connection openwireConn = factory .createConnection ()) {
134+ openwireConn .start ();
135+ Session session = openwireConn .createSession (false , Session .AUTO_ACKNOWLEDGE );
136+ Queue jmsDest = session .createQueue (TEST_QUEUE );
137137
138- MessageConsumer c = session .createConsumer (jmsDest );
138+ MessageConsumer c = session .createConsumer (jmsDest );
139139
140- Message message = c .receive (2000 );
140+ Message message = c .receive (2000 );
141141
142- assertNotNull ("Should have received a message" , message );
143- LOG .info ("Recieved message: {}" , message );
144- assertTrue (message instanceof BytesMessage );
145- Boolean nativeTransformationUsed = message .getBooleanProperty ("JMS_AMQP_NATIVE" );
146- assertTrue ("Didn't use the correct transformation, expected NATIVE" , nativeTransformationUsed );
147- assertEquals (DeliveryMode .PERSISTENT , message .getJMSDeliveryMode ());
142+ assertNotNull ("Should have received a message" , message );
143+ LOG .info ("Received message: {}" , message );
144+ assertTrue (message instanceof BytesMessage );
145+ Boolean nativeTransformationUsed = message .getBooleanProperty ("JMS_AMQP_NATIVE" );
146+ assertTrue ("Didn't use the correct transformation, expected NATIVE" , nativeTransformationUsed );
147+ assertEquals (DeliveryMode .PERSISTENT , message .getJMSDeliveryMode ());
148148
149- // should not equal 7 (should equal the default) because "raw" does not map headers
150- assertEquals (4 , message .getJMSPriority ());
149+ // should not equal 7 (should equal the default) because "raw" does not map headers
150+ assertEquals (4 , message .getJMSPriority ());
151151
152- c .close ();
153- session .close ();
154- openwireConn . close ();
152+ c .close ();
153+ session .close ();
154+ }
155155 }
156156
157157 @ Test (timeout = 30 * 1000 )
@@ -161,40 +161,40 @@ public void testJmsTransformation() throws Exception {
161161 startBrokerWithAmqpTransport (String .format (AMQP_URL , "?transport.transformer=jms" ));
162162
163163 // send "text message" with AMQP JMS API
164- Connection amqpConnection = JMSClientContext .INSTANCE .createConnection (amqpConnectionURI );
165- amqpConnection .start ();
164+ try ( Connection amqpConnection = JMSClientContext .INSTANCE .createConnection (amqpConnectionURI )) {
165+ amqpConnection .start ();
166166
167- Session amqpSession = amqpConnection .createSession (false , Session .AUTO_ACKNOWLEDGE );
168- Queue queue = amqpSession .createQueue (TEST_QUEUE );
169- MessageProducer p = amqpSession .createProducer (queue );
167+ Session amqpSession = amqpConnection .createSession (false , Session .AUTO_ACKNOWLEDGE );
168+ Queue queue = amqpSession .createQueue (TEST_QUEUE );
169+ MessageProducer p = amqpSession .createProducer (queue );
170170
171- TextMessage amqpMessage = amqpSession .createTextMessage ();
172- amqpMessage .setText ("hello" );
173- p .send (amqpMessage );
171+ TextMessage amqpMessage = amqpSession .createTextMessage ();
172+ amqpMessage .setText ("hello" );
173+ p .send (amqpMessage );
174174
175- p .close ();
176- amqpSession .close ();
177- amqpConnection . close ();
175+ p .close ();
176+ amqpSession .close ();
177+ }
178178
179179 // receive with openwire JMS
180180 ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory (openwireConnectionURI );
181- Connection openwireConn = factory .createConnection ();
182- openwireConn .start ();
183- Session session = openwireConn .createSession (false , Session .AUTO_ACKNOWLEDGE );
184- Queue jmsDest = session .createQueue (TEST_QUEUE );
181+ try ( Connection openwireConn = factory .createConnection ()) {
182+ openwireConn .start ();
183+ Session session = openwireConn .createSession (false , Session .AUTO_ACKNOWLEDGE );
184+ Queue jmsDest = session .createQueue (TEST_QUEUE );
185185
186- MessageConsumer c = session .createConsumer (jmsDest );
186+ MessageConsumer c = session .createConsumer (jmsDest );
187187
188- Message message = c .receive (1000 );
188+ Message message = c .receive (1000 );
189189
190- assertTrue (message instanceof TextMessage );
191- Boolean nativeTransformationUsed = message .getBooleanProperty ("JMS_AMQP_NATIVE" );
192- assertFalse ("Didn't use the correct transformation, expected NOT to be NATIVE" , nativeTransformationUsed );
193- assertEquals (DeliveryMode .PERSISTENT , message .getJMSDeliveryMode ());
190+ assertTrue (message instanceof TextMessage );
191+ Boolean nativeTransformationUsed = message .getBooleanProperty ("JMS_AMQP_NATIVE" );
192+ assertFalse ("Didn't use the correct transformation, expected NOT to be NATIVE" , nativeTransformationUsed );
193+ assertEquals (DeliveryMode .PERSISTENT , message .getJMSDeliveryMode ());
194194
195- c .close ();
196- session .close ();
197- openwireConn . close ();
195+ c .close ();
196+ session .close ();
197+ }
198198 }
199199
200200 @ Test (timeout = 60000 )
@@ -225,20 +225,14 @@ public void testSendAMQPMessageWithComplexAnnotationsReceiveCore() throws Except
225225 session .close ();
226226
227227 ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory (openwireConnectionURI );
228- Connection connection2 = factory .createConnection ();
229- try {
230-
228+ try (Connection connection2 = factory .createConnection ()) {
231229 Session session2 = connection2 .createSession (false , Session .AUTO_ACKNOWLEDGE );
232230 connection2 .start ();
233231 MessageConsumer consumer = session2 .createConsumer (session2 .createQueue (TEST_QUEUE ));
234232
235233 Message received = consumer .receive (5000 );
236234 assertNotNull (received );
237235 assertEquals (42 , received .getIntProperty ("IntProperty" ));
238-
239- connection2 .close ();
240- } finally {
241- connection2 .close ();
242236 }
243237 } finally {
244238 connection .close ();
0 commit comments