当前位置: 首页>>代码示例>>C#>>正文


C# Cluster.OpenBucket方法代码示例

本文整理汇总了C#中Cluster.OpenBucket方法的典型用法代码示例。如果您正苦于以下问题:C# Cluster.OpenBucket方法的具体用法?C# Cluster.OpenBucket怎么用?C# Cluster.OpenBucket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cluster的用法示例。


在下文中一共展示了Cluster.OpenBucket方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Test

        public void Test()
        {
            var keyValues = new Dictionary<string, string>();
            using (var cluster = new Cluster())
            {
                using (var bucket = cluster.OpenBucket())
                {
                    for (int i = 0; i <10; i++)
                    {
                        var key = "MGETKEY" + i;
                        var value = "{\"val:\"MGETVALUE" + i +"\"}";
                        bucket.Upsert(key, value);
                        keyValues.Add(key, value);
                    }

                    foreach (var keyValue in keyValues)
                    {
                        Console.WriteLine(bucket.Get<dynamic>(keyValue.Key).Value);
                    }
                }
            }

            var operations = new ConcurrentDictionary<uint, IOperation>();
            foreach (var keyValue in keyValues)
            {
                var getk = new GetK<dynamic>(keyValue.Key, GetVBucket(), Converter, Transcoder);
                operations.TryAdd(getk.Opaque, getk);
            }
            var noop = new Noop(Converter);
            operations.TryAdd(noop.Opaque, noop);

            var results = IOStrategy.Execute<dynamic>(operations);
        }
开发者ID:orangeloop,项目名称:couchbase-net-client,代码行数:33,代码来源:MultiGetTests.cs

示例2: TestFixtureSetUp

        public void TestFixtureSetUp()
        {
            _cluster = new Cluster("couchbaseClients/couchbase");

            using (var bucket = _cluster.OpenBucket())
            {
                bucket.Upsert(TestKeys.KeyWithInt32Value.Key, TestKeys.KeyWithInt32Value.Value);
                bucket.Upsert(TestKeys.KeyWithStringValue.Key, TestKeys.KeyWithStringValue.Value);

                // ISO-8601 and Microsoft JSON Date format:
                bucket.Upsert(TestKeys.KeyWithIsoDateValue.Key, TestKeys.KeyWithIsoDateValue.Value);
                bucket.Upsert(TestKeys.KeyWithIsoUtcDateValue.Key, TestKeys.KeyWithIsoUtcDateValue.Value);
                bucket.Upsert(TestKeys.KeyWithMsDateValue.Key, TestKeys.KeyWithMsDateValue.Value);

                // De-Serialize const JSON string into a Dictionary<string, dynamic> and write via bucket.Upsert(Couchbase.Document<dynamic>)
                var ADict = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(TestKeys.KeyWithJsonDocValueStr);
                var couchDoc = new Couchbase.Document<dynamic>()
                {
                    Id = TestKeys.KeyWithJsonDocKey,
                    Content = ADict
                };
                bucket.Upsert(couchDoc);


            }
        }
开发者ID:wpostma,项目名称:couchbase-net-client,代码行数:26,代码来源:GetOperationTests.cs

示例3: Test_CanAuthenticate_Views

        public void Test_CanAuthenticate_Views()
        {
            var credentials = new ClusterCredentials
            {
                ClusterUsername = "Administrator",
                ClusterPassword = "password",
                BucketCredentials = new AttributeDictionary
                {
                    {"authenticated", "secret"}
                }
            };

            var cluster = new Cluster(TestConfiguration.GetCurrentConfiguration());

            cluster.Authenticate(credentials);

            //if authentication failed - an exception would be thrown during bootstrapping
            var bucket = cluster.OpenBucket("authenticated");
            var query = bucket.CreateQuery("somedoc", "someview");
            var result = bucket.Query<dynamic>(query);

            //assert - view does not exist but should still return a response and no auth error
            Assert.IsFalse(result.Success);
            Assert.AreEqual(HttpStatusCode.NotFound, result.StatusCode);
        }
开发者ID:brantburnett,项目名称:couchbase-net-client,代码行数:25,代码来源:AuthenticatorTests.cs

示例4: When_Bucket_Is_Not_Open_IsOpen_Returns_False

 public void When_Bucket_Is_Not_Open_IsOpen_Returns_False()
 {
     var cluster = new Cluster("couchbaseClients/couchbase");
     var bucket = cluster.OpenBucket("default");
     cluster.CloseBucket(bucket);
     Assert.IsFalse(cluster.IsOpen("default"));
 }
开发者ID:brantburnett,项目名称:couchbase-net-client,代码行数:7,代码来源:ClusterTests.cs

示例5: When_InValid_Credentials_Provided_Bucket_Created_UnSuccesfully

        public void When_InValid_Credentials_Provided_Bucket_Created_UnSuccesfully()
        {
            try
            {
                var config = ClientConfigUtil.GetConfiguration();
                config.BucketConfigs = new Dictionary<string, BucketConfiguration>
                {
                    {
                        "authenticated",
                        new BucketConfiguration
                        {
                            BucketName = "authenticated"
                        }
                    }
                };

                var cluster = new Cluster(config);
                var bucket = cluster.OpenBucket("authenticated", "secretw");
                cluster.CloseBucket(bucket);
                Assert.IsNotNull(bucket);
            }
            catch (AggregateException e)
            {
                foreach (var exception in e.InnerExceptions)
                {
                    if (exception.GetType() == typeof (AuthenticationException))
                    {
                        throw exception;
                    }
                }
            }
        }
开发者ID:orangeloop,项目名称:couchbase-net-client,代码行数:32,代码来源:BucketAuthenticationTests.cs

示例6: When_Bucket_Is_Closed_By_Dispose_IsOpen_Returns_False

 public void When_Bucket_Is_Closed_By_Dispose_IsOpen_Returns_False()
 {
     var cluster = new Cluster("couchbaseClients/couchbase");
     var bucket = cluster.OpenBucket("default");
     bucket.Dispose();
     Assert.IsFalse(cluster.IsOpen("default"));
 }
开发者ID:brantburnett,项目名称:couchbase-net-client,代码行数:7,代码来源:ClusterTests.cs

示例7: Test_Timed_Execution_Parallel_Client

        public void Test_Timed_Execution_Parallel_Client()
        {
            var options = new ParallelOptions { MaxDegreeOfParallelism = 4 };
            var n = 1000;//set to a higher # if needed

            using (var cluster = new Cluster("couchbaseClients/couchbase"))
            {
                using (var bucket = cluster.OpenBucket())
                {
                    using (new OperationTimer())
                    {
                        var temp = bucket;
                        Parallel.For(0, n, options, i =>
                        {
                            var key = string.Format("key{0}", i);
                            var value = (int?) i;
                            var result = temp.Upsert(key, value);
                            Assert.IsTrue(result.Success);

                            var result1 = temp.Get<int?>(key);
                            Assert.IsTrue(result1.Success);
                            Assert.AreEqual(i, result1.Value);
                        });
                    }
                }
            }
        }
开发者ID:orangeloop,项目名称:couchbase-net-client,代码行数:27,代码来源:GetSetPerformanceTests.cs

示例8: When_Configuration_Contains_Bad_Bucket_Password_It_Is_Used_And_Fails

        public void When_Configuration_Contains_Bad_Bucket_Password_It_Is_Used_And_Fails()
        {
            var config = new ClientConfiguration((CouchbaseClientSection) ConfigurationManager.GetSection("couchbaseClients/couchbase"));
            config.BucketConfigs = new Dictionary<string, BucketConfiguration>
            {
                {
                    "default",
                    new BucketConfiguration
                    {
                        BucketName = "default",
                        Password = "secret"
                    }
                }
            };

            var cluster = new Cluster(config);
            var bucketName = config.BucketConfigs.Single().Value.BucketName;
            try
            {
                var bucket = cluster.OpenBucket(bucketName);
                Assert.Fail("Unexpected GetBucket success");
            }
            catch (AggregateException e)
            {
                e = e.Flatten();
                if (e.InnerExceptions.All(x => x.GetType() != typeof (AuthenticationException)))
                {
                    Assert.Fail("Expected authentication exception, got " + e.InnerException);
                }
                //success
            }
        }
开发者ID:brantburnett,项目名称:couchbase-net-client,代码行数:32,代码来源:ClusterTests.cs

示例9: GetBucketForKey

        public IBucket GetBucketForKey(string key)
        {
            var config = new ClientConfiguration();
            var fakeServer = new FakeServer(_connectionPool, null, null, _endPoint,
                new FakeIOStrategy(_endPoint, _connectionPool, false));

            var mappedNode = new Mock<IMappedNode>();
            mappedNode.Setup(x => x.LocatePrimary()).Returns(fakeServer);

            var mockKeyMapper = new Mock<IKeyMapper>();
            mockKeyMapper.Setup(x => x.MapKey(key)).Returns(mappedNode.Object);

            var mockConfigInfo = new Mock<IConfigInfo>();
            mockConfigInfo.Setup(x => x.GetKeyMapper()).Returns(mockKeyMapper.Object);
            mockConfigInfo.Setup(x => x.BucketConfig).Returns(_bucketConfig);
            mockConfigInfo.Setup(x => x.GetServer()).Returns(fakeServer);

            var mockController = new Mock<IClusterController>();
            mockController.Setup(x => x.Configuration).Returns(config);
            mockController.Setup(x => x.CreateBucket("memcached", ""))
                .Returns(new MemcachedBucket(mockController.Object, "memcached", _converter, _transcoder));

            var cluster = new Cluster(config, mockController.Object);
            var bucket = cluster.OpenBucket("memcached", "");

            //simulate a config event
            ((IConfigObserver) bucket).NotifyConfigChanged(mockConfigInfo.Object);

            return bucket;
        }
开发者ID:kendallb,项目名称:couchbase-net-client,代码行数:30,代码来源:MemcachedBucket_Async_Tests.cs

示例10: GetBucketForKey

        public IBucket GetBucketForKey(string key)
        {
            var config = new ClientConfiguration();
            var fakeServer = new FakeServer(_connectionPool, null, null, _endPoint,
                new FakeIOService(_endPoint, _connectionPool, false));

            var mockVBucket = new Mock<IVBucket>();
            mockVBucket.Setup(x => x.LocatePrimary()).Returns(fakeServer);

            var mockKeyMapper = new Mock<IKeyMapper>();
            mockKeyMapper.Setup(x => x.MapKey(key, It.IsAny<uint>())).Returns(mockVBucket.Object);

            var mockConfigInfo = new Mock<IConfigInfo>();
            mockConfigInfo.Setup(x => x.GetKeyMapper()).Returns(mockKeyMapper.Object);
            mockConfigInfo.Setup(x => x.BucketConfig).Returns(_bucketConfig);
            mockConfigInfo.Setup(x => x.GetServer()).Returns(fakeServer);
            mockConfigInfo.Setup(x => x.IsDataCapable).Returns(true);
            mockConfigInfo.Setup(x => x.ClientConfig).Returns(new ClientConfiguration());

            var mockController = new Mock<IClusterController>();
            mockController.Setup(x => x.Configuration).Returns(config);
            mockController.Setup(x => x.CreateBucket("default", "", null))
                .Returns(new CouchbaseBucket(mockController.Object, "default", _converter, _transcoder, null));

            var cluster = new Cluster(config, mockController.Object);
            var bucket = cluster.OpenBucket("default", "");

            //simulate a config event
            ((IConfigObserver)bucket).NotifyConfigChanged(mockConfigInfo.Object);

            return bucket;
        }
开发者ID:brantburnett,项目名称:couchbase-net-client,代码行数:32,代码来源:CouchbaseBucket_Async_Tests.cs

示例11: Test_KeySeqnoObserver

        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 clusterController = new Mock<IClusterController>();
            clusterController.Setup(x => x.Transcoder).Returns(new DefaultTranscoder());

            var pending = new ConcurrentDictionary<uint, IOperation>();

            var keyObserver = new KeySeqnoObserver("thekey", pending, configInfo, clusterController.Object, 0, 1000);
            var durabilityReached = keyObserver.Observe(result.Token, ReplicateTo.Zero, PersistTo.One);
            Assert.IsTrue(durabilityReached);
        }
开发者ID:brantburnett,项目名称:couchbase-net-client,代码行数:58,代码来源:KeySeqnoObserverTests.cs

示例12: Test_POCO_Basic

 public void Test_POCO_Basic()
 {
     using (var cluster = new Cluster(TestConfigurations.DefaultConfig()))
     {
         using (var bucket = cluster.OpenBucket("beer-sample"))
         {
         }
     }
 }
开发者ID:amccool,项目名称:Linq2Couchbase,代码行数:9,代码来源:BucketExtensionTests.cs

示例13: Test_POCO_Basic

 public void Test_POCO_Basic()
 {
     using (var cluster = new Cluster())
     {
         using (var bucket = cluster.OpenBucket("beer-sample"))
         {
         }
     }
 }
开发者ID:yonglehou,项目名称:Linq2Couchbase,代码行数:9,代码来源:BucketExtensionTests.cs

示例14: OneTimeSetUp

        public void OneTimeSetUp()
        {
            _cluster = new Cluster("couchbaseClients/couchbase");

            using (var bucket = _cluster.OpenBucket())
            {
                bucket.Upsert(TestKeys.KeyWithInt32Value.Key, TestKeys.KeyWithInt32Value.Value);
                bucket.Upsert(TestKeys.KeyWithStringValue.Key, TestKeys.KeyWithStringValue.Value);
            }
        }
开发者ID:brantburnett,项目名称:couchbase-net-client,代码行数:10,代码来源:GetOperationTests.cs

示例15: Main

 static void Main(string[] args)
 {
     using (var cluster = new Cluster())
     {
         using (var bucket = cluster.OpenBucket())
         {
             bucket.Upsert("somekey", "somevalue");
         }
     }
     Console.Read();
 }
开发者ID:vinaas,项目名称:couchbase-net-examples,代码行数:11,代码来源:Program.cs


注:本文中的Cluster.OpenBucket方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。