コード例 #1
0
        public async Task ProcessEvents_CancellationToken_CancelsExecution()
        {
            var partitionContext = EventHubTests.GetPartitionContext();
            var options          = new EventHubOptions();
            var processor        = new Mock <EventProcessorHost>(MockBehavior.Strict);

            processor.Setup(p => p.CheckpointAsync(partitionContext.PartitionId, It.IsAny <EventData>(), It.IsAny <CancellationToken>())).Returns(Task.CompletedTask);
            partitionContext.ProcessorHost = processor.Object;

            var loggerMock = new Mock <ILogger>();
            var executor   = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict);

            executor.Setup(p => p.TryExecuteAsync(It.IsAny <TriggeredFunctionData>(), It.IsAny <CancellationToken>()))
            .Callback <TriggeredFunctionData, CancellationToken>(async(TriggeredFunctionData triggeredFunctionData, CancellationToken cancellationToken) =>
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    await Task.Delay(100);
                }
            })
            .ReturnsAsync(new FunctionResult(true));
            var eventProcessor      = new EventHubListener.EventProcessor(options, executor.Object, loggerMock.Object, true);
            List <EventData> events = new List <EventData>()
            {
                new EventData(new byte[0])
            };
            CancellationTokenSource source = new CancellationTokenSource();

            // Start another thread to cancel execution
            _ = Task.Run(async() =>
            {
                await Task.Delay(500);
            });
            await eventProcessor.ProcessEventsAsync(partitionContext, events, source.Token);
        }
コード例 #2
0
        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
                }
            };

            var configuration = CreateConfiguration(new KeyValuePair <string, string>("connection", connectionString));
            var factory       = new EventHubClientFactory(configuration, Mock.Of <AzureComponentFactory>(), Options.Create(options), new DefaultNameResolver(configuration));

            var processor = factory.GetEventProcessorHost(expectedPathName, "connection", "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);
        }
コード例 #3
0
 public EventProcessor(EventHubOptions options, ITriggeredFunctionExecutor executor, ILogger logger, bool singleDispatch)
 {
     _executor                 = executor;
     _singleDispatch           = singleDispatch;
     _batchCheckpointFrequency = options.BatchCheckpointFrequency;
     _logger = logger;
 }
コード例 #4
0
        public async Task ProcessErrorsAsync_RebalancingExceptions_LoggedAsInformation()
        {
            var partitionContext = EventHubTests.GetPartitionContext(partitionId: "123", eventHubPath: "abc", owner: "def");
            var options          = new EventHubOptions();
            var executor         = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict);
            var testLogger       = new TestLogger("Test");
            var eventProcessor   = new EventHubListener.EventProcessor(options, executor.Object, testLogger, true);

            var disconnectedEx = new EventHubsException(true, "My ReceiverDisconnectedException!", EventHubsException.FailureReason.ConsumerDisconnected);

            await eventProcessor.ProcessErrorAsync(partitionContext, disconnectedEx);

            var msg = testLogger.GetLogMessages().Single();

            StringAssert.IsMatch("Processing error \\(Partition Id: '123', Owner: '[\\w\\d-]+', EventHubPath: 'abc'\\). An exception of type 'EventHubsException' was thrown. This exception type is typically a result of Event Hub processor rebalancing or a transient error and can be safely ignored.", msg.FormattedMessage);
            Assert.NotNull(msg.Exception);
            Assert.AreEqual(LogLevel.Information, msg.Level);

            testLogger.ClearLogMessages();

            var leaseLostEx = new EventHubsException(true, "My LeaseLostException!", EventHubsException.FailureReason.ConsumerDisconnected);

            await eventProcessor.ProcessErrorAsync(partitionContext, leaseLostEx);

            msg = testLogger.GetLogMessages().Single();
            StringAssert.IsMatch("Processing error \\(Partition Id: '123', Owner: '[\\w\\d-]+', EventHubPath: 'abc'\\). An exception of type 'EventHubsException' was thrown. This exception type is typically a result of Event Hub processor rebalancing or a transient error and can be safely ignored.", msg.FormattedMessage);
            Assert.NotNull(msg.Exception);
            Assert.AreEqual(LogLevel.Information, msg.Level);
        }
コード例 #5
0
        internal static void ConfigureInitialOffsetOptions(EventHubOptions options)
        {
            OffsetType?type = options?.InitialOffsetOptions?.Type;

            if (type.HasValue)
            {
                switch (type)
                {
                case OffsetType.FromStart:
                    options.EventProcessorOptions.DefaultStartingPosition = EventPosition.Earliest;
                    break;

                case OffsetType.FromEnd:
                    options.EventProcessorOptions.DefaultStartingPosition = EventPosition.Latest;
                    break;

                case OffsetType.FromEnqueuedTime:
                    if (!options.InitialOffsetOptions.EnqueuedTimeUtc.HasValue)
                    {
                        throw new InvalidOperationException(
                                  "A time must be specified for 'enqueuedTimeUtc', when " +
                                  "'initialOffsetOptions.type' is set to 'fromEnqueuedTime'.");
                    }

                    options.EventProcessorOptions.DefaultStartingPosition =
                        EventPosition.FromEnqueuedTime(options.InitialOffsetOptions.EnqueuedTimeUtc.Value);
                    break;

                default:
                    throw new InvalidOperationException(
                              "An unsupported value was supplied for initialOffsetOptions.type");
                }
                // If not specified, EventProcessor's default offset will apply
            }
        }
        public async Task ProcessEvents_SingleDispatch_SystemProperties()
        {
            var partitionContext = EventHubTests.GetPartitionContext();
            var options          = new EventHubOptions {
                BatchCheckpointFrequency = 1
            };

            var checkpointer = new Mock <EventHubListener.ICheckpointer>();

            var loggerMock = new Mock <ILogger>();
            var executor   = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict);

            executor.Setup(p => p.TryExecuteAsync(It.IsAny <TriggeredFunctionData>(), It.IsAny <CancellationToken>())).ReturnsAsync(new FunctionResult(true));
            var eventProcessor = new EventHubListener.EventProcessor(options, executor.Object, loggerMock.Object, true, checkpointer.Object);

            var diagnosticId = $"00-{ActivityTraceId.CreateRandom().ToHexString()}-{ActivitySpanId.CreateRandom().ToHexString()}-01";

            var eventData = new EventData(new byte[0])
            {
                SystemProperties = new EventData.SystemPropertiesCollection(-1, DateTime.Now, "0", "1")
                {
                    { "Diagnostic-Id", diagnosticId }
                }
            };

            await eventProcessor.ProcessEventsAsync(partitionContext, new[] { eventData });

            Func <Dictionary <string, object>, bool> checkLinksScope = (scope) => scope.TryGetValue("Links", out var links) &&
                                                                       links is IEnumerable <Activity> linksList &&
                                                                       linksList.Count() == 1 &&
                                                                       linksList.Single().ParentId == diagnosticId;

            loggerMock.Verify(l => l.BeginScope(It.Is <Dictionary <string, object> >(s => checkLinksScope(s))), Times.Once);
        }
コード例 #7
0
 public EventHubAdapterFactory(
     string name,
     EventHubOptions ehOptions,
     EventHubReceiverOptions receiverOptions,
     EventHubStreamCachePressureOptions cacheOptions,
     StreamCacheEvictionOptions cacheEvictionOptions,
     StreamStatisticOptions statisticOptions,
     IEventHubDataAdapter dataAdapter,
     IServiceProvider serviceProvider,
     SerializationManager serializationManager,
     ITelemetryProducer telemetryProducer,
     ILoggerFactory loggerFactory)
 {
     this.Name = name;
     this.cacheEvictionOptions = cacheEvictionOptions ?? throw new ArgumentNullException(nameof(cacheEvictionOptions));
     this.statisticOptions     = statisticOptions ?? throw new ArgumentNullException(nameof(statisticOptions));
     this.ehOptions            = ehOptions ?? throw new ArgumentNullException(nameof(ehOptions));
     this.cacheOptions         = cacheOptions ?? throw new ArgumentNullException(nameof(cacheOptions));
     this.dataAdapter          = dataAdapter ?? throw new ArgumentNullException(nameof(dataAdapter));
     this.receiverOptions      = receiverOptions ?? throw new ArgumentNullException(nameof(receiverOptions));
     this.serviceProvider      = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
     this.SerializationManager = serializationManager ?? throw new ArgumentNullException(nameof(serializationManager));
     this.telemetryProducer    = telemetryProducer ?? throw new ArgumentNullException(nameof(telemetryProducer));
     this.loggerFactory        = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
 }
コード例 #8
0
        public EventHubListener(
            string functionId,
            ITriggeredFunctionExecutor executor,
            EventProcessorHost eventProcessorHost,
            bool singleDispatch,
            IEventHubConsumerClient consumerClient,
            BlobCheckpointStoreInternal checkpointStore,
            EventHubOptions options,
            ILoggerFactory loggerFactory)
        {
            _loggerFactory      = loggerFactory;
            _executor           = executor;
            _eventProcessorHost = eventProcessorHost;
            _singleDispatch     = singleDispatch;
            _checkpointStore    = checkpointStore;
            _options            = options;
            _logger             = _loggerFactory.CreateLogger <EventHubListener>();

            _scaleMonitor = new Lazy <EventHubsScaleMonitor>(
                () => new EventHubsScaleMonitor(
                    functionId,
                    consumerClient,
                    checkpointStore,
                    _loggerFactory.CreateLogger <EventHubsScaleMonitor>()));

            _details = $"'namespace='{eventProcessorHost?.FullyQualifiedNamespace}', eventHub='{eventProcessorHost?.EventHubName}', " +
                       $"consumerGroup='{eventProcessorHost?.ConsumerGroup}', functionId='{functionId}', singleDispatch='{singleDispatch}'";
        }
コード例 #9
0
        public void RespectsConnectionOptionsForProducer(string expectedPathName, string connectionString)
        {
            var             testEndpoint = new Uri("http://mycustomendpoint.com");
            EventHubOptions options      = new EventHubOptions
            {
                CustomEndpointAddress = testEndpoint,
                ClientRetryOptions    = new EventHubsRetryOptions
                {
                    MaximumRetries = 10
                }
            };

            var configuration = CreateConfiguration(new KeyValuePair <string, string>("connection", connectionString));
            var factory       = CreateFactory(configuration, options);

            var producer = factory.GetEventHubProducerClient(expectedPathName, "connection");
            EventHubConnection connection = (EventHubConnection)typeof(EventHubProducerClient).GetProperty("Connection", BindingFlags.NonPublic | BindingFlags.Instance)
                                            .GetValue(producer);
            EventHubConnectionOptions connectionOptions = (EventHubConnectionOptions)typeof(EventHubConnection).GetProperty("Options", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(connection);

            Assert.AreEqual(testEndpoint, connectionOptions.CustomEndpointAddress);
            Assert.AreEqual(expectedPathName, producer.EventHubName);

            EventHubProducerClientOptions producerOptions = (EventHubProducerClientOptions)typeof(EventHubProducerClient).GetProperty("Options", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(producer);

            Assert.AreEqual(10, producerOptions.RetryOptions.MaximumRetries);
            Assert.AreEqual(expectedPathName, producer.EventHubName);
        }
コード例 #10
0
        public void EventHubBatchCheckpointFrequency(int num)
        {
            var options = new EventHubOptions();

            options.BatchCheckpointFrequency = num;
            Assert.AreEqual(num, options.BatchCheckpointFrequency);
        }
コード例 #11
0
        public EventHubIntegration(EventHubConfiguration configuration, EventHubOptions options)
        {
            Configuration = configuration;
            if (string.IsNullOrWhiteSpace(options.AccessKey))
            {
                this.Client = new EventHubProducerClient(options.FullyQualifiedName, configuration.Name, new DefaultAzureCredential());
            }
            else
            {
                this.Client = new EventHubProducerClient(options.ConnectionString, configuration.Name);
            }

            if (options.StorageOptions != default)
            {
                string consumerGroup = configuration.ConsumerGroup ?? "$Default";
                var    containerName = $"{configuration.Name.ToLower()}consumergroup";
                BlobContainerClient = string.IsNullOrWhiteSpace(options.StorageOptions.AccountKey) ? new BlobContainerClient(new Uri(string.Format("https://{0}.blob.core.windows.net/{1}",
                                                                                                                                                   options.StorageOptions.AccountName,
                                                                                                                                                   containerName)),
                                                                                                                             new DefaultAzureCredential()) :
                                      new BlobContainerClient(options.StorageOptions.GetConnectionString(), containerName);
                if (string.IsNullOrWhiteSpace(options.AccessKey))
                {
                    ClientReader = new EventProcessorClient(BlobContainerClient, consumerGroup, options.FullyQualifiedName, configuration.Name, new DefaultAzureCredential(), options.ProcessorOptions);
                }
                else
                {
                    ClientReader = new EventProcessorClient(BlobContainerClient, consumerGroup, options.ConnectionString, configuration.Name, options.ProcessorOptions);
                }
            }
        }
コード例 #12
0
        public void ConfigureOptions_Format_Returns_Expected()
        {
            EventHubOptions options = CreateOptionsFromConfig();

            string          format = ((IOptionsFormatter)options).Format();
            JObject         iObj   = JObject.Parse(format);
            EventHubOptions result = iObj.ToObject <EventHubOptions>();

            Assert.AreEqual(123, result.MaxBatchSize);
            Assert.AreEqual(5, result.BatchCheckpointFrequency);
            Assert.True(result.TrackLastEnqueuedEventProperties);
            Assert.True(result.InvokeFunctionAfterReceiveTimeout);
            Assert.AreEqual(123, result.PrefetchCount);
            Assert.AreEqual(TimeSpan.FromSeconds(33), result.MaximumWaitTime);
            Assert.AreEqual(TimeSpan.FromSeconds(31), result.PartitionOwnershipExpirationInterval);
            Assert.AreEqual(TimeSpan.FromSeconds(21), result.LoadBalancingUpdateInterval);
            Assert.AreEqual("FromEnqueuedTime", result.InitialOffsetOptions.Type);
            Assert.AreEqual("2020-09-13T12:00Z", result.InitialOffsetOptions.EnqueuedTimeUTC);
            Assert.AreEqual(5, result.RetryOptions.MaximumRetries);
            Assert.AreEqual(TimeSpan.FromSeconds(1), result.RetryOptions.Delay);
            Assert.AreEqual(TimeSpan.FromMinutes(1), result.RetryOptions.MaximumDelay);
            Assert.AreEqual(TimeSpan.FromSeconds(90), result.RetryOptions.TryTimeout);
            Assert.AreEqual(EventHubsRetryMode.Fixed, result.RetryOptions.Mode);
            Assert.AreEqual(EventHubsTransportType.AmqpWebSockets, result.ConnectionOptions.TransportType);
        }
コード例 #13
0
        public async Task ProcessEvents_Failure_Checkpoints()
        {
            var partitionContext = EventHubTests.GetPartitionContext();
            var options          = new EventHubOptions();
            var checkpointer     = new Mock <EventHubListener.ICheckpointer>(MockBehavior.Strict);

            checkpointer.Setup(p => p.CheckpointAsync(partitionContext)).Returns(Task.CompletedTask);

            List <EventData>      events  = new List <EventData>();
            List <FunctionResult> results = new List <FunctionResult>();

            for (int i = 0; i < 10; i++)
            {
                events.Add(new EventData(new byte[0]));
                var succeeded = i > 7 ? false : true;
                results.Add(new FunctionResult(succeeded));
            }

            var executor  = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict);
            int execution = 0;

            executor.Setup(p => p.TryExecuteAsync(It.IsAny <TriggeredFunctionData>(), It.IsAny <CancellationToken>())).ReturnsAsync(() =>
            {
                var result = results[execution++];
                return(result);
            });

            var loggerMock = new Mock <ILogger>();

            var eventProcessor = new EventHubListener.EventProcessor(options, executor.Object, loggerMock.Object, true, checkpointer.Object);

            await eventProcessor.ProcessEventsAsync(partitionContext, events);

            checkpointer.Verify(p => p.CheckpointAsync(partitionContext), Times.Once);
        }
コード例 #14
0
        public async Task ProcessEvents_SingleDispatch_CheckpointsCorrectly(int batchCheckpointFrequency, int expected)
        {
            var partitionContext = EventHubTests.GetPartitionContext();
            var checkpoints      = 0;
            var options          = new EventHubOptions
            {
                BatchCheckpointFrequency = batchCheckpointFrequency
            };
            var checkpointer = new Mock <EventHubListener.ICheckpointer>(MockBehavior.Strict);

            checkpointer.Setup(p => p.CheckpointAsync(partitionContext)).Callback <PartitionContext>(c =>
            {
                checkpoints++;
            }).Returns(Task.CompletedTask);
            var loggerMock = new Mock <ILogger>();
            var executor   = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict);

            executor.Setup(p => p.TryExecuteAsync(It.IsAny <TriggeredFunctionData>(), It.IsAny <CancellationToken>())).ReturnsAsync(new FunctionResult(true));
            var eventProcessor = new EventHubListener.EventProcessor(options, executor.Object, loggerMock.Object, true, checkpointer.Object);

            for (int i = 0; i < 100; i++)
            {
                List <EventData> events = new List <EventData>()
                {
                    new EventData(new byte[0])
                };
                await eventProcessor.ProcessEventsAsync(partitionContext, events);
            }

            Assert.AreEqual(expected, checkpoints);
        }
コード例 #15
0
 public EventDataGeneratorAdapterFactory(string name, EventDataGeneratorStreamOptions options,
                                         EventHubOptions ehOptions, EventHubReceiverOptions receiverOptions, EventHubStreamCachePressureOptions cacheOptions, StreamCacheEvictionOptions evictionOptions, StreamStatisticOptions statisticOptions,
                                         IServiceProvider serviceProvider, SerializationManager serializationManager, ITelemetryProducer telemetryProducer, ILoggerFactory loggerFactory)
     : base(name, ehOptions, receiverOptions, cacheOptions, evictionOptions, statisticOptions, serviceProvider, serializationManager, telemetryProducer, loggerFactory)
 {
     this.ehGeneratorOptions = options;
 }
コード例 #16
0
 public TestEventHubStreamAdapterFactory(string name, EventHubOptions ehOptions, EventHubReceiverOptions receiverOptions, EventHubStreamCachePressureOptions cacheOptions,
                                         StreamCacheEvictionOptions evictionOptions, StreamStatisticOptions statisticOptions,
                                         IServiceProvider serviceProvider, SerializationManager serializationManager, ITelemetryProducer telemetryProducer, ILoggerFactory loggerFactory)
     : base(name, ehOptions, receiverOptions, cacheOptions, evictionOptions, statisticOptions, serviceProvider, serializationManager, telemetryProducer, loggerFactory)
 {
     StreamFailureHandlerFactory = qid => TestAzureTableStorageStreamFailureHandler.Create(this.serviceProvider.GetRequiredService <SerializationManager>());
 }
コード例 #17
0
        public void RespectsConnectionOptionsForProducer(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.AddSender(expectedPathName, connectionString);

            var configuration = CreateConfiguration();
            var factory       = new EventHubClientFactory(configuration, Mock.Of <AzureComponentFactory>(), Options.Create(options), new DefaultNameResolver(configuration));

            var producer = factory.GetEventHubProducerClient(expectedPathName, null);
            EventHubConnection connection = (EventHubConnection)typeof(EventHubProducerClient).GetProperty("Connection", BindingFlags.NonPublic | BindingFlags.Instance)
                                            .GetValue(producer);
            EventHubConnectionOptions connectionOptions = (EventHubConnectionOptions)typeof(EventHubConnection).GetProperty("Options", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(connection);

            Assert.AreEqual(testEndpoint, connectionOptions.CustomEndpointAddress);
            Assert.AreEqual(expectedPathName, producer.EventHubName);

            EventHubProducerClientOptions producerOptions = (EventHubProducerClientOptions)typeof(EventHubProducerClient).GetProperty("Options", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(producer);

            Assert.AreEqual(10, producerOptions.RetryOptions.MaximumRetries);
            Assert.AreEqual(expectedPathName, producer.EventHubName);
        }
コード例 #18
0
        public async Task ProcessEvents_MultipleDispatch_CheckpointsCorrectly(int batchCheckpointFrequency, int expected)
        {
            var partitionContext = EventHubTests.GetPartitionContext();
            var options          = new EventHubOptions
            {
                BatchCheckpointFrequency = batchCheckpointFrequency
            };

            var processor = new Mock <EventProcessorHost>(MockBehavior.Strict);

            processor.Setup(p => p.CheckpointAsync(partitionContext.PartitionId, It.IsAny <EventData>(), It.IsAny <CancellationToken>())).Returns(Task.CompletedTask);
            partitionContext.ProcessorHost = processor.Object;

            var loggerMock = new Mock <ILogger>();
            var executor   = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict);

            executor.Setup(p => p.TryExecuteAsync(It.IsAny <TriggeredFunctionData>(), It.IsAny <CancellationToken>())).ReturnsAsync(new FunctionResult(true));
            var eventProcessor = new EventHubListener.EventProcessor(options, executor.Object, loggerMock.Object, false);

            for (int i = 0; i < 100; i++)
            {
                List <EventData> events = new List <EventData>()
                {
                    new EventData(new byte[0]), new EventData(new byte[0]), new EventData(new byte[0])
                };
                await eventProcessor.ProcessEventsAsync(partitionContext, events);
            }

            processor.Verify(
                p => p.CheckpointAsync(partitionContext.PartitionId, It.IsAny <EventData>(), It.IsAny <CancellationToken>()),
                Times.Exactly(expected));
        }
コード例 #19
0
        public void GetEventHubClient_AddsConnection(string expectedPathName, string connectionString)
        {
            EventHubOptions options = new EventHubOptions();
            var             client  = options.GetEventHubProducerClient("k1", connectionString);

            Assert.AreEqual(expectedPathName, client.EventHubName);
        }
コード例 #20
0
        public void RespectsConnectionOptionsForProcessor(string expectedPathName, string connectionString)
        {
            var             testEndpoint = new Uri("http://mycustomendpoint.com");
            EventHubOptions options      = new EventHubOptions
            {
                CustomEndpointAddress = testEndpoint,
                TransportType         = EventHubsTransportType.AmqpWebSockets,
                WebProxy           = new WebProxy("http://proxyserver/"),
                ClientRetryOptions = new EventHubsRetryOptions
                {
                    MaximumRetries = 10
                }
            };

            var configuration = CreateConfiguration(new KeyValuePair <string, string>("connection", connectionString));
            var factory       = CreateFactory(configuration, options);

            var processor = factory.GetEventProcessorHost(expectedPathName, "connection", "consumer");
            EventProcessorOptions processorOptions = (EventProcessorOptions)typeof(EventProcessor <EventProcessorHostPartition>)
                                                     .GetProperty("Options", BindingFlags.NonPublic | BindingFlags.Instance)
                                                     .GetValue(processor);

            Assert.AreEqual(testEndpoint, processorOptions.ConnectionOptions.CustomEndpointAddress);
            Assert.AreEqual(EventHubsTransportType.AmqpWebSockets, processorOptions.ConnectionOptions.TransportType);
            Assert.AreEqual("http://proxyserver/", ((WebProxy)processorOptions.ConnectionOptions.Proxy).Address.AbsoluteUri);
            Assert.AreEqual(10, processorOptions.RetryOptions.MaximumRetries);
            Assert.AreEqual(expectedPathName, processor.EventHubName);
        }
コード例 #21
0
        public void ConfigureOptions_Format_Returns_Expected()
        {
            EventHubOptions options = CreateOptionsFromConfig();
            JObject         jObject = new JObject
            {
                { ExtensionPath, JObject.Parse(((IOptionsFormatter)options).Format()) }
            };

            EventHubOptions result = TestHelpers.GetConfiguredOptions <EventHubOptions>(
                b => { b.AddEventHubs(); },
                jsonStream: new BinaryData(jObject.ToString()).ToStream());

            Assert.AreEqual(123, result.MaxEventBatchSize);
            Assert.AreEqual(5, result.BatchCheckpointFrequency);
            Assert.True(result.TrackLastEnqueuedEventProperties);
            Assert.AreEqual(123, result.PrefetchCount);
            Assert.AreEqual(TimeSpan.FromSeconds(31), result.PartitionOwnershipExpirationInterval);
            Assert.AreEqual(TimeSpan.FromSeconds(21), result.LoadBalancingUpdateInterval);
            Assert.AreEqual("FromEnqueuedTime", result.InitialOffsetOptions.Type.ToString());
            Assert.AreEqual("2020-09-13 12:00:00Z", result.InitialOffsetOptions.EnqueuedTimeUtc.Value.ToString("u"));
            Assert.AreEqual(5, result.ClientRetryOptions.MaximumRetries);
            Assert.AreEqual(TimeSpan.FromSeconds(1), result.ClientRetryOptions.Delay);
            Assert.AreEqual(TimeSpan.FromMinutes(1), result.ClientRetryOptions.MaximumDelay);
            Assert.AreEqual(TimeSpan.FromSeconds(90), result.ClientRetryOptions.TryTimeout);
            Assert.AreEqual(EventHubsRetryMode.Fixed, result.ClientRetryOptions.Mode);
            Assert.AreEqual(EventHubsTransportType.AmqpWebSockets, result.TransportType);
            Assert.AreEqual("http://proxyserver:8080/", ((WebProxy)result.WebProxy).Address.AbsoluteUri);
            Assert.AreEqual("http://www.customendpoint.com/", result.CustomEndpointAddress.AbsoluteUri);
        }
コード例 #22
0
        public void EntityPathInConnectionString(string expectedPathName, string connectionString)
        {
            EventHubOptions options = new EventHubOptions();

            // Test sender
            options.AddSender("k1", connectionString);
            var client = options.GetEventHubClient("k1", null);

            Assert.Equal(expectedPathName, client.EventHubName);
        }
コード例 #23
0
        public void GetEventHubClient_AddsConnection(string expectedPathName, string connectionString)
        {
            EventHubOptions options       = new EventHubOptions();
            var             configuration = CreateConfiguration(new KeyValuePair <string, string>("connection", connectionString));

            var factory = new EventHubClientFactory(configuration, Mock.Of <AzureComponentFactory>(), Options.Create(options), new DefaultNameResolver(configuration), new AzureEventSourceLogForwarder(new NullLoggerFactory()));

            var client = factory.GetEventHubProducerClient(expectedPathName, "connection");

            Assert.AreEqual(expectedPathName, client.EventHubName);
        }
コード例 #24
0
        public void GetEventHubClient_AddsConnection(string expectedPathName, string connectionString)
        {
            EventHubOptions options       = new EventHubOptions();
            var             configuration = CreateConfiguration(new KeyValuePair <string, string>("connection", connectionString));

            var factory = CreateFactory(configuration, options);

            var client = factory.GetEventHubProducerClient(expectedPathName, "connection");

            Assert.AreEqual(expectedPathName, client.EventHubName);
        }
コード例 #25
0
 public EHStreamProviderForMonitorTestsAdapterFactory(string name, EventDataGeneratorStreamOptions options, EventHubOptions ehOptions, EventHubReceiverOptions receiverOptions,
                                                      EventHubStreamCachePressureOptions cacheOptions, StreamCacheEvictionOptions streamCacheEvictionOptions, StreamStatisticOptions statisticOptions,
                                                      IEventHubDataAdapter dataAdapter, IServiceProvider serviceProvider, SerializationManager serializationManager, ITelemetryProducer telemetryProducer, ILoggerFactory loggerFactory)
     : base(name, options, ehOptions, receiverOptions, cacheOptions, streamCacheEvictionOptions, statisticOptions, dataAdapter, serviceProvider, serializationManager, telemetryProducer, loggerFactory)
 {
     this.serializationManager = serializationManager;
     this.cacheOptions         = cacheOptions;
     this.staticticOptions     = statisticOptions;
     this.ehOptions            = ehOptions;
     this.evictionOptions      = streamCacheEvictionOptions;
 }
コード例 #26
0
        public EHStreamProviderWithCreatedCacheListAdapterFactory(string name, EventDataGeneratorStreamOptions options, EventHubOptions ehOptions, EventHubReceiverOptions receiverOptions,
                                                                  EventHubStreamCachePressureOptions cacheOptions, StreamCacheEvictionOptions evictionOptions, StreamStatisticOptions statisticOptions,
                                                                  IServiceProvider serviceProvider, SerializationManager serializationManager, ITelemetryProducer telemetryProducer, ILoggerFactory loggerFactory)
            : base(name, options, ehOptions, receiverOptions, cacheOptions, evictionOptions, statisticOptions, serviceProvider, serializationManager, telemetryProducer, loggerFactory)

        {
            this.createdCaches    = new ConcurrentBag <QueueCacheForTesting>();
            this.cacheOptions     = cacheOptions;
            this.staticticOptions = statisticOptions;
            this.ehOptions        = ehOptions;
            this.evictionOptions  = evictionOptions;
        }
コード例 #27
0
        public void ConfigureOptions_AppliesValuesCorrectly()
        {
            EventHubOptions options = CreateOptions();

            Assert.Equal(123, options.EventProcessorOptions.MaxBatchSize);
            Assert.Equal(TimeSpan.FromSeconds(33), options.EventProcessorOptions.ReceiveTimeout);
            Assert.Equal(true, options.EventProcessorOptions.EnableReceiverRuntimeMetric);
            Assert.Equal(123, options.EventProcessorOptions.PrefetchCount);
            Assert.Equal(true, options.EventProcessorOptions.InvokeProcessorAfterReceiveTimeout);
            Assert.Equal(5, options.BatchCheckpointFrequency);
            Assert.Equal(31, options.PartitionManagerOptions.LeaseDuration.TotalSeconds);
            Assert.Equal(21, options.PartitionManagerOptions.RenewInterval.TotalSeconds);
        }
コード例 #28
0
        public async Task CloseAsync_Shutdown_DoesNotCheckpoint()
        {
            var partitionContext = EventHubTests.GetPartitionContext();
            var options          = new EventHubOptions();
            var checkpointer     = new Mock <EventHubListener.ICheckpointer>(MockBehavior.Strict);
            var executor         = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict);
            var loggerMock       = new Mock <ILogger>();
            var eventProcessor   = new EventHubListener.EventProcessor(options, executor.Object, loggerMock.Object, true, checkpointer.Object);

            await eventProcessor.CloseAsync(partitionContext, CloseReason.Shutdown);

            checkpointer.Verify(p => p.CheckpointAsync(partitionContext), Times.Never);
        }
コード例 #29
0
        public void ConfigureOptions_AppliesValuesCorrectly_BackCompat()
        {
            EventHubOptions options = CreateOptionsFromConfigBackCompat();

            Assert.AreEqual(123, options.MaxBatchSize);
            Assert.AreEqual(true, options.EventProcessorOptions.TrackLastEnqueuedEventProperties);
            Assert.AreEqual(123, options.EventProcessorOptions.PrefetchCount);
            Assert.AreEqual(5, options.BatchCheckpointFrequency);
            Assert.AreEqual(31, options.EventProcessorOptions.PartitionOwnershipExpirationInterval.TotalSeconds);
            Assert.AreEqual(21, options.EventProcessorOptions.LoadBalancingUpdateInterval.TotalSeconds);
            Assert.AreEqual("FromEnqueuedTime", options.InitialOffsetOptions.Type.ToString());
            Assert.AreEqual("2020-09-13 12:00:00Z", options.InitialOffsetOptions.EnqueuedTimeUtc.Value.ToString("u"));
        }
コード例 #30
0
        public void ConfigureOptions_AppliesValuesCorrectly()
        {
            EventHubOptions options = CreateOptions();

            Assert.AreEqual(123, options.MaxBatchSize);
            Assert.AreEqual(TimeSpan.FromSeconds(33), options.EventProcessorOptions.MaximumWaitTime);
            Assert.AreEqual(true, options.EventProcessorOptions.TrackLastEnqueuedEventProperties);
            Assert.AreEqual(123, options.EventProcessorOptions.PrefetchCount);
            Assert.AreEqual(true, options.InvokeProcessorAfterReceiveTimeout);
            Assert.AreEqual(5, options.BatchCheckpointFrequency);
            Assert.AreEqual(31, options.EventProcessorOptions.PartitionOwnershipExpirationInterval.TotalSeconds);
            Assert.AreEqual(21, options.EventProcessorOptions.LoadBalancingUpdateInterval.TotalSeconds);
        }