Пример #1
0
        public void Test_That_GetConfig_Returns_ConfigInfo()
        {
            var configInfo = _provider.GetConfig(BucketName);

            Assert.IsNotNull(configInfo);
            Assert.AreEqual(BucketName, configInfo.BucketConfig.Name);
        }
Пример #2
0
        public async void 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 DefaultIOStrategy(pool),
                (config, endpoint) => new ConnectionPool <Connection>(config, endpoint),
                SaslFactory.GetFactory(),
                new DefaultConverter(),
                new DefaultTranscoder(new DefaultConverter()));

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

            var observer          = new KeyObserver(configInfo, 10, 500);
            var constraintReached = await observer.ObserveRemoveAsync("Test_Timeout_Remove_Async", 0, ReplicateTo.Zero, PersistTo.One);

            Assert.IsTrue(constraintReached);
        }
        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 PooledIOService(pool),
                (config, endpoint) => new ConnectionPool <Connection>(config, endpoint),
                SaslFactory.GetFactory(),
                new DefaultConverter(),
#pragma warning disable 618
                new DefaultTranscoder(new DefaultConverter(), new DefaultSerializer()));

#pragma warning restore 618

            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);
            var constraintReached = observer.ObserveRemove("Test_Timeout_Remove", 0, ReplicateTo.Zero, PersistTo.One);
            Assert.IsTrue(constraintReached);
        }
Пример #4
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 keyObserver       = new KeySeqnoObserver(configInfo, 0, 1000);
            var durabilityReached = keyObserver.Observe(result.Token, ReplicateTo.Zero, PersistTo.One);

            Assert.IsTrue(durabilityReached);
        }
Пример #5
0
        public void BucketType_Is_Set_Correctly(string bucketType)
        {
            var capabilities = new List <string>();

            if (bucketType == "couchbase")
            {
                capabilities.Add("couchapi");
            }

            var mockConnectionPool = new Mock <IConnectionPool>();

            mockConnectionPool.Setup(x => x.EndPoint)
            .Returns(new IPEndPoint(IPAddress.Any, 0));
            var mockSaslMech  = new Mock <ISaslMechanism>();
            var mockIOService = new Mock <IIOService>();

            mockIOService.Setup(x => x.ConnectionPool)
            .Returns(mockConnectionPool.Object);
            mockIOService.Setup(x => x.SupportsEnhancedAuthentication)
            .Returns(false);
            mockIOService.Setup(x => x.Execute(It.IsAny <IOperation>()))
            .Returns(new OperationResult {
                Success = true
            });
            mockIOService.Setup(x => x.Execute(It.IsAny <IOperation <BucketConfig> >()))
            .Returns(new OperationResult <BucketConfig>
            {
                Success = true,
                Value   = new BucketConfig
                {
                    Name  = "default",
                    Nodes = new[] { new Node {
                                        Hostname = "localhost"
                                    } },
                    BucketCapabilities = capabilities.ToArray()
                }
            });

            var config   = new ClientConfiguration();
            var provider = new CarrierPublicationProvider(
                config,
                pool => mockIOService.Object,
                (c, e) => mockConnectionPool.Object,
                (ac, b, c, d) => mockSaslMech.Object,
                new DefaultConverter(),
                new DefaultTranscoder()
                );

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

            Assert.AreEqual(bucketType, result.BucketConfig.BucketType);
            Assert.AreEqual(Enum.Parse(typeof(BucketTypeEnum), bucketType, true), result.BucketType);
        }
        public async Task Test_Timeout_Add_PersistTo_Master_Async()
        {
            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 key = "Test_Timeout_Add_PersistTo_Master_Async";
            IOperationResult result;

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

            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.ObserveAddAsync(key, result.Cas, ReplicateTo.Zero, PersistTo.Zero, cts);

                Assert.IsTrue(constraintReached);
            }
        }
        public void When_Mutation_Happens_Observe_Fails()
        {
            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");

            ulong cas = 0;

            using (var cluster = new Cluster(configuration))
            {
                using (var bucket = cluster.OpenBucket())
                {
                    bucket.Remove("When_Mutation_Happens_Observe_Fails");
                    cas = bucket.Insert("When_Mutation_Happens_Observe_Fails", "").Cas;
                    bucket.Upsert("When_Mutation_Happens_Observe_Fails", "");
                }
            }
            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);
            var constraintReached = observer.ObserveAdd("When_Mutation_Happens_Observe_Fails", cas, ReplicateTo.One, PersistTo.One);

            Assert.IsFalse(constraintReached);
        }
        public void Only_Execute_SelectBuket_When_EnhancedAuthentication_Is_Enabled(bool enabled)
        {
            var mockConnectionPool = new Mock <IConnectionPool>();

            mockConnectionPool.Setup(x => x.EndPoint)
            .Returns(new IPEndPoint(IPAddress.Any, 0));
            var mockSaslMech  = new Mock <ISaslMechanism>();
            var mockIOService = new Mock <IIOService>();

            mockIOService.Setup(x => x.ConnectionPool)
            .Returns(mockConnectionPool.Object);
            mockIOService.Setup(x => x.SupportsEnhancedAuthentication)
            .Returns(enabled);
            mockIOService.Setup(x => x.Execute(It.IsAny <IOperation>()))
            .Returns(new OperationResult {
                Success = true
            });
            mockIOService.Setup(x => x.Execute(It.IsAny <IOperation <BucketConfig> >()))
            .Returns(new OperationResult <BucketConfig>
            {
                Success = true,
                Value   = new BucketConfig {
                    Name = "default", Nodes = new [] { new Node {
                                                           Hostname = "localhost"
                                                       } }
                }
            });

            var config   = new ClientConfiguration();
            var provider = new CarrierPublicationProvider(
                config,
                pool => mockIOService.Object,
                (c, e) => mockConnectionPool.Object,
                (ac, b, c, d) => mockSaslMech.Object,
                new DefaultConverter(),
                new DefaultTranscoder()
                );

            provider.GetConfig("bucket", "username", "password");
            mockIOService.Verify(x => x.Execute(It.IsAny <SelectBucket>()), Times.Exactly(enabled ? 1 : 0));
        }
Пример #9
0
        public async void Test_Timeout_Add_PersistTo_Master_Async()
        {
            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 <Connection>(config, endpoint),
                SaslFactory.GetFactory(),
                new DefaultConverter(),
                new DefaultTranscoder(new DefaultConverter()));

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

            var key = "Test_Timeout_Add_PersistTo_Master_Async";
            IOperationResult result;

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

            var observer          = new KeyObserver(configInfo, 10, 500);
            var constraintReached = await observer.ObserveAddAsync(key, result.Cas, ReplicateTo.Zero, PersistTo.Zero);

            Assert.IsTrue(constraintReached);
        }
Пример #10
0
        public async void When_Mutation_Happens_Observe_Fails_Async()
        {
            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 <Connection>(config, endpoint),
                SaslFactory.GetFactory(),
                new DefaultConverter(),
                new DefaultTranscoder(new DefaultConverter()));

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

            var   key = "When_Mutation_Happens_Observe_Fails_async";
            ulong cas = 0;

            using (var cluster = new Cluster(configuration))
            {
                using (var bucket = cluster.OpenBucket())
                {
                    bucket.Remove(key);
                    cas = bucket.Insert(key, "").Cas;
                    bucket.Upsert(key, "");
                }
            }
            var observer          = new KeyObserver(configInfo, 10, 500);
            var constraintReached = await observer.ObserveAddAsync(key, cas, ReplicateTo.One, PersistTo.One);

            Assert.IsFalse(constraintReached);
        }
Пример #11
0
        public async Task When_Observing_Key_During_AddAsync_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   key = "Test_Timeout_Add_Async";
            ulong cas = 0;

            using (var cluster = new Cluster(configuration))
            {
                using (var bucket = cluster.OpenBucket())
                {
                    bucket.Remove(key);
                    bucket.Insert(key, "");
                    cas = bucket.Upsert(key, "").Cas;
                }
            }
            var observer          = new KeyObserver(configInfo, 10, 500);
            var constraintReached = await observer.ObserveAddAsync(key, cas, ReplicateTo.Zero, PersistTo.Zero);

            Assert.IsTrue(constraintReached);
        }
Пример #12
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 DefaultTranscoder(new AutoByteConverter()));

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

            ulong cas = 0;

            using (var cluster = new Cluster(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);
        }
        public void Test_Timeout_Add_PersistTo_Master()
        {
            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");

            using (var cluster = new CouchbaseCluster(configuration))
            {
                using (var bucket = cluster.OpenBucket())
                {
                    bucket.Remove("Test_Timeout_Add_PersistTo_Master");
                    bucket.Insert("Test_Timeout_Add_PersistTo_Master", "");
                }
            }

            var observer          = new KeyObserver(configInfo, 10, 500);
            var constraintReached = observer.ObserveAdd("Test_Timeout_Add_PersistTo_Master", 0, ReplicateTo.Zero, PersistTo.Zero);

            Assert.IsTrue(constraintReached);
        }