Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="interceptor"></param>
        /// <returns></returns>
        public ISession OpenSession(IInterceptor interceptor)
        {
            long timestamp = Timestamper.Next();

            // specify true for autoClose because NHibernate has responsibility for
            // the IDbConnection.
            return(OpenSession(null, true, timestamp, interceptor));
        }
Ejemplo n.º 2
0
        // TODO: Try to understand what this is for and how it's used.
        public long NextTimestamp()
        {
            if (_logger.IsDebugEnabled)
            {
                _logger.DebugFormat("NextTimestamp() invoked in region '{0}'.", _regionAlphaNumeric);
            }

            return(Timestamper.Next());
        }
Ejemplo n.º 3
0
        public void AsyncOperationsThrow()
        {
            var      cache    = new HashtableCacheProvider().BuildCache("region", new Dictionary <string, string>());
            var      strategy = CreateCache(cache);
            CacheKey key      = CreateCacheKey("key");
            var      stamp    = Timestamper.Next();

            Assert.ThrowsAsync <InvalidOperationException>(
                () =>
                strategy.PutAsync(key, "value", stamp, 0, null, false, default(CancellationToken)));
            Assert.ThrowsAsync <InvalidOperationException>(() => strategy.GetAsync(key, stamp, default(CancellationToken)));
        }
Ejemplo n.º 4
0
        public void VerifyIncrease()
        {
            long currentTicks = 0;
            long newTicks     = 0;

            // the Timestampper will only generate 4095 increasing identifiers per millisecond.
            for (int i = 0; i < 4095; i++)
            {
                newTicks = Timestamper.Next();
                if ((newTicks - currentTicks) == 0)
                {
                    Assert.Fail("diff was " + (newTicks - currentTicks) + ".  It should always increase.  Loop i=" + i +
                                " with currentTicks = " + currentTicks + " and newTicks = " + newTicks);
                }
                currentTicks = newTicks;
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Generate a timestamp
 /// </summary>
 /// <returns>a timestamp</returns>
 public long NextTimestamp()
 {
     return(Timestamper.Next());
 }
Ejemplo n.º 6
0
 /// <inheritdoc />
 public override long NextTimestamp()
 {
     return(Timestamper.Next());
 }
        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.º 8
0
 /// <summary>
 /// Generate a timestamp
 /// </summary>
 /// <returns></returns>
 public virtual long NextTimestamp()
 {
     return(Timestamper.Next());
 }
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));
        }
 /// <inheritdoc />
 public override long NextTimestamp() => Timestamper.Next();