public void When_No_Bucket_Is_Defined_Default_Bucket_Is_Used()
        {
            var section = (CouchbaseClientSection)ConfigurationManager.GetSection("couchbaseClients/couchbase");
            Assert.Greater(section.Buckets.Count, 0);

            var buckets = new BucketElement[section.Buckets.Count];
            section.Buckets.CopyTo(buckets, 0);
            Assert.AreEqual("default", buckets[0].Name);
        }
        public void When_Bucket_Is_Defined_That_Bucket_Is_Used()
        {
            var section = (CouchbaseClientSection)ConfigurationManager.GetSection("couchbaseClients/couchbase_1");
            Assert.Greater(section.Buckets.Count, 0);

            var buckets = new BucketElement[section.Buckets.Count];
            section.Buckets.CopyTo(buckets, 0);

            var bucket = buckets.First();
            Assert.AreEqual("testbucket", bucket.Name);
            Assert.AreEqual("shhh!", bucket.Password);
            Assert.IsFalse(bucket.UseSsl);
        }
        public void When_Bucket_Contains_ConnectionPoolElement_It_Is_Used()
        {
            var section = (CouchbaseClientSection)ConfigurationManager.GetSection("couchbaseClients/couchbase_1");
            var buckets = new BucketElement[section.Buckets.Count];
            section.Buckets.CopyTo(buckets, 0);

            var bucket = buckets.First();

            Assert.IsNotNull(bucket.ConnectionPool);
            Assert.AreEqual(5000, bucket.ConnectionPool.WaitTimeout);
            Assert.AreEqual(3000, bucket.ConnectionPool.ShutdownTimeout);
            Assert.AreEqual(10, bucket.ConnectionPool.MaxSize);
            Assert.AreEqual(5, bucket.ConnectionPool.MinSize);
            Assert.AreEqual("custom", bucket.ConnectionPool.Name);
        }
        public void When_MaxCloseAttempts_And_MaxCloseInterval_Changed_In_AppConfig_ConnectionPoolElement_Is_Updated()
        {
            var section = (CouchbaseClientSection)ConfigurationManager.GetSection("couchbaseClients/couchbase_4");
            var buckets = new BucketElement[section.Buckets.Count];
            section.Buckets.CopyTo(buckets, 0);

            var default2 = buckets[1];
            Assert.AreEqual(6, default2.ConnectionPool.MaxCloseAttempts);
            Assert.AreEqual(120, default2.ConnectionPool.CloseAttemptInterval);
        }
        public void When_Bucket_UseSsl_Is_True_In_AppConfig_UseSsl_Returns_True()
        {
            var section = (CouchbaseClientSection) ConfigurationManager.GetSection("couchbaseClients/couchbase_2");

            var buckets = new BucketElement[section.Buckets.Count];
            section.Buckets.CopyTo(buckets, 0);

            Assert.IsFalse(section.UseSsl);
            Assert.IsTrue(buckets.First().UseSsl);
        }
        public static async Task<GrainStateCouchbaseDataManager> Initialize(CouchbaseClientSection configSection)
        {
            var instance = new GrainStateCouchbaseDataManager();
            var config = new ClientConfiguration(configSection);
            _cluster = new Cluster(config);


            var tcs = new TaskCompletionSource<IBucket>();
            Action initAction;
            if (configSection.Buckets.Count > 0)
            {
                var buckets = new BucketElement[configSection.Buckets.Count];
                configSection.Buckets.CopyTo(buckets, 0);

                var bucketSetting = buckets.First();
                initAction = () => { tcs.SetResult(_cluster.OpenBucket(bucketSetting.Name)); };
            }
            else
                initAction = () => { tcs.SetResult(_cluster.OpenBucket()); };

            WaitCallback initBucket = (state) =>
            {
                try { initAction(); }
                catch (Exception ex) { tcs.SetException(new Exception("GrainStateCouchbaseDataManager initialize exception", ex)); }
            };

            ThreadPool.QueueUserWorkItem(initBucket, null);

            instance._bucket = await tcs.Task;

            return instance;
        }