Exemplo n.º 1
0
        public void RemoveCollection()
        {
            var procCache = new InProcessCache();
            var cache     = new ObjectCache <int, Frog>(procCache);

            var frogs = new[]
            {
                new Frog {
                    Id = 6, Name = "Frank", DateOfBirth = DateTime.Today.AddDays(1)
                },
                new Frog {
                    Id = 7, Name = "Fred", DateOfBirth = DateTime.Today.AddDays(2)
                },
                new Frog {
                    Id = 8, Name = "Fergil", DateOfBirth = DateTime.Today.AddDays(3)
                },
            };

            cache.StoreCollection(frogs);

            Assert.True(cache.TryGetCollection(out var cacheFrogs));
            Assert.Equal(3, cacheFrogs.Length);

            cache.RemoveCollection();
            Assert.False(cache.TryGetCollection(out cacheFrogs));
            Assert.Null(cacheFrogs);
        }
Exemplo n.º 2
0
        public void TryGetCollection()
        {
            var procCache = new InProcessCache();
            var cache     = new ObjectCache <int, Frog>(procCache);

            var frogs = new[]
            {
                new Frog {
                    Id = 6, Name = "Frank", DateOfBirth = DateTime.Today.AddDays(1)
                },
                new Frog {
                    Id = 7, Name = "Fred", DateOfBirth = DateTime.Today.AddDays(2)
                },
                new Frog {
                    Id = 8, Name = "Fergil", DateOfBirth = DateTime.Today.AddDays(3)
                },
            };

            cache.StoreCollection(frogs);

            Assert.True(cache.TryGetCollection(out var cacheFrogs));
            Assert.Equal(3, cacheFrogs.Length);

            Assert.Contains(cacheFrogs, (f) => f.Id == 6 && f.Name == "Frank" && f.DateOfBirth == DateTime.Today.AddDays(1));
            Assert.Contains(cacheFrogs, (f) => f.Id == 7 && f.Name == "Fred" && f.DateOfBirth == DateTime.Today.AddDays(2));
            Assert.Contains(cacheFrogs, (f) => f.Id == 8 && f.Name == "Fergil" && f.DateOfBirth == DateTime.Today.AddDays(3));
        }
Exemplo n.º 3
0
        public void expired_in_put()
        {
            const string testKey = "TestKey";
            const string testValue = "TestValue";

            ICache cache = new InProcessCache();
            cache.Remove(testKey);
            cache.Set(testKey, testValue, new TimeSpan(0, 0, 1));
            Assert.IsTrue(cache.Exists(testKey));
        }
Exemplo n.º 4
0
        public void Get_OnExistingValue_ShouldReturnStoredObject()
        {
            var cache = new InProcessCache();

            cache.Set("abc", this);

            var actualStoredItem = cache.Get <InProcessCacheTests>("abc");

            Assert.AreEqual(this, actualStoredItem);
        }
Exemplo n.º 5
0
        public void expired_at_put()
        {
            const string testKey = "TestKey";
            const string testValue = "TestValue";

            ICache cache = new InProcessCache();
            cache.Remove(testKey);
            cache.Set(testKey, testValue, DateTime.Now.AddMinutes(1));
            Assert.IsTrue(cache.Exists(testKey));
        }
Exemplo n.º 6
0
        public void GetGroupTest()
        {
            var keys = new List<string> {"key1", "key2"};
            var cache = new InProcessCache();

            foreach(var key in keys)
                cache.Set(key, key);

            var values = cache.GetGroup<string>(keys);
            Assert.IsTrue(values.Count == 2);
        }
        public void expired_at_put()
        {
            const string testKey   = "TestKey";
            const string testValue = "TestValue";

            ICache cache = new InProcessCache();

            cache.Remove(testKey);
            cache.Set(testKey, testValue, DateTime.Now.AddMinutes(1));
            Assert.IsTrue(cache.Exists(testKey));
        }
        public void expired_in_put()
        {
            const string testKey   = "TestKey";
            const string testValue = "TestValue";

            ICache cache = new InProcessCache();

            cache.Remove(testKey);
            cache.Set(testKey, testValue, new TimeSpan(0, 0, 1));
            Assert.IsTrue(cache.Exists(testKey));
        }
Exemplo n.º 9
0
        public void Expiring()
        {
            var cache = new InProcessCache(TimeSpan.FromSeconds(1));

            cache.Store("key", "value");
            Assert.True(cache.TryGet("key", out var _));

            Thread.Sleep(300);
            Assert.True(cache.TryGet("key", out var _));

            Thread.Sleep(700);
            Assert.False(cache.TryGet("key", out var _));
        }
Exemplo n.º 10
0
        public void basic_put_and_get()
        {
            const string testKey = "TestKey";
            const string testValue = "TestValue";

            ICache cache = new InProcessCache();
            cache.Remove(testKey);
            cache.Set(testKey, testValue);

            var actual = (string)cache.Get(testKey);

            Assert.AreEqual(testValue, actual);
            Assert.IsTrue(cache.Exists(testKey));
        }
        public void basic_put_and_get()
        {
            const string testKey   = "TestKey";
            const string testValue = "TestValue";

            ICache cache = new InProcessCache();

            cache.Remove(testKey);
            cache.Set(testKey, testValue);

            var actual = (string)cache.Get(testKey);

            Assert.AreEqual(testValue, actual);
            Assert.IsTrue(cache.Exists(testKey));
        }
Exemplo n.º 12
0
        public Genesis(string user, string connectionString, ITraceExporter traceExporter)
        {
            _day = DateTime.MinValue;
            var cache = new InProcessCache();

            var tadpoleMine = new TadpoleMine(user, cache, connectionString, traceExporter);

            _pondMine            = new PondMine(user, cache, connectionString, traceExporter);
            _frogMine            = new FrogMine(user, cache, connectionString, traceExporter);
            _pairSelectionMine   = new PairSelectionMine(user, _frogMine, traceExporter);
            _maturationEventMine = new MaturationEventMine(user, _frogMine, tadpoleMine, traceExporter);
            _matingEventMine     = new MatingEventMine(user, _frogMine, tadpoleMine, traceExporter);
            _frogCountMine       = new FrogCountMine(user, connectionString, traceExporter);
            _tadpoleCountMine    = new TadpoleCountMine(user, connectionString, traceExporter);
        }
        public void GetGroupTest()
        {
            var keys = new List <string> {
                "key1", "key2"
            };
            var cache = new InProcessCache();

            foreach (var key in keys)
            {
                cache.Set(key, key);
            }

            var values = cache.GetGroup <string>(keys);

            Assert.IsTrue(values.Count == 2);
        }
Exemplo n.º 14
0
        public void TryGet()
        {
            var procCache = new InProcessCache();
            var cache     = new ObjectCache <int, Frog>(procCache);

            var frog = new Frog {
                Id = 6, Name = "Frank", DateOfBirth = DateTime.Today.AddDays(78)
            };

            cache.Store(frog.Id, frog);

            Assert.True(cache.TryGet(6, out var cacheFrog));
            Assert.Equal(frog, cacheFrog);

            Assert.False(cache.TryGet(9, out cacheFrog));
            Assert.Null(cacheFrog);
        }
Exemplo n.º 15
0
        public void General()
        {
            var cache = new InProcessCache();

            // ensure no error
            cache.Remove(Guid.NewGuid().ToString());

            Assert.ThrowsAny <ArgumentException>(() => cache.Store(null, 1));

            var key = Guid.NewGuid().ToString();

            Assert.False(cache.TryGet(key, out var _));

            cache.Store(key, this);

            Assert.True(cache.TryGet(key, out var test));
            Assert.Same(this, test);

            cache.Remove(key);

            Assert.False(cache.TryGet(key, out var _));
        }
Exemplo n.º 16
0
 public WMICache(InProcessCache cache)
 {
     try
     {
         this.cache = cache;
         string size;
         if (Config.GetValueOf("CACHE_STORAGE_SIZE", out size) && Convert.ToInt32(size) > 0)
         {
             maxCacheStorageSize = Convert.ToInt64(size) * 1024;
         }
         else
         {
             maxCacheStorageSize = -1;
         }
         wmicacheItems = new Hashtable();
         Instrumentation.Publish(this);
     }
     catch (Exception e)
     {
         GXLogging.Error(log, "WMI Error", e);
     }
 }
Exemplo n.º 17
0
        public void ManyItems()
        {
            var itemCount   = 10000;
            var cacheString = GetCacheValueString();

            var cache = new InProcessCache();

            for (var i = 0; i < itemCount; i++)
            {
                var key   = GetCacheKey(i);
                var value = $"{key}{cacheString}";

                cache.Store(key, value);
            }

            for (var i = 0; i < itemCount; i++)
            {
                var key           = GetCacheKey(i);
                var expectedValue = $"{key}{cacheString}";

                Assert.True(cache.TryGet(key, out var value));
                Assert.Equal(expectedValue, value);
            }
        }
Exemplo n.º 18
0
 public WMICache(InProcessCache inProcessCache)
 {
     this.inProcessCache = inProcessCache;
 }
Exemplo n.º 19
0
        public void Constructor_Valid_ShouldNotThrowException()
        {
            var cache = new InProcessCache();

            Assert.Pass("Did not throw exception");
        }
Exemplo n.º 20
0
        public void Set_Valid_ShouldNotThrowException()
        {
            var cache = new InProcessCache();

            cache.Set("abc", this);
        }
Exemplo n.º 21
0
 public InProcessCacheTests()
 {
     cache = new InProcessCache(Options.Create(new CacheOptions()));
 }
Exemplo n.º 22
0
 public InProcessCacheTests()
 {
     Cache = new InProcessCache(
         Microsoft.Extensions.Options.Options.Create(
             new CacheOptions()), () => DateTimeOffset.Now);
 }