Пример #1
0
        private string ReadDataFromSocket(string buildLogXmlUrl, int port, int fetchLogSize)
        {
            if (fetchLogSize > 160000)
                throw new Exception("Read data request was too large");

            var webResult = "";
            var request = new OptimizedHTTPRequest(new HTTPSocket())
                              {
                                  CooldownMS = 5000,
                                  NumberOfRetries = 10
                              };
            webResult = request.RequestURL(buildLogXmlUrl, port, fetchLogSize);

            if (string.IsNullOrEmpty(webResult))
                throw new Exception("HTTP request did not return any data");


            if (Regex.IsMatch(webResult, @"\<build .*\>") == false)
            {
                return ReadDataFromSocket(buildLogXmlUrl, port, fetchLogSize * 2);
            }

            var xmlData = Regex.Match(webResult, ".+(<cruisecontrol.*<build .+?>)", RegexOptions.Singleline | RegexOptions.IgnoreCase).Groups[1].Value;

            xmlData += " </build>\n</cruisecontrol>\n";

            return xmlData;
        }
Пример #2
0
        public void assure_to_handle_heavy_load_with_large_files()
        {
            ManualResetEvent resetEvent = new ManualResetEvent(false);
            const int bytesToFetch = 90000;
            const int numberOfRequests = 50;
            int completedRequests = 0;

            bool[] successfulRequests = new bool[numberOfRequests];

            for (int i = 0; i < numberOfRequests; i++)
            {
                int index = i;
                ThreadPool.QueueUserWorkItem((o) =>
                {
                    try
                    {
                        OptimizedHTTPRequest testRequest = new OptimizedHTTPRequest(new HTTPSocket());

                        string result = testRequest.RequestURL(LONGFILE_URL, 80, bytesToFetch);

                        if (result.Length != bytesToFetch)
                            throw new Exception("only got " + result.Length + " bytes");
                        successfulRequests[index] = true;

                        Console.WriteLine("File request {0} completed, {1} bytes returned", index, bytesToFetch);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("File request {0} FAILED", index);
                        Console.WriteLine(ex);
                    }
                    finally
                    {
                        completedRequests++;
                        if (completedRequests == numberOfRequests)
                            resetEvent.Set();
                    }
                });
            }

            resetEvent.WaitOne();
            successfulRequests.Where(r => r == true).Count().ShouldBe(numberOfRequests);
        }