Ejemplo n.º 1
0
        private void BuildCaches()
        {
            var regions = configuration.GetRegionNames();

            caches = new Dictionary <string, ICache>(regions.Count() + 1);
            caches.Add(DefaultRegionName, cacheProvider.BuildCache(DefaultRegionName));

            foreach (var region in regions)
            {
                caches.Add(region, cacheProvider.BuildCache(region));
            }
        }
Ejemplo n.º 2
0
        public void TestPut()
        {
            string key   = "key1";
            string value = "value";

            ICache cache = provider.BuildCache("nunit", props);

            Assert.IsNotNull(cache, "no cache returned");

            Assert.ShouldNotBeNull(cache.Get(key), "cache returned an item we didn't add !?!");

            cache.Put(key, value);
            Thread.Sleep(100);
            object item = cache.Get(key);

            Assert.IsNotNull(item);
            Assert.AreEqual(value, item, "didn't return the item we added");
        }
		public StandardQueryCache( ICacheProvider provider, IDictionary props, UpdateTimestampsCache updateTimestampsCache, string regionName )
		{
			if( regionName == null )
			{
				regionName = typeof( StandardQueryCache ).FullName;
			}
			log.Info( "starting query cache at region: " + regionName );
			this.queryCache = provider.BuildCache( regionName, props );
			this.updateTimestampsCache = updateTimestampsCache;
			this.regionName = regionName;
		}
Ejemplo n.º 4
0
 public StandardQueryCache(ICacheProvider provider, IDictionary props, UpdateTimestampsCache updateTimestampsCache, string regionName)
 {
     if (regionName == null)
     {
         regionName = typeof(StandardQueryCache).FullName;
     }
     log.Info("starting query cache at region: " + regionName);
     this.queryCache            = provider.BuildCache(regionName, props);
     this.updateTimestampsCache = updateTimestampsCache;
     this.regionName            = regionName;
 }
        public void TestClear()
        {
            string key   = "key1";
            string value = "value";

            ICache cache = provider.BuildCache("nunit", props);

            Assert.IsNotNull(cache, "no cache returned");

            // add the item
            cache.Put(key, value);
            Thread.Sleep(1000);

            // make sure it's there
            object item = cache.Get(key);

            Assert.IsNotNull(item, "couldn't find item in cache");

            // clear the cache
            cache.Clear();

            // make sure we don't get an item
            item = cache.Get(key);
            Assert.IsNull(item, "item still exists in cache");
        }
        public async Task DoTestCacheAsync(ICacheProvider cacheProvider, CancellationToken cancellationToken = default(CancellationToken))
        {
            ICache cache = cacheProvider.BuildCache(typeof(String).FullName, new Dictionary <string, string>());

            long longBefore = Timestamper.Next();

            await(Task.Delay(15, cancellationToken));

            long before = Timestamper.Next();

            await(Task.Delay(15, cancellationToken));

            ICacheConcurrencyStrategy ccs = new ReadWriteCache();

            ccs.Cache = cache;

            // cache something
            CacheKey fooKey = CreateCacheKey("foo");

            Assert.IsTrue(await(ccs.PutAsync(fooKey, "foo", before, null, null, false, cancellationToken)));

            await(Task.Delay(15, cancellationToken));

            long after = Timestamper.Next();

            Assert.IsNull(await(ccs.GetAsync(fooKey, longBefore, cancellationToken)));
            Assert.AreEqual("foo", await(ccs.GetAsync(fooKey, after, cancellationToken)));
            Assert.IsFalse(await(ccs.PutAsync(fooKey, "foo", before, null, null, false, cancellationToken)));

            // update it;

            ISoftLock fooLock = await(ccs.LockAsync(fooKey, null, cancellationToken));

            Assert.IsNull(await(ccs.GetAsync(fooKey, after, cancellationToken)));
            Assert.IsNull(await(ccs.GetAsync(fooKey, longBefore, cancellationToken)));
            Assert.IsFalse(await(ccs.PutAsync(fooKey, "foo", before, null, null, false, cancellationToken)));

            await(Task.Delay(15, cancellationToken));

            long whileLocked = Timestamper.Next();

            Assert.IsFalse(await(ccs.PutAsync(fooKey, "foo", whileLocked, null, null, false, cancellationToken)));

            await(Task.Delay(15, cancellationToken));

            await(ccs.ReleaseAsync(fooKey, fooLock, cancellationToken));

            Assert.IsNull(await(ccs.GetAsync(fooKey, after, cancellationToken)));
            Assert.IsNull(await(ccs.GetAsync(fooKey, longBefore, cancellationToken)));
            Assert.IsFalse(await(ccs.PutAsync(fooKey, "bar", whileLocked, null, null, false, cancellationToken)));
            Assert.IsFalse(await(ccs.PutAsync(fooKey, "bar", after, null, null, false, cancellationToken)));

            await(Task.Delay(15, cancellationToken));

            long longAfter = Timestamper.Next();

            Assert.IsTrue(await(ccs.PutAsync(fooKey, "baz", longAfter, null, null, false, cancellationToken)));
            Assert.IsNull(await(ccs.GetAsync(fooKey, after, cancellationToken)));
            Assert.IsNull(await(ccs.GetAsync(fooKey, whileLocked, cancellationToken)));

            await(Task.Delay(15, cancellationToken));

            long longLongAfter = Timestamper.Next();

            Assert.AreEqual("baz", await(ccs.GetAsync(fooKey, longLongAfter, cancellationToken)));

            // update it again, with multiple locks

            ISoftLock fooLock1 = await(ccs.LockAsync(fooKey, null, cancellationToken));
            ISoftLock fooLock2 = await(ccs.LockAsync(fooKey, null, cancellationToken));

            Assert.IsNull(await(ccs.GetAsync(fooKey, longLongAfter, cancellationToken)));

            await(Task.Delay(15, cancellationToken));

            whileLocked = Timestamper.Next();

            Assert.IsFalse(await(ccs.PutAsync(fooKey, "foo", whileLocked, null, null, false, cancellationToken)));

            await(Task.Delay(15, cancellationToken));

            await(ccs.ReleaseAsync(fooKey, fooLock2, cancellationToken));

            await(Task.Delay(15, cancellationToken));

            long betweenReleases = Timestamper.Next();

            Assert.IsFalse(await(ccs.PutAsync(fooKey, "bar", betweenReleases, null, null, false, cancellationToken)));
            Assert.IsNull(await(ccs.GetAsync(fooKey, betweenReleases, cancellationToken)));

            await(Task.Delay(15, cancellationToken));

            await(ccs.ReleaseAsync(fooKey, fooLock1, cancellationToken));

            Assert.IsFalse(await(ccs.PutAsync(fooKey, "bar", whileLocked, null, null, false, cancellationToken)));

            await(Task.Delay(15, cancellationToken));

            longAfter = Timestamper.Next();

            Assert.IsTrue(await(ccs.PutAsync(fooKey, "baz", longAfter, null, null, false, cancellationToken)));
            Assert.IsNull(await(ccs.GetAsync(fooKey, whileLocked, cancellationToken)));

            await(Task.Delay(15, cancellationToken));

            longLongAfter = Timestamper.Next();

            Assert.AreEqual("baz", await(ccs.GetAsync(fooKey, longLongAfter, cancellationToken)));
        }
Ejemplo n.º 7
0
        public void TestBuildCacheFromConfig()
        {
            ICache cache = provider.BuildCache("foo", null);

            Assert.IsNotNull(cache, "pre-configured cache not found");
        }
Ejemplo n.º 8
0
		public void DoTestCache(ICacheProvider cacheProvider)
		{
			ICache cache = cacheProvider.BuildCache(typeof(String).FullName, new Dictionary<string, string>());

			long longBefore = Timestamper.Next();

			Thread.Sleep(15);

			long before = Timestamper.Next();

			Thread.Sleep(15);

			ICacheConcurrencyStrategy ccs = new ReadWriteCache();
			ccs.Cache = cache;

			// cache something
			CacheKey fooKey = CreateCacheKey("foo");

			Assert.IsTrue(ccs.Put(fooKey, "foo", before, null, null, false));

			Thread.Sleep(15);

			long after = Timestamper.Next();

			Assert.IsNull(ccs.Get(fooKey, longBefore));
			Assert.AreEqual("foo", ccs.Get(fooKey, after));
			Assert.IsFalse(ccs.Put(fooKey, "foo", before, null, null, false));

			// update it;

			ISoftLock fooLock = ccs.Lock(fooKey, null);

			Assert.IsNull(ccs.Get(fooKey, after));
			Assert.IsNull(ccs.Get(fooKey, longBefore));
			Assert.IsFalse(ccs.Put(fooKey, "foo", before, null, null, false));

			Thread.Sleep(15);

			long whileLocked = Timestamper.Next();

			Assert.IsFalse(ccs.Put(fooKey, "foo", whileLocked, null, null, false));

			Thread.Sleep(15);

			ccs.Release(fooKey, fooLock);

			Assert.IsNull(ccs.Get(fooKey, after));
			Assert.IsNull(ccs.Get(fooKey, longBefore));
			Assert.IsFalse(ccs.Put(fooKey, "bar", whileLocked, null, null, false));
			Assert.IsFalse(ccs.Put(fooKey, "bar", after, null, null, false));

			Thread.Sleep(15);

			long longAfter = Timestamper.Next();

			Assert.IsTrue(ccs.Put(fooKey, "baz", longAfter, null, null, false));
			Assert.IsNull(ccs.Get(fooKey, after));
			Assert.IsNull(ccs.Get(fooKey, whileLocked));

			Thread.Sleep(15);

			long longLongAfter = Timestamper.Next();

			Assert.AreEqual("baz", ccs.Get(fooKey, longLongAfter));

			// update it again, with multiple locks

			ISoftLock fooLock1 = ccs.Lock(fooKey, null);
			ISoftLock fooLock2 = ccs.Lock(fooKey, null);

			Assert.IsNull(ccs.Get(fooKey, longLongAfter));

			Thread.Sleep(15);

			whileLocked = Timestamper.Next();

			Assert.IsFalse(ccs.Put(fooKey, "foo", whileLocked, null, null, false));

			Thread.Sleep(15);

			ccs.Release(fooKey, fooLock2);

			Thread.Sleep(15);

			long betweenReleases = Timestamper.Next();

			Assert.IsFalse(ccs.Put(fooKey, "bar", betweenReleases, null, null, false));
			Assert.IsNull(ccs.Get(fooKey, betweenReleases));

			Thread.Sleep(15);

			ccs.Release(fooKey, fooLock1);

			Assert.IsFalse(ccs.Put(fooKey, "bar", whileLocked, null, null, false));

			Thread.Sleep(15);

			longAfter = Timestamper.Next();

			Assert.IsTrue(ccs.Put(fooKey, "baz", longAfter, null, null, false));
			Assert.IsNull(ccs.Get(fooKey, whileLocked));

			Thread.Sleep(15);

			longLongAfter = Timestamper.Next();

			Assert.AreEqual("baz", ccs.Get(fooKey, longLongAfter));
		}
Ejemplo n.º 9
0
        public void DoTestCache(ICacheProvider cacheProvider)
        {
            ICache cache = cacheProvider.BuildCache(typeof(String).FullName, new Dictionary <string, string>());

            long longBefore = Timestamper.Next();

            Thread.Sleep(15);

            long before = Timestamper.Next();

            Thread.Sleep(15);

            ICacheConcurrencyStrategy ccs = new ReadWriteCache();

            ccs.Cache = cache;

            // cache something
            CacheKey fooKey = CreateCacheKey("foo");

            Assert.IsTrue(ccs.Put(fooKey, "foo", before, null, null, false));

            Thread.Sleep(15);

            long after = Timestamper.Next();

            Assert.IsNull(ccs.Get(fooKey, longBefore));
            Assert.AreEqual("foo", ccs.Get(fooKey, after));
            Assert.IsFalse(ccs.Put(fooKey, "foo", before, null, null, false));

            // update it;

            ISoftLock fooLock = ccs.Lock(fooKey, null);

            Assert.IsNull(ccs.Get(fooKey, after));
            Assert.IsNull(ccs.Get(fooKey, longBefore));
            Assert.IsFalse(ccs.Put(fooKey, "foo", before, null, null, false));

            Thread.Sleep(15);

            long whileLocked = Timestamper.Next();

            Assert.IsFalse(ccs.Put(fooKey, "foo", whileLocked, null, null, false));

            Thread.Sleep(15);

            ccs.Release(fooKey, fooLock);

            Assert.IsNull(ccs.Get(fooKey, after));
            Assert.IsNull(ccs.Get(fooKey, longBefore));
            Assert.IsFalse(ccs.Put(fooKey, "bar", whileLocked, null, null, false));
            Assert.IsFalse(ccs.Put(fooKey, "bar", after, null, null, false));

            Thread.Sleep(15);

            long longAfter = Timestamper.Next();

            Assert.IsTrue(ccs.Put(fooKey, "baz", longAfter, null, null, false));
            Assert.IsNull(ccs.Get(fooKey, after));
            Assert.IsNull(ccs.Get(fooKey, whileLocked));

            Thread.Sleep(15);

            long longLongAfter = Timestamper.Next();

            Assert.AreEqual("baz", ccs.Get(fooKey, longLongAfter));

            // update it again, with multiple locks

            ISoftLock fooLock1 = ccs.Lock(fooKey, null);
            ISoftLock fooLock2 = ccs.Lock(fooKey, null);

            Assert.IsNull(ccs.Get(fooKey, longLongAfter));

            Thread.Sleep(15);

            whileLocked = Timestamper.Next();

            Assert.IsFalse(ccs.Put(fooKey, "foo", whileLocked, null, null, false));

            Thread.Sleep(15);

            ccs.Release(fooKey, fooLock2);

            Thread.Sleep(15);

            long betweenReleases = Timestamper.Next();

            Assert.IsFalse(ccs.Put(fooKey, "bar", betweenReleases, null, null, false));
            Assert.IsNull(ccs.Get(fooKey, betweenReleases));

            Thread.Sleep(15);

            ccs.Release(fooKey, fooLock1);

            Assert.IsFalse(ccs.Put(fooKey, "bar", whileLocked, null, null, false));

            Thread.Sleep(15);

            longAfter = Timestamper.Next();

            Assert.IsTrue(ccs.Put(fooKey, "baz", longAfter, null, null, false));
            Assert.IsNull(ccs.Get(fooKey, whileLocked));

            Thread.Sleep(15);

            longLongAfter = Timestamper.Next();

            Assert.AreEqual("baz", ccs.Get(fooKey, longLongAfter));
        }
Ejemplo n.º 10
0
 public UpdateTimestampsCache(ICacheProvider provider, IDictionary props)
 {
     log.Info("starting update timestamps cache at region: " + RegionName);
     this.updateTimestamps = provider.BuildCache(RegionName, props);
 }
		public UpdateTimestampsCache( ICacheProvider provider, IDictionary props )
		{
			log.Info( "starting update timestamps cache at region: " + RegionName );
			this.updateTimestamps = provider.BuildCache( RegionName, props );
		}