Skip to content

Commit a1ef887

Browse files
authored
Merge pull request #56 from matrober-uk/pr55-tidyup
Clean up message after conn options test - #55
2 parents c12f9a5 + 612b0ee commit a1ef887

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

jms20subset/ConnectionFactory.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ type ConnectionFactory interface {
1818

1919
// CreateContext creates a connection to the messaging provider using the
2020
// configuration parameters that are encapsulated by this ConnectionFactory.
21-
// Optional options can be provided to configure the connection prior to initialisation.
21+
//
22+
// Optional MQOptions can be provided to configure the connection prior to initialisation
23+
// but are not typically required. Most calls to this function pass zero arguments.
2224
//
2325
// Defaults to sessionMode of JMSContextAUTOACKNOWLEDGE
2426
CreateContext(opts ...MQOptions) (JMSContext, JMSException)
2527

2628
// CreateContextWithSessionMode creates a connection to the messaging provider using the
2729
// configuration parameters that are encapsulated by this ConnectionFactory,
28-
// and the specified session mode. Optional options can be provided to configure the
29-
// connection prior to initialisation.
30+
// and the specified session mode.
31+
//
32+
// Optional MQOptions can be provided to configure the connection prior to initialisation
33+
// but are not typically required. Most calls to this function pass zero arguments.
3034
CreateContextWithSessionMode(sessionMode int, opts ...MQOptions) (JMSContext, JMSException)
3135
}

mq_connection_options_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
package main
1111

1212
import (
13+
"testing"
14+
1315
"github.com/ibm-messaging/mq-golang-jms20/jms20subset"
1416
"github.com/ibm-messaging/mq-golang/v5/ibmmq"
15-
"testing"
1617

1718
"github.com/ibm-messaging/mq-golang-jms20/mqjms"
1819
"github.com/stretchr/testify/assert"
@@ -73,14 +74,21 @@ func TestMQConnectionOptions(t *testing.T) {
7374
// Create a Queue object that points at an IBM MQ queue
7475
rQueue := rContext.CreateQueue("DEV.QUEUE.1")
7576
// Send a message to the queue that contains a large string
76-
consumer, errSend := rContext.CreateConsumer(rQueue)
77-
assert.NoError(t, errSend)
77+
consumer, errCons := rContext.CreateConsumer(rQueue)
78+
assert.NoError(t, errCons)
7879

7980
// expect that receiving the message will cause an JMS Data Length error
8081
_, err := consumer.ReceiveStringBodyNoWait()
8182
assert.Error(t, err)
8283
jmsErr, ok := err.(jms20subset.JMSExceptionImpl)
8384
assert.True(t, ok)
8485
assert.Equal(t, "MQRC_DATA_LENGTH_ERROR", jmsErr.GetReason())
86+
87+
// Now consume the message sucessfully to tidy up before the next test.
88+
tidyConsumer, errCons := sContext.CreateConsumer(sQueue)
89+
assert.NoError(t, errCons)
90+
gotMsg, err := tidyConsumer.ReceiveNoWait()
91+
assert.NoError(t, err)
92+
assert.NotNil(t, gotMsg)
8593
})
8694
}

0 commit comments

Comments
 (0)