public override void Run() { var config = new CouchbaseClientConfiguration(); config.Urls.Add(new Uri("http://localhost:8091/pools/")); config.Bucket = "default"; var client = new CouchbaseClient(config); //Store a key, but don't return success until it is written //to disk on the master (or times out) var success = client.ExecuteStore(StoreMode.Set, "key_1", 2, PersistTo.One); Console.WriteLine(success.Success); //will return false //Store a key, but don't return success until it is //replicated to 2 nodes (or times out) //will fail on a single or two node cluster success = client.ExecuteStore(StoreMode.Set, "key_1", 2, ReplicateTo.Two); Console.WriteLine(success.Success); //will return false //Store a key, but don't return success until it is written //to disk on the master and replicated to 2 nodes (or times out) //will fail on a single or two node cluster success = client.ExecuteStore(StoreMode.Set, "key_1", 2, PersistTo.One, ReplicateTo.Two); Console.WriteLine(success.Success); //will return false client.Remove("key_1"); client.Remove("key_2"); }
public override void Run() { var config = new CouchbaseClientConfiguration(); config.Urls.Add(new Uri("http://*****:*****@cia.gov", Password = "******", Logins = 0 }; var user2 = new User { Username = "******", Name = "Nicholas Brody", Email = "*****@*****.**", Password = "******", Logins = 0 }; //store the user - ExecuteStore returns detailed error info, if any var result1 = client.ExecuteStore(StoreMode.Set, user1.Email, user1); if (!result1.Success) { Console.WriteLine("Store failed with message {0} and status code {1}", result1.Message, result1.StatusCode); if (result1.Exception != null) { throw result1.Exception; } } var result2 = client.ExecuteStore(StoreMode.Set, user2.Email, user2); //same check as result1 would be useful var doc = client.Get<User>(user1.Email); Console.WriteLine(doc.Name); //get doc with extended info var result = client.ExecuteGet<User>(user1.Email); //update login count doc.Logins += 1; //update document (ignore errors for lab) client.ExecuteStore(StoreMode.Replace, user1.Email, doc); doc = client.Get<User>(user1.Email); Console.WriteLine("User {0} had {1} logins", doc.Name, doc.Logins); client.Remove(user1.Email); client.Remove(user2.Email); }
public void When_Creating_New_Bucket_Item_Counts_Are_Set_On_Basic_Stats() { var bucketName = "Bucket-" + DateTime.Now.Ticks; _bucket = new Bucket { Name = bucketName, AuthType = AuthTypes.Sasl, BucketType = BucketTypes.Membase, Quota = new Quota { RAM = 100 }, ReplicaNumber = ReplicaNumbers.Zero }; Cluster.CreateBucket(_bucket); _bucket = waitForListedBucket(bucketName); Assert.That(_bucket, Is.Not.Null, "New bucket was null"); var count = _bucket.BasicStats.ItemCount; Assert.That(count, Is.EqualTo(0), "Item count was not 0"); var client = new CouchbaseClient(bucketName, ""); var result = false; for (var i = 0; i < 10; i++) { var aResult = client.ExecuteStore(StoreMode.Set, "a", "a"); var bResult = client.ExecuteStore(StoreMode.Set, "b", "b"); var cResult = client.ExecuteStore(StoreMode.Set, "c", "c"); result = aResult.Success & bResult.Success & cResult.Success; if (result) { break; } Thread.Sleep(2000); //wait for the bucket to be ready for writing } Assert.That(result, Is.True, "Store operations failed"); for (var i = 0; i < 10; i++) { _bucket = Cluster.ListBuckets().Where(b => b.Name == bucketName).FirstOrDefault(); count = _bucket.BasicStats.ItemCount; if (count == 3) { break; } Thread.Sleep(2000); //wait for the bucket to compute writes into basic stats } Assert.That(count, Is.EqualTo(3), "Item count was not 3"); Cluster.DeleteBucket(bucketName); _bucket = waitForListedBucket(bucketName); Assert.That(_bucket, Is.Null, "Deleted bucket still exists"); }
static void ParallerInsert(CouchbaseClient client, int n) { var options = new ParallelOptions { MaxDegreeOfParallelism = 4 }; Parallel.For(0, n, options, i => { var key = "key" + i; var value = "value" + i; var result = client.ExecuteStore(StoreMode.Set, key, value); if (result.Success) { Console.WriteLine("Write Key: {0} - Value: {1}", key, value); var result2 = client.ExecuteGet <string>(key); if (result2.Success) { Console.WriteLine("Read Key: {0} - Value: {1}", key, result2.Value); } else { Console.WriteLine("Read Error: {0} - {1}", key, result.Message); } } else { Console.WriteLine("Write Error: {0} - {1}", key, result.Message); } }); }
static void SynchronousInsert(CouchbaseClient client, int n) { for (int i = 0; i < n; i++) { var key = "key" + i; var value = "value" + i; var result = client.ExecuteStore(StoreMode.Set, key, value); if (result.Success) { Console.WriteLine("Write Key: {0} - Value: {1}", key, value); var result2 = client.ExecuteGet <string>(key); if (result2.Success) { Console.WriteLine("Read Key: {0} - Value: {1}", key, result2.Value); } else { Console.WriteLine("Read Error: {0} - {1}", key, result.Message); } } else { Console.WriteLine("Write Error: {0} - {1}", key, result.Message); } } }
static void ParallerInsert(CouchbaseClient client, int n) { var options = new ParallelOptions { MaxDegreeOfParallelism = 4 }; Parallel.For(0, n, options, i => { var key = "key" + i; var value = "value" + i; var result = client.ExecuteStore(StoreMode.Set, key, value); if (result.Success) { Console.WriteLine("Write Key: {0} - Value: {1}", key, value); var result2 = client.ExecuteGet<string>(key); if (result2.Success) { Console.WriteLine("Read Key: {0} - Value: {1}", key, result2.Value); } else { Console.WriteLine("Read Error: {0} - {1}", key, result.Message); } } else { Console.WriteLine("Write Error: {0} - {1}", key, result.Message); } }); }
static void SynchronousInsert(CouchbaseClient client, int n) { for (int i = 0; i < n; i++) { var key = "key" + i; var value = "value" + i; var result = client.ExecuteStore(StoreMode.Set, key, value); if (result.Success) { Console.WriteLine("Write Key: {0} - Value: {1}", key, value); var result2 = client.ExecuteGet<string>(key); if (result2.Success) { Console.WriteLine("Read Key: {0} - Value: {1}", key, result2.Value); } else { Console.WriteLine("Read Error: {0} - {1}", key, result.Message); } } else { Console.WriteLine("Write Error: {0} - {1}", key, result.Message); } } }
public void When_Flushing_Bucket_Data_Are_Removed() { var storedConfig = ConfigurationManager.GetSection("couchbase") as ICouchbaseClientConfiguration; var config = new CouchbaseClientConfiguration(); config.Bucket = "Bucket-" + DateTime.Now.Ticks; config.Username = storedConfig.Username; config.Password = storedConfig.Password; config.Urls.Add(storedConfig.Urls[0]); var cluster = new CouchbaseCluster(config); cluster.CreateBucket(new Bucket { Name = config.Bucket, AuthType = AuthTypes.Sasl, BucketType = BucketTypes.Membase, Quota = new Quota { RAM = 100 }, ReplicaNumber = ReplicaNumbers.Zero, FlushOption = FlushOptions.Enabled } ); Bucket bucket = null; for (int i = 0; i < 10; i++) //wait for bucket to be ready to accept ops { bucket = waitForBucket(config.Bucket); if (bucket.Nodes.First().Status == "healthy") { break; } Thread.Sleep(1000); } Assert.That(bucket, Is.Not.Null); var client = new CouchbaseClient(config); var storeResult = client.ExecuteStore(StoreMode.Set, "SomeKey", "SomeValue"); Assert.That(storeResult.Success, Is.True, "Message: " + storeResult.Message); var getResult = client.ExecuteGet <string>("SomeKey"); Assert.That(getResult.Success, Is.True); Assert.That(getResult.Value, Is.StringMatching("SomeValue")); cluster.FlushBucket(config.Bucket); getResult = client.ExecuteGet <string>("SomeKey"); Assert.That(getResult.Success, Is.False); Assert.That(getResult.Value, Is.Null); _Cluster.DeleteBucket(config.Bucket); }
public override void Run() { var config = new CouchbaseClientConfiguration(); config.Urls.Add(new Uri("http://localhost:8091/pools/")); config.Bucket = "default"; var client = new CouchbaseClient(config); var post = new Post { Title = "Using Couchbase and .NET", Body = "Start by getting the client at Nuget.", Comments = new List <string> { "Great post!" }, Slug = "Using_Couchbase_Net" }; client.ExecuteStore(StoreMode.Set, post.Slug, post); var get1 = client.ExecuteGet <Post>(post.Slug); var get2 = client.ExecuteGet <Post>(post.Slug); Console.WriteLine("-------------------------------------"); Console.WriteLine("Set the Data, then Retrieve Two Copies of the Document"); Console.WriteLine(); Console.WriteLine("Both v1 and v2 are identical and have identical CAS [(cas1) {0} == {1} (cas2)]", get1.Cas, get2.Cas); Console.WriteLine(); Console.WriteLine("-------------------------------------"); Console.WriteLine("Now We'll update the document which results in a new CAS"); Console.WriteLine(); get1.Value.Comments.Add("Wicked good post!"); var result = client.ExecuteStore(StoreMode.Set, post.Slug, get1.Value); get1 = client.ExecuteGet <Post>(post.Slug); Console.WriteLine("Now CAS has changed [(cas1) {0} != {1} (cas2)]", get1.Cas, get2.Cas); Console.WriteLine(); Console.WriteLine("-------------------------------------"); }
public void Client_Operations_Succeed_When_Bootstrapping_To_Pools_Root_Uri() { var config = ConfigSectionUtils.GetConfigSection<CouchbaseClientSection>("pools-config"); var client = new CouchbaseClient(config); string key = GetUniqueKey(), value = GetRandomString(); var storeResult = client.ExecuteStore(StoreMode.Add, key, value); StoreAssertPass(storeResult); var getResult = client.ExecuteGet(key); GetAssertPass(getResult, value); }
// ---------- METHODS ---------- /// <summary> /// Adds or replaces a document in the store with the specified id. /// </summary> /// <param name="id">The id of the document to add or replace.</param> /// <param name="document">The document to add or replace.</param> /// <returns>The id of the document if it was added or replaced, null otherwise.</returns> public override string AddOrReplace(string id, ExpandoObject document) { if (!string.IsNullOrWhiteSpace(id) && document != null) { var result = client.ExecuteStore(StoreMode.Set, id, document); return(id); } else { return(null); } }
public void Client_Operations_Succeed_When_Heartbeat_Is_Not_Configured() { var config = ConfigSectionUtils.GetConfigSection<CouchbaseClientSection>("min-config"); var client = new CouchbaseClient(config); string key = GetUniqueKey(), value = GetRandomString(); var storeResult = client.ExecuteStore(StoreMode.Add, key, value); StoreAssertPass(storeResult); var getResult = client.ExecuteGet(key); GetAssertPass(getResult, value); }
public void When_Storing_A_Key_From_A_Down_Node_No_Exception_Is_Thrown_And_Success_Is_False() { var config = new CouchbaseClientConfiguration(); config.Urls.Add(new Uri("http://doesnotexist:8091/pools/")); config.Bucket = "default"; var client = new CouchbaseClient(config); var storeResult = client.ExecuteStore(StoreMode.Set, "foo", "bar"); Assert.That(storeResult.Success, Is.False); Assert.That(storeResult.Message, Is.StringContaining(ClientErrors.FAILURE_NODE_NOT_FOUND)); }
public void Client_Operations_Succeed_When_Bootstrapping_To_Pools_Default_Root_Uri() { var config = ConfigSectionUtils.GetConfigSection<CouchbaseClientSection>("pools-default-config"); var client = new CouchbaseClient(config); string key = GetUniqueKey(), value = GetRandomString(); var storeResult = client.ExecuteStore(StoreMode.Add, key, value); Assert.That(storeResult.Success, Is.True, "Success was false"); Assert.That(storeResult.Message, Is.Null.Or.Empty, "Message was not empty"); var getResult = client.ExecuteGet(key); GetAssertPass(getResult, value); }
protected IStoreOperationResult Store(StoreMode mode = StoreMode.Set, string key = null, string value = null) { if (string.IsNullOrEmpty(key)) { key = GetUniqueKey("store"); } if (value == null) { value = GetRandomString(); } return(_Client.ExecuteStore(mode, key, value)); }
public void Client_Operations_Succeed_When_Heartbeat_Is_Disabled() { var config = ConfigSectionUtils.GetConfigSection<CouchbaseClientSection>("heartbeat-config-off"); using (var client = new CouchbaseClient(config)) { string key = TestUtils.GetUniqueKey(), value = TestUtils.GetRandomString(); var storeResult = client.ExecuteStore(StoreMode.Add, key, value); TestUtils.StoreAssertPass(storeResult); var getResult = client.ExecuteGet(key); TestUtils.GetAssertPass(getResult, value); } }
private static void PerformGetSet(CouchbaseClient client, int i) { var key = string.Format("key{0}", i); var document = string.Concat("{\"value\":\"", i, "\"}"); var set = client.ExecuteStore(StoreMode.Set, key, document); Console.WriteLine("Set: {0} - {1} - {2}", key, set.Success, Thread.CurrentThread.ManagedThreadId); var get = client.ExecuteGet <dynamic>(key); Console.WriteLine("Get: {0} - {1} - {2}", key, get.Success, Thread.CurrentThread.ManagedThreadId); }
public void Client_Operations_Succeed_When_Bootstrapping_To_Pools_Root_Uri() { var config = ConfigSectionUtils.GetConfigSection <CouchbaseClientSection>("pools-config"); var client = new CouchbaseClient(config); string key = GetUniqueKey(), value = GetRandomString(); var storeResult = client.ExecuteStore(StoreMode.Add, key, value); StoreAssertPass(storeResult); var getResult = client.ExecuteGet(key); GetAssertPass(getResult, value); }
/// <summary> /// Stores the document. /// </summary> /// <param name="mode">The storage mode.</param> /// <param name="model">The model.</param> /// <returns><c>true</c> if the document was successfully stored, <c>false</c> otherwise</returns> private T StoreDocument(StoreMode mode, T model) { model.Version += 1; model.UpdatedAt = SetUpdatedAtWithNoTimeTravel(model.UpdatedAt); var json = model.ToJson(); var docKey = model.Key; var result = Client.ExecuteStore(mode, docKey, json); if (result.Success) { // set the cas value so we can use it later on model.CasValue = result.Cas; return(model); } int i = 0; while (i < 9) { var storeResult = Client.ExecuteStore(mode, docKey, json); if (storeResult.Success) { // set the cas value so we can use it later on model.CasValue = storeResult.Cas; return(model); } i++; } string message = "Store failed for the key " + docKey + ", after trying 10 times to store the document."; LogCouchbaseOperationResult(docKey, ToString(), message, result); return(model); }
public void Client_Operations_Succeed_When_Heartbeat_Is_Disabled() { var config = ConfigSectionUtils.GetConfigSection <CouchbaseClientSection>("heartbeat-config-off"); using (var client = new CouchbaseClient(config)) { string key = TestUtils.GetUniqueKey(), value = TestUtils.GetRandomString(); var storeResult = client.ExecuteStore(StoreMode.Add, key, value); TestUtils.StoreAssertPass(storeResult); var getResult = client.ExecuteGet(key); TestUtils.GetAssertPass(getResult, value); } }
public void Client_Operations_Succeed_When_Heartbeat_Is_Not_Configured() { var config = ConfigSectionUtils.GetConfigSection <CouchbaseClientSection>("min-config"); var client = new CouchbaseClient(config); string key = GetUniqueKey(), value = GetRandomString(); var storeResult = client.ExecuteStore(StoreMode.Add, key, value); StoreAssertPass(storeResult); var getResult = client.ExecuteGet(key); GetAssertPass(getResult, value); }
private static void import(CouchbaseClient client, string directory) { var dir = new DirectoryInfo(directory); foreach (var file in dir.GetFiles()) { if (file.Extension != ".json") continue; Console.WriteLine("Adding {0}", file); var json = File.ReadAllText(file.FullName); var key = file.Name.Replace(file.Extension, ""); json = Regex.Replace(json.Replace(key, "LAZY"), "\"_id\":\"LAZY\",",""); var storeResult = client.ExecuteStore(StoreMode.Set, key, json); Console.WriteLine(storeResult.Message); } }
private static void ThreadBody() { for (int i = 0; i < LOOPS; i++) { var result = s_cbClient.ExecuteStore(StoreMode.Set, Interlocked.Increment(ref s_keyCounter).ToString(), s_bigData, s_validity); if (!result.Success) { Assert.AreEqual(result.StatusCode, StatusCode.SocketPoolTimeout, "StatusCode is SocketTimeout"); } else { Debug.WriteLine("Success"); } } }
public void Client_Operations_Succeed_When_Bootstrapping_To_Pools_Root_Uri() { var config = new CouchbaseClientConfiguration(); config.Urls.Add(new Uri("http://localhost:8091/pools")); config.Bucket = "default"; var client = new CouchbaseClient(config); string key = GetUniqueKey(), value = GetRandomString(); var storeResult = client.ExecuteStore(StoreMode.Add, key, value); StoreAssertPass(storeResult); var getResult = client.ExecuteGet(key); GetAssertPass(getResult, value); }
public void Client_Operations_Succeed_When_Bootstrapping_To_Pools_Default_Root_Uri() { var config = ConfigSectionUtils.GetConfigSection <CouchbaseClientSection>("pools-default-config"); var client = new CouchbaseClient(config); string key = GetUniqueKey(), value = GetRandomString(); var storeResult = client.ExecuteStore(StoreMode.Add, key, value); Assert.That(storeResult.Success, Is.True, "Success was false"); Assert.That(storeResult.Message, Is.Null.Or.Empty, "Message was not empty"); var getResult = client.ExecuteGet(key); GetAssertPass(getResult, value); }
public void Client_Operations_Succeed_When_Bootstrapping_To_Pools_Default_Root_Uri() { var config = new CouchbaseClientConfiguration(); config.Urls.Add(new Uri("http://localhost:8091/pools/default")); config.Bucket = "default"; var client = new CouchbaseClient(config); string key = GetUniqueKey(), value = GetRandomString(); var storeResult = client.ExecuteStore(StoreMode.Add, key, value); Assert.That(storeResult.Success, Is.True, "Success was false"); Assert.That(storeResult.Message, Is.Null.Or.Empty, "Message was not empty"); var getResult = client.ExecuteGet(key); GetAssertPass(getResult, value); }
//--------------------------------------------------------------------- public bool executeStore(string db_key, string json_data) { Enyim.Caching.Memcached.Results.IStoreOperationResult ret = mCouchbaseClient.ExecuteStore(StoreMode.Set, db_key, json_data, Couchbase.Operations.PersistTo.Zero); if (ret.Success) { return(true); } else { //mLog.Error("CEntitySerializerCouchbase.handleSave() error! "); //mLog.Error("save entity to db: entity_type=" + data.entity_type + " entity_id=" + data.entity_guid); //mLog.Error(ret.Message); //mLog.Error(json_map_prop); return(false); } }
public static void Main() { var clientA = new CouchbaseClient("couchbase"); var clientB = new CouchbaseClient(); clientA.Remove("fooA"); IStoreOperationResult result = clientA.ExecuteStore(StoreMode.Set, "fooA", "barA"); var itemA = clientA.Get<string>("fooA"); Console.WriteLine(itemA); clientB.ExecuteStore(StoreMode.Set, "fooB", "barB"); var itemB = clientB.Get<string>("fooB"); Console.WriteLine(itemB); Console.ReadLine(); }
public void When_Using_App_Config_And_HttpClient_Factory_Is_Not_Set_Operations_Succeed() { var config = ConfigurationManager.GetSection("min-config") as CouchbaseClientSection; Assert.That(config, Is.Not.Null, "min-config section missing from app.config"); Assert.That(config.HttpClientFactory, Is.InstanceOf <ProviderElement <IHttpClientFactory> >()); var client = new CouchbaseClient(config); var kv = KeyValueUtils.GenerateKeyAndValue("default_config"); var result = client.ExecuteStore(StoreMode.Add, kv.Item1, kv.Item2); Assert.That(result.Success, Is.True, "Store failed: " + result.Message); var value = client.Get(kv.Item1); Assert.That(value, Is.StringMatching(kv.Item2)); }
public void Client_Operations_Succeed_When_Heartbeat_Is_Configured() { var config = new CouchbaseClientConfiguration(); config.Urls.Add(new Uri("http://localhost:8091/pools")); config.Bucket = "default"; config.HeartbeatMonitor = new HeartbeatMonitorElement(); config.HeartbeatMonitor.Enabled = true; config.HeartbeatMonitor.Interval = 100; config.HeartbeatMonitor.Uri = "http://localhost:8091/pools"; var client = new CouchbaseClient(config); string key = GetUniqueKey(), value = GetRandomString(); var storeResult = client.ExecuteStore(StoreMode.Add, key, value); StoreAssertPass(storeResult); var getResult = client.ExecuteGet(key); GetAssertPass(getResult, value); }
public void When_Using_Code_Config_And_HttpClient_Factory_Is_Not_Set_Operations_Succeed() { var config = new CouchbaseClientConfiguration(); config.Urls.Add(new Uri("http://localhost:8091/pools")); Assert.That(config.HttpClientFactory, Is.InstanceOf <DefaultHttpClientFactory>()); Assert.That(config, Is.Not.Null, "min-config section missing from app.config"); Assert.That(config.HttpClientFactory, Is.InstanceOf <DefaultHttpClientFactory>()); var client = new CouchbaseClient(config); var kv = KeyValueUtils.GenerateKeyAndValue("default_config"); var result = client.ExecuteStore(StoreMode.Add, kv.Item1, kv.Item2); Assert.That(result.Success, Is.True, "Store failed: " + result.Message); var value = client.Get(kv.Item1); Assert.That(value, Is.StringMatching(kv.Item2)); }
private static void Send_Helper(IEnumerable <KeyValuePair <string, string> > records) { var skipped = 0; try { var random = new Random(); var sent = 0; foreach (var record in records) { while (true) { var result = _client.ExecuteStore(StoreMode.Add, record.Key, record.Value); if (result.Success) { ++sent; break; } if (result.StatusCode == COUCHBASE_TEMPORARY_OUT_OF_MEMORY) { // couchbase needs to catch-up on writing to disk; take a break and continue Thread.Sleep((int)(100 + random.NextDouble() * 300)); continue; } if (result.StatusCode == COUCHBASE_OUT_OF_MEMORY) { // couchbase has run out of disk space; time to give up skipped = records.Count() - sent; return; } ++skipped; break; } } } finally { Interlocked.Add(ref _skippedRecords, skipped); Interlocked.Decrement(ref _threadCount); } }
public void When_Flushing_Bucket_Data_Are_Removed() { var config = new CouchbaseClientConfiguration(); config.Urls.Add(new Uri("http://10.0.0.79:8091/pools/default")); config.Bucket = "default"; var client = new CouchbaseClient(config); var storeResult = client.ExecuteStore(StoreMode.Set, "SomeKey", "SomeValue"); Assert.That(storeResult.Success, Is.True); var getResult = client.ExecuteGet <string>("SomeKey"); Assert.That(getResult.Success, Is.True); Assert.That(getResult.Value, Is.StringMatching("SomeValue")); _Cluster.FlushBucket("default"); getResult = client.ExecuteGet <string>("SomeKey"); Assert.That(getResult.Success, Is.False); Assert.That(getResult.Value, Is.Null); }
public void When_Using_Code_Config_And_HttpClient_Factory_Is_Not_Set_Operations_Succeed() { var config = new CouchbaseClientConfiguration(); config.Urls.Add(new Uri("http://localhost:8091/pools")); Assert.That(config.HttpClientFactory, Is.InstanceOf<DefaultHttpClientFactory>()); Assert.That(config, Is.Not.Null, "min-config section missing from app.config"); Assert.That(config.HttpClientFactory, Is.InstanceOf<DefaultHttpClientFactory>()); var client = new CouchbaseClient(config); var kv = KeyValueUtils.GenerateKeyAndValue("default_config"); var result = client.ExecuteStore(StoreMode.Add, kv.Item1, kv.Item2); Assert.That(result.Success, Is.True, "Store failed: " + result.Message); var value = client.Get(kv.Item1); Assert.That(value, Is.StringMatching(kv.Item2)); }
public override void Run() { var config = new CouchbaseClientConfiguration(); config.Urls.Add(new Uri("http://*****:*****@cia.gov", Password = "******", Logins = 0 }; var user2 = new User { Username = "******", Name = "Nicholas Brody", Email = "*****@*****.**", Password = "******", Logins = 0 }; //store the user - ExecuteStore returns detailed error info, if any var result1 = client.ExecuteStore(StoreMode.Set, user1.Email, user1); if (!result1.Success) { Console.WriteLine("Store failed with message {0} and status code {1}", result1.Message, result1.StatusCode); if (result1.Exception != null) { throw result1.Exception; } } var result2 = client.ExecuteStore(StoreMode.Set, user2.Email, user2); //same check as result1 would be useful var doc = client.Get <User>(user1.Email); Console.WriteLine(doc.Name); //get doc with extended info var result = client.ExecuteGet <User>(user1.Email); //update login count doc.Logins += 1; //update document (ignore errors for lab) client.ExecuteStore(StoreMode.Replace, user1.Email, doc); doc = client.Get <User>(user1.Email); Console.WriteLine("User {0} had {1} logins", doc.Name, doc.Logins); client.Remove(user1.Email); client.Remove(user2.Email); }
static void Main(string[] args) { Options options = new Options(); CommandLineParserSettings parserSettings = new CommandLineParserSettings(); parserSettings.CaseSensitive = true; CommandLineParser parser = new CommandLineParser(parserSettings); if (!parser.ParseArguments(args, options, Console.Error)) { return; } var config = new CouchbaseClientConfiguration(); config.Bucket = options.Bucket; var url = "http://"; if (!options.Hostname.Contains(":")) { options.Hostname += ":8091"; } url += options.Hostname + "/pools"; config.Urls.Add(new Uri(url)); Console.Error.WriteLine("URL: " + url + ", Bucket: " + config.Bucket); Console.Error.WriteLine("Design: " + options.Design + ", View: " + options.View); CouchbaseClient cli = new CouchbaseClient(config); var res = cli.ExecuteStore(Enyim.Caching.Memcached.StoreMode.Set, "foo", "bar"); Console.WriteLine("Store result ? {0}", res.Success); var view = cli.GetView(options.Design, options.View); if (options.Group) { view.Group(options.Group); } if (options.GroupLevel > 0) { view.GroupAt(options.GroupLevel); } if (options.Range != null) { if (options.Range.Count > 2) { Console.Error.WriteLine("Too many keys in range (use -R for compount keys)"); return; } if (!String.IsNullOrEmpty(options.Range[0])) { view.StartKey(options.Range[0]); } if (!String.IsNullOrEmpty(options.Range[1])) { view.EndKey(options.Range[1]); } } else if (options.CompoundRanges != null) { IList <string> sk = null, ek = null; int firstIx = options.CompoundRanges.IndexOf(":"); if (firstIx == -1) { Console.Error.WriteLine("Malformed compound range"); return; } if (firstIx == 0) { ek = options.CompoundRanges.Skip(1).ToList(); } else if (firstIx == options.CompoundRanges.Count - 1) { sk = options.CompoundRanges.Take( options.CompoundRanges.Count - 1).ToList(); } else { sk = options.CompoundRanges.Take(firstIx).ToList(); ek = options.CompoundRanges.Skip(firstIx + 1).ToList(); } if (sk != null) { Console.Error.WriteLine("Using start key " + new JavaScriptSerializer().Serialize(sk)); view.StartKey(sk); } if (ek != null) { if (ek[0].StartsWith("+")) { ek[0] = new String(ek[0].Skip(1).ToArray()); view.WithInclusiveEnd(true); } Console.Error.WriteLine("Using end key " + new JavaScriptSerializer().Serialize(ek)); view.EndKey(ek); } } if (options.Limit > 0) { view = view.Limit(options.Limit); } if (options.Fresh) { view.Stale(StaleMode.False); } try { DoExecuteView(view); } catch (WebException exc) { Console.WriteLine(exc); } }
public IStoreOperationResult Set(string key, object value) { return(_client.ExecuteStore(StoreMode.Set, key, value)); }
public void When_Flushing_Bucket_Data_Are_Removed() { var config = new CouchbaseClientConfiguration(); config.Urls.Add(new Uri("http://10.0.0.79:8091/pools/default")); config.Bucket = "default"; var client = new CouchbaseClient(config); var storeResult = client.ExecuteStore(StoreMode.Set, "SomeKey", "SomeValue"); Assert.That(storeResult.Success, Is.True); var getResult = client.ExecuteGet<string>("SomeKey"); Assert.That(getResult.Success, Is.True); Assert.That(getResult.Value, Is.StringMatching("SomeValue")); _Cluster.FlushBucket("default"); getResult = client.ExecuteGet<string>("SomeKey"); Assert.That(getResult.Success, Is.False); Assert.That(getResult.Value, Is.Null); }
public void When_Using_App_Config_And_HttpClient_Factory_Is_Not_Set_Operations_Succeed() { var config = ConfigurationManager.GetSection("min-config") as CouchbaseClientSection; Assert.That(config, Is.Not.Null, "min-config section missing from app.config"); Assert.That(config.HttpClientFactory, Is.InstanceOf<ProviderElement<IHttpClientFactory>>()); var client = new CouchbaseClient(config); var kv = KeyValueUtils.GenerateKeyAndValue("default_config"); var result = client.ExecuteStore(StoreMode.Add, kv.Item1, kv.Item2); Assert.That(result.Success, Is.True, "Store failed: " + result.Message); var value = client.Get(kv.Item1); Assert.That(value, Is.StringMatching(kv.Item2)); }
public void When_Creating_New_Bucket_Item_Counts_Are_Set_On_Basic_Stats() { var bucketName = "Bucket-" + DateTime.Now.Ticks; _bucket = new Bucket { Name = bucketName, AuthType = AuthTypes.Sasl, BucketType = BucketTypes.Membase, Quota = new Quota {RAM = 100}, ReplicaNumber = ReplicaNumbers.Zero }; Cluster.CreateBucket(_bucket); _bucket = waitForListedBucket(bucketName); Assert.That(_bucket, Is.Not.Null, "New bucket was null"); var count = _bucket.BasicStats.ItemCount; Assert.That(count, Is.EqualTo(0), "Item count was not 0"); var client = new CouchbaseClient(bucketName, ""); var result = false; for(var i = 0; i < 10; i++) { var aResult = client.ExecuteStore(StoreMode.Set, "a", "a"); var bResult = client.ExecuteStore(StoreMode.Set, "b", "b"); var cResult = client.ExecuteStore(StoreMode.Set, "c", "c"); result = aResult.Success & bResult.Success & cResult.Success; if (result) break; Thread.Sleep(2000); //wait for the bucket to be ready for writing } Assert.That(result, Is.True, "Store operations failed"); for (var i = 0; i < 10; i++) { _bucket = Cluster.ListBuckets().Where(b => b.Name == bucketName).FirstOrDefault(); count = _bucket.BasicStats.ItemCount; if (count == 3) break; Thread.Sleep(2000); //wait for the bucket to compute writes into basic stats } Assert.That(count, Is.EqualTo(3), "Item count was not 3"); Cluster.DeleteBucket(bucketName); _bucket = waitForListedBucket(bucketName); Assert.That(_bucket, Is.Null, "Deleted bucket still exists"); }
static void Main(string[] args) { Options options = new Options(); CommandLineParserSettings parserSettings = new CommandLineParserSettings(); parserSettings.CaseSensitive = true; CommandLineParser parser = new CommandLineParser(parserSettings); if (!parser.ParseArguments(args, options, Console.Error)) { return; } var config = new CouchbaseClientConfiguration(); config.Bucket = options.Bucket; var url = "http://"; if (!options.Hostname.Contains(":")) { options.Hostname += ":8091"; } url += options.Hostname + "/pools"; config.Urls.Add(new Uri(url)); Console.Error.WriteLine("URL: " + url + ", Bucket: " + config.Bucket); Console.Error.WriteLine("Design: " + options.Design + ", View: " + options.View); CouchbaseClient cli = new CouchbaseClient(config); var res = cli.ExecuteStore(Enyim.Caching.Memcached.StoreMode.Set, "foo", "bar"); Console.WriteLine("Store result ? {0}", res.Success); var view = cli.GetView(options.Design, options.View); if (options.Group) { view.Group(options.Group); } if (options.GroupLevel > 0) { view.GroupAt(options.GroupLevel); } if (options.Range != null) { if (options.Range.Count > 2) { Console.Error.WriteLine("Too many keys in range (use -R for compount keys)"); return; } if (!String.IsNullOrEmpty(options.Range[0])) { view.StartKey(options.Range[0]); } if (!String.IsNullOrEmpty(options.Range[1])) { view.EndKey(options.Range[1]); } } else if (options.CompoundRanges != null) { IList<string> sk = null, ek = null; int firstIx = options.CompoundRanges.IndexOf(":"); if (firstIx == -1) { Console.Error.WriteLine("Malformed compound range"); return; } if (firstIx == 0) { ek = options.CompoundRanges.Skip(1).ToList(); } else if (firstIx == options.CompoundRanges.Count - 1) { sk = options.CompoundRanges.Take( options.CompoundRanges.Count - 1).ToList(); } else { sk = options.CompoundRanges.Take(firstIx).ToList(); ek = options.CompoundRanges.Skip(firstIx + 1).ToList(); } if (sk != null) { Console.Error.WriteLine("Using start key " + new JavaScriptSerializer().Serialize(sk)); view.StartKey(sk); } if (ek != null) { if (ek[0].StartsWith("+")) { ek[0] = new String(ek[0].Skip(1).ToArray()); view.WithInclusiveEnd(true); } Console.Error.WriteLine("Using end key " + new JavaScriptSerializer().Serialize(ek)); view.EndKey(ek); } } if (options.Limit > 0) { view = view.Limit(options.Limit); } if (options.Fresh) { view.Stale(StaleMode.False); } try { DoExecuteView(view); } catch (WebException exc) { Console.WriteLine(exc); } }
public void When_Flushing_Bucket_Data_Are_Removed() { var storedConfig = ConfigurationManager.GetSection("couchbase") as ICouchbaseClientConfiguration; var config = new CouchbaseClientConfiguration(); config.Bucket = "Bucket-" + DateTime.Now.Ticks; config.Username = storedConfig.Username; config.Password = storedConfig.Password; config.Urls.Add(storedConfig.Urls[0]); var cluster = new CouchbaseCluster(config); cluster.CreateBucket(new Bucket { Name = config.Bucket, AuthType = AuthTypes.Sasl, BucketType = BucketTypes.Membase, Quota = new Quota { RAM = 100 }, ReplicaNumber = ReplicaNumbers.Zero, FlushOption = FlushOptions.Enabled } ); for (int i = 0; i < 10; i++) //wait for bucket to be ready to accept ops { _bucket = waitForBucket(config.Bucket); if (_bucket.Nodes.First().Status == "healthy") break; Thread.Sleep(1000); } Assert.That(_bucket, Is.Not.Null); using (var client = new CouchbaseClient(config)) { var storeResult = client.ExecuteStore(StoreMode.Set, "SomeKey", "SomeValue"); Assert.That(storeResult.Success, Is.True, "Message: " + storeResult.Message); var getResult = client.ExecuteGet<string>("SomeKey"); Assert.That(getResult.Success, Is.True); Assert.That(getResult.Value, Is.StringMatching("SomeValue")); cluster.FlushBucket(config.Bucket); getResult = client.ExecuteGet<string>("SomeKey"); Assert.That(getResult.Success, Is.False); Assert.That(getResult.Value, Is.Null); } }