コード例 #1
0
        protected void runTest(int count)
        {
            ManualResetEvent[] waitHandles = new ManualResetEvent[count];
            nodes = new WriteLock[count];
            for (int i = 0; i < count; i++)
            {
                waitHandles[i] = new ManualResetEvent(true);
                ZooKeeper keeper = CreateClient();
                WriteLock leader = new WriteLock(keeper, dir, null);
                leader.LockAcquired += () => waitHandles[i].Set();
                nodes[i] = leader;
                leader.Lock();
            }

            // lets wait for any previous leaders to die and one of our new
            // nodes to become the new leader
            foreach (var handle in waitHandles)
                handle.WaitOne(5000);

            WriteLock first = nodes[0];
            dumpNodes(count);

            // lets assert that the first election is the leader
            Assert.True(first.Owner, "The first znode should be the leader " + first.Id);

            for (int i = 1; i < count; i++)
            {
                WriteLock node = nodes[i];
                Assert.False(node.Owner, "Node should not be the leader " + node.Id);
            }

            if (count > 1)
            {
                LOG.Debug("Now killing the leader");
                // now lets kill the leader
                var firstReleased = new ManualResetEvent(false);
                var secondAcquired = new ManualResetEvent(false);
                first.LockReleased += () => firstReleased.Set();
                WriteLock second = nodes[1];
                second.LockAcquired += () => secondAcquired.Set();
                first.Unlock();
                firstReleased.WaitOne(5000);
                secondAcquired.WaitOne(5000);
                dumpNodes(count);
                // lets assert that the first election is the leader
                Assert.True(second.Owner, "The second znode should be the leader " + second.Id);

                for (int i = 2; i < count; i++)
                {
                    WriteLock node = nodes[i];
                    Assert.False(node.Owner, "Node should not be the leader " + node.Id);
                }
            }
        }
コード例 #2
0
 public DisposableLock(WriteLock writeLock)
 {
     this.writeLock = writeLock;
 }
コード例 #3
0
 public LockWatcher(WriteLock writeLock)
 {
     this.writeLock = writeLock;
 }