@@ -62,9 +62,20 @@ func TestLargeTextMessage(t *testing.T) {
62
62
63
63
// The message is still left on the queue since it failed to be received successfully.
64
64
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
+ }
68
79
69
80
context2 , ctxErr2 := cf .CreateContext ()
70
81
assert .Nil (t , ctxErr2 )
@@ -78,7 +89,7 @@ func TestLargeTextMessage(t *testing.T) {
78
89
defer consumer2 .Close ()
79
90
}
80
91
81
- rcvMsg2 , errRcv2 := consumer2 .ReceiveNoWait ()
92
+ rcvMsg2 , errRcv2 := consumer2 .ReceiveNoWait () // receive the message using the correct (larger) buffer size
82
93
assert .Nil (t , errRcv2 )
83
94
assert .NotNil (t , rcvMsg2 )
84
95
@@ -134,9 +145,20 @@ func TestLargeReceiveStringBodyTextMessage(t *testing.T) {
134
145
135
146
// The message is still left on the queue since it failed to be received successfully.
136
147
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
+ }
140
162
141
163
context2 , ctxErr2 := cf .CreateContext ()
142
164
assert .Nil (t , ctxErr2 )
@@ -200,9 +222,20 @@ func TestLargeBytesMessage(t *testing.T) {
200
222
201
223
// The message is still left on the queue since it failed to be received successfully.
202
224
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
+ }
206
239
207
240
context2 , ctxErr2 := cf .CreateContext ()
208
241
assert .Nil (t , ctxErr2 )
@@ -273,9 +306,20 @@ func TestLargeReceiveBytesBodyBytesMessage(t *testing.T) {
273
306
274
307
// The message is still left on the queue since it failed to be received successfully.
275
308
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
+ }
279
323
280
324
context2 , ctxErr2 := cf .CreateContext ()
281
325
assert .Nil (t , ctxErr2 )
@@ -348,8 +392,21 @@ func TestTruncatedTextMessage(t *testing.T) {
348
392
assert .Fail (t , "Got something other than a text message" )
349
393
}
350
394
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
+ }
353
410
354
411
context2 , ctxErr2 := cf .CreateContext ()
355
412
assert .Nil (t , ctxErr2 )
0 commit comments