@@ -62,9 +62,20 @@ func TestLargeTextMessage(t *testing.T) {
6262
6363 // The message is still left on the queue since it failed to be received successfully.
6464
65- // Since the buffer size is configured using the ConnectionFactoy we will
66- // create a second connection in order to successfully retrieve the message.
67- cf .ReceiveBufferSize = len (txtOver32kb ) + 50
65+ // Use a special attribute of the returned exception to look up what the actual length of the
66+ // message is, so that we can correctly increase the buffer size in order to receive the message.
67+ switch jmsExc := errRcv .(type ) {
68+ case jms20subset.JMSExceptionImpl :
69+ realMessageLength := jmsExc .GetMessageLength ()
70+ assert .Equal (t , len (txtOver32kb ), realMessageLength ) // check it matches the original (long) length
71+
72+ // Since the buffer size is configured using the ConnectionFactory we will
73+ // create a second connection in order to successfully retrieve the message.
74+ cf .ReceiveBufferSize = realMessageLength
75+
76+ default :
77+ assert .Fail (t , "Got something other than a JMSExceptionImpl" )
78+ }
6879
6980 context2 , ctxErr2 := cf .CreateContext ()
7081 assert .Nil (t , ctxErr2 )
@@ -78,7 +89,7 @@ func TestLargeTextMessage(t *testing.T) {
7889 defer consumer2 .Close ()
7990 }
8091
81- rcvMsg2 , errRcv2 := consumer2 .ReceiveNoWait ()
92+ rcvMsg2 , errRcv2 := consumer2 .ReceiveNoWait () // receive the message using the correct (larger) buffer size
8293 assert .Nil (t , errRcv2 )
8394 assert .NotNil (t , rcvMsg2 )
8495
@@ -134,9 +145,20 @@ func TestLargeReceiveStringBodyTextMessage(t *testing.T) {
134145
135146 // The message is still left on the queue since it failed to be received successfully.
136147
137- // Since the buffer size is configured using the ConnectionFactory we will
138- // create a second connection in order to successfully retrieve the message.
139- cf .ReceiveBufferSize = len (txtOver32kb ) + 50
148+ // Use a special attribute of the returned exception to look up what the actual length of the
149+ // message is, so that we can correctly increase the buffer size in order to receive the message.
150+ switch jmsExc := errRcv .(type ) {
151+ case jms20subset.JMSExceptionImpl :
152+ realMessageLength := jmsExc .GetMessageLength ()
153+ assert .Equal (t , len (txtOver32kb ), realMessageLength ) // check it matches the original (long) length
154+
155+ // Since the buffer size is configured using the ConnectionFactory we will
156+ // create a second connection in order to successfully retrieve the message.
157+ cf .ReceiveBufferSize = realMessageLength
158+
159+ default :
160+ assert .Fail (t , "Got something other than a JMSExceptionImpl" )
161+ }
140162
141163 context2 , ctxErr2 := cf .CreateContext ()
142164 assert .Nil (t , ctxErr2 )
@@ -200,9 +222,20 @@ func TestLargeBytesMessage(t *testing.T) {
200222
201223 // The message is still left on the queue since it failed to be received successfully.
202224
203- // Since the buffer size is configured using the ConnectionFactoy we will
204- // create a second connection in order to successfully retrieve the message.
205- cf .ReceiveBufferSize = len (bytesOver32kb ) + 50
225+ // Use a special attribute of the returned exception to look up what the actual length of the
226+ // message is, so that we can correctly increase the buffer size in order to receive the message.
227+ switch jmsExc := errRcv .(type ) {
228+ case jms20subset.JMSExceptionImpl :
229+ realMessageLength := jmsExc .GetMessageLength ()
230+ assert .Equal (t , len (txtOver32kb ), realMessageLength ) // check it matches the original (long) length
231+
232+ // Since the buffer size is configured using the ConnectionFactory we will
233+ // create a second connection in order to successfully retrieve the message.
234+ cf .ReceiveBufferSize = realMessageLength
235+
236+ default :
237+ assert .Fail (t , "Got something other than a JMSExceptionImpl" )
238+ }
206239
207240 context2 , ctxErr2 := cf .CreateContext ()
208241 assert .Nil (t , ctxErr2 )
@@ -273,9 +306,20 @@ func TestLargeReceiveBytesBodyBytesMessage(t *testing.T) {
273306
274307 // The message is still left on the queue since it failed to be received successfully.
275308
276- // Since the buffer size is configured using the ConnectionFactoy we will
277- // create a second connection in order to successfully retrieve the message.
278- cf .ReceiveBufferSize = len (bytesOver32kb ) + 50
309+ // Use a special attribute of the returned exception to look up what the actual length of the
310+ // message is, so that we can correctly increase the buffer size in order to receive the message.
311+ switch jmsExc := errRcv .(type ) {
312+ case jms20subset.JMSExceptionImpl :
313+ realMessageLength := jmsExc .GetMessageLength ()
314+ assert .Equal (t , len (txtOver32kb ), realMessageLength ) // check it matches the original (long) length
315+
316+ // Since the buffer size is configured using the ConnectionFactory we will
317+ // create a second connection in order to successfully retrieve the message.
318+ cf .ReceiveBufferSize = realMessageLength
319+
320+ default :
321+ assert .Fail (t , "Got something other than a JMSExceptionImpl" )
322+ }
279323
280324 context2 , ctxErr2 := cf .CreateContext ()
281325 assert .Nil (t , ctxErr2 )
@@ -348,8 +392,21 @@ func TestTruncatedTextMessage(t *testing.T) {
348392 assert .Fail (t , "Got something other than a text message" )
349393 }
350394
351- // Make sure we tidy up in case the previous part of the test failed.
352- cf .ReceiveBufferSize = len (txtOver32kb ) + 50
395+ // Use a special attribute of the returned exception to look up what the actual length of the
396+ // message is, so that we can tidy up the message (read successfully) in the event the previous
397+ // step failed.
398+ switch jmsExc := errRcv .(type ) {
399+ case jms20subset.JMSExceptionImpl :
400+ realMessageLength := jmsExc .GetMessageLength ()
401+ assert .Equal (t , len (txtOver32kb ), realMessageLength ) // check it matches the original (long) length
402+
403+ // Since the buffer size is configured using the ConnectionFactory we will
404+ // create a second connection in order to successfully retrieve the message.
405+ cf .ReceiveBufferSize = realMessageLength
406+
407+ default :
408+ assert .Fail (t , "Got something other than a JMSExceptionImpl" )
409+ }
353410
354411 context2 , ctxErr2 := cf .CreateContext ()
355412 assert .Nil (t , ctxErr2 )
0 commit comments