< Summary

Class:Azure.Messaging.ServiceBus.Amqp.AmqpTransactionManager
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Amqp\AmqpTransactionManager.cs
Covered lines:0
Uncovered lines:25
Coverable lines:25
Total lines:62
Line coverage:0% (0 of 25)
Covered branches:0
Total branches:6
Branch coverage:0% (0 of 6)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor()-0%100%
get_Instance()-0%100%
EnlistAsync()-0%0%
RemoveEnlistment(...)-0%100%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Threading.Tasks;
 7using System.Transactions;
 8
 9namespace Azure.Messaging.ServiceBus.Amqp
 10{
 11    internal class AmqpTransactionManager
 12    {
 013        private readonly object _syncRoot = new object();
 014        private readonly Dictionary<string, AmqpTransactionEnlistment> _enlistmentMap = new Dictionary<string, AmqpTrans
 15
 016        public static AmqpTransactionManager Instance { get; } = new AmqpTransactionManager();
 17
 18        public async Task<ArraySegment<byte>> EnlistAsync(
 19            Transaction transaction,
 20            AmqpConnectionScope connectionScope,
 21            TimeSpan timeout)
 22        {
 023            if (transaction.IsolationLevel != IsolationLevel.Serializable)
 24            {
 025                throw new InvalidOperationException($"The only supported IsolationLevel is {nameof(IsolationLevel.Serial
 26            }
 27
 028            string transactionId = transaction.TransactionInformation.LocalIdentifier;
 29            AmqpTransactionEnlistment transactionEnlistment;
 30
 031            lock (_syncRoot)
 32            {
 033                if (!_enlistmentMap.TryGetValue(transactionId, out transactionEnlistment))
 34                {
 035                    transactionEnlistment = new AmqpTransactionEnlistment(
 036                        transaction,
 037                        this,
 038                        connectionScope,
 039                        timeout);
 040                    _enlistmentMap.Add(transactionId, transactionEnlistment);
 41
 042                    if (!transaction.EnlistPromotableSinglePhase(transactionEnlistment))
 43                    {
 044                        _enlistmentMap.Remove(transactionId);
 045                        throw new InvalidOperationException("Local transactions are not supported with other resource ma
 46                    }
 47                }
 048            }
 49
 050            transactionEnlistment = await transactionEnlistment.GetOrCreateAsync(timeout).ConfigureAwait(false);
 051            return transactionEnlistment.AmqpTransactionId;
 052        }
 53
 54        public void RemoveEnlistment(string transactionId)
 55        {
 056            lock (_syncRoot)
 57            {
 058                _enlistmentMap.Remove(transactionId);
 059            }
 060        }
 61    }
 62}