示例#1
0
        private async Task <FunctionSnapshot[]> GetSnapshotsAsync()
        {
            if (_snapshots == null)
            {
                string[] results = await _reader.GetFunctionNamesAsync();

                _snapshots = Array.ConvertAll(results, name => new FunctionSnapshot
                {
                    Id         = name,
                    FullName   = name,
                    ShortName  = name,
                    Parameters = new Dictionary <string, ParameterSnapshot>()
                });
            }
            return(_snapshots);
        }
示例#2
0
        public async Task LogExactWriteAndRead()
        {
            // Make some very precise writes and verify we read exactly what we'd expect.

            var table = GetNewLoggingTable();

            try
            {
                ILogWriter writer = LogFactory.NewWriter("c1", table);
                ILogReader reader = LogFactory.NewReader(table);

                string Func1 = "alpha";
                string Func2 = "beta";

                var t1a = new DateTime(2010, 3, 6, 10, 11, 20);
                var t1b = new DateTime(2010, 3, 6, 10, 11, 21); // same time bucket as t1a
                var t2  = new DateTime(2010, 3, 7, 10, 11, 21);

                FunctionInstanceLogItem l1 = new FunctionInstanceLogItem
                {
                    FunctionInstanceId = Guid.NewGuid(),
                    FunctionName       = Func1,
                    StartTime          = t1a,
                    LogOutput          = "one"
                };
                await WriteAsync(writer, l1);

                await writer.FlushAsync(); // Multiple flushes; test starting & stopping the backgrounf worker.

                FunctionInstanceLogItem l2 = new FunctionInstanceLogItem
                {
                    FunctionInstanceId = Guid.NewGuid(),
                    FunctionName       = Func2,
                    StartTime          = t1b,
                    LogOutput          = "two"
                };
                await WriteAsync(writer, l2);

                FunctionInstanceLogItem l3 = new FunctionInstanceLogItem
                {
                    FunctionInstanceId = Guid.NewGuid(),
                    FunctionName       = Func1,
                    StartTime          = t2,
                    LogOutput          = "three",
                    ErrorDetails       = "this failed"
                };
                await WriteAsync(writer, l3);

                await writer.FlushAsync();

                // Now read
                string[] functionNames = await reader.GetFunctionNamesAsync();

                Array.Sort(functionNames);
                Assert.Equal(Func1, functionNames[0]);
                Assert.Equal(Func2, functionNames[1]);

                // Read Func1
                {
                    var segment1 = await reader.GetAggregateStatsAsync(Func1, DateTime.MinValue, DateTime.MaxValue, null);

                    Assert.Null(segment1.ContinuationToken);
                    var stats1 = segment1.Results;
                    Assert.Equal(2, stats1.Length); // includes t1 and t2

                    // First bucket has l1, second bucket has l3
                    Assert.Equal(stats1[0].TotalPass, 1);
                    Assert.Equal(stats1[0].TotalRun, 1);
                    Assert.Equal(stats1[0].TotalFail, 0);

                    Assert.Equal(stats1[1].TotalPass, 0);
                    Assert.Equal(stats1[1].TotalRun, 1);
                    Assert.Equal(stats1[1].TotalFail, 1);

                    // reverse order. So l3 latest function, is listed first.
                    var recent1 = await GetRecentAsync(reader, Func1);

                    Assert.Equal(2, recent1.Length);

                    Assert.Equal(recent1[0].FunctionInstanceId, l3.FunctionInstanceId);
                    Assert.Equal(recent1[1].FunctionInstanceId, l1.FunctionInstanceId);
                }

                // Read Func2
                {
                    var segment2 = await reader.GetAggregateStatsAsync(Func2, DateTime.MinValue, DateTime.MaxValue, null);

                    var stats2 = segment2.Results;
                    Assert.Equal(1, stats2.Length);
                    Assert.Equal(stats2[0].TotalPass, 1);
                    Assert.Equal(stats2[0].TotalRun, 1);
                    Assert.Equal(stats2[0].TotalFail, 0);

                    var recent2 = await GetRecentAsync(reader, Func2);

                    Assert.Equal(1, recent2.Length);
                    Assert.Equal(recent2[0].FunctionInstanceId, l2.FunctionInstanceId);
                }
            }
            finally
            {
                // Cleanup
                table.DeleteIfExists();
            }
        }