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>()); }
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>()); }
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."); }
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"); }
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"); }
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"); }
/// <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); }
/// <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);
/// <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);
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); }
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); }