Exemple #1
0
 public TestDistributedMachineInfo(int machineId, string localContentDirectoryPath, IAbsFileSystem fileSystem, AbsolutePath machineInfoRoot)
 {
     LocalMachineId             = new MachineId(machineId);
     Directory                  = new MemoryContentDirectory(fileSystem, machineInfoRoot);
     _fileSystem                = fileSystem;
     _localContentDirectoryPath = new AbsolutePath(localContentDirectoryPath);
 }
Exemple #2
0
        public async Task OutOfRangeTimestampsNormalized()
        {
            var context = new Context(Logger);

            using (var testDirectory = new DisposableDirectory(FileSystem))
            {
                // Construct a valid directory with some legit entries.
                using (var directory = new MemoryContentDirectory(FileSystem, testDirectory.Path))
                {
                    await directory.StartupAsync(context).ShouldBeSuccess();
                    await PopulateRandomInfo(directory);

                    await directory.ShutdownAsync(context).ShouldBeSuccess();
                }

                // Corrupt it in place with out of range timestamps.
                var i = 0;
                await MemoryContentDirectory.TransformFile(context, FileSystem, testDirectory.Path, pair =>
                {
                    ContentFileInfo fileInfo    = pair.Value;
                    var lastAccessedFileTimeUtc = (i++ % 2) == 0 ? -1 : long.MaxValue;
                    var updatedFileInfo         = new ContentFileInfo(fileInfo.FileSize, lastAccessedFileTimeUtc, fileInfo.ReplicaCount);
                    return(new KeyValuePair <ContentHash, ContentFileInfo>(pair.Key, updatedFileInfo));
                });

                // Load the directory again, fixing the bad timestamps.
                using (var directory = new MemoryContentDirectory(FileSystem, testDirectory.Path))
                {
                    await directory.StartupAsync(context).ShouldBeSuccess();

                    await directory.ShutdownAsync(context).ShouldBeSuccess();
                }

                // Verify timestamps are now in range.
                long nowFileTimeUtc = DateTime.UtcNow.ToFileTimeUtc();
                await MemoryContentDirectory.TransformFile(context, FileSystem, testDirectory.Path, pair =>
                {
                    long fileTimeUtc = pair.Value.LastAccessedFileTimeUtc;
                    fileTimeUtc.Should().BePositive();
                    fileTimeUtc.Should().BeLessOrEqualTo(nowFileTimeUtc);
                    return(pair);
                });
            }
        }