@@ -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+ }
0 commit comments