Ejemplo n.º 1
0
        /// <summary>
        ///   Performs the tasks needed to create a new Event Hub instance with the requested
        ///   partition count and a dynamically assigned unique name.
        /// </summary>
        ///
        /// <param name="partitionCount">The number of partitions that the Event Hub should be configured with.</param>
        /// <param name="consumerGroups">The set of consumer groups to create and associate with the Event Hub; the default consumer group should not be included, as it is implicitly created.</param>
        /// <param name="caller">The name of the calling method; this is intended to be populated by the runtime.</param>
        ///
        /// <returns>The <see cref="EventHubScope" /> in which the test should be executed.</returns>
        ///
        private static async Task <EventHubScope> BuildScopeWithNewEventHub(int partitionCount,
                                                                            IEnumerable <string> consumerGroups,
                                                                            [CallerMemberName] string caller = "")
        {
            caller = (caller.Length < 16) ? caller : caller.Substring(0, 15);

            var groups            = (consumerGroups ?? Enumerable.Empty <string>()).ToList();
            var resourceGroup     = TestEnvironment.EventHubsResourceGroup;
            var eventHubNamespace = TestEnvironment.EventHubsNamespace;
            var token             = await ResourceManager.AquireManagementTokenAsync();

            string CreateName() => $"{ Guid.NewGuid().ToString("D").Substring(0, 13) }-{ caller }";

            using (var client = new EventHubManagementClient(new TokenCredentials(token))
            {
                SubscriptionId = TestEnvironment.EventHubsSubscription
            })
            {
                var eventHub = new Eventhub(partitionCount: partitionCount);
                eventHub = await ResourceManager.CreateRetryPolicy <Eventhub>().ExecuteAsync(() => client.EventHubs.CreateOrUpdateAsync(resourceGroup, eventHubNamespace, CreateName(), eventHub));

                Polly.IAsyncPolicy <ConsumerGroup> consumerPolicy = ResourceManager.CreateRetryPolicy <ConsumerGroup>();

                await Task.WhenAll
                (
                    consumerGroups.Select(groupName =>
                {
                    var group = new ConsumerGroup(name: groupName);
                    return(consumerPolicy.ExecuteAsync(() => client.ConsumerGroups.CreateOrUpdateAsync(resourceGroup, eventHubNamespace, eventHub.Name, groupName, group)));
                })
                );

                return(new EventHubScope(eventHub.Name, groups, wasEventHubCreated: true));
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="NamedAsyncPolicy"/> class.
 /// </summary>
 /// <param name="name">Name of the policy.</param>
 /// <param name="underlyingPolicy">The underlying <see cref="Polly.IAsyncPolicy"/>.</param>
 public NamedAsyncPolicy(string name, Polly.IAsyncPolicy underlyingPolicy)
     : base(underlyingPolicy)
 {
     Name = name;
 }
Ejemplo n.º 3
0
 public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddPolicyHandler(this Microsoft.Extensions.DependencyInjection.IHttpClientBuilder builder, Polly.IAsyncPolicy <System.Net.Http.HttpResponseMessage> policy)
 {
     throw null;
 }
Ejemplo n.º 4
0
 public PolicyHttpMessageHandler(Polly.IAsyncPolicy <System.Net.Http.HttpResponseMessage> policy)
 {
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncPolicy"/> class.
 /// </summary>
 /// <param name="underlyingPolicy">The underlying <see cref="Polly.IAsyncPolicy"/>.</param>
 public AsyncPolicy(Polly.IAsyncPolicy underlyingPolicy)
 {
     UnderlyingPolicy = underlyingPolicy;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncPolicyFor{T}"/> class.
 /// </summary>
 /// <param name="underlyingPolicy">The underlying <see cref="Polly.IAsyncPolicy"/>.</param>
 public AsyncPolicyFor(Polly.IAsyncPolicy underlyingPolicy)
     : base(underlyingPolicy)
 {
 }