public void Test_Peek() { var key = "CouchbaseQueueTests.Test_Peek"; _bucket.Remove(key); var queue = new CouchbaseQueue <Poco>(_bucket, key); queue.Enqueue(new Poco { Name = "pcoco1" }); queue.Enqueue(new Poco { Name = "pcoco2" }); queue.Enqueue(new Poco { Name = "pcoco3" }); var item = queue.Peek(); Assert.AreEqual("pcoco1", item.Name); var items = _bucket.Get <List <Poco> >(key).Value; Assert.AreEqual(3, items.Count); }
public void Test_Peek() { var key = "CouchbaseQueueTests.Test_Peek"; _bucket.Remove(key); var queue = new CouchbaseQueue<Poco>(_bucket, key); queue.Enqueue(new Poco { Name = "pcoco1" }); queue.Enqueue(new Poco { Name = "pcoco2" }); queue.Enqueue(new Poco { Name = "pcoco3" }); var item = queue.Peek(); Assert.AreEqual("pcoco1", item.Name); var items = _bucket.Get<List<Poco>>(key).Value; Assert.AreEqual(3, items.Count); }
public void Test_Enqueue() { var key = "CouchbaseQueueTests.Test_Enqueue"; _bucket.Remove(key); var queue = new CouchbaseQueue<Poco>(_bucket, "CouchbaseQueueTests.Test_Enqueue"); queue.Enqueue(new Poco {Name = "pcoco"}); var items = _bucket.Get<List<Poco>>(key).Value; Assert.AreEqual(1, items.Count); }
private static void QueueDemo(IBucket bucket) { //var orders = new Queue<PizzaOrder>(); var orders = new CouchbaseQueue <PizzaOrder>(bucket, "Queue_PizzaOrders"); orders.Clear(); orders.Enqueue(new PizzaOrder { Name = "Matt", OrderNumber = 1, OrderTime = DateTime.Now.AddMinutes(-10) }); orders.Enqueue(new PizzaOrder { Name = "Ali", OrderNumber = 2, OrderTime = DateTime.Now.AddMinutes(-5) }); var order1 = orders.Dequeue(); Console.WriteLine($"Order #{order1.OrderNumber} completed for: {order1.Name}"); orders.Enqueue(new PizzaOrder { Name = "Caesar", OrderNumber = 3, OrderTime = DateTime.Now }); Console.WriteLine($"There are {orders.Count} orders left in the queue."); }
public void Test_Enqueue() { var key = "CouchbaseQueueTests.Test_Enqueue"; _bucket.Remove(key); var queue = new CouchbaseQueue <Poco>(_bucket, "CouchbaseQueueTests.Test_Enqueue"); queue.Enqueue(new Poco { Name = "pcoco" }); var items = _bucket.Get <List <Poco> >(key).Value; Assert.AreEqual(1, items.Count); }
public static void Main(string[] args) { ClusterHelper.Initialize(new ClientConfiguration { Servers = new List <Uri> { new Uri("couchbase://localhost") } }); var bucket = ClusterHelper.GetBucket("data-structures"); // creates list document or uses existing list document // tag::createlist[] var list = new CouchbaseList <dynamic>(bucket, "myList"); // end::createlist[] // tag::examplesoflist[] // add 10 objects to the list for (var i = 0; i < 10; i++) { list.Add(new { num = i, foo = "bar" + Guid.NewGuid() }); } // remove an item from the list by index list.RemoveAt(5); // show an item from the list by index var item = list[5]; Console.WriteLine("6th item in the list: " + item.foo + " / " + item.num); // end::examplesoflist[] // --- queue Console.WriteLine(); // creates queue document or uses existing queue document // tag::createqueue[] var queue = new CouchbaseQueue <dynamic>(bucket, "myQueue"); // end::createqueue[] // tag::queueexample[] for (var i = 0; i < 3; i++) { queue.Enqueue(new { num = i, foo = "baz" + Guid.NewGuid() }); } // dequeue var item = queue.Dequeue(); Console.WriteLine("item num " + item.num + " was dequeued. There are now " + queue.Count + " items left in the queue."); // end::queueexample[] // --- dictionary Console.WriteLine(); // creates dictionary document or uses existing dictionary document // tag::createdict[] var dict = new CouchbaseDictionary <string, dynamic>(bucket, "myDict"); // end::createdict[] // add 5 k/v pairs to the dictionary // tag::dictexample[] for (var i = 0; i < 5; i++) { dict.Add("key" + Guid.NewGuid(), new { num = i, foo = "qux" + Guid.NewGuid() }); } // print out keys in the dictionary Console.WriteLine("There are " + dict.Keys.Count + " keys in the dictionary."); foreach (var key in dict.Keys) { Console.WriteLine("key: " + key + ", value.num: " + dict[key].num); } // end::dictexample[] ClusterHelper.Close(); }