Exemplo n.º 1
0
        public void When_Type_Is_String_DataFormat_String_Is_Used()
        {
            var key = "When_Type_Is_String_DataFormat_String_Is_Used";

            //delete the value if it exists
            var delete = new Delete(key, GetVBucket(), new AutoByteConverter(), new DefaultTranscoder(new ManualByteConverter()));

            IOStrategy.Execute(delete);

            //Add the key
            var add = new Add <string>(key, "foo", GetVBucket(), new AutoByteConverter(), new DefaultTranscoder(new ManualByteConverter()));

            Assert.IsTrue(IOStrategy.Execute(add).Success);

            var getK = new GetK <string>(key, GetVBucket(), new AutoByteConverter(),
                                         new DefaultTranscoder(new AutoByteConverter()));

            getK.CreateExtras();
            Assert.AreEqual(DataFormat.String, getK.Format);

            var result = IOStrategy.Execute(getK);

            Assert.IsTrue(result.Success);

            Assert.AreEqual(DataFormat.String, getK.Format);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a <see cref="CramMd5Mechanism"/> object using a given username (which is a Couchbase Bucket) and password.
 /// </summary>
 /// <param name="ioStrategy">The <see cref="IOStrategy"/>to use for I/O.</param>
 /// <param name="username">The name of the Bucket you are connecting to.</param>
 /// <param name="password">The password for the Bucket.</param>
 public CramMd5Mechanism(IOStrategy ioStrategy, string username, string password, IByteConverter converter)
 {
     _ioStrategy = ioStrategy;
     Username    = username;
     Password    = password;
     _converter  = converter;
 }
        public void When_Key_Exists_GetT_Returns_Value()
        {
            var key = "When_Key_Exists_GetT_Returns_Value";

            //delete the value if it exists
            var delete = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout);

            IOStrategy.Execute(delete);

            //Add the key
            var add = new Add <dynamic>(key, new { foo = "foo" }, GetVBucket(), Transcoder, OperationLifespanTimeout);

            Assert.IsTrue(IOStrategy.Execute(add).Success);

            var get = new GetT <dynamic>(key, GetVBucket(), Transcoder, OperationLifespanTimeout)
            {
                Expires = new TimeSpan(0, 0, 0, 1).ToTtl()
            };

            var result = IOStrategy.Execute(get);

            Assert.IsTrue(result.Success);

            var expected = new { foo = "foo" };

            Assert.AreEqual(result.Value.foo.Value, expected.foo);
        }
        public void When_Type_Is_Object_DataFormat_Json_Is_Used()
        {
            var key = "When_Type_Is_Object_GetK_Uses_DataFormat_Json";

            //delete the value if it exists
            var delete = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout);

            IOStrategy.Execute(delete);

            //Add the key
            var add = new Add <dynamic>(key, new { foo = "foo" }, GetVBucket(), Transcoder, OperationLifespanTimeout);

            Assert.IsTrue(IOStrategy.Execute(add).Success);

            var getK = new GetK <dynamic>(key, GetVBucket(), Transcoder, OperationLifespanTimeout);

            getK.CreateExtras();
            Assert.AreEqual(DataFormat.Json, getK.Format);

            var result = IOStrategy.Execute(getK);

            Assert.IsTrue(result.Success);

            Assert.AreEqual(DataFormat.Json, getK.Format);
        }
Exemplo n.º 5
0
        public void When_Type_Is_String_DataFormat_String_Is_Used()
        {
            var key = "When_Type_Is_String_DataFormat_String_Is_Used";

            //delete the value if it exists
            var delete = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout);

            IOStrategy.Execute(delete);

            //Add the key
            var add = new Add <string>(key, "foo", GetVBucket(), Transcoder, OperationLifespanTimeout);

            Assert.IsTrue(IOStrategy.Execute(add).Success);

            var get = new Get <string>(key, GetVBucket(), Transcoder, OperationLifespanTimeout);

            get.CreateExtras();
            Assert.AreEqual(DataFormat.String, get.Format);

            var result = IOStrategy.Execute(get);

            Assert.IsTrue(result.Success);

            Assert.AreEqual(DataFormat.String, get.Format);
        }
Exemplo n.º 6
0
        public void Test_Config()
        {
            var config = new Config(Transcoder, OperationLifespanTimeout, EndPoint);
            var result = IOStrategy.Execute(config);

            Assert.IsTrue(result.Success);
        }
        public void Test_NoOp()
        {
            var noop   = new Noop(new AutoByteConverter());
            var result = IOStrategy.Execute(noop);

            Assert.IsTrue(result.Success);
        }
Exemplo n.º 8
0
        public void When_Document_Exists_Replace_Succeeds()
        {
            const string key = "Replace.When_Document_Exists_Replace_Succeeds";

            //delete the value if it exists
            var delete = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout);
            var result = IOStrategy.Execute(delete);

            Console.WriteLine(result.Message);

            //add the new doc
            var add     = new Add <dynamic>(key, new { foo = "foo" }, GetVBucket(), Transcoder, OperationLifespanTimeout);
            var result1 = IOStrategy.Execute(add);

            Assert.IsTrue(result1.Success);

            //replace it the old doc with a new one
            var replace = new Replace <dynamic>(key, new { bar = "bar" }, GetVBucket(), Transcoder, OperationLifespanTimeout);
            var result2 = IOStrategy.Execute(replace);

            Assert.IsTrue(result2.Success);

            //check that doc has been updated
            var get     = new Get <dynamic>(key, GetVBucket(), Transcoder, OperationLifespanTimeout);
            var result3 = IOStrategy.Execute(get);

            Assert.IsTrue(result3.Success);
            Assert.AreEqual(result3.Value.bar.Value, "bar");
        }
 /// <summary>
 /// Creates a <see cref="CramMd5Mechanism"/> object using a given username (which is a Couchbase Bucket) and password.
 /// </summary>
 /// <param name="ioStrategy">The <see cref="IOStrategy"/>to use for I/O.</param>
 /// <param name="username">The name of the Bucket you are connecting to.</param>
 /// <param name="password">The password for the Bucket.</param>
 /// <param name="transcoder"></param>
 public CramMd5Mechanism(IOStrategy ioStrategy, string username, string password, ITypeTranscoder transcoder)
 {
     _ioStrategy = ioStrategy;
     Username    = username;
     Password    = password;
     _transcoder = transcoder;
 }
 /// <summary>
 /// Creates a <see cref="CramMd5Mechanism"/> object using a given username (which is a Couchbase Bucket) and password.
 /// </summary>
 /// <param name="ioStrategy">The <see cref="IOStrategy"/>to use for I/O.</param>
 /// <param name="username">The name of the Bucket you are connecting to.</param>
 /// <param name="password">The password for the Bucket.</param>
 /// <param name="transcoder"></param>
 public CramMd5Mechanism(IOStrategy ioStrategy, string username, string password, ITypeTranscoder transcoder)
 {
     _ioStrategy = ioStrategy;
     Username = username;
     Password = password;
     _transcoder = transcoder;
 }
Exemplo n.º 11
0
        public void Test_DecrementOperation()
        {
            const string key = "Test_DecrementOperation";

            //delete key if exists
            var delete = new Delete(key, GetVBucket(), Converter, Transcoder);
            var result = IOStrategy.Execute(delete);

            Console.WriteLine("Deleting key {0}: {1}", key, result.Success);

            //increment the key
            var operation = new Increment(key, 1, 1, 0, GetVBucket(), Converter, Transcoder);
            var result1   = IOStrategy.Execute(operation);

            Assert.IsTrue(result1.Success);
            Assert.AreEqual(result1.Value, 1);

            //key should be 1
            var get     = new Get <string>(key, GetVBucket(), Converter, Transcoder);
            var result3 = IOStrategy.Execute(get);

            Assert.AreEqual(result1.Value.ToString(CultureInfo.InvariantCulture), result3.Value);

            //decrement the key
            var decrement = new Decrement(key, 1, 1, 0, GetVBucket(), Converter, Transcoder);
            var result2   = IOStrategy.Execute(decrement);

            Assert.IsTrue(result2.Success);
            Assert.AreEqual(result2.Value, 0);

            //key should be 0
            get     = new Get <string>(key, GetVBucket(), Converter, Transcoder);
            result3 = IOStrategy.Execute(get);
            Assert.AreEqual(0.ToString(CultureInfo.InvariantCulture), result3.Value);
        }
Exemplo n.º 12
0
        public async void Test_Observe2()
        {
            const string key    = "Test_Observe2";
            var          remove = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout);

            var set    = new Set <int?>(key, 10, GetVBucket(), Transcoder, OperationLifespanTimeout);
            var result = IOStrategy.Execute(set);

            Assert.IsTrue(result.Success);

            var get     = new Get <dynamic>(key, GetVBucket(), Transcoder, OperationLifespanTimeout);
            var result1 = IOStrategy.Execute(get);

            Assert.IsTrue(result1.Success);
            Assert.AreEqual(result.Cas, result1.Cas);

            await Task.Delay(100);

            var operation = new Observe(key, GetVBucket(), Transcoder, OperationLifespanTimeout);
            var result2   = IOStrategy.Execute(operation);

            Assert.AreEqual(result1.Cas, result2.Value.Cas);

            Assert.AreEqual(KeyState.FoundPersisted, result2.Value.KeyState);
            Assert.IsTrue(result2.Success);
        }
Exemplo n.º 13
0
        public void Test_Timed_Execution_Parallel()
        {
            var options = new ParallelOptions {
                MaxDegreeOfParallelism = 4
            };
            var converter  = new AutoByteConverter();
            var transcoder = new DefaultTranscoder(converter);
            var vbucket    = GetVBucket();
            var n          = 1000;//set to a higher # if needed

            using (new OperationTimer())
            {
                Parallel.For(0, n, options, i =>
                {
                    var key    = string.Format("key{0}", i);
                    var set    = new Set <int?>(key, i, vbucket, converter);
                    var result = IOStrategy.Execute(set);
                    Assert.IsTrue(result.Success);

                    var get     = new Get <int?>(key, vbucket, converter, transcoder);
                    var result1 = IOStrategy.Execute(get);
                    Assert.IsTrue(result1.Success);
                    Assert.AreEqual(i, result1.Value);
                });
            }
        }
Exemplo n.º 14
0
        public void When_Key_Exists_Get_Returns_Value()
        {
            var key = "When_Key_Exists_Get_Returns_Value";

            //delete the value if it exists
            var delete = new Delete(key, GetVBucket(), new AutoByteConverter(), new DefaultTranscoder(new ManualByteConverter()));

            IOStrategy.Execute(delete);

            //Add the key
            var add = new Add <dynamic>(key, new { foo = "foo" }, GetVBucket(), new AutoByteConverter(), new DefaultTranscoder(new ManualByteConverter()));

            Assert.IsTrue(IOStrategy.Execute(add).Success);

            var get = new Get <dynamic>(key, GetVBucket(), new AutoByteConverter(),
                                        new DefaultTranscoder(new AutoByteConverter()));

            var result = IOStrategy.Execute(get);

            Assert.IsTrue(result.Success);

            var expected = new { foo = "foo" };

            Assert.AreEqual(result.Value.foo.Value, expected.foo);
        }
Exemplo n.º 15
0
        public void When_Type_Is_ByteArray_DataFormat_Binary_Is_Used()
        {
            var key = "When_Type_Is_Object_DataFormat_Json_Is_Used";

            //delete the value if it exists
            var delete = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout);

            IOStrategy.Execute(delete);

            //Add the key
            var add = new Add <byte[]>(key, new byte[] { 0x0 }, GetVBucket(), Transcoder, OperationLifespanTimeout);

            Assert.IsTrue(IOStrategy.Execute(add).Success);

            var get = new Get <byte[]>(key, GetVBucket(), Transcoder, OperationLifespanTimeout);

            get.CreateExtras();
            Assert.AreEqual(DataFormat.Binary, get.Format);

            var result = IOStrategy.Execute(get);

            Assert.IsTrue(result.Success);

            Assert.AreEqual(DataFormat.Binary, get.Format);
        }
 public PlainTextMechanism(IOStrategy strategy, string username, string password, IByteConverter converter)
 {
     _strategy = strategy;
     Username = username;
     Password = password;
     _converter = converter;
 }
Exemplo n.º 17
0
 public PlainTextMechanism(IOStrategy strategy, string username, string password, IByteConverter converter)
 {
     _strategy  = strategy;
     Username   = username;
     Password   = password;
     _converter = converter;
 }
Exemplo n.º 18
0
        public void When_Type_Is_Object_DataFormat_Json_Is_Used()
        {
            var key = "When_Type_Is_Object_DataFormat_Json_Is_Used";

            //delete the value if it exists
            var delete = new Delete(key, GetVBucket(), new AutoByteConverter(), new DefaultTranscoder(new ManualByteConverter()));

            IOStrategy.Execute(delete);

            //Add the key
            var add = new Add <dynamic>(key, new { foo = "foo" }, GetVBucket(), new AutoByteConverter(), new DefaultTranscoder(new ManualByteConverter()));

            Assert.IsTrue(IOStrategy.Execute(add).Success);

            var get = new Get <dynamic>(key, GetVBucket(), new AutoByteConverter(),
                                        new DefaultTranscoder(new AutoByteConverter()));

            get.CreateExtras();
            Assert.AreEqual(DataFormat.Json, get.Format);

            var result = IOStrategy.Execute(get);

            Assert.IsTrue(result.Success);

            Assert.AreEqual(DataFormat.Json, get.Format);
        }
        public void LoadConfig(IOStrategy ioStrategy)
        {
            try
            {
                Lock.EnterWriteLock();
                Log.Info(m => m("o2-Creating the Servers list using rev#{0}", BucketConfig.Rev));

                var clientBucketConfig = ClientConfig.BucketConfigs[BucketConfig.Name];
                var servers            = new Dictionary <IPAddress, IServer>();
                var nodes = BucketConfig.GetNodes();
                foreach (var adapter in nodes)
                {
                    var endpoint = adapter.GetIPEndPoint(clientBucketConfig.UseSsl);
                    try
                    {
                        IServer server = null;
                        if (Equals(ioStrategy.EndPoint, endpoint) || nodes.Count() == 1)
                        {
                            server = new Core.Server(ioStrategy, adapter, ClientConfig, BucketConfig, Transcoder);
                        }
                        else
                        {
                            var poolConfig     = ClientConfig.BucketConfigs[BucketConfig.Name].PoolConfiguration;
                            var connectionPool = ConnectionPoolFactory(poolConfig, endpoint);
                            var newIoStrategy  = IOStrategyFactory(connectionPool);

                            server = new Core.Server(newIoStrategy, adapter, ClientConfig, BucketConfig, Transcoder)
                            {
                                SaslFactory = SaslFactory
                            };
                            server.CreateSaslMechanismIfNotExists();
                        }
                        servers.Add(endpoint.Address, server);
                    }
                    catch (Exception e)
                    {
                        Log.ErrorFormat("Could not add server {0}. Exception: {1}", endpoint, e);
                    }
                }

                UpdateServices(servers);

                Log.Info(m => m("Creating the KeyMapper list using rev#{0}", BucketConfig.Rev));
                var old = Interlocked.Exchange(ref Servers, servers);
                var vBucketKeyMapper = new VBucketKeyMapper(Servers, BucketConfig.VBucketServerMap, BucketConfig.Rev);
                Interlocked.Exchange(ref KeyMapper, vBucketKeyMapper);
                if (old != null)
                {
                    foreach (var server in old.Values)
                    {
                        server.Dispose();
                    }
                    old.Clear();
                }
            }
            finally
            {
                Lock.ExitWriteLock();
            }
        }
Exemplo n.º 20
0
        public void Test_IncrementOperation()
        {
            const string key = "Test_IncrementOperation";

            var delete = new Delete(key, GetVBucket(), Converter, Transcoder);
            var result = IOStrategy.Execute(delete);

            Console.WriteLine("Deleting key {0}: {1}", key, result.Success);

            var increment = new Increment(key, 0, 1, 0, GetVBucket(), Converter, Transcoder);
            var result1   = IOStrategy.Execute(increment);

            Assert.IsTrue(result1.Success);
            Assert.AreEqual(result1.Value, uint.MinValue);

            var result2 = IOStrategy.Execute(increment);

            Assert.IsTrue(result2.Success);
            Assert.AreEqual(1, result2.Value);

            var getOperation = new Get <string>(key, GetVBucket(), Converter, Transcoder);
            var result3      = IOStrategy.Execute(getOperation);
            var value        = result3.Value;

            Assert.AreEqual(result2.Value.ToString(CultureInfo.InvariantCulture), result3.Value);
        }
Exemplo n.º 21
0
        public void When_Type_Is_ByteArray_DataFormat_Binary_Is_Used()
        {
            var key = "When_Type_Is_Object_GetK_Uses_DataFormat_Json";

            //delete the value if it exists
            var delete = new Delete(key, GetVBucket(), new AutoByteConverter(), new DefaultTranscoder(new ManualByteConverter()));

            IOStrategy.Execute(delete);

            //Add the key
            var add = new Add <byte[]>(key, new byte[] { 0x0 }, GetVBucket(), new AutoByteConverter(), new DefaultTranscoder(new ManualByteConverter()));

            Assert.IsTrue(IOStrategy.Execute(add).Success);

            var getK = new GetK <byte[]>(key, GetVBucket(), new AutoByteConverter(),
                                         new DefaultTranscoder(new AutoByteConverter()));

            getK.CreateExtras();
            Assert.AreEqual(DataFormat.Binary, getK.Format);

            var result = IOStrategy.Execute(getK);

            Assert.IsTrue(result.Success);

            Assert.AreEqual(DataFormat.Binary, getK.Format);
        }
 /// <summary>
 /// Creates a <see cref="CramMd5Mechanism"/> object using a given username (which is a Couchbase Bucket) and password.
 /// </summary>
 /// <param name="ioStrategy">The <see cref="IOStrategy"/>to use for I/O.</param>
 /// <param name="username">The name of the Bucket you are connecting to.</param>
 /// <param name="password">The password for the Bucket.</param>
 public CramMd5Mechanism(IOStrategy ioStrategy, string username, string password, IByteConverter converter)
 {
     _ioStrategy = ioStrategy;
     Username = username;
     Password = password;
     _converter = converter;
 }
 public PlainTextMechanism(IOStrategy strategy, string username, string password, ITypeTranscoder transcoder)
 {
     _strategy = strategy;
     Username = username;
     Password = password;
     _transcoder = transcoder;
 }
 public PlainTextMechanism(IOStrategy strategy, string username, string password, ITypeTranscoder transcoder)
 {
     _strategy   = strategy;
     Username    = username;
     Password    = password;
     _transcoder = transcoder;
 }
Exemplo n.º 25
0
        public void When_Key_Exists_Append_Succeeds()
        {
            const string key      = "Hello";
            const string expected = "Hello!";

            //clean up old keys
            var deleteOperation = new Delete(key, GetVBucket(), Converter, Serializer);

            IOStrategy.Execute(deleteOperation);

            deleteOperation = new Delete(key + "!", GetVBucket(), Converter, Serializer);
            IOStrategy.Execute(deleteOperation);

            //create the key
            var set       = new Set <string>(key, "Hello", GetVBucket(), Converter);
            var addResult = IOStrategy.Execute(set);

            Assert.IsTrue(addResult.Success);

            var append = new Append <string>(key, "!", Serializer, GetVBucket(), Converter);
            var result = IOStrategy.Execute(append);


            Assert.IsTrue(result.Success);
            Assert.AreEqual(string.Empty, result.Value);

            var get       = new Get <string>(key, GetVBucket(), Converter, Serializer);
            var getResult = IOStrategy.Execute(get);

            Assert.AreEqual(expected, getResult.Value);
        }
Exemplo n.º 26
0
        public void Test_Config()
        {
            var config = new Config(Converter);
            var result = IOStrategy.Execute(config);

            Assert.IsTrue(result.Success);
        }
Exemplo n.º 27
0
        public void Test_NoOp()
        {
            var noop   = new Noop(new DefaultTranscoder(), OperationLifespanTimeout);
            var result = IOStrategy.Execute(noop);

            Assert.IsTrue(result.Success);
        }
Exemplo n.º 28
0
 public Server(IOStrategy ioStrategy, Node node, ClientConfiguration clientConfiguration, IBucketConfig bucketConfig) :
     this(ioStrategy,
          new ViewClient(new HttpClient(), new JsonDataMapper(clientConfiguration), bucketConfig, clientConfiguration),
          new QueryClient(new HttpClient(), new JsonDataMapper(clientConfiguration)),
          node, clientConfiguration)
 {
 }
 public void TestFixtureSetUp()
 {
     var ipEndpoint = UriExtensions.GetEndPoint(Address);
     var connectionPoolConfig = new PoolConfiguration();
     _connectionPool = new ConnectionPool<EapConnection>(connectionPoolConfig, ipEndpoint);
     _ioStrategy = new DefaultIOStrategy(_connectionPool);
 }
Exemplo n.º 30
0
        public void Release(IOStrategy strategy)
        {
            Log.Debug(m => m("Releasing strategy: {0} [{1}, {2}]", strategy.GetHashCode(), _count, _pool.Count));

            _pool.Enqueue(strategy);
            _autoResetEvent.Set();
        }
Exemplo n.º 31
0
        public Server(IOStrategy ioStrategy, IViewClient viewClient, IQueryClient queryClient, INodeAdapter nodeAdapter,
                      ClientConfiguration clientConfiguration, ITypeTranscoder transcoder, IBucketConfig bucketConfig)
        {
            _ioStrategy = ioStrategy;
            _ioStrategy.ConnectionPool.Owner = this;
            _nodeAdapter         = nodeAdapter;
            _clientConfiguration = clientConfiguration;
            _timingEnabled       = _clientConfiguration.EnableOperationTiming;
            _typeTranscoder      = transcoder;
            _bucketConfig        = bucketConfig;

            //services that this node is responsible for
            IsMgmtNode  = _nodeAdapter.MgmtApi > 0;
            IsDataNode  = _nodeAdapter.KeyValue > 0;
            IsQueryNode = _nodeAdapter.N1QL > 0;
            IsIndexNode = _nodeAdapter.IndexAdmin > 0;
            IsViewNode  = _nodeAdapter.Views > 0;

            //View and query clients
            ViewClient  = viewClient;
            QueryClient = queryClient;

            //timer and node status
            _heartBeatTimer = new Timer(1000)
            {
                Enabled = false
            };
            _heartBeatTimer.Elapsed += _heartBeatTimer_Elapsed;
            TakeOffline(_ioStrategy.ConnectionPool.InitializationFailed);
        }
Exemplo n.º 32
0
        public void Test_Timed_Execution()
        {
            var converter  = new AutoByteConverter();
            var transcoder = new DefaultTranscoder(converter);
            var vbucket    = GetVBucket();
            int n          = 1000; //set to a higher # if needed

            using (new OperationTimer())
            {
                var key = string.Format("key{0}", 111);

                for (var i = 0; i < n; i++)
                {
                    var set = new Set <int?>(key, 111, vbucket, converter, transcoder);
                    var get = new Get <int?>(key, vbucket, converter, transcoder);

                    var result = IOStrategy.Execute(set);
                    Assert.IsTrue(result.Success);

                    var result1 = IOStrategy.Execute(get);
                    Assert.IsTrue(result1.Success);
                    Assert.AreEqual(111, result1.Value);
                }
            }
        }
Exemplo n.º 33
0
 public Server(IOStrategy ioStrategy, INodeAdapter nodeAdapter, ClientConfiguration clientConfiguration,
               IBucketConfig bucketConfig, ITypeTranscoder transcoder, ConcurrentDictionary <string, QueryPlan> queryCache) :
     this(ioStrategy,
          new ViewClient(new HttpClient(), new JsonDataMapper(clientConfiguration), bucketConfig, clientConfiguration),
          new QueryClient(new HttpClient(), new JsonDataMapper(clientConfiguration), clientConfiguration, queryCache),
          nodeAdapter, clientConfiguration, transcoder, bucketConfig)
 {
 }
Exemplo n.º 34
0
 public Server(IOStrategy ioStrategy, INodeAdapter nodeAdapter, ClientConfiguration clientConfiguration,
               IBucketConfig bucketConfig, ITypeTranscoder transcoder) :
     this(ioStrategy,
          new ViewClient(new HttpClient(), new JsonDataMapper(clientConfiguration), bucketConfig, clientConfiguration),
          new QueryClient(new HttpClient(), new JsonDataMapper(clientConfiguration), clientConfiguration),
          nodeAdapter, clientConfiguration, transcoder, bucketConfig)
 {
 }
Exemplo n.º 35
0
 public Server(IOStrategy ioStrategy, IViewClient viewClient, IQueryClient queryClient, Node nodeInfo, ClientConfiguration clientConfiguration)
 {
     _ioStrategy          = ioStrategy;
     ViewClient           = viewClient;
     QueryClient          = queryClient;
     _nodeInfo            = nodeInfo;
     _clientConfiguration = clientConfiguration;
 }
 public virtual void TestFixtureSetUp()
 {
     EndPoint = UriExtensions.GetEndPoint(Address);
     var connectionPoolConfig = new PoolConfiguration();
     _connectionPool = new ConnectionPool<Connection>(connectionPoolConfig, EndPoint);
     _ioStrategy = new DefaultIOStrategy(_connectionPool);
     Transcoder = new DefaultTranscoder();
 }
 public void TestFixtureSetUp()
 {
     var ipEndpoint = UriExtensions.GetEndPoint(_address.Replace("11210", "11207"));
     var connectionPoolConfig = new PoolConfiguration
     {
         UseSsl = true
     };
     _connectionPool = new ConnectionPool<SslConnection>(connectionPoolConfig, ipEndpoint);
     _connectionPool.Initialize();
     _ioStrategy = new DefaultIOStrategy(_connectionPool, null);
 }
        public void TestFixtureSetUp()
        {
            _endPoint = UriExtensions.GetEndPoint(_address);
            var connectionPoolConfig = new PoolConfiguration
            {
                MinSize = 1,
                MaxSize = 1
            };
            _connectionPool = new ConnectionPool<Connection>(connectionPoolConfig, _endPoint);

            _ioStrategy = new DefaultIOStrategy(_connectionPool);
        }
        public void Test_GetConfig_Non_Default_Bucket()
        {
            var saslMechanism = new PlainTextMechanism(_ioStrategy, "authenticated", "secret", new DefaultTranscoder());
            _ioStrategy = new DefaultIOStrategy(_connectionPool, saslMechanism);

            var response = _ioStrategy.Execute(new Config(new DefaultTranscoder(), OperationLifespan, _endPoint));

            Assert.IsTrue(response.Success);
            Assert.IsNotNull(response.Value);
            Assert.AreEqual("authenticated", response.Value.Name);
            Console.WriteLine(response.Value.ToString());
        }
 public PlainTextMechanism(IOStrategy strategy, ITypeTranscoder transcoder)
 {
     _strategy = strategy;
     _transcoder = transcoder;
 }
 public PlainTextMechanism(IOStrategy strategy, IByteConverter converter)
 {
     _strategy = strategy;
     _converter = converter;
 }
 /// <summary>
 /// Creates a <see cref="CramMd5Mechanism"/> object using a given <see cref="IOStrategy"/>.
 /// </summary>
 /// <param name="ioStrategy">The I/O strategy to use.</param>
 /// <param name="converter">The <see cref="IByteConverter"/> to use for converting to and from byte arrays.</param>
 public CramMd5Mechanism(IOStrategy ioStrategy, IByteConverter converter)
 {
     _ioStrategy = ioStrategy;
     _converter = converter;
 }
        /// <exception cref="CouchbaseBootstrapException">Condition.</exception>
        public void LoadConfig(IOStrategy ioStrategy)
        {
            var supportsEnhancedDurability = false;
            try
            {
                Lock.EnterWriteLock();
                Log.Info(m => m("o2-Creating the Servers list using rev#{0}", BucketConfig.Rev));

                var queryUris = new ConcurrentBag<FailureCountingUri>();
                var clientBucketConfig = ClientConfig.BucketConfigs[BucketConfig.Name];
                var servers = new Dictionary<IPAddress, IServer>();
                var nodes = BucketConfig.GetNodes();
                foreach (var adapter in nodes)
                {
                    var endpoint = adapter.GetIPEndPoint(clientBucketConfig.UseSsl);
                    try
                    {
                        IServer server = null;
                        if (Equals(ioStrategy.EndPoint, endpoint) || nodes.Count() == 1)
                        {
                            server = new Core.Server(ioStrategy, adapter, ClientConfig, BucketConfig, Transcoder, QueryCache);
                            supportsEnhancedDurability = ioStrategy.SupportsEnhancedDurability;
                            SupportsEnhancedDurability = supportsEnhancedDurability;
                            if (server.IsQueryNode)
                            {
                                queryUris.Add(UrlUtil.GetFailureCountingBaseUri(adapter, clientBucketConfig));
                            }
                        }
                        else
                        {
                            if (adapter.IsQueryNode)
                            {
                                queryUris.Add(UrlUtil.GetFailureCountingBaseUri(adapter, clientBucketConfig));
                            }
                            if (adapter.IsDataNode) //a data node so create a connection pool
                            {
                                var poolConfiguration = ClientConfig.BucketConfigs[BucketConfig.Name].PoolConfiguration;
                                var connectionPool = ConnectionPoolFactory(poolConfiguration, endpoint);
                                var newIoStrategy = IOStrategyFactory(connectionPool);

                                server = new Core.Server(newIoStrategy, adapter, ClientConfig, BucketConfig, Transcoder, QueryCache)
                                {
                                    SaslFactory = SaslFactory
                                };
                                server.CreateSaslMechanismIfNotExists();

                                //Note: "ioStrategy has" already made a HELO command to check if
                                //the cluster supports enhanced durability so we are reusing the flag
                                //instead of having "newIoStrategy" do it again, later.
                                SupportsEnhancedDurability = ioStrategy.SupportsEnhancedDurability;
                            }
                            else
                            {
                                server = new Core.Server(null, adapter, ClientConfig, BucketConfig, Transcoder, QueryCache);
                            }
                        }
                        servers.Add(endpoint.Address, server);
                    }
                    catch (Exception e)
                    {
                        Log.ErrorFormat("Could not add server {0}. Exception: {1}", endpoint, e);
                    }
                }

                UpdateServices(servers);

                //for caching uri's
                Interlocked.Exchange(ref QueryUris, queryUris);

                Log.Info(m => m("Creating the KeyMapper list using rev#{0}", BucketConfig.Rev));
                var old = Interlocked.Exchange(ref Servers, servers);
                var vBucketKeyMapper = new VBucketKeyMapper(Servers, BucketConfig.VBucketServerMap, BucketConfig.Rev);
                Interlocked.Exchange(ref KeyMapper, vBucketKeyMapper);
                if (old != null)
                {
                    foreach (var server in old.Values)
                    {
                        server.Dispose();
                    }
                    old.Clear();
                }
            }
            finally
            {
                Lock.ExitWriteLock();
            }
        }
        public void LoadConfig(IOStrategy ioStrategy)
        {
            try
            {
                Lock.EnterWriteLock();
                Log.Info(m => m("o2-Creating the Servers list using rev#{0}", BucketConfig.Rev));
                var servers = new List<IServer>();
                var nodes = BucketConfig.Nodes;
                for (var i = 0; i < nodes.Length; i++)
                {
                    var node = nodes[i];
                    var ip = BucketConfig.VBucketServerMap.ServerList[i];
                    var endpoint = GetEndPoint(ip, BucketConfig);
                    try
                    {
                        IServer server = null;
                        if (Equals(ioStrategy.EndPoint, endpoint) || nodes.Length == 1)
                        {
                            server = new Core.Server(ioStrategy, node, ClientConfig);
                        }
                        else
                        {
                            var poolConfig = ClientConfig.BucketConfigs[BucketConfig.Name].PoolConfiguration;
                            var connectionPool = ConnectionPoolFactory(poolConfig, endpoint);
                            var newIoStrategy = IOStrategyFactory(connectionPool);
                            var saslMechanism = SaslFactory(BucketConfig.Name, BucketConfig.Password,
                                newIoStrategy, Converter);
                            newIoStrategy.SaslMechanism = saslMechanism;
                            server = new Core.Server(newIoStrategy, nodes[i], ClientConfig);
                        }
                        servers.Add(server);
                    }
                    catch (Exception e)
                    {
                        Log.ErrorFormat("Could not add server {0}. Exception: {1}", ip, e);
                    }
                }

                Log.Info(m => m("Creating the KeyMapper list using rev#{0}", BucketConfig.Rev));
                var old = Interlocked.Exchange(ref Servers, servers);
                if (old != null)
                {
                    old.ForEach(x => x.Dispose());
                    old.Clear();
                }
                Interlocked.Exchange(ref KeyMapper, new VBucketKeyMapper(Servers, BucketConfig.VBucketServerMap)
                {
                    Rev = BucketConfig.Rev
                });
            }
            finally
            {
                Lock.ExitWriteLock();
            }
        }
        public void LoadConfig(IOStrategy ioStrategy)
        {
            try
            {
                Lock.EnterWriteLock();
                Log.Info(m => m("o2-Creating the Servers list using rev#{0}", BucketConfig.Rev));

                var clientBucketConfig = ClientConfig.BucketConfigs[BucketConfig.Name];
                var servers = new Dictionary<IPAddress, IServer>();
                var nodes = BucketConfig.GetNodes();
                foreach (var adapter in nodes)
                {
                    var endpoint = adapter.GetIPEndPoint(clientBucketConfig.UseSsl);
                    try
                    {
                        IServer server = null;
                        if (Equals(ioStrategy.EndPoint, endpoint) || nodes.Count() == 1)
                        {
                            server = new Core.Server(ioStrategy, adapter, ClientConfig, BucketConfig, Transcoder);
                        }
                        else
                        {
                            var poolConfig = ClientConfig.BucketConfigs[BucketConfig.Name].PoolConfiguration;
                            var connectionPool = ConnectionPoolFactory(poolConfig, endpoint);
                            var newIoStrategy = IOStrategyFactory(connectionPool);

                            server = new Core.Server(newIoStrategy, adapter, ClientConfig, BucketConfig, Transcoder)
                            {
                                SaslFactory = SaslFactory
                            };
                            server.CreateSaslMechanismIfNotExists();
                        }
                        servers.Add(endpoint.Address, server);
                    }
                    catch (Exception e)
                    {
                        Log.ErrorFormat("Could not add server {0}. Exception: {1}", endpoint, e);
                    }
                }

                UpdateServices(servers);

                Log.Info(m => m("Creating the KeyMapper list using rev#{0}", BucketConfig.Rev));
                var old = Interlocked.Exchange(ref Servers, servers);
                var vBucketKeyMapper = new VBucketKeyMapper(Servers, BucketConfig.VBucketServerMap, BucketConfig.Rev);
                Interlocked.Exchange(ref KeyMapper, vBucketKeyMapper);
                if (old != null)
                {
                    foreach (var server in old.Values)
                    {
                        server.Dispose();
                    }
                    old.Clear();
                }
            }
            finally
            {
                Lock.ExitWriteLock();
            }
        }
 /// <summary>
 /// Creates a <see cref="CramMd5Mechanism"/> object using a given <see cref="IOStrategy"/>.
 /// </summary>
 /// <param name="ioStrategy">The I/O strategy to use.</param>
 /// <param name="transcoder"></param>
 public CramMd5Mechanism(IOStrategy ioStrategy, ITypeTranscoder transcoder)
 {
     _ioStrategy = ioStrategy;
     _transcoder = transcoder;
 }
 public override void SetUp()
 {
     base.SetUp();
     _ioStrategy = new BlockingIOStrategy(_connectionPool);
 }