示例#1
0
        public async Task TestSelfCheckIncrementality()
        {
            // This test checks that an incremental state is saved if self check operation takes too much time.
            // (the test relies on SelfCheckBatchLimit instead of time though.)
            using (var testDirectory = new DisposableDirectory(FileSystem))
            {
                var context = new Context(Logger);

                var settings = new SelfCheckSettings()
                {
                    InvalidFilesLimit = 1,
                    // If SelfCheckEnabled is false then self check is not run within startup.
                    StartSelfCheckInStartup = false,
                };

                var store = CreateStore(testDirectory, ContentStoreSettings(settings));

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

                var putResult0 = await store.PutRandomAsync(context, ValueSize).ShouldBeSuccess();

                var putResult1 = await store.PutRandomAsync(context, ValueSize).ShouldBeSuccess();

                var putResult2 = await store.PutRandomAsync(context, ValueSize).ShouldBeSuccess();

                var hashes = new List <ContentHash> {
                    putResult0.ContentHash, putResult1.ContentHash, putResult2.ContentHash
                }.OrderBy(h => h).ToList();

                // Explicitly making the second hash incorrect keeping the first one as valid one.
                var pathInCache = store.GetPrimaryPathFor(hashes[1]);
                FileSystem.WriteAllText(pathInCache, "Definitely wrong content");

                var pathInCache2 = store.GetPrimaryPathFor(hashes[2]);
                FileSystem.WriteAllText(pathInCache2, "Definitely wrong content");

                // Moving the time forward to make self check is not up-to-date.
                Clock.UtcNow = Clock.UtcNow + TimeSpan.FromDays(2);

                var result = await store.SelfCheckContentDirectoryAsync(context, CancellationToken.None).ShouldBeSuccess();

                // The self check should stop after the limit of 1 hash is reached.
                result.Value.InvalidFiles.Should().Be(1);
                // Because the first hash is correct, we should've enumerate 2 entries because only the second one is wrong.
                result.Value.TotalProcessedFiles.Should().Be(2);

                // Now the self check should continue from the previous step
                result = await store.SelfCheckContentDirectoryAsync(context, CancellationToken.None).ShouldBeSuccess();

                result.Value.InvalidFiles.Should().Be(1);
                result.Value.TotalProcessedFiles.Should().Be(1, "Because of incrementality we should check only one file.");

                result = await store.SelfCheckContentDirectoryAsync(context, CancellationToken.None).ShouldBeSuccess();

                result.Value.InvalidFiles.Should().Be(0);
                result.Value.TotalProcessedFiles.Should().Be(-1, "Self check procedure should be skipped due to up-to-date check.");
            }
        }
示例#2
0
        public async Task TestSelfCheckWithNewEpoch()
        {
            // This test checks that an incremental state is saved if self check operation takes too much time.
            // (the test relies on SelfCheckBatchLimit instead of time though.)
            using (var testDirectory = new DisposableDirectory(FileSystem))
            {
                var context = new Context(Logger);

                var settings = new SelfCheckSettings()
                {
                    Epoch = "E1", StartSelfCheckInStartup = false
                };

                //
                // Using store with original settings
                //
                var store = CreateStore(testDirectory, ContentStoreSettings(settings));

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

                var result = await store.SelfCheckContentDirectoryAsync(context, CancellationToken.None).ShouldBeSuccess();

                var putResult = await store.PutRandomAsync(context, ValueSize).ShouldBeSuccess();

                var pathInCache = store.GetPrimaryPathFor(putResult.ContentHash);
                FileSystem.WriteAllText(pathInCache, "Definitely wrong content");

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

                //
                // Recreating a store with a new epoch
                //

                // Disable self check won't run within startup
                settings = new SelfCheckSettings()
                {
                    Epoch = "E2", StartSelfCheckInStartup = false
                };
                store = CreateStore(testDirectory, ContentStoreSettings(settings));

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

                result = await store.SelfCheckContentDirectoryAsync(context, CancellationToken.None).ShouldBeSuccess();

                // Even though the time in marker file is the same, but epoch has change.
                // So the self check should be performed.
                result.Value.InvalidFiles.Should().Be(1);
            }
        }
        private static SelfCheckSettings CreateSelfCheckSettings(DistributedContentSettings settings)
        {
            var selfCheckSettings = new SelfCheckSettings()
            {
                Epoch = settings.SelfCheckEpoch,
                StartSelfCheckInStartup = settings.StartSelfCheckAtStartup,
                Frequency = TimeSpan.FromMinutes(settings.SelfCheckFrequencyInMinutes),
            };

            ApplyIfNotNull(settings.SelfCheckProgressReportingIntervalInMinutes, minutes => selfCheckSettings.ProgressReportingInterval = TimeSpan.FromMinutes(minutes));
            ApplyIfNotNull(settings.SelfCheckDelayInMilliseconds, milliseconds => selfCheckSettings.HashAnalysisDelay = TimeSpan.FromMilliseconds(milliseconds));
            ApplyIfNotNull(settings.SelfCheckDefaultHddDelayInMilliseconds, milliseconds => selfCheckSettings.DefaultHddHashAnalysisDelay = TimeSpan.FromMilliseconds(milliseconds));

            return(selfCheckSettings);
        }
示例#4
0
 private static ContentStoreSettings ContentStoreSettings(SelfCheckSettings settings) => new ContentStoreSettings
 {
     SelfCheckSettings = settings
 };