Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up message after conn options test - #55 #56

Merged
merged 1 commit into from
Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
}