コード例 #1
0
        public async Task MinValueTimestampAsync()
        {
            ICache cache = new HashtableCacheProvider().BuildCache("region", new Dictionary <string, string>());
            ICacheConcurrencyStrategy strategy = new ReadWriteCache();

            strategy.Cache = cache;

            await(DoTestMinValueTimestampOnStrategyAsync(cache, new ReadWriteCache()));
            await(DoTestMinValueTimestampOnStrategyAsync(cache, new NonstrictReadWriteCache()));
            await(DoTestMinValueTimestampOnStrategyAsync(cache, new ReadOnlyCache()));
        }
コード例 #2
0
        public void MinValueTimestamp()
        {
            var cache = new HashtableCacheProvider().BuildCache("region", new Dictionary <string, string>());
            ICacheConcurrencyStrategy strategy = new ReadWriteCache();

            strategy.Cache = cache;

            DoTestMinValueTimestampOnStrategy(cache, new ReadWriteCache());
            DoTestMinValueTimestampOnStrategy(cache, new NonstrictReadWriteCache());
            DoTestMinValueTimestampOnStrategy(cache, new ReadOnlyCache());
        }
コード例 #3
0
        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)));
        }
コード例 #4
0
ファイル: CacheFixture.cs プロジェクト: jrauber/GH1429
        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));
        }