Beispiel #1
0
        public void Does_flush_all()
        {
            3.Times(i => cache.Set("Car" + i, "Audi"));
            3.Times(i => Assert.That(cache.Get <string>("Car" + i), Is.EqualTo("Audi")));

            cache.FlushAll();

            3.Times(i => Assert.That(cache.Get <string>("Car" + i), Is.EqualTo(default(string))));
            3.Times(i => cache.Remove("Car" + i));
        }
        protected override async Task <JobResult> RunInternalAsync(CancellationToken token)
        {
            if (!ConfigurationManager.AppSettings.GetBool("Migration:CanResetData").GetValueOrDefault())
            {
                return(JobResult.FailedWithMessage("Migration:CanResetData was not set in the app.config."));
            }

            Log.Info().Message("Flushing redis cache").Write();
            _cacheClient.FlushAll();

            Log.Info().Message("Resetting elastic search").Write();
            ElasticSearchConfiguration.ConfigureMapping(_elasticClient, true);

            foreach (var collectionName in _mongoDatabase.GetCollectionNames().Where(name => !name.StartsWith("system")))
            {
                Log.Info().Message("Dropping collection: {0}", collectionName).Write();
                _mongoDatabase.DropCollection(collectionName);
            }

            Log.Info().Message("Creating indexes...").Write();
            new ApplicationRepository(_mongoDatabase);
            new OrganizationRepository(_mongoDatabase);
            new ProjectRepository(_mongoDatabase);
            new TokenRepository(_mongoDatabase);
            new WebHookRepository(_mongoDatabase);
            new UserRepository(_mongoDatabase);
            Log.Info().Message("Finished creating indexes...").Write();

            return(JobResult.Success);
        }
Beispiel #3
0
        protected override async Task <JobResult> RunInternalAsync(CancellationToken token)
        {
            var ip = Util.GetExternalIP();

            if (ip != null)
            {
                Log.Info().Message("Public IP:" + ip).Write();
            }

            CopyCollections("error", "errorstack", "errorstack.stats.day", "errorstack.stats.month", "jobhistory", "joblock", "log", "project.stats.day", "project.stats.month");

            Log.Info().Message("Running migrations...").Write();
            MongoMigrationChecker.EnsureLatest(Settings.Current.MongoConnectionString, new MongoUrl(Settings.Current.MongoConnectionString).DatabaseName);
            Log.Info().Message("Finished running migrations").Write();

            Log.Info().Message("Creating indexes...").Write();
            new ApplicationRepository(_mongoDatabase);
            new OrganizationRepository(_mongoDatabase);
            new ProjectRepository(_mongoDatabase);
            new TokenRepository(_mongoDatabase);
            new WebHookRepository(_mongoDatabase);
            new UserRepository(_mongoDatabase);
            Log.Info().Message("Finished creating indexes...").Write();

            Log.Info().Message("Flushing redis cache").Write();
            _cacheClient.FlushAll();

            return(JobResult.Success);
        }
 public void OnBeforeEachTest()
 {
     cacheClient = new MemoryCacheClient();
     //cacheClient = new RedisCacheClient(TestConfig.SingleHost);
     cacheClient.FlushAll();
     model    = ModelWithIdAndName.Create(1);
     xmlModel = DataContractSerializer.Instance.Parse(model);
 }
		public void OnBeforeEachTest()
		{
			if (cacheClient != null)
				cacheClient.Dispose();

			cacheClient = new RedisClient(TestConfig.SingleHost);
			cacheClient.FlushAll();
		}
 public void OnBeforeEachTest()
 {
     cacheClient = new MemoryCacheClient();
     //cacheClient = new RedisCacheClient(TestConfig.SingleHost);
     cacheClient.FlushAll();
     model = ModelWithIdAndName.Create(1);
     xmlModel = DataContractSerializer.Instance.Parse(model);
 }
        public void OnBeforeEachTest()
        {
            if (cacheClient != null)
            {
                cacheClient.Dispose();
            }

            cacheClient = new RedisClient(TestConfig.SingleHost);
            cacheClient.FlushAll();
        }
Beispiel #8
0
 /// <summary>
 /// 构造函数
 /// </summary>
 public RedisCacheProvider()
 {
     if (cacheClient != null)
     {
         cacheClient.Dispose();
     }
     cacheClient = new RedisClient();
     try
     {
         string          path       = WebHelper.GetConfigFilePath("rediscache.config");
         RedisConfigInfo configInfo = (RedisConfigInfo)XmlHelper.DeserializeFromXML(typeof(RedisConfigInfo), path);
         if (configInfo != null)
         {
             string        pwd   = string.IsNullOrEmpty(configInfo.Pwd) ? null : configInfo.Pwd;
             RedisEndpoint point = new RedisEndpoint(configInfo.Host, configInfo.Port, pwd, configInfo.InitalDB);
             cacheClient = new RedisClient(point);
         }
     }
     catch { }
     cacheClient.FlushAll();
 }
Beispiel #9
0
        public static void CacheAllWorlds(this IDbConnection db, ICacheClient cache)
        {
            cache.FlushAll();

            // concurrently create a list of world ids
            var worlds = db.GetWorlds();

            Parallel.ForEach<World>(worlds, w =>
            {
                var cacheKey = UrnId.Create<World>("Id", w.id.ToString());

                cache.Set<World>(cacheKey, w);
            });
        }
        public static void CacheAllWorlds(this IDbConnection db, ICacheClient cache)
        {
            cache.FlushAll();

            // concurrently create a list of world ids
            var worlds = db.GetWorlds();

            Parallel.ForEach <World>(worlds, w =>
            {
                var cacheKey = UrnId.Create <World>("Id", w.id.ToString());

                cache.Set <World>(cacheKey, w);
            });
        }
Beispiel #11
0
        public static void CacheAllWorlds(this MongoDatabase db, ICacheClient cache, string dbType)
        {
            cache.FlushAll();

            // concurrently create a list of world ids
            var worlds = db.GetWorlds();

            Parallel.ForEach <World>(worlds, w =>
            {
                var cacheKey = UrnId.CreateWithParts <World>(new string[] { dbType, w.id.ToString() });

                cache.Set <World>(cacheKey, w);
            });
        }
        public void DyanmoDb_ExerciseCacheClient()
        {
            // Expecting the Set operation to succeed
            bool setResponse = _client.Set <DummyObject>(_itemCacheKey, _item);

            Assert.AreEqual(true, setResponse);

            // Expecting the Get to return the item cached above
            var actual = _client.Get <DummyObject>(_itemCacheKey);

            Assert.IsNotNull(actual);
            Assert.AreEqual(_item.UserId, actual.UserId);

            // Expecting Add to return false since the item is already cached
            bool addResponse = _client.Add <DummyObject>(_itemCacheKey, _item);

            Assert.AreEqual(false, addResponse);

            // Expecting remove to succeed
            bool removeResponse = _client.Remove(_itemCacheKey);

            Assert.AreEqual(true, removeResponse);

            // Add the item back, expecting success
            addResponse = _client.Add <DummyObject>(_itemCacheKey, _item);
            Assert.AreEqual(true, addResponse);

            // Remove it again
            removeResponse = _client.Remove(_itemCacheKey);

            // Clear the counter if it exists
            removeResponse = _client.Remove(_counterCacheKey);

            // Initialize the counter, incResponse should be equal to 0 since the counter doesn't exist
            long incResponse = _client.Increment(_counterCacheKey, 0);

            // Increment by 1
            long updatedIncResponse = _client.Increment(_counterCacheKey, 1);

            Assert.AreEqual(incResponse + 1, updatedIncResponse);
            // Decrement by 1
            long decResponse = _client.Decrement(_counterCacheKey, 1);

            Assert.AreEqual(incResponse, decResponse);

            // Clear out the cache - this will cause a very long delete/re-create DynamoDB table sequence
            _client.FlushAll();
        }
Beispiel #13
0
 public void Clear()
 {
     cacheClient.FlushAll();
 }
Beispiel #14
0
 protected CacheClientTestsBase()
 {
     Cache = CreateClient();
     Cache.FlushAll();
 }
Beispiel #15
0
        public static void CacheAllWorlds(this MongoDatabase db, ICacheClient cache, string dbType)
        {
            cache.FlushAll();

            // concurrently create a list of world ids
            var worlds = db.GetWorlds();

            Parallel.ForEach<World>(worlds, w =>
            {
                var cacheKey = UrnId.CreateWithParts<World>(new string[] { dbType, w.id.ToString() });

                cache.Set<World>(cacheKey, w);
            });
        }
 protected CacheClientTestsBase()
 {
     Cache = CreateCacheClient();
     Cache.FlushAll();
 }
 public void SetUp()
 {
     Cache.FlushAll();
 }
 public void FlushAll()
 {
     // Cannot be prefixed
     cache.FlushAll();
 }