Skip to content

Commit 229f5c7

Browse files
committed
use mqput1 instead of mqopen mqput and mqclose, closes #37
1 parent 8999e62 commit 229f5c7

File tree

4 files changed

+151
-155
lines changed

4 files changed

+151
-155
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
mq-golang-jms20.test
22
vendor
33
.DS_Store
4+
.idea

asyncput_test.go

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func TestAsyncPutCheckCountWithFailure(t *testing.T) {
296296

297297
// Messages will start to fail at number 25 but we don't get an error until
298298
// the next check which takes place at 30.
299-
if i == 0 && errSend != nil && errSend.GetReason() == "MQRC_UNKNOWN_OBJECT_NAME" {
299+
if i == 0 && isUnknownObjectName(errSend) {
300300

301301
fmt.Println("Skipping TestAsyncPutCheckCountWithFailure as queue " + QUEUE_25_NAME + " is not defined.")
302302
queueExists = false
@@ -575,19 +575,19 @@ func TestAsyncPutTransactedCheckCountWithFailure(t *testing.T) {
575575

576576
errSend2 := producer.Send(asyncQueue, msg)
577577

578-
// Skip the test if the destination does not exist on this queue manager.
579-
if i == 0 && errSend2 != nil && errSend2.GetReason() == "MQRC_UNKNOWN_OBJECT_NAME" {
580-
581-
fmt.Println("Skipping TestAsyncPutTransactedCheckCountWithFailure as queue " + QUEUE_25_NAME + " is not defined.")
582-
queueExists = false
583-
break // Stop the loop at this point as we know it won't change.
584-
585-
}
586-
587578
// In the Transacted case the response from Send is always Nil, because any errors
588579
// will be reflected on the Commit call.
589580
assert.Nil(t, errSend2)
590581

582+
// Skip the test if the destination does not exist on this queue manager.
583+
if i == 0 {
584+
if err := transactedContext.Commit(); isUnknownObjectName(err) {
585+
fmt.Println("Skipping TestAsyncPutTransactedCheckCountWithFailure as queue " + QUEUE_25_NAME + " is not defined.")
586+
queueExists = false
587+
break // Stop the loop at this point as we know it won't change.
588+
}
589+
}
590+
591591
if i%10 == 0 {
592592
commitErr := transactedContext.Commit()
593593

@@ -695,15 +695,6 @@ func TestAsyncPutTransactedNonPersistentCheckCountWithFailure(t *testing.T) {
695695

696696
errSend2 := producer.Send(asyncQueue, msg)
697697

698-
// Skip the test if the destination does not exist on this queue manager.
699-
if i == 0 && errSend2 != nil && errSend2.GetReason() == "MQRC_UNKNOWN_OBJECT_NAME" {
700-
701-
fmt.Println("Skipping TestAsyncPutTransactedNonPersistentCheckCountWithFailure as queue " + QUEUE_25_NAME + " is not defined.")
702-
queueExists = false
703-
break // Stop the loop at this point as we know it won't change.
704-
705-
}
706-
707698
// In the Transacted case the response from Send is always Nil, because any errors
708699
// will be reflected on the Commit call.
709700
assert.Nil(t, errSend2)
@@ -717,12 +708,19 @@ func TestAsyncPutTransactedNonPersistentCheckCountWithFailure(t *testing.T) {
717708
}
718709
}
719710

711+
// ----------------------------------
712+
// Receive the messages back again to tidy the queue back to a clean state
713+
consumer, errCons := transactedContext.CreateConsumer(asyncQueue)
714+
715+
// Skip the test if the destination does not exist on this queue manager.
716+
if isUnknownObjectName(errCons) {
717+
fmt.Println("Skipping TestAsyncPutTransactedNonPersistentCheckCountWithFailure as queue " + QUEUE_25_NAME + " is not defined.")
718+
queueExists = false
719+
}
720+
720721
// If the queue exists then tidy up the messages we sent.
721722
if queueExists {
722723

723-
// ----------------------------------
724-
// Receive the messages back again to tidy the queue back to a clean state
725-
consumer, errCons := transactedContext.CreateConsumer(asyncQueue)
726724
assert.Nil(t, errCons)
727725
if consumer != nil {
728726
defer consumer.Close()
@@ -743,3 +741,15 @@ func TestAsyncPutTransactedNonPersistentCheckCountWithFailure(t *testing.T) {
743741
transactedContext.Commit()
744742
}
745743
}
744+
745+
func isUnknownObjectName(exception jms20subset.JMSException) bool {
746+
if exception != nil {
747+
if exception.GetReason() == "MQRC_UNKNOWN_OBJECT_NAME" {
748+
return true
749+
}
750+
if err, ok := exception.GetLinkedError().(jms20subset.JMSExceptionImpl); ok {
751+
return err.GetReason() == "MQRC_UNKNOWN_OBJECT_NAME" || isUnknownObjectName(err)
752+
}
753+
}
754+
return false
755+
}

largemessage_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package main
1111

1212
import (
13+
"strconv"
1314
"testing"
1415
"time"
1516

@@ -299,7 +300,7 @@ func getStringOver32kb() string {
299300
// Build a text string which is over 32KB (in a not very efficient way!)
300301
// First snippet is 100 chars long.
301302
txt100chars := "The quick brown fox jumped over the lazy dog into the flowing river that rushed over the cliff edge."
302-
txt1300chars := string(time.Now().UnixNano()) + txt100chars + txt100chars + txt100chars + txt100chars + txt100chars +
303+
txt1300chars := strconv.FormatInt(time.Now().UnixNano(), 10) + txt100chars + txt100chars + txt100chars + txt100chars + txt100chars +
303304
txt100chars + txt100chars + txt100chars + txt100chars + txt100chars +
304305
txt100chars + txt100chars + txt100chars
305306

0 commit comments

Comments
 (0)