Author: alanmc
Date: 2008-01-26 10:34:23 -0500 (Sat, 26 Jan 2008)
New Revision: 93992

Modified:
   trunk/bitsharp/src/TrackerApp/StressTest.cs
Log:
Created two tests

Modified: trunk/bitsharp/src/TrackerApp/StressTest.cs
===================================================================
--- trunk/bitsharp/src/TrackerApp/StressTest.cs 2008-01-26 15:33:50 UTC (rev 
93991)
+++ trunk/bitsharp/src/TrackerApp/StressTest.cs 2008-01-26 15:34:23 UTC (rev 
93992)
@@ -73,9 +73,43 @@
             tracker.RegisterListener(listener);
         }
 
-        internal void Initialise()
+        internal void Initialise(bool testA)
         {
+            if (testA)
+                TestA();
+            else
+                TestB();
+        }
+        private void TestB()
+        {
             long ipAddress;
+            byte[] torrent;
+
+            List<KeyValuePair<int, int>> list = new List<KeyValuePair<int, 
int>>();
+            list.Add(new KeyValuePair<int, int>(50, 1000));
+            list.Add(new KeyValuePair<int, int>(100, 500));
+            list.Add(new KeyValuePair<int, int>(250, 50));
+            list.Add(new KeyValuePair<int, int>(200, 60));
+            foreach (KeyValuePair<int, int> pair in list)
+            {
+                for (int i = 0; i < pair.Key; i++)
+                {
+                    // Create the fake infohash and add the torrent to the 
tracker.
+                    torrent = new byte[20];
+                    random.NextBytes(torrent);
+                    tracker.Add(new InfoHashTrackable(i.ToString(), torrent));
+                    hashes.Add(torrent);
+
+                    ipAddress = 1;
+                    for (int j = 0; j < pair.Value; j++)
+                        listener.Handle(torrent, new IPAddress(ipAddress++), 
true);
+                }
+            }
+        }
+
+        private void TestA()
+        {
+            long ipAddress;
             int peers;
             byte[] torrent;
 
@@ -94,12 +128,11 @@
                 hashes.Add(torrent);
 
                 ipAddress = 1;
-                peers = random.Next((int)(averagePeers * 0.5), 
(int)(averagePeers * 1.5));
+                peers = averagePeers;// random.Next((int)(averagePeers * 0.5), 
(int)(averagePeers * 1.5));
                 for (int j = 0; j < peers; j++)
                     listener.Handle(torrent, new IPAddress(ipAddress++), true);
             }
         }
-
         public void StartThreadedStress(int count)
         {
             for (int i = 0; i < count; i++)
@@ -114,7 +147,7 @@
             while (true)
             {
                 int torrent = random.Next(0, hashes.Count - 1);
-                int ipaddress = random.Next(0, 300);
+                int ipaddress = random.Next(0, averagePeers);
                 listener.Handle(hashes[torrent], new IPAddress(ipaddress), 
false);
                 TotalRequests++;
                 System.Threading.Thread.Sleep(100);

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to