public void SendRequiresEvents() { var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducerClient(new MockConnection(() => transportProducer)); Assert.That(async() => await producer.SendAsync(default(IEnumerable <EventData>), new SendEventOptions()), Throws.ArgumentNullException); }
public void SendRequiresTheBatch() { var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducer(transportProducer, "dummy", new EventHubProducerOptions(), Mock.Of <EventHubRetryPolicy>()); Assert.That(async() => await producer.SendAsync(default(EventDataBatch)), Throws.ArgumentNullException); }
public async Task ExpireClosesTheRemovedItemWhenForced() { var transportProducer = new ObservableTransportProducerMock(); var startingPool = new ConcurrentDictionary <string, TransportProducerPool.PoolItem> { ["0"] = new TransportProducerPool.PoolItem("0", transportProducer), ["1"] = new TransportProducerPool.PoolItem("1", transportProducer), ["2"] = new TransportProducerPool.PoolItem("2", transportProducer), }; var transportProducerPool = new TransportProducerPool(partition => transportProducer, pool: startingPool, eventHubProducer: transportProducer); // Validate the initial state. Assert.That(startingPool.TryGetValue("0", out _), Is.True, "The requested partition should appear in the pool."); Assert.That(transportProducer.CloseCallCount, Is.EqualTo(0), "The producer should not have been closed."); // Request the producer and hold the reference to ensure that it is flagged as being in use. await using var poolItem = transportProducerPool.GetPooledProducer("0"); // Expire the producer and validate the removal state. await transportProducerPool.ExpirePooledProducerAsync("0", forceClose : true); Assert.That(startingPool.TryGetValue("0", out _), Is.False, "The requested partition should have been removed."); Assert.That(transportProducer.CloseCallCount, Is.EqualTo(1), "The producer should have been closed."); }
public void SendSingleRequiresAnEvent() { var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducer(transportProducer, "dummy", new EventHubProducerOptions()); Assert.That(async() => await producer.SendAsync(default(EventData), new SendOptions()), Throws.ArgumentNullException); }
public void SendRequiresEvents() { var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducer(transportProducer, new Uri("amqp://some.endpoint.com/path"), "dummy", new EventHubProducerOptions(), Mock.Of <EventHubRetryPolicy>()); Assert.That(async() => await producer.SendAsync(default(IEnumerable <EventData>), new SendOptions()), Throws.ArgumentNullException); }
public void SendWithoutOptionsRequiresEvents() { var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducer(transportProducer, "dummy", new EventHubProducerOptions()); Assert.That(async() => await producer.SendAsync(default(IEnumerable <EventData>)), Throws.ArgumentNullException); }
public void SendRequiresTheBatch() { var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducerClient(new MockConnection(transportProducer)); Assert.That(async() => await producer.SendAsync(default(EventDataBatch)), Throws.ArgumentNullException); }
public void CreateBatchForASpecificPartitionDoesNotAllowAPartitionHashKey() { var batchOptions = new CreateBatchOptions { PartitionKey = "testKey", PartitionId = "1" }; var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducerClient(new MockConnection(() => transportProducer)); Assert.That(async () => await producer.CreateBatchAsync(batchOptions), Throws.InvalidOperationException); }
public async Task CloseAsyncDoesNotCloseTheConnectionWhenNotOwned() { var transportProducer = new ObservableTransportProducerMock(); var connection = new MockConnection(() => transportProducer); var producer = new EventHubProducerClient(connection); await producer.CloseAsync(); Assert.That(connection.Closed, Is.False); }
public void SendForASpecificPartitionDoesNotAllowAPartitionHashKey() { var sendOptions = new SendOptions { PartitionKey = "testKey", PartitionId = "1" }; var events = new[] { new EventData(new byte[] { 0x44, 0x66, 0x88 }) }; var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducerClient(new MockConnection(() => transportProducer)); Assert.That(async () => await producer.SendAsync(events, sendOptions), Throws.InvalidOperationException); }
public void SendAllowsAPartitionHashKeyWithABatch() { var batchOptions = new CreateBatchOptions { PartitionKey = "testKey" }; var batch = new EventDataBatch(new MockTransportBatch(), batchOptions); var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducerClient(new MockConnection(() => transportProducer)); Assert.That(async () => await producer.SendAsync(batch), Throws.Nothing); }
public void CloseClosesTheTransportProducer() { var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducerClient(new MockConnection(transportProducer)); producer.Close(); Assert.That(transportProducer.WasCloseCalled, Is.True); }
public void CloseDoesNotCloseTheConnectionWhenNotOwned() { var transportProducer = new ObservableTransportProducerMock(); var connection = new MockConnection(() => transportProducer); var producer = new EventHubProducerClient(connection); producer.Close(); Assert.That(connection.IsClosed, Is.False); }
public async Task CloseAsyncClosesTheTransportProducer() { var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducer(transportProducer, "dummy", new EventHubProducerOptions()); await producer.CloseAsync(); Assert.That(transportProducer.WasCloseCalled, Is.True); }
public async Task CloseAsyncClosesTheTransportProducer() { var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducer(transportProducer, new Uri("amqp://some.endpoint.com/path"), "dummy", new EventHubProducerOptions(), Mock.Of <EventHubRetryPolicy>()); await producer.CloseAsync(); Assert.That(transportProducer.WasCloseCalled, Is.True); }
public async Task CloseAsyncClosesTheTransportProducer() { var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducerClient(new MockConnection(transportProducer)); await producer.CloseAsync(); Assert.That(transportProducer.WasCloseCalled, Is.True); }
public void SendAllowsAPartitionHashKey() { var sendOptions = new SendOptions { PartitionKey = "testKey" }; var events = new[] { new EventData(new byte[] { 0x44, 0x66, 0x88 }) }; var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducerClient(new MockConnection(() => transportProducer)); Assert.That(async () => await producer.SendAsync(events, sendOptions), Throws.Nothing); }
public void CloseClosesTheTransportProducer() { var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducer(transportProducer, "dummy", new EventHubProducerOptions(), Mock.Of <EventHubRetryPolicy>()); producer.Close(); Assert.That(transportProducer.WasCloseCalled, Is.True); }
public void SettingTheRetryUpdatesTheTransportProducer() { var customRetry = Mock.Of <EventHubRetryPolicy>(); var transportProducer = new ObservableTransportProducerMock(); var producerOptions = new EventHubProducerOptions(); var producer = new EventHubProducer(transportProducer, "dummy", producerOptions, Mock.Of <EventHubRetryPolicy>()); producer.RetryPolicy = customRetry; Assert.That(transportProducer.UpdateRetryPolicyCalledWith, Is.SameAs(customRetry), "The custom retry policy should have been passed to the transport producer."); }
public async Task SendInvokesTheTransportProducerWithABatch() { var batchOptions = new CreateBatchOptions { PartitionKey = "testKey" }; var batch = new EventDataBatch(new MockTransportBatch(), batchOptions); var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducerClient(new MockConnection(() => transportProducer)); await producer.SendAsync(batch); Assert.That(transportProducer.SendBatchCalledWith, Is.SameAs(batch), "The batch should be the same instance."); }
public async Task CreateBatchSetsTheSendOptionsForTheEventBatch() { var batchOptions = new CreateBatchOptions { PartitionKey = "Hi", MaximumSizeInBytes = 9999 }; var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducerClient(new MockConnection(() => transportProducer)); var eventBatch = await producer.CreateBatchAsync(batchOptions); Assert.That(eventBatch.SendOptions, Is.SameAs(transportProducer.CreateBatchCalledWith), "The batch options should have used for the send options."); ; }
public void SendAllowsAPartitionHashKey() { var batchingOptions = new SendOptions { PartitionKey = "testKey" }; var events = new[] { new EventData(new byte[] { 0x44, 0x66, 0x88 }) }; var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducer(transportProducer, "dummy", new EventHubProducerOptions(), Mock.Of <EventHubRetryPolicy>()); Assert.That(async() => await producer.SendAsync(events, batchingOptions), Throws.Nothing); }
public void SendAllowsAPartitionHashKeyWithABatch() { var batchOptions = new BatchOptions { PartitionKey = "testKey" }; var batch = new EventDataBatch(new MockTransportBatch(), batchOptions); var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducer(transportProducer, new Uri("amqp://some.endpoint.com/path"), "dummy", new EventHubProducerOptions(), Mock.Of <EventHubRetryPolicy>()); Assert.That(async() => await producer.SendAsync(batch), Throws.Nothing); }
public void SendForASpecificPartitionDoesNotAllowAPartitionHashKeyWithABatch() { var batchOptions = new CreateBatchOptions { PartitionKey = "testKey", PartitionId = "1" }; var batch = new EventDataBatch(new MockTransportBatch(), "ns", "eh", batchOptions.ToSendOptions()); var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducerClient(new MockConnection(() => transportProducer)); Assert.That(async() => await producer.SendAsync(batch), Throws.InvalidOperationException); }
public async Task CreateBatchSetsTheSendOptionsForTheEventBatch() { var batchOptions = new BatchOptions { PartitionKey = "Hi", MaximumizeInBytes = 9999 }; var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducer(transportProducer, new Uri("amqp://some.endpoint.com/path"), "dummy", new EventHubProducerOptions(), Mock.Of <EventHubRetryPolicy>()); EventDataBatch eventBatch = await producer.CreateBatchAsync(batchOptions); Assert.That(eventBatch.SendOptions, Is.SameAs(transportProducer.CreateBatchCalledWith), "The batch options should have used for the send options."); ; }
public void SettingTheRetryUpdatesTheTransportProducer() { EventHubRetryPolicy customRetry = Mock.Of <EventHubRetryPolicy>(); var transportProducer = new ObservableTransportProducerMock(); var producerOptions = new EventHubProducerOptions(); var producer = new EventHubProducer(transportProducer, new Uri("amqp://some.endpoint.com/path"), "dummy", producerOptions, Mock.Of <EventHubRetryPolicy>()) { RetryPolicy = customRetry }; Assert.That(transportProducer.UpdateRetryPolicyCalledWith, Is.SameAs(customRetry), "The custom retry policy should have been passed to the transport producer."); }
public async Task SendSingleWitOptionsDelegatesToBatchSend() { var transportProducer = new ObservableTransportProducerMock(); var producer = new Mock<EventHubProducerClient> { CallBase = true }; producer .Setup(instance => instance.SendAsync(It.Is<IEnumerable<EventData>>(value => value.Count() == 1), It.IsAny<SendOptions>(), It.IsAny<CancellationToken>())) .Returns(Task.CompletedTask) .Verifiable("The single send should delegate to the batch send."); await producer.Object.SendAsync(new EventData(new byte[] { 0x22 }), new SendOptions()); }
public async Task CreateBatchSetsTheSendOptionsForTheEventBatch() { var batchOptions = new CreateBatchOptions { PartitionKey = "Hi", MaximumSizeInBytes = 9999 }; var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducerClient(new MockConnection(() => transportProducer)); var eventBatch = await producer.CreateBatchAsync(batchOptions); Assert.That(eventBatch.SendOptions.PartitionId, Is.EqualTo(transportProducer.CreateBatchCalledWith.PartitionId), "The batch options should have used for the send options, but the partition identifier didn't match."); Assert.That(eventBatch.SendOptions.PartitionKey, Is.EqualTo(transportProducer.CreateBatchCalledWith.PartitionKey), "The batch options should have used for the send options, but the partition key didn't match."); }
public void CreateBatchForASpecificPartitionDoesNotAllowAPartitionHashKey() { var batchOptions = new BatchOptions { PartitionKey = "testKey" }; var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducer(transportProducer, new Uri("amqp://some.endpoint.com/path"), "dummy", new EventHubProducerOptions { PartitionId = "1" }, Mock.Of <EventHubRetryPolicy>()); Assert.That(async() => await producer.CreateBatchAsync(batchOptions), Throws.InvalidOperationException); }
public async Task CreateBatchDefaultsBatchOptions() { var expectedOptions = new CreateBatchOptions(); var transportProducer = new ObservableTransportProducerMock(); var producer = new EventHubProducerClient(new MockConnection(() => transportProducer)); await producer.CreateBatchAsync(); Assert.That(transportProducer.CreateBatchCalledWith, Is.Not.Null, "The batch creation should have passed options."); Assert.That(transportProducer.CreateBatchCalledWith, Is.Not.SameAs(expectedOptions), "The options should have been cloned."); Assert.That(transportProducer.CreateBatchCalledWith.PartitionKey, Is.EqualTo(expectedOptions.PartitionKey), "The partition key should match."); Assert.That(transportProducer.CreateBatchCalledWith.MaximumSizeInBytes, Is.EqualTo(expectedOptions.MaximumSizeInBytes), "The maximum size should match."); }