Пример #1
0
 public void TestLockOpCountByVersion(RedisConnection conn, int expected, bool existFirst)
 {
     const int DB = 0, LockDuration = 30;
     const string Key = "TestOpCountByVersion";
     conn.Wait(conn.Open());
     conn.Keys.Remove(DB, Key);
     var newVal = "us:" + Config.CreateUniqueName();
     string expectedVal = newVal;
     if (existFirst)
     {
         expectedVal = "other:" + Config.CreateUniqueName();
         conn.Strings.Set(DB, Key, expectedVal, LockDuration);
     }
     int countBefore = conn.GetCounters().MessagesSent;
     var taken = conn.Wait(conn.Strings.TakeLock(DB, Key, newVal, LockDuration));
     int countAfter = conn.GetCounters().MessagesSent;
     var valAfter = conn.Wait(conn.Strings.GetString(DB, Key));
     Assert.AreEqual(!existFirst, taken, "lock taken");
     Assert.AreEqual(expectedVal, valAfter, "taker");
     Assert.AreEqual(expected, (countAfter - countBefore) - 1, "expected ops (including ping)");
     // note we get a ping from GetCounters
 }