|
23 | 23 | using Microsoft.Azure.WebJobs.Script.Description;
|
24 | 24 | using Microsoft.Azure.WebJobs.Script.Diagnostics;
|
25 | 25 | using Microsoft.Azure.WebJobs.Script.Eventing;
|
| 26 | +using Microsoft.Azure.WebJobs.ServiceBus; |
26 | 27 | using Microsoft.Extensions.Logging;
|
| 28 | +using Microsoft.ServiceBus.Messaging; |
27 | 29 | using Microsoft.WebJobs.Script.Tests;
|
28 | 30 | using Moq;
|
29 | 31 | using Newtonsoft.Json.Linq;
|
@@ -524,6 +526,83 @@ public void ApplyConfiguration_Http()
|
524 | 526 | Assert.Equal(10, httpConfig.MaxOutstandingRequests);
|
525 | 527 | }
|
526 | 528 |
|
| 529 | + [Fact] |
| 530 | + public void ApplyConfiguration_EventHubs_UsesWebJobsDefaults() |
| 531 | + { |
| 532 | + JObject config = new JObject(); |
| 533 | + JObject eventHub = new JObject(); |
| 534 | + config["eventHub"] = eventHub; |
| 535 | + |
| 536 | + ScriptHostConfiguration scriptConfig = new ScriptHostConfiguration(); |
| 537 | + scriptConfig.HostConfig.HostConfigMetadata = config; |
| 538 | + TraceWriter traceWriter = new TestTraceWriter(TraceLevel.Verbose); |
| 539 | + |
| 540 | + var provider = new ServiceBusScriptBindingProvider(scriptConfig.HostConfig, config, traceWriter); |
| 541 | + provider.Initialize(); |
| 542 | + |
| 543 | + new JobHost(scriptConfig.HostConfig).CreateMetadataProvider(); // will cause extensions to initialize and consume config metadata. |
| 544 | + |
| 545 | + IExtensionRegistry extensions = scriptConfig.HostConfig.GetService<IExtensionRegistry>(); |
| 546 | + var eventHubConfig = extensions.GetExtensions<IExtensionConfigProvider>().OfType<EventHubConfiguration>().Single(); |
| 547 | + |
| 548 | + // I don't want to update any of the V1 public surface area, so I'll just use reflection for this test. |
| 549 | + var getOptionsMethod = typeof(EventHubConfiguration) |
| 550 | + .GetMethod("GetOptions", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); |
| 551 | + |
| 552 | + Assert.NotNull(getOptionsMethod); |
| 553 | + |
| 554 | + var eventHubOptions = (EventProcessorOptions)getOptionsMethod.Invoke(eventHubConfig, new object[] { }); |
| 555 | + |
| 556 | + // Now lets find out what the defaults should be |
| 557 | + var defaultEventHubConfiguration = new EventHubConfiguration(); |
| 558 | + var defaultOptions = (EventProcessorOptions)getOptionsMethod.Invoke(defaultEventHubConfiguration, new object[] { }); |
| 559 | + |
| 560 | + // And verify they match |
| 561 | + Assert.Equal(defaultOptions.MaxBatchSize, eventHubOptions.MaxBatchSize); |
| 562 | + Assert.Equal(defaultOptions.PrefetchCount, eventHubOptions.PrefetchCount); |
| 563 | + Assert.Equal(defaultEventHubConfiguration.BatchCheckpointFrequency, eventHubConfig.BatchCheckpointFrequency); |
| 564 | + } |
| 565 | + |
| 566 | + [Fact] |
| 567 | + public void ApplyConfiguration_EventHubs_UsesCustomConfiguration() |
| 568 | + { |
| 569 | + JObject config = new JObject(); |
| 570 | + JObject eventHub = new JObject(); |
| 571 | + config["eventHub"] = eventHub; |
| 572 | + |
| 573 | + var customBatchSize = 33; |
| 574 | + var customPrefetchCount = 99; |
| 575 | + var customCheckpointFrequency = 4; |
| 576 | + |
| 577 | + eventHub["maxBatchSize"] = customBatchSize; |
| 578 | + eventHub["prefetchCount"] = customPrefetchCount; |
| 579 | + eventHub["batchCheckpointFrequency"] = customCheckpointFrequency; |
| 580 | + |
| 581 | + ScriptHostConfiguration scriptConfig = new ScriptHostConfiguration(); |
| 582 | + scriptConfig.HostConfig.HostConfigMetadata = config; |
| 583 | + TraceWriter traceWriter = new TestTraceWriter(TraceLevel.Verbose); |
| 584 | + |
| 585 | + var provider = new ServiceBusScriptBindingProvider(scriptConfig.HostConfig, config, traceWriter); |
| 586 | + provider.Initialize(); |
| 587 | + |
| 588 | + new JobHost(scriptConfig.HostConfig).CreateMetadataProvider(); // will cause extensions to initialize and consume config metadata. |
| 589 | + |
| 590 | + IExtensionRegistry extensions = scriptConfig.HostConfig.GetService<IExtensionRegistry>(); |
| 591 | + var eventHubConfig = extensions.GetExtensions<IExtensionConfigProvider>().OfType<EventHubConfiguration>().Single(); |
| 592 | + |
| 593 | + // I don't want to update any of the V1 public surface area, so I'll just use reflection for this test. |
| 594 | + var getOptionsMethod = typeof(EventHubConfiguration) |
| 595 | + .GetMethod("GetOptions", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); |
| 596 | + |
| 597 | + Assert.NotNull(getOptionsMethod); |
| 598 | + |
| 599 | + var eventHubOptions = (EventProcessorOptions)getOptionsMethod.Invoke(eventHubConfig, new object[] { }); |
| 600 | + |
| 601 | + Assert.Equal(customBatchSize, eventHubOptions.MaxBatchSize); |
| 602 | + Assert.Equal(customPrefetchCount, eventHubOptions.PrefetchCount); |
| 603 | + Assert.Equal(customCheckpointFrequency, eventHubConfig.BatchCheckpointFrequency); |
| 604 | + } |
| 605 | + |
527 | 606 | [Fact]
|
528 | 607 | public void ApplyConfiguration_Blobs()
|
529 | 608 | {
|
|
0 commit comments