// Returns null if no legacy table.
        public static CloudTable GetLegacyTable(ILogTableProvider tableProvider)
        {
            var table = tableProvider.GetTable(OldTableName);

            if (!table.Exists())
            {
                return(null);
            }
            return(table);
        }
Пример #2
0
        public static CloudTable GetTableForDateTime(this ILogTableProvider tableLookup, DateTime epoch)
        {
            // Epoch(DateTime.MaxValue) is 94146, still a 5 digit number.
            string suffix;

            if (epoch == CommonEpoch)
            {
                suffix = CommonEpochSuffix;
            }
            else
            {
                var ts = GetEpochSuffixNumber(epoch);
                suffix = string.Format(CultureInfo.InvariantCulture, "{0:D5}", ts);
            }
            var table = tableLookup.GetTable(suffix);

            return(table);
        }
Пример #3
0
        public async Task TimeRangeAcrossEpochs()
        {
            // 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);

            // Time that functios are called.
            DateTime[] times = new DateTime[] {
                // Epoch 37
                new DateTime(2012, 3, 6, 10, 11, 20, DateTimeKind.Utc),
                new DateTime(2012, 3, 7, 10, 11, 20, DateTimeKind.Utc),

                // consecutive Epoch 38
                new DateTime(2012, 4, 8, 10, 11, 20, DateTimeKind.Utc),

                // Skip to Epoch  41
                new DateTime(2012, 7, 9, 10, 11, 20, DateTimeKind.Utc)
            };

            var logs = Array.ConvertAll(times, time => new FunctionInstanceLogItem
            {
                FunctionInstanceId = Guid.NewGuid(),
                FunctionName       = commonFuncName1,
                StartTime          = time,
            });

            var tasks = Array.ConvertAll(logs, log => WriteAsync(writer, log));
            await Task.WhenAll(tasks);

            await writer.FlushAsync();

            // Test point lookups for individual function instances.
            foreach (var log in logs)
            {
                var entry = await reader.LookupFunctionInstanceAsync(log.FunctionInstanceId);

                Assert.NotNull(entry);

                Assert.Equal(log.FunctionInstanceId, entry.FunctionInstanceId);
                Assert.Equal(log.FunctionName, entry.FunctionName);
                Assert.Equal(log.StartTime, entry.StartTime);
                Assert.Equal(log.EndTime, entry.EndTime);
            }

            // Try various combinations.
            await Verify(reader, DateTime.MinValue, DateTime.MaxValue, logs[3], logs[2], logs[1], logs[0]); // Infinite range, includes all.

            // Various combinations of straddling an epoch boundary
            await Verify(reader, Before(times[1]), After(times[2]), logs[2], logs[1]);
            await Verify(reader, Before(times[1]), Before(times[2]), logs[1]);
            await Verify(reader, After(times[1]), Before(times[2]));

            // Skipping over an empty epoch
            await Verify(reader, Before(times[1]), Before(times[3]), logs[2], logs[1]);

            // Now... delete the middle table; and verify the other data is still there.
            ILogTableProvider provider = this;
            var table = provider.GetTable("201204");

            Assert.True(await table.ExistsAsync());
            await table.DeleteAsync();

            await Verify(reader, DateTime.MinValue, DateTime.MaxValue, logs[3], logs[1], logs[0]); // Infinite range, includes all.

            // function instance entry from the table we deleted is now missing.
            var entry2 = await reader.LookupFunctionInstanceAsync(logs[2].FunctionInstanceId);

            Assert.Null(entry2);
        }