Esempio n. 1
0
        public void TestParameterNull()
        {
            var loadTimeoutConfigFromFile = new LoadTimeoutConfigFromFile();

            var apiTimeoutValue = loadTimeoutConfigFromFile.GetSpecificApiReadTimeoutValue(_product, _version, null);

            Assert.Equal(0, apiTimeoutValue);
        }
Esempio n. 2
0
        public void TestJsonDataNull()
        {
            var loadTimeoutConfigFromFile = new LoadTimeoutConfigFromFile();

            var apiTimeoutValue =
                loadTimeoutConfigFromFile.GetSpecificApiReadTimeoutValue(_product, _version, "error-actionName");

            Assert.Equal(0, apiTimeoutValue);
        }
Esempio n. 3
0
        public void TestApiTimeoutValue()
        {
            var loadTimeoutConfigFromFile = new LoadTimeoutConfigFromFile();

            var timeoutValue =
                loadTimeoutConfigFromFile.GetSpecificApiReadTimeoutValue(_product, _version, _actionName);

            Assert.Equal(86000, timeoutValue);
        }
Esempio n. 4
0
        public void TestLoadTimeoutFromFileException()
        {
            var exception = Assert.Throws <ClientException>(() =>
            {
                var loadTimeoutConfigFromFile = new LoadTimeoutConfigFromFile("fileNotFound.json");
                var apiValue =
                    loadTimeoutConfigFromFile.GetSpecificApiReadTimeoutValue(_product, _version, _actionName);
            });

            Assert.Equal("LoadTimeoutJsonFileError", exception.ErrorCode);
        }
Esempio n. 5
0
        public void TestCachedJsonData()
        {
            var loadTimeoutConfigFromFile = new LoadTimeoutConfigFromFile();

            Stopwatch sw = Stopwatch.StartNew();
            var       apiTimeoutValue =
                loadTimeoutConfigFromFile.GetSpecificApiReadTimeoutValue(_product, _version, _actionName);
            var executeTime1 = sw.ElapsedMilliseconds;

            Assert.Equal(86000, apiTimeoutValue);

            sw.Restart();
            apiTimeoutValue =
                loadTimeoutConfigFromFile.GetSpecificApiReadTimeoutValue(_product, _version, "AllocateEipAddress");
            var executeTime2 = sw.ElapsedMilliseconds;

            Assert.Equal(17000, apiTimeoutValue);
        }
Esempio n. 6
0
        private void ResolveTimeout(HttpRequest request, string product, string version, string actionName)
        {
            var apiReadTimeout = new LoadTimeoutConfigFromFile()
                                 .GetSpecificApiReadTimeoutValue(product, version, actionName);

            int finalReadTimeout;

            if (request.ReadTimeout > 0)
            {
                finalReadTimeout = request.ReadTimeout;
            }
            else if (ReadTimeout > 0)
            {
                finalReadTimeout = ReadTimeout;
            }
            else if (apiReadTimeout > 0)
            {
                finalReadTimeout = apiReadTimeout;
            }
            else
            {
                finalReadTimeout = 0;
            }

            request.SetReadTimeoutInMilliSeconds(finalReadTimeout);

            int finalConnectTimeout;

            if (request.ConnectTimeout > 0)
            {
                finalConnectTimeout = request.ConnectTimeout;
            }
            else if (ConnectTimeout > 0)
            {
                finalConnectTimeout = ConnectTimeout;
            }
            else
            {
                finalConnectTimeout = 0;
            }

            request.SetConnectTimeoutInMilliSeconds(finalConnectTimeout);
        }