Ejemplo n.º 1
0
        public async Task SendEnumerableEnsuresNotClosed()
        {
            var producer = new AmqpEventHubProducer("aHub", null, Mock.Of <AmqpConnectionScope>(), new AmqpMessageConverter(), Mock.Of <EventHubRetryPolicy>());
            await producer.CloseAsync(CancellationToken.None);

            Assert.That(async() => await producer.SendAsync(Enumerable.Empty <EventData>(), new SendOptions(), CancellationToken.None), Throws.InstanceOf <EventHubsClientClosedException>());
        }
Ejemplo n.º 2
0
        public void SendEnumerableRespectsTheCancellationTokenIfSetWhenCalled()
        {
            using CancellationTokenSource cancellationSource = new CancellationTokenSource();
            cancellationSource.Cancel();

            var producer = new AmqpEventHubProducer("aHub", null, Mock.Of <AmqpConnectionScope>(), new AmqpMessageConverter(), Mock.Of <EventHubRetryPolicy>());

            Assert.That(async() => await producer.SendAsync(new[] { new EventData(new byte[] { 0x15 }) }, new SendOptions(), cancellationSource.Token), Throws.InstanceOf <TaskCanceledException>());
        }
Ejemplo n.º 3
0
        public void CloseRespectsTheCancellationToken()
        {
            var producer = new AmqpEventHubProducer("aHub", null, Mock.Of <AmqpConnectionScope>(), Mock.Of <AmqpMessageConverter>(), Mock.Of <EventHubRetryPolicy>());

            using var cancellationSource = new CancellationTokenSource();

            cancellationSource.Cancel();
            Assert.That(async() => await producer.CloseAsync(cancellationSource.Token), Throws.InstanceOf <TaskCanceledException>(), "Cancellation should trigger the appropriate exception.");
            Assert.That(producer.Closed, Is.False, "Cancellation should have interrupted closing and left the producer in an open state.");
        }
Ejemplo n.º 4
0
        public async Task CloseMarksTheProducerAsClosed()
        {
            var producer = new AmqpEventHubProducer("aHub", "0", Mock.Of <AmqpConnectionScope>(), Mock.Of <AmqpMessageConverter>(), Mock.Of <EventHubRetryPolicy>());

            Assert.That(producer.Closed, Is.False, "The producer should not be closed on creation");

            await producer.CloseAsync(CancellationToken.None);

            Assert.That(producer.Closed, Is.True, "The producer should be marked as closed after closing");
        }
Ejemplo n.º 5
0
        public void UpdateRetryPolicyUpdatesTheRetryPolicy()
        {
            var newPolicy = new BasicRetryPolicy(new RetryOptions {
                Delay = TimeSpan.FromMilliseconds(50)
            });
            var producer = new AmqpEventHubProducer("aHub", null, Mock.Of <AmqpConnectionScope>(), Mock.Of <AmqpMessageConverter>(), Mock.Of <EventHubRetryPolicy>());

            Assert.That(GetActiveRetryPolicy(producer), Is.Not.SameAs(newPolicy), "The initial policy should be a unique instance");

            producer.UpdateRetryPolicy(newPolicy);
            Assert.That(GetActiveRetryPolicy(producer), Is.SameAs(newPolicy), "The updated policy should match");
        }
Ejemplo n.º 6
0
        public void UpdateRetryPolicyUpdatesTheOperationTimeout()
        {
            var initialPolicy = new BasicRetryPolicy(new RetryOptions {
                TryTimeout = TimeSpan.FromSeconds(17)
            });
            var initialTimeout = initialPolicy.CalculateTryTimeout(0);
            var producer       = new AmqpEventHubProducer("aHub", "0", Mock.Of <AmqpConnectionScope>(), Mock.Of <AmqpMessageConverter>(), initialPolicy);

            Assert.That(GetTimeout(producer), Is.EqualTo(initialTimeout), "The initial timeout should match");

            var newPolicy = new BasicRetryPolicy(new RetryOptions {
                TryTimeout = TimeSpan.FromMilliseconds(50)
            });
            TimeSpan newTimeout = newPolicy.CalculateTryTimeout(0);

            producer.UpdateRetryPolicy(newPolicy);
            Assert.That(GetTimeout(producer), Is.EqualTo(newTimeout), "The updated timeout should match");
        }
Ejemplo n.º 7
0
 /// <summary>
 ///   Sets the maximum message size for the given producer, using its
 ///   private accessor.
 /// </summary>
 ///
 private static void SetMaximumMessageSize(AmqpEventHubProducer target, long value)
 {
     typeof(AmqpEventHubProducer)
     .GetProperty("MaximumMessageSize", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetProperty)
     .SetValue(target, value);
 }
Ejemplo n.º 8
0
 /// <summary>
 ///   Gets the active operation timeout for the given producer, using the
 ///   private field.
 /// </summary>
 ///
 private static TimeSpan GetTimeout(AmqpEventHubProducer target) =>
 (TimeSpan)
 typeof(AmqpEventHubProducer)
 .GetField("_tryTimeout", BindingFlags.Instance | BindingFlags.NonPublic)
 .GetValue(target);
Ejemplo n.º 9
0
 /// <summary>
 ///   Gets the active retry policy for the given producer, using the
 ///   private field.
 /// </summary>
 ///
 private static EventHubRetryPolicy GetActiveRetryPolicy(AmqpEventHubProducer target) =>
 (EventHubRetryPolicy)
 typeof(AmqpEventHubProducer)
 .GetField("_retryPolicy", BindingFlags.Instance | BindingFlags.NonPublic)
 .GetValue(target);
Ejemplo n.º 10
0
        public void SendBatchValidatesTheBatch()
        {
            var producer = new AmqpEventHubProducer("aHub", null, Mock.Of <AmqpConnectionScope>(), new AmqpMessageConverter(), Mock.Of <EventHubRetryPolicy>());

            Assert.That(async() => await producer.SendAsync(null, CancellationToken.None), Throws.ArgumentNullException);
        }
Ejemplo n.º 11
0
        public void UpdateRetryPolicyValidatesTheRetryPolicy()
        {
            var producer = new AmqpEventHubProducer("aHub", "0", Mock.Of <AmqpConnectionScope>(), Mock.Of <AmqpMessageConverter>(), Mock.Of <EventHubRetryPolicy>());

            Assert.That(() => producer.UpdateRetryPolicy(null), Throws.ArgumentNullException);
        }