Esempio n. 1
0
        public void acquire_lock_with_timeout()
        {
            //Initialize and set counter to '1'
            redisWrapper.Increment("atomic-counter");

            //Acquire lock and never release it
            LockFactory.GetLock("testlock");

            var waitFor = TimeSpan.FromSeconds(2);
            var now     = DateTimeOffset.Now;

            try
            {
                //Attempt to acquire a lock with a 2 second timeout
                using (LockFactory.GetLock("testlock", waitFor))
                {
                    //If lock was acquired this would be incremented to '2'
                    redisWrapper.Increment("atomic-counter");
                }
            }
            catch (TimeoutException tex)
            {
                var timeTaken = DateTimeOffset.Now - now;
                testOutput.WriteLine(String.Format("After '{0}', Received TimeoutException: '{1}'", timeTaken, tex.Message));

                var counter = redisWrapper.Get("atomic-counter").ToString().ToInt();
                testOutput.WriteLine(String.Format("atomic-counter remains at '{0}'", counter));
            }
        }
Esempio n. 2
0
        public void redis_increment_test()
        {
            var key   = string.Format(keyTemplate, 2);
            var value = redisWrapper.Increment(key);

            value.Should().Be(1);

            value = redisWrapper.Increment(key);
            value.Should().Be(2);
        }