internal ValidateContentCountCollector(SessionCounters sessionCounters) { m_sessionCounters = sessionCounters; m_elapsed = ElapsedTimer.StartNew(); m_state = ValidateContentStatus.NotSupported; m_size = 0; }
public async Task CorruptionRecovery() { const string TestName = nameof(CorruptionRecovery); string testCacheId = MakeCacheId(TestName); ICache cache = await CreateCacheAsync(testCacheId); string testSessionId = "Session1-" + testCacheId; ICacheSession session = await CreateSessionAsync(cache, testSessionId); // Use the testname to generate a CAS items. CasHash item = (await session.AddToCasAsync(TestName.AsStream())).Success(); // Verify that we can read the content after it was added in // this session since it was pinned using (Stream stream = (await session.GetStreamAsync(item)).Success()) { XAssert.AreEqual(TestName, stream.AsString(), "Failed to read back matching content from cache"); } ValidateContentStatus goodStatus = (await session.ValidateContentAsync(item)).Success(); // We can have implemented ValidateContent and not have a way to test corruption but // we must have implemented ValidateCotent if we have a way to test corruption if (CanTestCorruption || (goodStatus != ValidateContentStatus.NotSupported)) { // We should have returned Ok since the content was not corrupted XAssert.AreEqual(ValidateContentStatus.Ok, goodStatus, "Content should have matched in hash at this point!"); // NoItem should always be valid XAssert.AreEqual(ValidateContentStatus.Ok, (await session.ValidateContentAsync(CasHash.NoItem)).Success(), "NoItem should always be valid!"); // Now, only if we can test corruption (which requires that we can corrupt an item) // do we go down this next path if (CanTestCorruption) { await CorruptCasEntry(cache, item); using (Stream stream = (await session.GetStreamAsync(item)).Success()) { XAssert.AreNotEqual(TestName, stream.AsString(), "Failed to corrupt CAS entry!"); } ValidateContentStatus corruptedStatus = (await session.ValidateContentAsync(item)).Success(); // At this point, caches can do a number of possible things // They can not return OK or NotImplemented (since we already checked that earlier) XAssert.AreNotEqual(ValidateContentStatus.Ok, corruptedStatus, "The item was corrupted - something should have happened"); XAssert.AreNotEqual(ValidateContentStatus.NotSupported, corruptedStatus, "It was implemented a moment earlier"); } } await CloseSessionAsync(session, testSessionId); await ShutdownCacheAsync(cache, testCacheId); }
public ValidateContentStatus Invalid() { m_state = ValidateContentStatus.Invalid; return(m_state); }
public ValidateContentStatus Remediated() { m_state = ValidateContentStatus.Remediated; return(m_state); }
public ValidateContentStatus Ok() { m_state = ValidateContentStatus.Ok; return(m_state); }