コード例 #1
0
        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);
            }
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
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);
        }