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); }
[InlineData(20, 80)] // 3/4's of the entries should be dropped public async Task LogsAreDroppedWhenBufferIsFull(int maxBufferedEntryCount, int logItemCount) { List <Exception> caughtExceptions = new List <Exception>(); LogWriter writer = (LogWriter)LogFactory.NewWriter(defaultHost, "c1", this, (ex) => caughtExceptions.Add(ex)); writer.MaxBufferedEntryCount = maxBufferedEntryCount; ILogReader reader = LogFactory.NewReader(this); var logItems = new List <FunctionInstanceLogItem>(); for (int i = 0; i < logItemCount; i++) { logItems.Add(new FunctionInstanceLogItem { FunctionInstanceId = Guid.NewGuid(), FunctionName = "test", StartTime = DateTime.UtcNow - TimeSpan.FromMilliseconds(50), EndTime = DateTime.UtcNow, LogOutput = "output 1" }); } foreach (var item in logItems) { await writer.AddAsync(item); } await writer.FlushAsync(); var id = logItems[0].FunctionId; if (maxBufferedEntryCount < logItemCount) { Assert.NotEmpty(caughtExceptions); Assert.StartsWith("The limit on the number of buffered log entries was reached.", caughtExceptions[0].Message); } // Counts should be intact var segment1 = await reader.GetAggregateStatsAsync(id, DateTime.MinValue, DateTime.MaxValue, null); var runs = segment1.Results.Sum(x => x.TotalRun); Assert.Equal(runs, logItemCount); // Some of the results should be missing var segmentRecent = await reader.GetRecentFunctionInstancesAsync(new RecentFunctionQuery { FunctionId = id, Start = DateTime.MinValue, End = DateTime.MaxValue, MaximumResults = 1000 }, null); int expectedLoggedCount = Math.Min(logItemCount, maxBufferedEntryCount); Assert.NotNull(segmentRecent); Assert.Equal(expectedLoggedCount, segmentRecent.Results.Length); }
static async Task <IRecentFunctionEntry[]> GetRecentAsync(ILogReader reader, FunctionId functionId, DateTime start, DateTime end) { var query = await reader.GetRecentFunctionInstancesAsync(new RecentFunctionQuery { FunctionId = functionId, Start = start, End = end, MaximumResults = 1000 }, null); var results = query.Results; return(results); }
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(); } }
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); } }
static async Task<IRecentFunctionEntry[]> GetRecentAsync(ILogReader reader, string functionName, DateTime start, DateTime end) { var query = await reader.GetRecentFunctionInstancesAsync(new RecentFunctionQuery { FunctionName = functionName, Start = start, End = end, MaximumResults = 1000 }, null); var results = query.Results; return results; }