public void RespectsConnectionOptionsForProcessor(string expectedPathName, string connectionString) { var testEndpoint = new Uri("http://mycustomendpoint.com"); EventHubOptions options = new EventHubOptions { ConnectionOptions = new EventHubConnectionOptions { CustomEndpointAddress = testEndpoint }, RetryOptions = new EventHubsRetryOptions { MaximumRetries = 10 } }; options.AddReceiver(expectedPathName, connectionString); var configuration = CreateConfiguration(); var factory = new EventHubClientFactory(configuration, Mock.Of <AzureComponentFactory>(), Options.Create(options), new DefaultNameResolver(configuration)); var processor = factory.GetEventProcessorHost(expectedPathName, null, "consumer"); EventProcessorOptions processorOptions = (EventProcessorOptions)typeof(EventProcessor <EventProcessorHostPartition>) .GetProperty("Options", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(processor); Assert.AreEqual(testEndpoint, processorOptions.ConnectionOptions.CustomEndpointAddress); Assert.AreEqual(10, processorOptions.RetryOptions.MaximumRetries); Assert.AreEqual(expectedPathName, processor.EventHubName); }
public void UsesDefaultConnectionToStorageAccount() { EventHubOptions options = new EventHubOptions(); // Test sender options.AddReceiver("k1", ConnectionString); var configuration = CreateConfiguration(new KeyValuePair <string, string>("AzureWebJobsStorage", "UseDevelopmentStorage=true")); var factory = new EventHubClientFactory(configuration, Mock.Of <AzureComponentFactory>(), Options.Create(options), new DefaultNameResolver(configuration)); var client = factory.GetCheckpointStoreClient("k1"); Assert.AreEqual("azure-webjobs-eventhub", client.Name); Assert.AreEqual("devstoreaccount1", client.AccountName); }
public void RespectsConnectionOptionsForConsumer(string expectedPathName, string connectionString) { var testEndpoint = new Uri("http://mycustomendpoint.com"); EventHubOptions options = new EventHubOptions { ConnectionOptions = new EventHubConnectionOptions { CustomEndpointAddress = testEndpoint }, RetryOptions = new EventHubsRetryOptions { MaximumRetries = 10 } }; options.AddReceiver(expectedPathName, connectionString); var configuration = CreateConfiguration(); var factory = new EventHubClientFactory(configuration, Mock.Of <AzureComponentFactory>(), Options.Create(options), new DefaultNameResolver(configuration)); var consumer = factory.GetEventHubConsumerClient(expectedPathName, null, "consumer"); var consumerClient = (EventHubConsumerClient)typeof(EventHubConsumerClientImpl) .GetField("_client", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(consumer); EventHubConnection connection = (EventHubConnection)typeof(EventHubConsumerClient) .GetProperty("Connection", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(consumerClient); EventHubConnectionOptions connectionOptions = (EventHubConnectionOptions)typeof(EventHubConnection) .GetProperty("Options", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(connection); Assert.AreEqual(testEndpoint, connectionOptions.CustomEndpointAddress); EventHubsRetryPolicy retryPolicy = (EventHubsRetryPolicy)typeof(EventHubConsumerClient) .GetProperty("RetryPolicy", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(consumerClient); // Reflection was still necessary here because BasicRetryOptions (which is the concrete derived type) // is internal. EventHubsRetryOptions retryOptions = (EventHubsRetryOptions)retryPolicy.GetType() .GetProperty("Options", BindingFlags.Public | BindingFlags.Instance) .GetValue(retryPolicy); Assert.AreEqual(10, retryOptions.MaximumRetries); Assert.AreEqual(expectedPathName, consumer.EventHubName); }
public void UsesRegisteredConnectionToStorageAccount() { EventHubOptions options = new EventHubOptions(); // Test sender options.AddReceiver("k1", ConnectionString, "BlobEndpoint=http://blobs/;AccountName=test;AccountKey=abc2564="); var configuration = CreateConfiguration(); var factory = new EventHubClientFactory(configuration, Mock.Of <AzureComponentFactory>(), Options.Create(options), new DefaultNameResolver(configuration)); var client = factory.GetCheckpointStoreClient("k1"); Assert.AreEqual("azure-webjobs-eventhub", client.Name); Assert.AreEqual("http://blobs/azure-webjobs-eventhub", client.Uri.ToString()); }