@@ -296,7 +296,7 @@ func TestAsyncPutCheckCountWithFailure(t *testing.T) {
296
296
297
297
// Messages will start to fail at number 25 but we don't get an error until
298
298
// 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 ) {
300
300
301
301
fmt .Println ("Skipping TestAsyncPutCheckCountWithFailure as queue " + QUEUE_25_NAME + " is not defined." )
302
302
queueExists = false
@@ -575,19 +575,19 @@ func TestAsyncPutTransactedCheckCountWithFailure(t *testing.T) {
575
575
576
576
errSend2 := producer .Send (asyncQueue , msg )
577
577
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
-
587
578
// In the Transacted case the response from Send is always Nil, because any errors
588
579
// will be reflected on the Commit call.
589
580
assert .Nil (t , errSend2 )
590
581
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
+
591
591
if i % 10 == 0 {
592
592
commitErr := transactedContext .Commit ()
593
593
@@ -695,15 +695,6 @@ func TestAsyncPutTransactedNonPersistentCheckCountWithFailure(t *testing.T) {
695
695
696
696
errSend2 := producer .Send (asyncQueue , msg )
697
697
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
-
707
698
// In the Transacted case the response from Send is always Nil, because any errors
708
699
// will be reflected on the Commit call.
709
700
assert .Nil (t , errSend2 )
@@ -717,12 +708,19 @@ func TestAsyncPutTransactedNonPersistentCheckCountWithFailure(t *testing.T) {
717
708
}
718
709
}
719
710
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
+
720
721
// If the queue exists then tidy up the messages we sent.
721
722
if queueExists {
722
723
723
- // ----------------------------------
724
- // Receive the messages back again to tidy the queue back to a clean state
725
- consumer , errCons := transactedContext .CreateConsumer (asyncQueue )
726
724
assert .Nil (t , errCons )
727
725
if consumer != nil {
728
726
defer consumer .Close ()
@@ -743,3 +741,15 @@ func TestAsyncPutTransactedNonPersistentCheckCountWithFailure(t *testing.T) {
743
741
transactedContext .Commit ()
744
742
}
745
743
}
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
+ }
0 commit comments