internal static ICache CreateCache(
            ILogger logger, ICache innerCache, string redisNamespace, string testClassName, ReadThroughMode readThroughMode)
        {
            var redisDb = RedisDatabases.GetOrAdd(redisNamespace, _ => new MockRedisDatabase(SystemClock.Instance));

            RedisConnectionMultiplexer.TestConnectionMultiplexer = MockRedisDatabaseFactory.CreateConnection(redisDb);
            var tracer        = new DistributedCacheSessionTracer(TestGlobal.Logger, testClassName);
            var metadataCache = new RedisMetadataCache(
                new EnvironmentConnectionStringProvider(string.Empty), new RedisSerializer(), redisNamespace, tracer);

            return(new DistributedCache(logger, innerCache, metadataCache, tracer, readThroughMode));
        }
        private async Task RunTest(MockRedisDatabase redisDb, Func <Context, IMetadataCache, MockRedisDatabase, Task> test)
        {
            var context = new Context(TestGlobal.Logger);

            RedisConnectionMultiplexer.TestConnectionMultiplexer = MockRedisDatabaseFactory.CreateConnection(redisDb);
            var tracer        = new DistributedCacheSessionTracer(TestGlobal.Logger, nameof(MemoryMetadataCacheTests));
            var metadataCache = new RedisMetadataCache(new EnvironmentConnectionStringProvider(string.Empty), new RedisSerializer(), RedisNameSpace, tracer);
            await metadataCache.StartupAsync(context).ShouldBeSuccess();

            await test(context, metadataCache, redisDb);

            await metadataCache.ShutdownAsync(context).ShouldBeSuccess();
        }
Beispiel #3
0
        /// <inheritdoc />
        protected override RedisGlobalStore CreateRedisGlobalStore()
        {
            var primaryConnection      = MockRedisDatabaseFactory.CreateConnection(_primaryRedisDatabase);
            var primaryDatabaseAdapter = new RedisDatabaseAdapter(
                RedisDatabaseFactory.CreateAsync(new EnvironmentConnectionStringProvider("TestConnectionString"), primaryConnection).GetAwaiter().GetResult(),
                DefaultKeySpace);
            var secondaryConnection      = MockRedisDatabaseFactory.CreateConnection(_secondaryRedisDatabase);
            var secondaryDatabaseAdapter = new RedisDatabaseAdapter(
                RedisDatabaseFactory.CreateAsync(new EnvironmentConnectionStringProvider("TestConnectionString"), secondaryConnection).GetAwaiter().GetResult(),
                DefaultKeySpace);

            return(new RedisGlobalStore(Clock, Configuration, primaryDatabaseAdapter, secondaryDatabaseAdapter, primaryDatabaseAdapter, secondaryDatabaseAdapter));
        }
        public async Task <IContentLocationStore> CreateAsync(MachineLocation machineLocation)
        {
            var connection = MockRedisDatabaseFactory.CreateConnection(RedisDatabase);

            RedisDatabaseAdapter = RedisDatabaseAdapter ?? new RedisDatabaseAdapter(await RedisDatabaseFactory.CreateAsync(new EnvironmentConnectionStringProvider("TestConnectionString"), connection), RedisContentLocationStoreFactory.DefaultKeySpace);
            var machineLocationConnection = MockRedisDatabaseFactory.CreateConnection(MachineLocationRedisDatabase);

            MachineRedisDatabaseAdapter = MachineRedisDatabaseAdapter ?? new RedisDatabaseAdapter(await RedisDatabaseFactory.CreateAsync(new EnvironmentConnectionStringProvider("TestConnectionString"), machineLocationConnection), RedisContentLocationStoreFactory.DefaultKeySpace);
            IContentLocationStore store = new RedisContentLocationStore(
                RedisDatabaseAdapter,
                MachineRedisDatabaseAdapter,
                _mockClock,
                BumpTime,
                machineLocation.Data,
                _configuration);

            var redisStore = (RedisContentLocationStore)store;

            redisStore.DisableReplica = true;
            return(store);
        }