示例#1
0
 protected Task TestStore(
     Context context,
     ITestClock clock,
     Func <TestFileSystemContentStoreInternal, Task> func)
 {
     return(TestStoreImpl(context, clock, func));
 }
示例#2
0
        protected FileSystemContentStoreInternalPurgeTests(Func <IAbsFileSystem> createFileSystemFunc, ILogger logger, ITestOutputHelper output = null)
            : base(createFileSystemFunc, logger, output)
        {
            Context = new Context(Logger);

            Clock = FileSystem is MemoryFileSystem fileSystem ? fileSystem.Clock : new TestSystemClock();
        }
示例#3
0
 //private static TestDistributedContentCopier CreateTestCopier()
 private static TestDistributedContentCopier CreateTestCopier(ITestClock clock, AbsolutePath rootDirectory)
 {
     var(copier, _) = DistributedContentCopierTests.CreateMocks(
         new MemoryFileSystem(clock),
         rootDirectory,
         TimeSpan.FromSeconds(1));
     return(copier);
 }
示例#4
0
 protected Task TestStore(
     Context context,
     ITestClock clock,
     IContentChangeAnnouncer announcer,
     Func <TestFileSystemContentStoreInternal, Task> func)
 {
     return(TestStoreImpl(context, clock, func, announcer: announcer));
 }
示例#5
0
 protected Task TestStore(
     Context context,
     ITestClock clock,
     DisposableDirectory testDirectory,
     Func <TestFileSystemContentStoreInternal, Task> func,
     Action <TestFileSystemContentStoreInternal> preStartupAction = null)
 {
     return(TestStoreImpl(context, clock, func, testDirectory, preStartupAction: preStartupAction));
 }
 protected Task TestStore
 (
     Context context,
     ITestClock clock,
     Func <TestFileSystemContentStoreInternal, Task> func,
     NagleQueue <ContentHash> nagleBlock
 )
 {
     return(TestStoreImpl(context, clock, func, nagleBlock: nagleBlock));
 }
示例#7
0
 public MockContentLocationStoreFactory(
     ITestRedisDatabase primaryRedisDatabase,
     ITestRedisDatabase secondaryRedisDatabase,
     AbsolutePath rootDirectory,
     ITestClock mockClock = null,
     RedisContentLocationStoreConfiguration configuration = null)
     : base(mockClock ?? TestSystemClock.Instance, configuration ?? CreateDefaultConfiguration(rootDirectory), CreateTestCopier(mockClock ?? TestSystemClock.Instance, rootDirectory))
 {
     _primaryRedisDatabase   = primaryRedisDatabase;
     _secondaryRedisDatabase = secondaryRedisDatabase;
 }
示例#8
0
        protected virtual TestFileSystemContentStoreInternal CreateElastic(
            AbsolutePath rootPath,
            ITestClock clock,
            MaxSizeQuota initialQuota = null,
            int?windowSize            = default(int?))
        {
            var maxSizeQuota = initialQuota ?? new MaxSizeQuota(MaxSizeHard, MaxSizeSoft);

            // Some tests rely on maxSizeQuota being set in the configuration although it is ignored if elasticity is enabled.
            var config = new ContentStoreConfiguration(maxSizeQuota: maxSizeQuota, enableElasticity: true, initialElasticSize: maxSizeQuota, historyWindowSize: windowSize);

            return(new TestFileSystemContentStoreInternal(FileSystem, clock, rootPath, config, settings: ContentStoreSettings));
        }
示例#9
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="MemoryFileSystem" /> class.
        /// </summary>
        /// <param name="clock">Clock to use.</param>
        /// <param name="drives">Drives to support. If null, have the same drive letters as the current OS.</param>
        /// <param name="useHardLinks">Whether all drives support hardlinks.</param>
        /// <param name="tempPath">Optional override of default temporary directory.</param>
        public MemoryFileSystem(ITestClock clock, IEnumerable <char> drives = null, bool useHardLinks = true, AbsolutePath tempPath = null)
        {
            Contract.Requires(clock != null);

            Clock         = clock;
            _useHardLinks = useHardLinks;

            if (OperatingSystemHelper.IsUnixOS)
            {
                _drives.Add(Path.VolumeSeparatorChar, new FileObject());
            }
            else
            {
                drives = drives ?? Directory.GetLogicalDrives().Select(driveString => driveString[0]);

                foreach (char driveLetter in drives)
                {
                    _drives.Add(char.ToUpperInvariant(driveLetter), new FileObject());
                }
            }

            if (tempPath != null)
            {
                if (!_drives.ContainsKey(char.ToUpperInvariant(tempPath.Path[0])))
                {
                    throw new ArgumentException("tempPath is not on an available drive");
                }

                _tempPath = tempPath;
            }
            else
            {
                if (OperatingSystemHelper.IsUnixOS)
                {
                    _tempPath = new AbsolutePath(Path.VolumeSeparatorChar + "temp");
                }
                else
                {
                    var firstDriveLetter = _drives.Keys.First();
                    var path             = string.Format(CultureInfo.InvariantCulture, "{0}:\\temp", firstDriveLetter);
                    _tempPath = new AbsolutePath(path);
                }
            }
        }
        private async Task TestStoreImpl
        (
            Context context,
            ITestClock clock,
            Func <TestFileSystemContentStoreInternal, Task> func,
            DisposableDirectory testDirectory   = null,
            IContentChangeAnnouncer announcer   = null,
            NagleQueue <ContentHash> nagleBlock = null,
            Action <TestFileSystemContentStoreInternal> preStartupAction = null
        )
        {
            using (var tempTestDirectory = new DisposableDirectory(FileSystem))
            {
                DisposableDirectory disposableDirectory = testDirectory ?? tempTestDirectory;
                using (var store = Create(disposableDirectory.Path, clock, nagleBlock))
                {
                    if (announcer != null)
                    {
                        store.Announcer = announcer;
                    }

                    store.Should().NotBeNull();
                    try
                    {
                        preStartupAction?.Invoke(store);
                        var r = await store.StartupAsync(context);

                        r.ShouldBeSuccess();
                        await func(store);
                    }
                    finally
                    {
                        if (!store.ShutdownStarted)
                        {
                            await store.ShutdownAsync(context).ShouldBeSuccess();
                        }
                    }
                }
            }
        }
 public MyMemoryFileSystem(ITestClock clock, long volumeSize)
     : base(clock, volumeSize)
 {
 }
        protected override TestFileSystemContentStoreInternal Create(AbsolutePath rootPath, ITestClock clock, NagleQueue <ContentHash> nagleBlock = null)
        {
            Contract.Assert(ReferenceEquals(clock, Clock));
            var config = new ContentStoreConfiguration(null, _quota);

            return(new TestFileSystemContentStoreInternal(
                       FileSystem,
                       clock,
                       rootPath,
                       config,
                       contentHashWithSize => ((MyMemoryFileSystem)FileSystem).ContentAdded(contentHashWithSize.Size),
                       contentHashWithSize => ((MyMemoryFileSystem)FileSystem).ContentEvicted(contentHashWithSize.Size),
                       nagleBlock
                       ));
        }
示例#13
0
 protected override TestFileSystemContentStoreInternal Create(AbsolutePath rootPath, ITestClock clock)
 {
     return(CreateElastic(rootPath, clock, new MaxSizeQuota(InitialMaxSizeHard), WindowSize));
 }
示例#14
0
 protected override TestFileSystemContentStoreInternal Create(AbsolutePath rootPath, ITestClock clock)
 {
     var config = new ContentStoreConfiguration(_quota);
     return new TestFileSystemContentStoreInternal(FileSystem, clock, rootPath, config, settings: ContentStoreSettings);
 }
示例#15
0
 public MockFileSystem(ITestClock clock) : base(clock)
 {
 }
示例#16
0
 public GeneralSteps(ITestClock testClock)
 {
     _testClock = testClock;
 }
示例#17
0
 protected MemoryFileSystem(ITestClock clock, long volumeSize)
     : this(clock)
 {
     Contract.Requires(volumeSize > 0);
     _volumeSize = volumeSize;
 }
        protected override TestFileSystemContentStoreInternal Create(AbsolutePath rootPath, ITestClock clock, NagleQueue <ContentHash> nagleBlock = null)
        {
            var config = new ContentStoreConfiguration(_quota);

            return(new TestFileSystemContentStoreInternal(FileSystem, clock, rootPath, config, nagleQueue: nagleBlock));
        }
 protected override TestFileSystemContentStoreInternal Create(AbsolutePath rootPath, ITestClock clock)
 {
     return(CreateElastic(rootPath, clock, _quota));
 }
示例#20
0
 protected virtual TestFileSystemContentStoreInternal Create(AbsolutePath rootPath, ITestClock clock)
 {
     return(new TestFileSystemContentStoreInternal(FileSystem, clock, rootPath, Config, settings: ContentStoreSettings));
 }
示例#21
0
 protected override TestFileSystemContentStoreInternal Create(AbsolutePath rootPath, ITestClock clock, NagleQueue <ContentHash> nagleBlock = null)
 {
     return(CreateElastic(rootPath, clock, nagleBlock, new MaxSizeQuota(MaxSizeHard)));
 }
 protected virtual TestFileSystemContentStoreInternal Create(AbsolutePath rootPath, ITestClock clock, NagleQueue <ContentHash> nagleBlock = null)
 {
     return(new TestFileSystemContentStoreInternal(FileSystem, clock, rootPath, Config, nagleQueue: nagleBlock, settings: ContentStoreSettings));
 }