Skip to content

Commit

Permalink
Clean up message after conn options test - #55
Browse files Browse the repository at this point in the history
  • Loading branch information
matrober-uk committed Nov 5, 2022
1 parent 44b5720 commit f1ffeae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
10 changes: 7 additions & 3 deletions jms20subset/ConnectionFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ type ConnectionFactory interface {

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

// CreateContextWithSessionMode creates a connection to the messaging provider using the
// configuration parameters that are encapsulated by this ConnectionFactory,
// and the specified session mode. Optional options can be provided to configure the
// connection prior to initialisation.
// and the specified session mode.
//
// Optional MQOptions can be provided to configure the connection prior to initialisation
// but are not typically required. Most calls to this function pass zero arguments.
CreateContextWithSessionMode(sessionMode int, opts ...MQOptions) (JMSContext, JMSException)
}
14 changes: 11 additions & 3 deletions mq_connection_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
package main

import (
"testing"

"github.com/ibm-messaging/mq-golang-jms20/jms20subset"
"github.com/ibm-messaging/mq-golang/v5/ibmmq"
"testing"

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

// expect that receiving the message will cause an JMS Data Length error
_, err := consumer.ReceiveStringBodyNoWait()
assert.Error(t, err)
jmsErr, ok := err.(jms20subset.JMSExceptionImpl)
assert.True(t, ok)
assert.Equal(t, "MQRC_DATA_LENGTH_ERROR", jmsErr.GetReason())

// Now consume the message sucessfully to tidy up before the next test.
tidyConsumer, errCons := sContext.CreateConsumer(sQueue)
assert.NoError(t, errCons)
gotMsg, err := tidyConsumer.ReceiveNoWait()
assert.NoError(t, err)
assert.NotNil(t, gotMsg)
})
}

0 comments on commit f1ffeae

Please sign in to comment.