コード例 #1
0
        public async Task EventCollectorOnly()
        {
            using (_functionCompletedEvent = new ManualResetEvent(initialState: false))
            {
                _hostConfig.Tracing.ConsoleLevel = TraceLevel.Off;

                // disable the aggregator
                _hostConfig.Aggregator.IsEnabled = false;

                // add a FunctionEventCollector
                var eventCollector = new TestFunctionEventCollector();
                _hostConfig.AddService <IAsyncCollector <FunctionInstanceLogEntry> >(eventCollector);

                JobHost host = new JobHost(_hostConfig);

                await host.StartAsync();

                await host.CallAsync(typeof(AsyncChainEndToEndTests).GetMethod("WriteStartDataMessageToQueue"));

                await TestHelpers.Await(() => _functionCompletedEvent.WaitOne(200), 30000);

                // ensure all logs have had a chance to flush
                await Task.Delay(3000);

                await host.StopAsync();

                // Make sure the aggregator was logged to
                var logger = _loggerProvider.CreatedLoggers.Where(l => l.Category == LogCategories.Aggregator).SingleOrDefault();
                Assert.Null(logger);

                // Make sure the eventCollector was logged
                eventCollector.AssertFunctionCount(4);
            }
        }
コード例 #2
0
        public async Task AggregatorAndEventCollector()
        {
            using (_functionCompletedEvent = new ManualResetEvent(initialState: false))
            {
                // enable the aggregator
                _hostConfig.Aggregator.IsEnabled = true;
                _hostConfig.Aggregator.BatchSize = 1;

                // add a FunctionEventCollector
                var eventCollector = new TestFunctionEventCollector();
                _hostConfig.AddService <IAsyncCollector <FunctionInstanceLogEntry> >(eventCollector);

                JobHost host = new JobHost(_hostConfig);

                await host.StartAsync();

                await host.CallAsync(typeof(AsyncChainEndToEndTests).GetMethod(nameof(WriteStartDataMessageToQueue)));

                await WaitForFunctionCompleteAsync();

                // ensure all logs have had a chance to flush
                await Task.Delay(3000);

                await host.StopAsync();

                // Make sure the aggregator was logged to
                var logger = _loggerProvider.CreatedLoggers.Where(l => l.Category == LogCategories.Aggregator).Single();
                var count  = logger.GetLogMessages().Count;
                Assert.True(count == 4, $"Expected 4. Actual {count}.{Environment.NewLine}{_loggerProvider.GetLogString()}");
                // Make sure the eventCollector was logged
                eventCollector.AssertFunctionCount(4, _loggerProvider.GetLogString());
            }
        }
コード例 #3
0
        public async Task AggregatorAndEventCollector()
        {
            using (_functionCompletedEvent = new ManualResetEvent(initialState: false))
            {
                // enable the aggregator
                _hostConfig.Aggregator.IsEnabled = true;
                _hostConfig.Aggregator.BatchSize = 1;

                // add a FunctionEventCollector
                var eventCollector = new TestFunctionEventCollector();
                _hostConfig.AddService <IAsyncCollector <FunctionInstanceLogEntry> >(eventCollector);

                JobHost host = new JobHost(_hostConfig);

                await host.StartAsync();

                await host.CallAsync(typeof(AsyncChainEndToEndTests).GetMethod(nameof(WriteStartDataMessageToQueue)));

                await TestHelpers.Await(() => _functionCompletedEvent.WaitOne(200), 30000);

                // ensure all logs have had a chance to flush
                await Task.Delay(3000);

                await host.StopAsync();

                // Make sure the aggregator was logged to
                var logger = _loggerProvider.CreatedLoggers.Where(l => l.Category == LogCategories.Aggregator).Single();
                Assert.Equal(4, logger.LogMessages.Count);

                // Make sure the eventCollector was logged
                eventCollector.AssertFunctionCount(4);
            }
        }
コード例 #4
0
        public async Task EventCollectorOnly()
        {
            using (_functionCompletedEvent = new ManualResetEvent(initialState: false))
            {
                // aggregator is disabled by default in these tests

                // add a FunctionEventCollector
                var eventCollector = new TestFunctionEventCollector();

                _hostBuilder.ConfigureServices(services =>
                {
                    services.AddSingleton <IAsyncCollector <FunctionInstanceLogEntry> >(eventCollector);
                });

                IHost   host    = _hostBuilder.Build();
                JobHost jobHost = host.GetJobHost();

                await jobHost.StartAsync();

                await jobHost.CallAsync(typeof(AsyncChainEndToEndTests).GetMethod("WriteStartDataMessageToQueue"));

                var loggerProvider = host.GetTestLoggerProvider();
                await WaitForFunctionCompleteAsync(loggerProvider);

                // ensure all logs have had a chance to flush
                await Task.Delay(3000);

                await jobHost.StopAsync();

                // Make sure the aggregator was logged to
                var logger = host.GetTestLoggerProvider().CreatedLoggers.Where(l => l.Category == LogCategories.Aggregator).SingleOrDefault();
                Assert.Null(logger);

                // Make sure the eventCollector was logged
                eventCollector.AssertFunctionCount(4, loggerProvider.GetLogString());
            }
        }