10
10
package main
11
11
12
12
import (
13
+ "github.com/ibm-messaging/mq-golang-jms20/jms20subset"
13
14
"github.com/ibm-messaging/mq-golang/v5/ibmmq"
14
15
"testing"
15
16
@@ -18,17 +19,18 @@ import (
18
19
)
19
20
20
21
func TestMQConnectionOptions (t * testing.T ) {
21
- t .Run ("MaxMsgLength" , func (t * testing.T ) {
22
+
23
+ t .Run ("MaxMsgLength set on CreateContext" , func (t * testing.T ) {
22
24
// Loads CF parameters from connection_info.json and applicationApiKey.json in the Downloads directory
23
25
cf , cfErr := mqjms .CreateConnectionFactoryFromDefaultJSONFiles ()
24
26
assert .Nil (t , cfErr )
25
27
26
28
// Ensure that the options were applied when setting connection options on Context creation
27
29
msg := "options were not applied"
28
30
context , ctxErr := cf .CreateContext (
29
- mqjms .WithMaxMsgLength (2000 ),
31
+ jms20subset .WithMaxMsgLength (2000 ),
30
32
func (cno * ibmmq.MQCNO ) {
31
- assert .Equal (t , 2000 , cno .ClientConn .MaxMsgLength )
33
+ assert .Equal (t , int32 ( 2000 ) , cno .ClientConn .MaxMsgLength )
32
34
msg = "options applied"
33
35
},
34
36
)
@@ -40,4 +42,45 @@ func TestMQConnectionOptions(t *testing.T) {
40
42
41
43
assert .Equal (t , "options applied" , msg )
42
44
})
45
+
46
+ t .Run ("MaxMsgLength is respected when receive message on CreateContextWithSessionMode" , func (t * testing.T ) {
47
+ // Loads CF parameters from connection_info.json and applicationApiKey.json in the Downloads directory
48
+ cf , cfErr := mqjms .CreateConnectionFactoryFromDefaultJSONFiles ()
49
+ assert .Nil (t , cfErr )
50
+
51
+ sContext , ctxErr := cf .CreateContext ()
52
+ assert .Nil (t , ctxErr )
53
+ if sContext != nil {
54
+ defer sContext .Close ()
55
+ }
56
+
57
+ // Create a Queue object that points at an IBM MQ queue
58
+ sQueue := sContext .CreateQueue ("DEV.QUEUE.1" )
59
+ // Send a message to the queue that contains a large string
60
+ errSend := sContext .CreateProducer ().SendString (sQueue , "This has more than data than the max message length" )
61
+ assert .NoError (t , errSend )
62
+
63
+ // create consumer with low msg length
64
+ rContext , ctxErr := cf .CreateContextWithSessionMode (
65
+ jms20subset .JMSContextAUTOACKNOWLEDGE ,
66
+ jms20subset .WithMaxMsgLength (20 ),
67
+ )
68
+ assert .Nil (t , ctxErr )
69
+ if rContext != nil {
70
+ defer rContext .Close ()
71
+ }
72
+
73
+ // Create a Queue object that points at an IBM MQ queue
74
+ rQueue := rContext .CreateQueue ("DEV.QUEUE.1" )
75
+ // Send a message to the queue that contains a large string
76
+ consumer , errSend := rContext .CreateConsumer (rQueue )
77
+ assert .NoError (t , errSend )
78
+
79
+ // expect that receiving the message will cause an JMS Data Length error
80
+ _ , err := consumer .ReceiveStringBodyNoWait ()
81
+ assert .Error (t , err )
82
+ jmsErr , ok := err .(jms20subset.JMSExceptionImpl )
83
+ assert .True (t , ok )
84
+ assert .Equal (t , "MQRC_DATA_LENGTH_ERROR" , jmsErr .GetReason ())
85
+ })
43
86
}
0 commit comments