Ejemplo n.º 1
0
        private CosmosConfiguration BuildCosmosConfiguration()
        {
            var configuration = new CosmosConfiguration(_endPoint, _authKey)
            {
                UserAgentSuffix = _userAgent,
                ConnectionMode  = ConnectionMode.Direct
            };

            if (_region != null)
            {
                configuration = configuration.UseCurrentRegion(_region);
            }

            return(configuration);
        }
Ejemplo n.º 2
0
        public void VerifyCosmosConfigurationPropertiesGetUpdated()
        {
            string               endpoint          = AccountEndpoint;
            string               key               = Guid.NewGuid().ToString();
            string               region            = CosmosRegions.WestCentralUS;
            ConnectionMode       connectionMode    = ConnectionMode.Gateway;
            TimeSpan             requestTimeout    = TimeSpan.FromDays(1);
            int                  maxConnections    = 9001;
            string               userAgentSuffix   = "testSuffix";
            CosmosRequestHandler preProcessHandler = new TestHandler();
            ApiType              apiType           = ApiType.Sql;
            int                  maxRetryAttemptsOnThrottledRequests = 9999;
            TimeSpan             maxRetryWaitTime = TimeSpan.FromHours(6);

            CosmosConfiguration configuration = new CosmosConfiguration(
                accountEndPoint: endpoint,
                accountKey: key);

            Assert.AreEqual(endpoint, configuration.AccountEndPoint.OriginalString, "AccountEndPoint did not save correctly");
            Assert.AreEqual(key, configuration.AccountKey, "AccountKey did not save correctly");

            //Verify the default values are different from the new values
            Assert.AreNotEqual(region, configuration.CurrentRegion);
            Assert.AreNotEqual(connectionMode, configuration.ConnectionMode);
            Assert.AreNotEqual(maxConnections, configuration.MaxConnectionLimit);
            Assert.AreNotEqual(requestTimeout, configuration.RequestTimeout);
            Assert.AreNotEqual(userAgentSuffix, configuration.UserAgentSuffix);
            Assert.AreNotEqual(apiType, configuration.ApiType);
            Assert.IsNull(configuration.CustomHandlers);

            //Verify GetConnectionPolicy returns the correct values for default
            ConnectionPolicy policy = configuration.GetConnectionPolicy();

            Assert.AreEqual(ConnectionMode.Direct, policy.ConnectionMode);
            Assert.AreEqual(Protocol.Tcp, policy.ConnectionProtocol);
            Assert.AreEqual(configuration.MaxConnectionLimit, policy.MaxConnectionLimit);
            Assert.AreEqual(configuration.RequestTimeout, policy.RequestTimeout);

            configuration.UseCurrentRegion(region)
            .UseConnectionModeGateway(maxConnections)
            .UseRequestTimeout(requestTimeout)
            .UseUserAgentSuffix(userAgentSuffix)
            .AddCustomHandlers(preProcessHandler)
            .UseApiType(apiType)
            .UseThrottlingRetryOptions(maxRetryWaitTime, maxRetryAttemptsOnThrottledRequests);

            //Verify all the values are updated
            Assert.AreEqual(region, configuration.CurrentRegion);
            Assert.AreEqual(connectionMode, configuration.ConnectionMode);
            Assert.AreEqual(maxConnections, configuration.MaxConnectionLimit);
            Assert.AreEqual(requestTimeout, configuration.RequestTimeout);
            Assert.AreEqual(userAgentSuffix, configuration.UserAgentSuffix);
            Assert.AreEqual(preProcessHandler, configuration.CustomHandlers[0]);
            Assert.AreEqual(apiType, configuration.ApiType);
            Assert.AreEqual(maxRetryAttemptsOnThrottledRequests, configuration.MaxRetryAttemptsOnThrottledRequests);
            Assert.AreEqual(maxRetryWaitTime, configuration.MaxRetryWaitTimeOnThrottledRequests);

            //Verify GetConnectionPolicy returns the correct values
            policy = configuration.GetConnectionPolicy();
            Assert.AreEqual(region, policy.PreferredLocations[0]);
            Assert.AreEqual(ConnectionMode.Gateway, policy.ConnectionMode);
            Assert.AreEqual(Protocol.Https, policy.ConnectionProtocol);
            Assert.AreEqual(maxConnections, policy.MaxConnectionLimit);
            Assert.AreEqual(requestTimeout, policy.RequestTimeout);
            Assert.AreEqual(userAgentSuffix, policy.UserAgentSuffix);
            Assert.IsTrue(policy.UseMultipleWriteLocations);
            Assert.AreEqual(maxRetryAttemptsOnThrottledRequests, policy.RetryOptions.MaxRetryAttemptsOnThrottledRequests);
            Assert.AreEqual((int)maxRetryWaitTime.TotalSeconds, policy.RetryOptions.MaxRetryWaitTimeInSeconds);
        }