From f449415b56f127ab892441bfc1def899e3b70b03 Mon Sep 17 00:00:00 2001 From: Jesse Squire Date: Thu, 4 Feb 2021 11:37:33 -0500 Subject: [PATCH] [Event Hubs Client] Producer Dead Code Removal (#18424) The focus of these changes is to trim the dead code paths for publishing a single event from the producer client and assocaited tests. This overload existed in early pre-GA betas but has been determined to be unlikely to return to the public API in the future. --- .../src/Producer/EventHubProducerClient.cs | 58 --------------- .../tests/Diagnostics/DiagnosticsTests.cs | 2 +- .../EventHubProducerClientLiveTests.cs | 71 +------------------ .../Producer/EventHubProducerClientTests.cs | 62 ---------------- 4 files changed, 3 insertions(+), 190 deletions(-) diff --git a/sdk/eventhub/Azure.Messaging.EventHubs/src/Producer/EventHubProducerClient.cs b/sdk/eventhub/Azure.Messaging.EventHubs/src/Producer/EventHubProducerClient.cs index ab9d9447bd706..d1084f68f460a 100644 --- a/sdk/eventhub/Azure.Messaging.EventHubs/src/Producer/EventHubProducerClient.cs +++ b/sdk/eventhub/Azure.Messaging.EventHubs/src/Producer/EventHubProducerClient.cs @@ -491,64 +491,6 @@ internal virtual async Task GetPartitionPublishin } } - /// - /// Sends the to the associated Event Hub. To avoid the - /// overhead associated with measuring and validating the size in the client, validation will - /// be delegated to the Event Hubs service and is deferred until the operation is invoked. - /// The call will fail if the size of the specified exceeds the - /// maximum allowable size of a single event. - /// - /// - /// The event data to send. - /// An optional instance to signal the request to cancel the operation. - /// - /// - /// A task to be resolved on when the operation has completed; if no exception is thrown when awaited, the - /// Event Hubs service has acknowledge receipt and assumed responsibility for delivery of the event. - /// - /// - /// - /// - /// - /// - /// - internal virtual async Task SendAsync(EventData eventData, - CancellationToken cancellationToken = default) - { - Argument.AssertNotNull(eventData, nameof(eventData)); - await SendAsync(new[] { eventData }, null, cancellationToken).ConfigureAwait(false); - } - - /// - /// Sends the to the associated Event Hub. To avoid the - /// overhead associated with measuring and validating the size in the client, validation will - /// be delegated to the Event Hubs service and is deferred until the operation is invoked. - /// The call will fail if the size of the specified exceeds the - /// maximum allowable size of a single event. - /// - /// - /// The event data to send. - /// The set of options to consider when sending this batch. - /// An optional instance to signal the request to cancel the operation. - /// - /// - /// A task to be resolved on when the operation has completed; if no exception is thrown when awaited, the - /// Event Hubs service has acknowledge receipt and assumed responsibility for delivery of the event. - /// - /// - /// - /// - /// - /// - /// - internal virtual async Task SendAsync(EventData eventData, - SendEventOptions options, - CancellationToken cancellationToken = default) - { - Argument.AssertNotNull(eventData, nameof(eventData)); - await SendAsync(new[] { eventData }, options, cancellationToken).ConfigureAwait(false); - } - /// /// Sends a set of events to the associated Event Hub as a single operation. To avoid the /// overhead associated with measuring and validating the size in the client, validation will diff --git a/sdk/eventhub/Azure.Messaging.EventHubs/tests/Diagnostics/DiagnosticsTests.cs b/sdk/eventhub/Azure.Messaging.EventHubs/tests/Diagnostics/DiagnosticsTests.cs index 533c5ea92fbf0..3b112d4efd4c4 100644 --- a/sdk/eventhub/Azure.Messaging.EventHubs/tests/Diagnostics/DiagnosticsTests.cs +++ b/sdk/eventhub/Azure.Messaging.EventHubs/tests/Diagnostics/DiagnosticsTests.cs @@ -59,7 +59,7 @@ public async Task EventHubProducerCreatesDiagnosticScopeOnSend() var producer = new EventHubProducerClient(fakeConnection, transportMock.Object); var eventData = new EventData(ReadOnlyMemory.Empty); - await producer.SendAsync(eventData); + await producer.SendAsync(new[] { eventData }); activity.Stop(); diff --git a/sdk/eventhub/Azure.Messaging.EventHubs/tests/Producer/EventHubProducerClientLiveTests.cs b/sdk/eventhub/Azure.Messaging.EventHubs/tests/Producer/EventHubProducerClientLiveTests.cs index b5c2c651f5986..8d08898ec3f78 100644 --- a/sdk/eventhub/Azure.Messaging.EventHubs/tests/Producer/EventHubProducerClientLiveTests.cs +++ b/sdk/eventhub/Azure.Messaging.EventHubs/tests/Producer/EventHubProducerClientLiveTests.cs @@ -229,48 +229,6 @@ public async Task ProducerCanSendAnEventBatchUsingAPartitionHashKey() } } - /// - /// Verifies that the is able to - /// connect to the Event Hubs service and perform operations. - /// - /// - [Test] - public async Task ProducerCanSendSingleZeroLengthEvent() - { - await using (EventHubScope scope = await EventHubScope.CreateAsync(1)) - { - var connectionString = EventHubsTestEnvironment.Instance.BuildConnectionStringForEventHub(scope.EventHubName); - - await using (var producer = new EventHubProducerClient(connectionString)) - { - var singleEvent = new EventData(Array.Empty()); - Assert.That(async () => await producer.SendAsync(singleEvent), Throws.Nothing); - } - } - } - - /// - /// Verifies that the is able to - /// connect to the Event Hubs service and perform operations. - /// - /// - [Test] - public async Task ProducerCanSendSingleLargeEvent() - { - await using (EventHubScope scope = await EventHubScope.CreateAsync(1)) - { - var connectionString = EventHubsTestEnvironment.Instance.BuildConnectionStringForEventHub(scope.EventHubName); - - await using (var producer = new EventHubProducerClient(connectionString, new EventHubProducerClientOptions { RetryOptions = new EventHubsRetryOptions { TryTimeout = TimeSpan.FromMinutes(5) } })) - { - // Actual limit is 1046520 for a single event. - - var singleEvent = new EventData(new byte[100000]); - Assert.That(async () => await producer.SendAsync(singleEvent), Throws.Nothing); - } - } - } - /// /// Verifies that the is able to /// connect to the Event Hubs service and perform operations. @@ -293,31 +251,6 @@ public async Task ProducerCanSendSingleLargeEventInASet() } } - /// - /// Verifies that the is able to - /// connect to the Event Hubs service and perform operations. - /// - /// - [Test] - public async Task ProducerCannotSendSingleEventLargerThanMaximumSize() - { - await using (EventHubScope scope = await EventHubScope.CreateAsync(1)) - { - var connectionString = EventHubsTestEnvironment.Instance.BuildConnectionStringForEventHub(scope.EventHubName); - - await using (var producer = new EventHubProducerClient(connectionString)) - { - // Actual limit is 1046520 for a single event. - - var singleEvent = new EventData(new byte[1500000]); - EventData[] eventBatch = new[] { new EventData(new byte[1500000]) }; - - Assert.That(async () => await producer.SendAsync(singleEvent), Throws.InstanceOf().And.Property(nameof(EventHubsException.Reason)).EqualTo(EventHubsException.FailureReason.MessageSizeExceeded)); - Assert.That(async () => await producer.SendAsync(eventBatch), Throws.InstanceOf().And.Property(nameof(EventHubsException.Reason)).EqualTo(EventHubsException.FailureReason.MessageSizeExceeded)); - } - } - } - /// /// Verifies that the is able to /// connect to the Event Hubs service and perform operations. @@ -1011,7 +944,7 @@ public async Task ProducerSendsEventsWithTheSamePartitionHashKeyToTheSamePartiti for (var index = 0; index < batches; index++) { - await producer.SendAsync(new EventData(Encoding.UTF8.GetBytes($"Just a few messages ({ index })")), batchOptions); + await producer.SendAsync(new[] { new EventData(Encoding.UTF8.GetBytes($"Just a few messages ({ index })")) }, batchOptions); } // Read the events. @@ -1076,7 +1009,7 @@ public async Task ProducerCannotSendWhenProxyIsInvalid() await using (var invalidProxyProducer = new EventHubProducerClient(connectionString, producerOptions)) { - Assert.That(async () => await invalidProxyProducer.SendAsync(new EventData(new byte[1])), Throws.InstanceOf().Or.InstanceOf()); + Assert.That(async () => await invalidProxyProducer.SendAsync(new[] { new EventData(new byte[1]) }), Throws.InstanceOf().Or.InstanceOf()); } } } diff --git a/sdk/eventhub/Azure.Messaging.EventHubs/tests/Producer/EventHubProducerClientTests.cs b/sdk/eventhub/Azure.Messaging.EventHubs/tests/Producer/EventHubProducerClientTests.cs index ed54bea17ca08..e62fa465ea03d 100644 --- a/sdk/eventhub/Azure.Messaging.EventHubs/tests/Producer/EventHubProducerClientTests.cs +++ b/sdk/eventhub/Azure.Messaging.EventHubs/tests/Producer/EventHubProducerClientTests.cs @@ -514,68 +514,6 @@ public async Task ReadPartitionPublishingPropertiesAsyncReturnsEmptyPartitionSta "Partition state should not have been initialized."); } - /// - /// Verifies functionality of the - /// method. - /// - /// - [Test] - public void SendSingleWithoutOptionsRequiresAnEvent() - { - var producer = new EventHubProducerClient(new MockConnection()); - Assert.That(async () => await producer.SendAsync(default(EventData)), Throws.ArgumentNullException); - } - - /// - /// Verifies functionality of the - /// method. - /// - /// - [Test] - public void SendSingleRequiresAnEvent() - { - var producer = new EventHubProducerClient(new MockConnection()); - Assert.That(async () => await producer.SendAsync(default(EventData), new SendEventOptions()), Throws.ArgumentNullException); - } - - /// - /// Verifies functionality of the - /// method. - /// - /// - [Test] - public async Task SendSingleWithoutOptionsDelegatesToBatchSend() - { - var transportProducer = new ObservableTransportProducerMock(); - var producer = new Mock { CallBase = true }; - - producer - .Setup(instance => instance.SendAsync(It.Is>(value => value.Count() == 1), It.IsAny(), It.IsAny())) - .Returns(Task.CompletedTask) - .Verifiable("The single send should delegate to the batch send."); - - await producer.Object.SendAsync(new EventData(new byte[] { 0x22 })); - } - - /// - /// Verifies functionality of the - /// method. - /// - /// - [Test] - public async Task SendSingleWitOptionsDelegatesToBatchSend() - { - var transportProducer = new ObservableTransportProducerMock(); - var producer = new Mock { CallBase = true }; - - producer - .Setup(instance => instance.SendAsync(It.Is>(value => value.Count() == 1), It.IsAny(), It.IsAny())) - .Returns(Task.CompletedTask) - .Verifiable("The single send should delegate to the batch send."); - - await producer.Object.SendAsync(new EventData(new byte[] { 0x22 }), new SendEventOptions()); - } - /// /// Verifies functionality of the /// method.