コード例 #1
0
        public void When_GetBaseViewUri_Is_Called_With_EncryptTraffic_True_Uri_Is_SSL_URI()
        {
            var configuration = new ClientConfiguration
            {
                UseSsl = true
            };
            configuration.Initialize();

            var json = File.ReadAllText(@"Data\\Configuration\\cb4-config-4-nodes.json");
            var config = JsonConvert.DeserializeObject<BucketConfig>(json);
            var nodes = config.GetNodes();

            var node = nodes.Find(x => x.Hostname.Equals("192.168.109.104"));

            var ioStrategy = new FakeIOStrategy(UriExtensions.GetEndPoint(node.Hostname + ":" + node.KeyValue),
                new FakeConnectionPool(), false);

            using (var server = new Server(ioStrategy,
                node,
                configuration,
                config,
                new FakeTranscoder()))
            {
                var uri = server.CachedViewBaseUri;
                Assert.AreEqual("https://192.168.109.104:18092/default", uri);
            }
        }
コード例 #2
0
        public async Task When_Observing_Key_During_RemoveAsync_Durability_Constraint_Is_Reached()
        {
            var configuration = new ClientConfiguration
            {
                Servers = new List<Uri>
                {
                    new Uri(ConfigurationManager.AppSettings["bootstrapUrl"])
                }
            };
            configuration.Initialize();

            var provider = new CarrierPublicationProvider(
                configuration,
                (pool) => new PooledIOService(pool),
                (config, endpoint) => new ConnectionPool<Connection>(config, endpoint),
                SaslFactory.GetFactory(),
                new DefaultConverter(),
                new DefaultTranscoder(new DefaultConverter()));

            var configInfo = provider.GetConfig("default");

            var clusterController = new Mock<IClusterController>();
            clusterController.Setup(x => x.Transcoder).Returns(new DefaultTranscoder());

            var pending = new ConcurrentDictionary<uint, IOperation>();

            var observer = new KeyObserver(pending, configInfo, clusterController.Object, 10, 500);
            using (var cts = new CancellationTokenSource(configuration.ObserveTimeout))
            {
                var constraintReached =
                    await observer.ObserveRemoveAsync("Test_Timeout_Remove_Async", 0, ReplicateTo.Zero, PersistTo.One, cts);
                Assert.IsTrue(constraintReached);
            }
        }
        public void SetUp()
        {
            var configuration = new ClientConfiguration
            {
                UseSsl = true
            };
            configuration.Initialize();

            var json = File.ReadAllText(@"Data\\Configuration\\cb4-config-4-nodes.json");
            var config = JsonConvert.DeserializeObject<BucketConfig>(json);
            var nodes = config.GetNodes();

            var node = nodes.Find(x => x.Hostname.Equals("192.168.109.104"));

            var ioStrategy = new FakeIOStrategy(UriExtensions.GetEndPoint(node.Hostname + ":" + node.KeyValue),
                new FakeConnectionPool(), false);

            _configContext = new CouchbaseConfigContext(config,
                configuration,
                pool => ioStrategy,
                (c, e) => new FakeConnectionPool(),
                SaslFactory.GetFactory(),
                new DefaultTranscoder(new DefaultConverter()));

            _configContext.LoadConfig();
        }
コード例 #4
0
        public void Test_Custom()
        {
            var config = new ClientConfiguration
            {
                PoolConfiguration = new PoolConfiguration
                {
                    MaxSize = 10,
                    MinSize = 10
                }
            };
            config.Initialize();

            Assert.AreEqual(1, config.BucketConfigs.Count);

            var bucketConfig = config.BucketConfigs.First().Value;

            IPAddress ipAddress;
            IPAddress.TryParse("127.0.0.1", out ipAddress);
            var endPoint = new IPEndPoint(ipAddress, bucketConfig.Port);
            Assert.AreEqual(endPoint, bucketConfig.GetEndPoint());

            Assert.IsEmpty(bucketConfig.Password);
            Assert.IsEmpty(bucketConfig.Username);
            Assert.AreEqual(11210, bucketConfig.Port);
            Assert.AreEqual("default", bucketConfig.BucketName);

            Assert.AreEqual(10, bucketConfig.PoolConfiguration.MaxSize);
            Assert.AreEqual(10, bucketConfig.PoolConfiguration.MinSize);
            Assert.AreEqual(2500, bucketConfig.PoolConfiguration.RecieveTimeout);
            Assert.AreEqual(2500, bucketConfig.PoolConfiguration.OperationTimeout);
            Assert.AreEqual(10000, bucketConfig.PoolConfiguration.ShutdownTimeout);
        }
コード例 #5
0
        public void When_Observing_Key_During_Remove_Durability_Constraint_Is_Reached()
        {
            var configuration = new ClientConfiguration
            {
                Servers = new List<Uri>
                {
                    new Uri(ConfigurationManager.AppSettings["bootstrapUrl"])
                }
            };
            configuration.Initialize();

            var provider = new CarrierPublicationProvider(
                configuration,
                (pool) => new DefaultIOStrategy(pool),
                (config, endpoint) => new ConnectionPool<EapConnection>(config, endpoint),
                SaslFactory.GetFactory3(),
                new AutoByteConverter(),
                new TypeSerializer(new AutoByteConverter()));

            var configInfo = provider.GetConfig("default");

            var observer = new KeyObserver(configInfo, 10, 500);
            var constraintReached = observer.ObserveRemove("Test_Timeout_Remove", 0, ReplicateTo.Zero, PersistTo.One);
            Assert.IsTrue(constraintReached);
        }
コード例 #6
0
        public void When_Observing_Key_During_Add_Durability_Constraint_Is_Reached()
        {
            var configuration = new ClientConfiguration
            {
                Servers = new List<Uri>
                {
                    new Uri(ConfigurationManager.AppSettings["bootstrapUrl"])
                }
            };
            configuration.Initialize();

            var provider = new CarrierPublicationProvider(
                configuration,
                (pool) => new DefaultIOStrategy(pool),
                (config, endpoint) => new ConnectionPool<EapConnection>(config, endpoint),
                SaslFactory.GetFactory3(),
                new AutoByteConverter(),
                new TypeSerializer(new AutoByteConverter()));

            var configInfo = provider.GetConfig("default");

            ulong cas = 0;
            using (var cluster = new CouchbaseCluster(configuration))
            {
                using (var bucket = cluster.OpenBucket())
                {
                    bucket.Remove("Test_Timeout_Add");
                    bucket.Insert("Test_Timeout_Add", "");
                    cas = bucket.Upsert("Test_Timeout_Add", "").Cas;
                }
            }
            var observer = new KeyObserver(configInfo, 10, 500);
            var constraintReached = observer.ObserveAdd("Test_Timeout_Add", cas, ReplicateTo.One, PersistTo.One);
            Assert.IsTrue(constraintReached);
        }
コード例 #7
0
        //[Test]
        public void Test_LoadConfig()
        {
            var clientConfig = new ClientConfiguration
            {
                Servers = new List<Uri>
                {
                    new Uri(ConfigurationManager.AppSettings["bootstrapUrl"])
                },
                PoolConfiguration = new PoolConfiguration
                {
                    MaxSize = 2,
                    MinSize = 1
                },
                UseSsl = false
            };
            clientConfig.Initialize();

            var bucketConfig =
                JsonConvert.DeserializeObject<BucketConfig>(
                    File.ReadAllText("Data\\Configuration\\config-revision-8934.json"));
            var configInfo = new CouchbaseConfigContext(bucketConfig,
                clientConfig,
                pool => new DefaultIOStrategy(pool),
                (config, endpoint) => new ConnectionPool<Connection>(config, endpoint),
                SaslFactory.GetFactory3(),
                new DefaultTranscoder(new DefaultConverter()));
            configInfo.LoadConfig();


            var servers = configInfo.GetServers();
            Assert.AreEqual(servers.Count(), bucketConfig.Nodes.Count());

            var vbuckets = configInfo.GetVBuckets();
            for (int i = 0; i < 1024; i++)
            {
                var actual = vbuckets[i].Primary;
                var expected = bucketConfig.VBucketServerMap.VBucketMap[i][0];
                Assert.AreEqual(expected, actual);
            }

            var bucketConfig2 =
                JsonConvert.DeserializeObject<BucketConfig>(
                    File.ReadAllText("Data\\Configuration\\config-revision-9958.json"));
            configInfo.LoadConfig(bucketConfig2);

            servers = configInfo.GetServers();
            Assert.AreEqual(servers.Count(), bucketConfig2.Nodes.Count());
            vbuckets = configInfo.GetVBuckets();
            for (int i = 0; i < 1024; i++)
            {
                var actual = vbuckets[i].Primary;
                var expected = bucketConfig2.VBucketServerMap.VBucketMap[i][0];
                Assert.AreEqual(expected, actual);
            }

            Log.Debug(m => m("CLEANUP!"));
            configInfo.Dispose();
        }
コード例 #8
0
        public void Test_KeySeqnoObserver()
        {

            var configuration = new ClientConfiguration
            {
                Servers = new List<Uri>
                {
                    new Uri(ConfigurationManager.AppSettings["bootstrapUrl"])
                }
            };

            var key = "Test_KeySeqnoObserver";
            using (var cluster = new Cluster(configuration))
            {
                using (var bucket = cluster.OpenBucket())
                {
                    bucket.Remove(key);
                }
            }

            configuration.Initialize();

            var provider = new CarrierPublicationProvider(
                configuration,
                (pool) => new PooledIOService(pool),
                (config, endpoint) => new ConnectionPool<Connection>(config, endpoint),
                SaslFactory.GetFactory(),
                new DefaultConverter(),
                new DefaultTranscoder(new DefaultConverter(), new DefaultSerializer()));

            var configInfo = provider.GetConfig("default");

            var features = new List<short>();
            features.Add((short)ServerFeatures.MutationSeqno);

            var keyMapper = configInfo.GetKeyMapper();
            var mappedNode = keyMapper.MapKey(key);
            var node = mappedNode.LocatePrimary();

            foreach (var server in configInfo.Servers.Where(x=>x.IsDataNode))
            {
                var hello = new Hello("couchbase-net-sdk/2.1.4", features.ToArray(), provider.Transcoder, 0, 0);
                var result3 = server.Send(hello);
                Assert.IsTrue(result3.Success);
            }

            var result = node.Send(new Add<string>(key, "", (VBucket)mappedNode,
                new DefaultTranscoder(new DefaultConverter(), new DefaultSerializer()), 1000));

            var clusterController = new Mock<IClusterController>();
            clusterController.Setup(x => x.Transcoder).Returns(new DefaultTranscoder());

            var pending = new ConcurrentDictionary<uint, IOperation>();

            var keyObserver = new KeySeqnoObserver("thekey", pending, configInfo, clusterController.Object, 0, 1000);
            var durabilityReached = keyObserver.Observe(result.Token, ReplicateTo.Zero, PersistTo.One);
            Assert.IsTrue(durabilityReached);
        }
コード例 #9
0
        public void When_EnableTcpKeepAlives_Disabled_On_PoolConfiguration_Defaults_Are_Not_Used()
        {
            var clientConfig = new ClientConfiguration();
            clientConfig.PoolConfiguration.EnableTcpKeepAlives = false;

            clientConfig.Initialize();

            Assert.AreEqual(ClientConfiguration.Defaults.EnableTcpKeepAlives, clientConfig.EnableTcpKeepAlives);
            Assert.AreEqual(false, clientConfig.PoolConfiguration.EnableTcpKeepAlives);
        }
コード例 #10
0
        public void When_TcpKeepAliveTime_Set_On_PoolConfiguration_Defaults_Are_Not_Used()
        {
            var clientConfig = new ClientConfiguration();
            clientConfig.PoolConfiguration.TcpKeepAliveTime = 1000;

            clientConfig.Initialize();

            Assert.AreEqual(ClientConfiguration.Defaults.TcpKeepAliveTime, clientConfig.TcpKeepAliveTime);
            Assert.AreEqual(1000, clientConfig.PoolConfiguration.TcpKeepAliveTime);
        }
コード例 #11
0
        public void When_TcpKeepAliveInterval_Set_On_ClientConfiguration_Defaults_Are_Not_Used()
        {
            var clientConfig = new ClientConfiguration
            {
                TcpKeepAliveInterval = 10
            };

            clientConfig.Initialize();

            Assert.AreEqual(10, clientConfig.TcpKeepAliveInterval);
            Assert.AreEqual(10, clientConfig.PoolConfiguration.TcpKeepAliveInterval);
        }
コード例 #12
0
 /// <summary>
 /// Gets the connection using the value of the <c>bootstrapUrl</c> in the App.Config as the node to bootstrap from.
 /// </summary>
 /// <returns></returns>
 public static ClientConfiguration GetConfiguration()
 {
     var config = new ClientConfiguration
     {
         Servers = new List<Uri>
         {
             new Uri(ConfigurationManager.AppSettings["bootstrapUrl"])
         }
     };
     config.ConnectionPoolCreator = ConnectionPoolFactory.GetFactory<ConnectionPool<MultiplexingConnection>>();
     config.IOServiceCreator = IOServiceFactory.GetFactory<MultiplexingIOService>();
     config.Initialize();
     return config;
 }
コード例 #13
0
        public void When_GetBaseViewUri_Is_Called_With_EncryptTraffic_True_Uri_Is_SSL_URI()
        {
            var configuration = new ClientConfiguration
            {
                UseSsl = true
            };
            configuration.Initialize();

            var connectionPool = new ConnectionPool<EapConnection>(new PoolConfiguration(), UriExtensions.GetEndPoint(Address));
            var ioStrategy = new DefaultIOStrategy(connectionPool);
            using (var server = new Server(ioStrategy, new Node(), configuration))
            {
                var uri = server.GetBaseViewUri("default");
                Assert.AreEqual("https://localhost:18092/default", uri);
            }
        }
コード例 #14
0
        public void Test_Custom()
        {
            var config = new ClientConfiguration
            {
                DefaultOperationLifespan = 123,
                PoolConfiguration = new PoolConfiguration
                {
                    MaxSize = 10,
                    MinSize = 10,
                    SendTimeout = 12000,
                    MaxCloseAttempts = 6,
                    CloseAttemptInterval = 120
                },
                ViewRequestTimeout = 5000
            };
            config.Initialize();

            Assert.AreEqual(1, config.BucketConfigs.Count);

            var bucketConfig = config.BucketConfigs.First().Value;

            IPAddress ipAddress;
            IPAddress.TryParse("127.0.0.1", out ipAddress);
            var endPoint = new IPEndPoint(ipAddress, bucketConfig.Port);
            Assert.AreEqual(endPoint, bucketConfig.GetEndPoint());

            Assert.IsEmpty(bucketConfig.Password);
            Assert.IsEmpty(bucketConfig.Username);
            Assert.AreEqual(11210, bucketConfig.Port);
            Assert.AreEqual("default", bucketConfig.BucketName);

            Assert.AreEqual(10, bucketConfig.PoolConfiguration.MaxSize);
            Assert.AreEqual(10, bucketConfig.PoolConfiguration.MinSize);
#pragma warning disable 612
            Assert.AreEqual(2500, bucketConfig.PoolConfiguration.RecieveTimeout);
#pragma warning restore 612
#pragma warning disable 618
            Assert.AreEqual(2500, bucketConfig.PoolConfiguration.OperationTimeout);
#pragma warning restore 618
            Assert.AreEqual(10000, bucketConfig.PoolConfiguration.ShutdownTimeout);
            Assert.AreEqual(12000, bucketConfig.PoolConfiguration.SendTimeout);
            Assert.AreEqual(123, bucketConfig.DefaultOperationLifespan);
            Assert.AreEqual(120, bucketConfig.PoolConfiguration.CloseAttemptInterval);
            Assert.AreEqual(6, bucketConfig.PoolConfiguration.MaxCloseAttempts);
            Assert.AreEqual(5000, config.ViewRequestTimeout);
        }
コード例 #15
0
        public void Test_ClientConnection_With_Ssl()
        {
            var bootstrapUrl = ConfigurationManager.AppSettings["bootstrapUrl"];
            var config = new ClientConfiguration
            {
                UseSsl = true,
                Servers = new List<Uri>
            {
                new Uri(bootstrapUrl)
            }};
            config.Initialize();

            var cluster = new Cluster(config);
            using (var bucket = cluster.OpenBucket())
            {
                Assert.IsNotNull(bucket);
            }
        }
コード例 #16
0
        public void When_Servers_List_Does_Not_Change_The_BucketConfig_Is_Not_Updated()
        {
            var couchbaseConfiguration = new ClientConfiguration();
            couchbaseConfiguration.Initialize();

            Assert.AreEqual(1, couchbaseConfiguration.Servers.Count);

            var bucketConfig = couchbaseConfiguration.BucketConfigs.First().Value;
            Assert.AreEqual(1, bucketConfig.Servers.Count);
            Assert.Contains(new Uri("http://localhost:8091/pools"), bucketConfig.Servers);
        }
コード例 #17
0
        public void When_NotSupportedException_Thrown_When_Proxy_Port_Is_Configured()
        {
            var configuration = new ClientConfiguration {PoolConfiguration = {MaxSize = 10, MinSize = 10}};

            configuration.Servers.Clear();
            configuration.Servers.Add(new Uri("http://127.0.0.1:8091/pools"));

            var bc = new BucketConfiguration();
            bc.Password = "******";
            bc.Username = "******";
            bc.BucketName = "authenticated";

            bc.Servers.Clear();
            bc.Servers.Add(new Uri("http://127.0.0.1:8091/pools"));
            bc.Port = 11211;

            configuration.BucketConfigs.Clear();
            configuration.BucketConfigs.Add("authenticated", bc);
            configuration.Initialize();
        }
コード例 #18
0
        public void Test_UseSslOnBucketDontCascade()
        {
            const string name = "IAmProtected";
            var config = new ClientConfiguration
            {
                UseSsl = false
            };
            config.BucketConfigs.Add(name, new BucketConfiguration()
            {
                BucketName = name,
                UseSsl = true
            });
            config.Initialize();


            var bucket = config.BucketConfigs.First().Value;
            Assert.AreNotEqual(name, bucket.BucketName);
            Assert.AreEqual(false, bucket.UseSsl);
            Assert.AreEqual("127.0.0.1:"+config.DirectPort, bucket.GetEndPoint().ToString());

            var protectedBucket = config.BucketConfigs[name];
            Assert.AreEqual(true, protectedBucket.UseSsl);
            Assert.AreEqual("127.0.0.1:"+config.SslPort, protectedBucket.GetEndPoint().ToString());
        }
コード例 #19
0
        public void Test_UseSsl()
        {
            var config = new ClientConfiguration {UseSsl = true};
            config.Initialize();

            var bucket = config.BucketConfigs.First().Value;
            Assert.AreEqual(true, bucket.UseSsl);
            Assert.AreEqual("https://localhost:18091/pools", config.Servers.First().ToString());

            Assert.AreEqual("127.0.0.1:11207", bucket.GetEndPoint().ToString());
        }
コード例 #20
0
        public void When_AppConfig_Used_PoolConfiguration_Reflects_Tuning()
        {
            var config = new ClientConfiguration((CouchbaseClientSection) ConfigurationManager.GetSection("couchbaseClients/couchbase_1"));
            config.Initialize();

            var bucketConfig = config.BucketConfigs["testbucket"];
            var bucketPoolConfig = bucketConfig.PoolConfiguration;
            Assert.AreEqual(10, bucketPoolConfig.MaxSize);
            Assert.AreEqual(5, bucketPoolConfig.MinSize);
            Assert.AreEqual(5000, bucketPoolConfig.WaitTimeout);
            Assert.AreEqual(3000, bucketPoolConfig.ShutdownTimeout);
            Assert.AreEqual(12000, bucketPoolConfig.SendTimeout);
        }
コード例 #21
0
        public void When_AppConfig_Used_OperationLifespan_Priority_Is_Respected()
        {
            var config = new ClientConfiguration((CouchbaseClientSection)ConfigurationManager.GetSection("couchbaseClients/couchbase_1"));
            config.Initialize();

            //check the global value
            Assert.AreEqual(1000, config.DefaultOperationLifespan);

            //check that if a bucket specific value is set, it supersedes global value
            var bucketConfig = config.BucketConfigs["testbucket"];
            Assert.AreEqual(2000, bucketConfig.DefaultOperationLifespan);

            //check that leaving the bucket's value to its default results in using global value
            bucketConfig = config.BucketConfigs["beer-sample"];
            Assert.AreEqual(1000, bucketConfig.DefaultOperationLifespan);
        }
コード例 #22
0
        /// <summary>
        /// Ctor for creating Cluster instance.
        /// </summary>
        /// <param name="configurationSectionName">The name of the configuration section to use.</param>
        /// <remarks>Note that <see cref="CouchbaseClientSection"/> needs include the sectionGroup name as well: "couchbaseSection/couchbase" </remarks>
        public static void Initialize(string configurationSectionName)
        {
            var configurationSection =
                (CouchbaseClientSection) ConfigurationManager.GetSection(configurationSectionName);
            var configuration = new ClientConfiguration(configurationSection);
            configuration.Initialize();

            var factory = new Func<Cluster>(() => new Cluster(configuration));
            Initialize(factory);
        }
コード例 #23
0
        /// <summary>
        /// Creates a Cluster instance.
        /// </summary>
        /// <param name="configuration">
        /// The ClientConfiguration to use when initialize the internal ClusterManager
        /// </param>
        /// <remarks>
        /// This is an heavy-weight object intended to be long-lived. Create one per process or App.Domain.
        /// </remarks>
        public static void Initialize(ClientConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            configuration.Initialize();
            var factory = new Func<Cluster>(() => new Cluster(configuration));
            Initialize(factory);
        }
コード例 #24
0
        /// <summary>
        /// Initializes a new Cluster instance with a given ClientConfiguration and ClusterManager.
        /// This overload is primarily provided for testing given that it allows you to set the
        /// major dependencies of the Cluster class and it's scope is internal.
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="clusterManager"></param>
        internal static void Initialize(ClientConfiguration configuration, IClusterController clusterManager)
        {
            if (configuration == null || clusterManager == null)
            {
                throw new ArgumentNullException(configuration == null ? "configuration" : "clusterManager");
            }

            configuration.Initialize();
            var factory = new Func<Cluster>(() => new Cluster(configuration, clusterManager));
            Initialize(factory);
        }
コード例 #25
0
        public void When_EnableTcpKeepAlives_Is_Enabled_In_AppConfig_EnableTcpKeepAlives_Is_True()
        {
            var config = new ClientConfiguration((CouchbaseClientSection) ConfigurationManager.GetSection("couchbaseClients/couchbase_4"));
            config.Initialize();

            var bucket = config.BucketConfigs["default2"];
            Assert.IsTrue(bucket.PoolConfiguration.EnableTcpKeepAlives);
            Assert.AreEqual(10000, bucket.PoolConfiguration.TcpKeepAliveInterval);
            Assert.AreEqual(60000, bucket.PoolConfiguration.TcpKeepAliveTime);
        }
コード例 #26
0
        public void When_Servers_List_Changes_The_BucketConfig_Is_Updated()
        {
            var couchbaseConfiguration = new ClientConfiguration();
            couchbaseConfiguration.Servers.Clear();
            couchbaseConfiguration.Servers.Add(new Uri("http://192.168.37.2"));
            couchbaseConfiguration.Servers.Add(new Uri("http://192.168.37.101"));
            couchbaseConfiguration.Initialize();

            Assert.AreEqual(2, couchbaseConfiguration.Servers.Count);

            var bucketConfig = couchbaseConfiguration.BucketConfigs.First().Value;
            Assert.AreEqual(2, bucketConfig.Servers.Count);
            Assert.Contains(new Uri("http://192.168.37.2"), bucketConfig.Servers);
            Assert.Contains(new Uri("http://192.168.37.101"), bucketConfig.Servers);
        }
コード例 #27
0
        public void When_EnableTcpKeepAlives_Is_Disabled_In_AppConfig_EnableTcpKeepAlives_Is_False()
        {
            var config = new ClientConfiguration((CouchbaseClientSection)ConfigurationManager.GetSection("couchbaseClients/couchbase_4"));
            config.Initialize();

            var bucket = config.BucketConfigs["default"];
            Assert.IsFalse(bucket.PoolConfiguration.EnableTcpKeepAlives);
        }
コード例 #28
0
        public void Test_EnableTcpKeepAlives()
        {
            var section = (CouchbaseClientSection)ConfigurationManager.GetSection("couchbaseClients/couchbase_3");
            Assert.AreEqual(true, section.EnableTcpKeepAlives);
            Assert.AreEqual(100, section.TcpKeepAliveInterval);
            Assert.AreEqual(10, section.TcpKeepAliveTime);

            var configuration = new ClientConfiguration(section);
            configuration.Initialize();

            var bucket = configuration.BucketConfigs["default"];
            Assert.AreEqual(true, bucket.PoolConfiguration.EnableTcpKeepAlives);
            Assert.AreEqual(100, bucket.PoolConfiguration.TcpKeepAliveInterval);
            Assert.AreEqual(10, bucket.PoolConfiguration.TcpKeepAliveTime);
        }
コード例 #29
0
        public void Test_CustomBucketConfigurations()
        {
            var config = new ClientConfiguration
            {
                BucketConfigs = new Dictionary<string, BucketConfiguration>
                {
                    {"default", new BucketConfiguration
                    {
                        PoolConfiguration = new PoolConfiguration
                        {
                            MaxSize = 5,
                            MinSize = 5
                        }
                    }},
                    {"authenticated", new BucketConfiguration
                    {
                        PoolConfiguration = new PoolConfiguration
                        {
                            MaxSize = 6,
                            MinSize = 4,
                            SendTimeout = 12000
                        },
                        DefaultOperationLifespan = 123,
                        Password = "******",
                        Username = "******",
                        BucketName = "authenticated"
                    }}
                }
            };

            config.Initialize();
            Assert.AreEqual(2, config.BucketConfigs.Count);

            var bucketConfig = config.BucketConfigs.First().Value;

            IPAddress ipAddress;
            IPAddress.TryParse("127.0.0.1", out ipAddress);
            var endPoint = new IPEndPoint(ipAddress, bucketConfig.Port);
            Assert.AreEqual(endPoint, bucketConfig.GetEndPoint());

            Assert.IsEmpty(bucketConfig.Password);
            Assert.IsEmpty(bucketConfig.Username);
            Assert.AreEqual(11210, bucketConfig.Port);
            Assert.AreEqual("default", bucketConfig.BucketName);

            Assert.AreEqual(5, bucketConfig.PoolConfiguration.MaxSize);
            Assert.AreEqual(5, bucketConfig.PoolConfiguration.MinSize);
            Assert.AreEqual(2500, bucketConfig.PoolConfiguration.RecieveTimeout);
            Assert.AreEqual(2500, bucketConfig.PoolConfiguration.OperationTimeout);
            Assert.AreEqual(10000, bucketConfig.PoolConfiguration.ShutdownTimeout);
            Assert.AreEqual(2500, bucketConfig.DefaultOperationLifespan);

            //test the second configuration was taken into account as well
            bucketConfig = config.BucketConfigs.Last().Value;
            Assert.AreEqual("password", bucketConfig.Password);
            Assert.AreEqual("username", bucketConfig.Username);
            Assert.AreEqual("authenticated", bucketConfig.BucketName);

            Assert.AreEqual(6, bucketConfig.PoolConfiguration.MaxSize);
            Assert.AreEqual(4, bucketConfig.PoolConfiguration.MinSize);
            Assert.AreEqual(2500, bucketConfig.PoolConfiguration.RecieveTimeout);
            Assert.AreEqual(2500, bucketConfig.PoolConfiguration.OperationTimeout);
            Assert.AreEqual(10000, bucketConfig.PoolConfiguration.ShutdownTimeout);
            Assert.AreEqual(12000, bucketConfig.PoolConfiguration.SendTimeout);
            Assert.AreEqual(123, bucketConfig.DefaultOperationLifespan);
        }
コード例 #30
0
        public void Test_Connection_Pool_Settings_Inheritance()
        {
            //use section with client-wide connection pool settings and one bucket overriding the settings
            var section = (CouchbaseClientSection)ConfigurationManager.GetSection("couchbaseClients/couchbase_5");
            var config = new ClientConfiguration(section);
            config.Initialize();

            Assert.AreEqual(4, config.BucketConfigs["default"].PoolConfiguration.MaxSize, "Bucket specific setting of MaxSize=4 should have been used.");
            Assert.AreEqual(3, config.BucketConfigs["default2"].PoolConfiguration.MaxSize, "Client default setting of MaxSize=3 should have been used.");

            //use section with no connection pool definitions at all
            section = (CouchbaseClientSection)ConfigurationManager.GetSection("couchbaseClients/couchbase_2");
            config = new ClientConfiguration(section);
            config.Initialize();

            //get default value for connection pool max size
            var propInfo = typeof(ConnectionPoolElement).GetProperty("MaxSize");
            var confProp = (ConfigurationPropertyAttribute)Attribute.GetCustomAttribute(propInfo, typeof(ConfigurationPropertyAttribute));

            Assert.AreEqual(confProp.DefaultValue, config.BucketConfigs["default"].PoolConfiguration.MaxSize, "Default setting of MaxSize should have been used.");
        }