예제 #1
0
 internal static void TestFollowerConcurrency(AbstractClient C)
 {
     const int Iterations = 10000;
     // Two threads racing each other adding and removing followers
     new Thread(new ThreadStart(() =>
     {
         for (int i = 0; i < Iterations; i++)
         {
             C.AddFollower(R.Next());
         }
     })).Start();
     new Thread(new ThreadStart(() =>
     {
         for (int i = 0; i < Iterations; i++)
         {
             var List = C.GetCurrentFollowers();
             if (List.Count > 0)
             {
                 C.RemoveFollower(List[R.Next(List.Count)]);
             }
             else
             {
                 // Remove non-existant followers should work too!
                 C.RemoveFollower(R.Next());
             }
         }
     })).Start();
     // No exception should be thrown
     Assert.Pass();
 }
예제 #2
0
        internal static void TestFollowerConcurrency(AbstractClient C)
        {
            const int Iterations = 10000;

            // Two threads racing each other adding and removing followers
            new Thread(new ThreadStart(() =>
            {
                for (int i = 0; i < Iterations; i++)
                {
                    C.AddFollower(R.Next());
                }
            })).Start();
            new Thread(new ThreadStart(() =>
            {
                for (int i = 0; i < Iterations; i++)
                {
                    var List = C.GetCurrentFollowers();
                    if (List.Count > 0)
                    {
                        C.RemoveFollower(List[R.Next(List.Count)]);
                    }
                    else
                    {
                        // Remove non-existant followers should work too!
                        C.RemoveFollower(R.Next());
                    }
                }
            })).Start();
            // No exception should be thrown
            Assert.Pass();
        }
예제 #3
0
        // Shared with Connected client too
        internal static void TestFollowers(AbstractClient C)
        {
            C.AddFollower(1);
            C.AddFollower(2);
            // Double add
            C.AddFollower(2);
            C.AddFollower(3);
            var Followers = C.GetCurrentFollowers();

            Assert.That(Followers.Count == 3, "Dummy client's follower adding error! A follower with the same ID can only be added once!");
            Assert.That(Followers.Contains(2), "Dummy client's follower adding error!");
            Assert.False(Followers.Contains(4), "Dummy client's follower checking error!");

            // External modification must not affect internal operation
            Followers.Add(5);
            Assert.False(C.GetCurrentFollowers().Contains(5), "Dummy client's GetCurrentFollowers should not return the internal follower list!");
        }
예제 #4
0
 /// <summary>
 /// Take data from another client, the other client should be discarded shortly after so this
 /// instance can take oker
 /// </summary>
 /// <param name="Other">Client to take followers and messages from</param>
 public void TakeOverFrom(AbstractClient Other)
 {
     this.Followers = new HashSet<int>(Other.GetCurrentFollowers());
     this.Messages = new Queue<Payload>(Other.GetMessages());
 }
예제 #5
0
        // Shared with Connected client too
        internal static void TestFollowers(AbstractClient C)
        {
            C.AddFollower(1);
            C.AddFollower(2);
            // Double add
            C.AddFollower(2);
            C.AddFollower(3);
            var Followers = C.GetCurrentFollowers();
            Assert.That(Followers.Count == 3, "Dummy client's follower adding error! A follower with the same ID can only be added once!");
            Assert.That(Followers.Contains(2), "Dummy client's follower adding error!");
            Assert.False(Followers.Contains(4), "Dummy client's follower checking error!");

            // External modification must not affect internal operation
            Followers.Add(5);
            Assert.False(C.GetCurrentFollowers().Contains(5), "Dummy client's GetCurrentFollowers should not return the internal follower list!");
        }
예제 #6
0
 /// <summary>
 /// Take data from another client, the other client should be discarded shortly after so this
 /// instance can take oker
 /// </summary>
 /// <param name="Other">Client to take followers and messages from</param>
 public void TakeOverFrom(AbstractClient Other)
 {
     this.Followers = new HashSet <int>(Other.GetCurrentFollowers());
     this.Messages  = new Queue <Payload>(Other.GetMessages());
 }