示例#1
0
        public static (TestDistributedContentCopier, MockFileCopier) CreateMocks(
            IAbsFileSystem fileSystem,
            AbsolutePath rootDirectory,
            TimeSpan retryInterval,
            int retries = 1,
            MachineLocation[] designatedLocations = null)
        {
            var mockFileCopier   = new MockFileCopier();
            var existenceChecker = new TestFileCopier();
            var contentCopier    = new TestDistributedContentCopier(
                rootDirectory,
                // Need to use exactly one retry.
                new DistributedContentStoreSettings()
            {
                RetryIntervalForCopies = Enumerable.Range(0, retries).Select(r => retryInterval).ToArray(),
                PrioritizeDesignatedLocationsOnCopies = designatedLocations != null,
                TrustedHashFileSizeBoundary           = long.MaxValue // Disable trusted hash because we never actually move bytes and thus the hasher thinks there is a mismatch.
            },
                fileSystem,
                mockFileCopier,
                existenceChecker,
                copyRequester: null,
                new TestDistributedContentCopier.NoOpPathTransformer(rootDirectory),
                designatedLocations);

            return(contentCopier, mockFileCopier);
        }
示例#2
0
        protected async Task RunTestAsync(Func <OperationContext, ColdStorage, DisposableDirectory, Task> funcAsync)
        {
            var context   = new OperationContext(new Context(Logger));
            var directory = new DisposableDirectory(FileSystem);

            ColdStorageSettings coldStorageSettings = new ColdStorageSettings(directory.Path.Path, "1MB");

            TestDistributedContentCopier copier = DistributedContentCopierTests.CreateMocks(
                new MemoryFileSystem(TestSystemClock.Instance),
                directory.CreateRandomFileName(),
                TimeSpan.FromSeconds(1)).Item1;

            var store = new ColdStorage(FileSystem, coldStorageSettings, copier);

            try
            {
                Assert.False(store.StartupStarted);
                Assert.False(store.StartupCompleted);
                Assert.False(store.ShutdownStarted);
                Assert.False(store.ShutdownCompleted);

                await store.StartupAsync(context).ShouldBeSuccess();

                await funcAsync(context, store, directory);
            }
            finally
            {
                await store.ShutdownAsync(context).ShouldBeSuccess();
            }

            Assert.True(store.StartupStarted);
            Assert.True(store.StartupCompleted);
            Assert.True(store.ShutdownStarted);
            Assert.True(store.ShutdownCompleted);
        }
        public static (TestDistributedContentCopier, MockFileCopier) CreateMocks(
            IAbsFileSystem fileSystem,
            AbsolutePath rootDirectory,
            TimeSpan retryInterval,
            int retries = 1,
            int copyAttemptsWithRestrictedReplicas = 0,
            int restrictedCopyReplicaCount         = 3,
            int maxRetryCount = 32)
        {
            var mockFileCopier = new MockFileCopier();
            var contentCopier  = new TestDistributedContentCopier(
                rootDirectory,
                // Need to use exactly one retry.
                new DistributedContentStoreSettings()
            {
                RetryIntervalForCopies             = Enumerable.Range(0, retries).Select(r => retryInterval).ToArray(),
                CopyAttemptsWithRestrictedReplicas = copyAttemptsWithRestrictedReplicas,
                RestrictedCopyReplicaCount         = restrictedCopyReplicaCount,
                TrustedHashFileSizeBoundary        = long.MaxValue, // Disable trusted hash because we never actually move bytes and thus the hasher thinks there is a mismatch.
                MaxRetryCount = maxRetryCount,
            },
                fileSystem,
                mockFileCopier,
                copyRequester: null);

            return(contentCopier, mockFileCopier);
        }
        private async Task <(DistributedContentCopier <AbsolutePath>, MockFileCopier)> CreateAsync(Context context, AbsolutePath rootDirectory, TimeSpan retryInterval, int retries = 1)
        {
            var mockFileCopier   = new MockFileCopier();
            var existenceChecker = new TestFileCopier();
            var contentCopier    = new TestDistributedContentCopier(
                rootDirectory,
                // Need to use exactly one retry.
                new DistributedContentStoreSettings()
            {
                RetryIntervalForCopies = Enumerable.Range(0, retries).Select(r => retryInterval).ToArray()
            },
                FileSystem,
                mockFileCopier,
                existenceChecker,
                copyRequester: null,
                new NoOpPathTransformer(rootDirectory),
                new MockContentLocationStore());
            await contentCopier.StartupAsync(context).ThrowIfFailure();

            return(contentCopier, mockFileCopier);
        }