< Summary

Class:Microsoft.Azure.ServiceBus.Amqp.AmqpTransactionEnlistment
Assembly:Microsoft.Azure.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\Amqp\AmqpTransactionEnlistment.cs
Covered lines:0
Uncovered lines:51
Coverable lines:51
Total lines:112
Line coverage:0% (0 of 51)
Covered branches:0
Total branches:0

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-0%100%
get_AmqpTransactionId()-0%100%
OnCreateAsync()-0%100%
OnSafeClose(...)-0%100%
System.Transactions.IPromotableSinglePhaseNotification.Initialize()-0%100%
System.Transactions.IPromotableSinglePhaseNotification.SinglePhaseCommit(...)-0%100%
SinglePhaseCommitAsync()-0%100%
System.Transactions.IPromotableSinglePhaseNotification.Rollback(...)-0%100%
RollbackAsync()-0%100%
System.Transactions.ITransactionPromoter.Promote()-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\Amqp\AmqpTransactionEnlistment.cs

#LineLine coverage
 1// Copyright (c) Microsoft. All rights reserved.
 2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
 3
 4namespace Microsoft.Azure.ServiceBus.Amqp
 5{
 6    using System;
 7    using System.Threading.Tasks;
 8    using System.Transactions;
 9    using Microsoft.Azure.Amqp;
 10    using Microsoft.Azure.ServiceBus.Primitives;
 11
 12    class AmqpTransactionEnlistment : Singleton<AmqpTransactionEnlistment>, IPromotableSinglePhaseNotification
 13    {
 14        readonly string transactionId;
 15        readonly AmqpTransactionManager transactionManager;
 16        readonly ServiceBusConnection serviceBusConnection;
 17
 018        public AmqpTransactionEnlistment(
 019            Transaction transaction,
 020            AmqpTransactionManager transactionManager,
 021            ServiceBusConnection serviceBusConnection)
 22        {
 023            this.transactionId = transaction.TransactionInformation.LocalIdentifier;
 024            this.transactionManager = transactionManager;
 025            this.serviceBusConnection = serviceBusConnection;
 026        }
 27
 028        public ArraySegment<byte> AmqpTransactionId { get; private set; }
 29
 30        protected override async Task<AmqpTransactionEnlistment> OnCreateAsync(TimeSpan timeout)
 31        {
 32            try
 33            {
 034                var faultTolerantController = this.serviceBusConnection.TransactionController;
 035                var controller = await faultTolerantController.GetOrCreateAsync(this.serviceBusConnection.OperationTimeo
 036                this.AmqpTransactionId = await controller.DeclareAsync().ConfigureAwait(false);
 037                MessagingEventSource.Log.AmqpTransactionDeclared(this.transactionId, this.AmqpTransactionId);
 038                return this;
 39            }
 040            catch (Exception exception)
 41            {
 042                MessagingEventSource.Log.AmqpTransactionInitializeException(this.transactionId, exception);
 043                this.transactionManager.RemoveEnlistment(this.transactionId);
 044                throw;
 45            }
 046        }
 47
 48        protected override void OnSafeClose(AmqpTransactionEnlistment value)
 49        {
 050        }
 51
 52        void IPromotableSinglePhaseNotification.Initialize()
 53        {
 054        }
 55
 56        void IPromotableSinglePhaseNotification.SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
 57        {
 058            this.transactionManager.RemoveEnlistment(this.transactionId);
 059            TaskExtensionHelper.Schedule(() => this.SinglePhaseCommitAsync(singlePhaseEnlistment));
 060        }
 61
 62        async Task SinglePhaseCommitAsync(SinglePhaseEnlistment singlePhaseEnlistment)
 63        {
 64            try
 65            {
 066                var faultTolerantController = this.serviceBusConnection.TransactionController;
 067                var controller = await faultTolerantController.GetOrCreateAsync(this.serviceBusConnection.OperationTimeo
 68
 069                await controller.DischargeAsync(this.AmqpTransactionId, fail: false).ConfigureAwait(false);
 070                singlePhaseEnlistment.Committed();
 071                MessagingEventSource.Log.AmqpTransactionDischarged(this.transactionId, this.AmqpTransactionId, false);
 072                await this.CloseAsync().ConfigureAwait(false);
 073            }
 74            catch (Exception e)
 75            {
 076                Exception exception = AmqpExceptionHelper.GetClientException(e, null);
 077                MessagingEventSource.Log.AmqpTransactionDischargeException(this.transactionId, this.AmqpTransactionId, e
 078                singlePhaseEnlistment.InDoubt(exception);
 079            }
 080        }
 81
 82        void IPromotableSinglePhaseNotification.Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
 83        {
 084            this.transactionManager.RemoveEnlistment(this.transactionId);
 085            TaskExtensionHelper.Schedule(() => this.RollbackAsync(singlePhaseEnlistment));
 086        }
 87
 88        async Task RollbackAsync(SinglePhaseEnlistment singlePhaseEnlistment)
 89        {
 90            try
 91            {
 092                var faultTolerantController = this.serviceBusConnection.TransactionController;
 093                var controller = await faultTolerantController.GetOrCreateAsync(this.serviceBusConnection.OperationTimeo
 94
 095                await controller.DischargeAsync(this.AmqpTransactionId, fail: true).ConfigureAwait(false);
 096                singlePhaseEnlistment.Aborted();
 097                MessagingEventSource.Log.AmqpTransactionDischarged(this.transactionId, this.AmqpTransactionId, true);
 098            }
 99            catch (Exception e)
 100            {
 0101                Exception exception = AmqpExceptionHelper.GetClientException(e, null);
 0102                MessagingEventSource.Log.AmqpTransactionDischargeException(this.transactionId, this.AmqpTransactionId, e
 0103                singlePhaseEnlistment.Aborted(exception);
 0104            }
 0105        }
 106
 107        byte[] ITransactionPromoter.Promote()
 108        {
 0109            throw new TransactionPromotionException("Local transactions are not supported with other resource managers/D
 110        }
 111    }
 112}