Beispiel #1
0
        public async Task FailToCreateL2CacheWorks()
        {
            const string TestName    = "FailToCreateL2CacheWorks";
            string       testCacheId = MakeCacheId(TestName);

            string localConfig  = new TestInMemory().NewCache(testCacheId + VerticalAggregatorBaseTests.LocalMarker, false);
            string remoteConfig = new TestInMemory().NewCacheFailure(testCacheId + VerticalAggregatorBaseTests.RemoteMarker, true, authoritative: true);

            string cacheConfigData = VerticalAggregatorBaseTests.NewCacheString(testCacheId, localConfig, remoteConfig, false, false, false, false);

            ICache cache = await InitializeCacheAsync(cacheConfigData).SuccessAsync();

            bool   warningSent     = false;
            string warningMessage  = string.Empty;
            string expectedWarning = string.Format(System.Globalization.CultureInfo.InvariantCulture, VerticalCacheAggregatorFactory.RemoteConstructionFailureWarning, testCacheId + VerticalAggregatorBaseTests.LocalMarker);

            cache.SuscribeForCacheStateDegredationFailures((failure) => { warningSent    = true;
                                                                          warningMessage = failure.Describe(); });

            XAssert.IsTrue(warningSent);

            XAssert.IsNull(cache as VerticalCacheAggregator, "We should have eliminated the VerticalCacheAggregator as there is only 1 operating cache");

            XAssert.AreEqual(expectedWarning, warningMessage);

            await cache.ShutdownAsync().SuccessAsync();
        }
Beispiel #2
0
        public override string NewCache(string cacheId, bool strictMetadataCasCoupling, bool authoritative = false)
        {
            string localConfig  = new TestInMemory().NewCache(cacheId + VerticalAggregatorBaseTests.LocalMarker, false);
            string remoteConfig = new TestInMemory().NewCache(cacheId + VerticalAggregatorBaseTests.RemoteMarker, true, authoritative: true);

            string configString = VerticalAggregatorBaseTests.NewCacheString(cacheId, localConfig, remoteConfig, false, false, false);

            return(configString);
        }
Beispiel #3
0
        public virtual async Task NonDeterministicContentRespectsDisconnect()
        {
            string testCacheId = "Disconnected";
            ICache testCache   = await InitializeCacheAsync(NewCache(testCacheId, false)).SuccessAsync();

            VerticalCacheAggregator vertCache = testCache as VerticalCacheAggregator;

            XAssert.IsNotNull(vertCache);

            ICacheSession aggregatorSession = (await testCache.CreateSessionAsync()).Success();
            ICacheSession localSession      = (await vertCache.LocalCache.CreateSessionAsync()).Success();
            ICacheSession remoteSession     = (await vertCache.RemoteCache.CreateSessionAsync()).Success();

            VerticalCacheAggregatorSession vertSession = aggregatorSession as VerticalCacheAggregatorSession;

            XAssert.IsNotNull(vertSession);

            CallbackCacheSessionWrapper wrappedSession = vertSession.RemoteSession as CallbackCacheSessionWrapper;

            XAssert.IsNotNull(wrappedSession);
            PoisonSession(wrappedSession);

            CacheDeterminism determinismSource = CacheDeterminism.None;

            const string PipName = "TestPip";

            // Populate the remote cache with one set of outputs.
            FullCacheRecord remoteCacheRecord = await FakeBuild.DoNonDeterministicPipAsync(remoteSession, PipName);

            // And the local cache with a set forced to be unique.
            FullCacheRecord localCacheRecord = await FakeBuild.DoNonDeterministicPipAsync(localSession, PipName, generateVerifiablePip: true);

            PoisonAllRemoteSessions(testCache);
            DisconnectRemoteCache(testCache);

            // Now query each cache, and verify only the remote content is in each.
            // Make sure the content is in each cache. (Placing the aggregator cache first will cause backfill of the local cache)
            foreach (var currentCache in new Tuple <ICache, CacheDeterminism, string, int>[]
            {
                new Tuple <ICache, CacheDeterminism, string, int>(testCache, CacheDeterminism.None, vertCache.LocalCache.CacheId, 1),
                new Tuple <ICache, CacheDeterminism, string, int>(vertCache.LocalCache, CacheDeterminism.None, vertCache.LocalCache.CacheId, 1)
            })
            {
                await VerticalAggregatorBaseTests.ValidateItemsInCacheAsync(
                    currentCache.Item1,
                    localCacheRecord.StrongFingerprint.WeakFingerprint,
                    new List <CasHash>(localCacheRecord.CasEntries),
                    currentCache.Item2,
                    localCacheRecord.StrongFingerprint.CasElement,
                    currentCache.Item3,
                    currentCache.Item4);
            }

            XAssert.IsTrue((await testCache.ShutdownAsync()).Succeeded);
        }
Beispiel #4
0
        /// <summary>
        /// Returns the config string for a VerticalCacheAggregator that has a local cache wrapped by the CallbackCacheWrapper using the InMemoryCache as the local and remote
        /// backing stores
        /// </summary>
        /// <param name="cacheId">Id of the cache.</param>
        /// <param name="strictMetadataCasCoupling">If the cache should require a strick metadata CAS coupling.</param>
        /// <param name="writeThroughCasData">If the VerticalAggregator should force write through of CAS data.</param>
        /// <returns>A VerticalCacheAggregator </returns>
        internal static string NewWrappedLocalCache(string cacheId, bool strictMetadataCasCoupling, bool writeThroughCasData)
        {
            TestInMemory memTests          = new TestInMemory();
            string       localCacheString  = memTests.NewCache(cacheId + VerticalAggregatorBaseTests.LocalMarker, strictMetadataCasCoupling);
            string       remoteCacheString = memTests.NewCache(cacheId + VerticalAggregatorBaseTests.RemoteMarker, strictMetadataCasCoupling, authoritative: true);

            localCacheString = TestCallbackCache.FormatNewCacheConfig(localCacheString);

            string vertCacheConfig = VerticalAggregatorBaseTests.NewCacheString(cacheId, localCacheString, remoteCacheString, false, false, writeThroughCasData);

            return(vertCacheConfig);
        }
Beispiel #5
0
        private async Task AddToEmptyCacheAsync(bool contentIsDeterministic)
        {
            string testCacheId = "Disconnected";
            ICache testCache   = await InitializeCacheAsync(NewCache(testCacheId, false)).SuccessAsync();

            VerticalCacheAggregator vertCache = testCache as VerticalCacheAggregator;

            XAssert.IsNotNull(vertCache);

            CacheDeterminism localDeterminism = CacheDeterminism.None;

            if (contentIsDeterministic)
            {
                localDeterminism = CacheDeterminism.Tool;
            }

            CacheDeterminism initialDeterminism = contentIsDeterministic ? CacheDeterminism.Tool : CacheDeterminism.None;

            ICacheSession session = (await testCache.CreateSessionAsync()).Success();

            VerticalCacheAggregatorSession vertSession = session as VerticalCacheAggregatorSession;

            XAssert.IsNotNull(vertSession);

            CallbackCacheSessionWrapper wrappedSession = vertSession.RemoteSession as CallbackCacheSessionWrapper;

            XAssert.IsNotNull(wrappedSession);
            PoisonSession(wrappedSession);
            DisconnectRemoteCache(testCache);

            FullCacheRecord cacheRecord = await FakeBuild.DoPipAsync(session, "TestPip", determinism: initialDeterminism);

            await VerticalAggregatorBaseTests.ValidateItemsInCacheAsync(
                vertCache.LocalCache,
                cacheRecord.StrongFingerprint.WeakFingerprint,
                new List <CasHash>(cacheRecord.CasEntries),
                localDeterminism,
                cacheRecord.StrongFingerprint.CasElement,
                vertCache.LocalCache.CacheId,
                1);

            await VerticalAggregatorBaseTests.ValidateItemsInCacheAsync(
                vertCache.RemoteCache,
                cacheRecord.StrongFingerprint.WeakFingerprint,
                new List <CasHash>(cacheRecord.CasEntries),
                localDeterminism,
                cacheRecord.StrongFingerprint.CasElement,
                vertCache.RemoteCache.CacheId,
                0);

            XAssert.IsTrue((await testCache.ShutdownAsync()).Succeeded);
        }
Beispiel #6
0
        public async Task FailToCreateL2CacheFails()
        {
            const string TestName    = "FailToCreateL2CacheFails";
            string       testCacheId = MakeCacheId(TestName);

            string localConfig  = new TestInMemory().NewCache(testCacheId + VerticalAggregatorBaseTests.LocalMarker, false);
            string remoteConfig = new TestInMemory().NewCacheFailure(testCacheId + VerticalAggregatorBaseTests.RemoteMarker, true, authoritative: true);

            string cacheConfigData = VerticalAggregatorBaseTests.NewCacheString(testCacheId, localConfig, remoteConfig, false, false, false, true);

            Possible <ICache, Failure> cachePossible = await InitializeCacheAsync(cacheConfigData);

            XAssert.IsFalse(cachePossible.Succeeded, "This should have failed cache construction");
        }
Beispiel #7
0
        public virtual async Task ReadOnlyRemoteIsNotUpdatedWhenDisconnected()
        {
            string testCacheId = "Disconnected";
            ICache testCache   = await InitializeCacheAsync(NewCache(testCacheId, false)).SuccessAsync();

            VerticalCacheAggregator vertCache = testCache as VerticalCacheAggregator;

            XAssert.IsNotNull(vertCache);

            PoisonAllRemoteSessions(testCache);
            DisconnectRemoteCache(testCache);

            ICacheSession session = (await testCache.CreateSessionAsync()).Success();

            FullCacheRecord cacheRecord = await FakeBuild.DoPipAsync(session, "TestPip");

            await VerticalAggregatorBaseTests.ValidateItemsInCacheAsync(
                vertCache.LocalCache,
                cacheRecord.StrongFingerprint.WeakFingerprint,
                new List <CasHash>(cacheRecord.CasEntries),
                CacheDeterminism.None,
                cacheRecord.StrongFingerprint.CasElement,
                vertCache.LocalCache.CacheId,
                1);

            var remoteSession = await vertCache.RemoteCache.CreateReadOnlySessionAsync().SuccessAsync();

            int fingerprintsReturned = 0;

            foreach (var fingerprint in remoteSession.EnumerateStrongFingerprints(cacheRecord.StrongFingerprint.WeakFingerprint))
            {
                fingerprintsReturned++;
            }

            XAssert.AreEqual(0, fingerprintsReturned, "No fingerprints should have been found in the remote cache.");
            AssertSuccess(await testCache.ShutdownAsync());
        }