Example #1
0
        public async Task ReadNoTable()
        {
            ILogReader reader = LogFactory.NewReader(this);

            Assert.Empty(_tables); // no tables yet.

            var segmentDef = await reader.GetFunctionDefinitionsAsync(null, null);

            Assert.Empty(segmentDef.Results);

            var segmentTimeline = await reader.GetActiveContainerTimelineAsync(DateTime.MinValue, DateTime.MaxValue, null);

            Assert.Empty(segmentTimeline.Results);

            var segmentRecent = await reader.GetRecentFunctionInstancesAsync(new RecentFunctionQuery
            {
                FunctionId     = FunctionId.Parse("abc"),
                Start          = DateTime.MinValue,
                End            = DateTime.MaxValue,
                MaximumResults = 1000
            }, null);

            Assert.Empty(segmentRecent.Results);

            var item = await reader.LookupFunctionInstanceAsync(Guid.NewGuid());

            Assert.Null(item);
        }
        public async Task ReadNoTable()
        {
            var        table  = GetNewLoggingTable();
            ILogReader reader = LogFactory.NewReader(table);

            Assert.False(table.Exists());

            var segmentDef = await reader.GetFunctionDefinitionsAsync(null);

            Assert.Equal(0, segmentDef.Results.Length);

            var segmentTimeline = await reader.GetActiveContainerTimelineAsync(DateTime.MinValue, DateTime.MaxValue, null);

            Assert.Equal(0, segmentTimeline.Results.Length);

            var segmentRecent = await reader.GetRecentFunctionInstancesAsync(new RecentFunctionQuery
            {
                FunctionName   = "abc",
                Start          = DateTime.MinValue,
                End            = DateTime.MaxValue,
                MaximumResults = 1000
            }, null);

            Assert.Equal(0, segmentRecent.Results.Length);

            var item = await reader.LookupFunctionInstanceAsync(Guid.NewGuid());

            Assert.Null(item);
        }
        public async Task Casing()
        {
            // 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 FuncOriginal = "UPPER-lower";
                string Func2        = FuncOriginal.ToLower(); // casing permutations
                string Func3        = Func2.ToLower();

                var t1a = new DateTime(2010, 3, 6, 10, 11, 20, DateTimeKind.Utc);

                FunctionInstanceLogItem l1 = new FunctionInstanceLogItem
                {
                    FunctionInstanceId = Guid.NewGuid(),
                    FunctionName       = FuncOriginal,
                    StartTime          = t1a,
                    LogOutput          = "one"
                                         // inferred as Running since no end time.
                };
                await writer.AddAsync(l1);

                await writer.FlushAsync();

                // Start event should exist.


                var definitionSegment = await reader.GetFunctionDefinitionsAsync(null);

                Assert.Equal(1, definitionSegment.Results.Length);
                Assert.Equal(FuncOriginal, definitionSegment.Results[0].Name);

                // Lookup various casings
                foreach (var name in new string[] { FuncOriginal, Func2, Func3 })
                {
                    var entries = await GetRecentAsync(reader, name);

                    Assert.Equal(1, entries.Length);
                    Assert.Equal(entries[0].Status, FunctionInstanceStatus.Running);
                    Assert.Equal(entries[0].EndTime, null);
                    Assert.Equal(entries[0].FunctionName, FuncOriginal); // preserving.
                }
            }
            finally
            {
                // Cleanup
                table.DeleteIfExists();
            }
        }
Example #4
0
        private async Task <FunctionSnapshot[]> GetSnapshotsAsync(string hostName = null)
        {
            var segment = await _reader.GetFunctionDefinitionsAsync(hostName, null);

            var definitions = segment.Results;

            DateTime latest = GetLatestModifiedTime(definitions);

            var snapshots = Array.ConvertAll(definitions, definition => new FunctionSnapshot
            {
                Id          = definition.FunctionId.ToString(),
                FullName    = definition.Name,
                ShortName   = definition.Name,
                Parameters  = new Dictionary <string, ParameterSnapshot>(),
                HostVersion = definition.LastModified
            });

            _version = latest;

            return(snapshots);
        }
Example #5
0
        static async Task Reader(ILogReader reader, DateTime startDate, DateTime endDate)
        {
            Segment <IFunctionDefinition> definitions = await reader.GetFunctionDefinitionsAsync(null, null);

            foreach (IFunctionDefinition definition in definitions.Results)
            {
                Console.WriteLine("Function:  {0}", definition.Name);

                var query = new RecentFunctionQuery
                {
                    FunctionId     = definition.FunctionId,
                    MaximumResults = 20,
                    Start          = startDate,
                    End            = endDate
                };
                Segment <IRecentFunctionEntry> instances = await reader.GetRecentFunctionInstancesAsync(query, null);

                foreach (IRecentFunctionEntry instance in instances.Results)
                {
                    Console.WriteLine("  {2}: start={0}, end={1}", instance.StartTime, instance.EndTime, instance.Status);
                }
                Console.WriteLine();
            }
        }
Example #6
0
        private async Task <FunctionSnapshot[]> GetSnapshotsAsync()
        {
            var segment = await _reader.GetFunctionDefinitionsAsync(null);

            var definitions = segment.Results;

            var current = _snapshots;

            DateTime latest = GetLatestModifiedTime(definitions);

            if ((_snapshots == null) || (latest > _version))
            {
                _snapshots = Array.ConvertAll(definitions, definition => new FunctionSnapshot
                {
                    Id          = definition.Name,
                    FullName    = definition.Name,
                    ShortName   = definition.Name,
                    Parameters  = new Dictionary <string, ParameterSnapshot>(),
                    HostVersion = definition.LastModified
                });
                _version = latest;
            }
            return(_snapshots);
        }
Example #7
0
        public async Task LogExactWriteAndRead()
        {
            // Make some very precise writes and verify we read exactly what we'd expect.
            ILogWriter writer = LogFactory.NewWriter(defaultHost, "c1", this);
            ILogReader reader = LogFactory.NewReader(this);

            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
            var definitionSegment = await reader.GetFunctionDefinitionsAsync(null, null);

            string[] functionNames = Array.ConvertAll(definitionSegment.Results, definition => definition.Name);
            Array.Sort(functionNames);
            Assert.Equal(Func1, functionNames[0]);
            Assert.Equal(Func2, functionNames[1]);

            // Read Func1
            {
                var segment1 = await reader.GetAggregateStatsAsync(l3.FunctionId, 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, l3.FunctionId);

                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(l2.FunctionId, DateTime.MinValue, DateTime.MaxValue, null);

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

                var recent2 = await GetRecentAsync(reader, l2.FunctionId);

                Assert.Single(recent2);
                Assert.Equal(recent2[0].FunctionInstanceId, l2.FunctionInstanceId);
            }
        }
Example #8
0
        public async Task DifferentHosts()
        {
            // 1a & 1b are 2 instances (different machines) of the same host. They share.
            // 2 is a separate host.
            string     host1    = "h1-1"; // includes an tricky character that requires escaping.
            string     host2    = "h22";
            ILogWriter writer1a = LogFactory.NewWriter(host1, "c1", this);
            ILogWriter writer1b = LogFactory.NewWriter(host1, "c2", this);
            ILogWriter writer2  = LogFactory.NewWriter(host2, "c3", this);

            ILogReader reader1 = LogFactory.NewReader(this);
            ILogReader reader2 = LogFactory.NewReader(this);

            string Func1 = "alpha";

            var f1a = await QuickWriteAsync(writer1a, Func1); // first

            var f1b = await QuickWriteAsync(writer1b, Func1);

            var f1aa = await QuickWriteAsync(writer1a, Func1); // second write

            var f2 = await QuickWriteAsync(writer2, Func1);

            // Verify readers
            // Function definitions. Search all hosts if no host specified
            {
                var segment = await reader1.GetFunctionDefinitionsAsync(null, null);

                Assert.Equal(2, segment.Results.Length);
                var allDefinitions = segment.Results;

                segment = await reader1.GetFunctionDefinitionsAsync(host1, null);

                Assert.Single(segment.Results);
                var host1Defs = segment.Results[0];
                Assert.Equal(Func1, host1Defs.Name);
                Assert.Equal(FunctionId.Build(host1, Func1), host1Defs.FunctionId);

                segment = await reader1.GetFunctionDefinitionsAsync(host2, null);

                Assert.Single(segment.Results);
                var host2Defs = segment.Results[0];
                Assert.Equal(Func1, host2Defs.Name);
                Assert.Equal(FunctionId.Build(host2, Func1), host2Defs.FunctionId);

                Assert.Equal(Func1, allDefinitions[0].Name);
                Assert.Equal(Func1, allDefinitions[1].Name);
                Assert.Equal(host1Defs.FunctionId, allDefinitions[0].FunctionId);
                Assert.Equal(host2Defs.FunctionId, allDefinitions[1].FunctionId);
            }

            // Recent list
            {
                var segment = await reader1.GetRecentFunctionInstancesAsync(new RecentFunctionQuery
                {
                    FunctionId = FunctionId.Build(host1, Func1),
                    End        = DateTime.MaxValue,
                }, null);

                Guid[] guids = Array.ConvertAll(segment.Results, x => x.FunctionInstanceId);

                Assert.Equal(3, guids.Length); // Only include host 1
                Assert.Equal(f1a, guids[2]);   // reverse chronological
                Assert.Equal(f1b, guids[1]);
                Assert.Equal(f1aa, guids[0]);
            }

            // cross polination. Lookup across hosts.
            {
                var entry = await reader2.LookupFunctionInstanceAsync(f1a);

                Assert.NotNull(entry);
                Assert.Equal(entry.FunctionName, Func1);
            }
        }