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();
        }
        //[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();
        }
        public void Test_Server_With_FQDN_Is_Properly_Resolved()
        {
            var clientConfig = new ClientConfiguration
            {
                Servers = new List<Uri>
                {
                    new Uri("http://localhost:8091")
                },
                UseSsl = false
            };
            clientConfig.Initialize();

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

            Assert.DoesNotThrow(() => configInfo.LoadConfig());
            Assert.IsNotNull(configInfo.GetKeyMapper());
            Assert.AreEqual("127.0.0.1", configInfo.GetServers().First().EndPoint.Address.ToString());

            Log.Debug(m => m("CLEANUP!"));
            configInfo.Dispose();
        }
        public void When_NodesExt_Does_Not_Exist_Defaults_are_used()
        {
            var clientConfig = new ClientConfiguration
            {
                Servers = new List<Uri>
                {
                    new Uri("http://localhost:8091")
                },
                UseSsl = false
            };
            clientConfig.Initialize();

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

            Assert.DoesNotThrow(() => configInfo.LoadConfig());
            Assert.IsNotNull(configInfo.GetKeyMapper());
        }
        public void When_BucketConfig_Contains_VBucketMapForwards_The_Context_Is_Updated()
        {
            var clientConfig = new ClientConfiguration
            {
                Servers = new List<Uri>
                {
                    new Uri("http://*****:*****@"Data\\Configuration\\config-1070.json");
            var bucket1070 = JsonConvert.DeserializeObject<BucketConfig>(json1070);

            //same config but has vbucketforwardmaps
            var json1071 = File.ReadAllText(@"Data\\Configuration\\config-1071.json");
            var bucket1071 = JsonConvert.DeserializeObject<BucketConfig>(json1071);

            var configInfo = new CouchbaseConfigContext(bucket1070,
                clientConfig,
                pool => new DefaultIOStrategy(pool),
                (config, endpoint) => new ConnectionPool<Connection>(config, endpoint),
                SaslFactory.GetFactory3(),
                new DefaultTranscoder(new DefaultConverter()));

            configInfo.LoadConfig();
            Assert.AreEqual(1070, configInfo.BucketConfig.Rev);

            configInfo.LoadConfig(bucket1071);
            Assert.AreEqual(1071, configInfo.BucketConfig.Rev);
        }