예제 #1
0
        private Task <List <NodeData> > GetEntities(string filter)
        {
            var query = _bucket.CreateQuery("entities", "all").GroupLevel(2);

            if (!string.IsNullOrEmpty(filter))
            {
                query = query.StartKey(new string[] { filter, null }).EndKey(new string[] { filter, "\uefff" }).InclusiveEnd(true);
            }

            return(_bucket.QueryAsync <dynamic>(query).ContinueWith(t =>
            {
                if (!string.IsNullOrEmpty(t.Result.Error))
                {
                    Console.WriteLine(t.Result.Error.ToString());
                }
                if (t.Result.Exception != null)
                {
                    Console.WriteLine(t.Result.Exception.ToString());
                }

                return t.Result.Rows.Select(row => new NodeData {
                    Key = row.Key[0], Type = row.Key[1]
                }).ToList();
            }));
        }
예제 #2
0
        public void Test_QueryNoDeadlock()
        {
            // Using an asynchronous HttpClient request within an MVC Web API action may cause
            // a deadlock when we wait for the result synchronously.

            var context = new Mock <SynchronizationContext>
            {
                CallBase = true
            };

            SynchronizationContext.SetSynchronizationContext(context.Object);
            try
            {
                var query = _bucket.CreateQuery("beer", "brewery_beers")
                            .Limit(1);

                _bucket.Query <dynamic>(query);

                // If view queries are incorrectly awaiting on the current SynchronizationContext
                // We will see calls to Post or Send on the mock

                context.Verify(m => m.Post(It.IsAny <SendOrPostCallback>(), It.IsAny <object>()), Times.Never);
                context.Verify(m => m.Send(It.IsAny <SendOrPostCallback>(), It.IsAny <object>()), Times.Never);
            }
            finally
            {
                SynchronizationContext.SetSynchronizationContext(null);
            }
        }
예제 #3
0
        public void Test_QueryAsyncNoDeadlock()
        {
            // NCBC-1074 https://issues.couchbase.com/browse/NCBC-1074
            // Using an asynchronous view query within an MVC Web API action causes
            // a deadlock if you wait for the result synchronously.

            var context = new Mock <SynchronizationContext>
            {
                CallBase = true
            };

            SynchronizationContext.SetSynchronizationContext(context.Object);
            try
            {
                var query = _bucket.CreateQuery("beer", "brewery_beers")
                            .Limit(1);

                _bucket.QueryAsync <object>(query).Wait();

                // If view queries are incorrectly awaiting on the current SynchronizationContext
                // We will see calls to Post or Send on the mock

                context.Verify(m => m.Post(It.IsAny <SendOrPostCallback>(), It.IsAny <object>()), Times.Never);
                context.Verify(m => m.Send(It.IsAny <SendOrPostCallback>(), It.IsAny <object>()), Times.Never);
            }
            finally
            {
                SynchronizationContext.SetSynchronizationContext(null);
            }
        }
예제 #4
0
        public List <string> getDeleteDocIdsFromView()
        {
            List <string> docIds = new List <string>();

            for (int j = 1; j <= 30; j++)
            {
                string dateNumber = "" + j;
                if (j < 10)
                {
                    dateNumber = "0" + j;
                }
                object[] sldkf = new object[2];
                sldkf[0] = 6;
                sldkf[1] = "2015-09-" + dateNumber;
                var query = bucket.CreateQuery("testing", "test", true);
                query.StartKey(sldkf);
                query.EndKey(sldkf);
                var result = bucket.Query <dynamic>(query);
                if (result.Rows.Count() > 0)
                {
                    for (int i = 0; i < result.Rows.Count(); i++)
                    {
                        string rw       = result.Rows.ElementAt(i).Value;
                        string sendData = result.Rows.ElementAt(i).Id;
                        docIds.Add(deleteExtraDoc(sendData + "?rev=" + rw));
                    }
                }
            }
            return(docIds);
        }
예제 #5
0
        public void Submitting_View_Query_To_Ephemeral_Bucket_Fails()
        {
            var viewQuery = _bucket.CreateQuery("designDoc", "viewName");
            var result    = _bucket.Query <dynamic>(viewQuery);

            Assert.IsFalse(result.Success);
            Assert.AreEqual(result.Error, ExceptionUtil.EphemeralBucketViewQueries);
        }
예제 #6
0
        static void BasicQuery(IBucket bucket)
        {
            var query = bucket.CreateQuery("beer", "brewery_beers").
                Limit(5);

            var result = bucket.Query<dynamic>(query);
            foreach (var row in result.Rows)
            {
                Console.WriteLine(row);
            }
        }
예제 #7
0
        static void BasicQuery(IBucket bucket)
        {
            var query = bucket.CreateQuery("beer", "brewery_beers").
                        Limit(5);

            var result = bucket.Query <dynamic>(query);

            foreach (var row in result.Rows)
            {
                Console.WriteLine(JsonConvert.SerializeObject(row));
            }
        }
        public override IEnumerable <KeyValuePair <long, Tick> > Read()
        {
            IBucket    bucket = buckets[0];
            IViewQuery query  = bucket.CreateQuery(DocDesignName, ViewName, false).Asc();

            foreach (var item in buckets[0].Query <dynamic>(query).Rows)
            {
                long key    = Int64.Parse(item.Key.ToString());
                Tick record = item.Value;

                yield return(new KeyValuePair <long, Tick>(key, record));
            }
        }
        public async Task <IEnumerable <string> > ReadFrom(Guid grainId, ulong eventId = 0)
        {
            //if (!hasDesignDoc)
            //{
            //    Test();
            //    var designDoc = bucketManager.GetDesignDocument(DESGIN_DOC_NAME);
            //    if (!designDoc.Success)
            //    {
            //        var createResult = bucketManager.InsertDesignDocument(DESGIN_DOC_NAME, desginDoc);
            //        if (createResult.Success) hasDesignDoc = true;
            //    }
            //}

            var startKey = new object[] { grainId.ToString(), eventId };
            var endKey   = new object[] { grainId.ToString(), int.MaxValue };
            var query    = _bucket.CreateQuery(DESGIN_DOC_NAME, VIEW_NAME)
                           .StartKey(startKey)
                           .EndKey(endKey);

            var result = new List <string>();

            var indexs = await _bucket.QueryAsync <dynamic>(query);

            var keys = indexs.Rows.Select(r => r.Id).ToList();

            if (keys.Count > 0)
            {
                var events = _bucket.Get <string>(keys);

                if (events.Count(e => e.Value.Success) == keys.Count)
                {
                    result = events.Select(et => et.Value.Value).ToList();
                }
                else
                {
                    throw new Exception("read from event store exception", events.Select(et => et.Value.Exception).FirstOrDefault());
                }
            }

            return(result);
        }
        private IEnumerable <QvxDataRow> GetEntities(string entityName)
        {
            var entityMap = _models.ToLookup(e => e.Name);

            int         limit  = PageSize;
            int         offset = 0;
            int         rows   = 0;
            EntityModel model;
            List <Task <QvxDataRow> > tasks;

            do
            {
                tasks = new List <Task <QvxDataRow> >();
                var query    = _bucket.CreateQuery("entities", "raw").Reduce(false).Limit(limit).Skip(offset);
                var result   = _bucket.Query <dynamic>(query);
                var entities = new List <Dictionary <string, object> >();

                rows = result.Rows.Count();
                foreach (var row in result.Rows)
                {
                    var id = row.Id;
                    model = entityMap[entityName].FirstOrDefault();

                    tasks.Add(MakeEntry(id, model, FindTable(entityName, MTables)));
                }

                Task.WaitAll(tasks.ToArray());
                foreach (var t in tasks)
                {
                    if (t.Result != null)
                    {
                        yield return(t.Result);
                    }
                }

                offset += rows;
            }while (rows > 0);
        }
예제 #11
0
        private static async void DemoQueryUserByDate()
        {
            var from = DateTime.ParseExact("01/01/1980", "dd/MM/yyyy", CultureInfo.InvariantCulture);
            var to   = DateTime.ParseExact("31/12/1984", "dd/MM/yyyy", CultureInfo.InvariantCulture);

            var viewQuery = bucket.CreateQuery(DDOC_PERSONS, VIEW_BYBIRTHDAY).Reduce(false);

            var startKey = QueryHelper.ToDateArray(from);
            var endKey   = QueryHelper.ToDateArray(to);

            viewQuery.StartKey(startKey);
            viewQuery.EndKey(endKey);

            var result = await bucket.QueryAsync <dynamic>(viewQuery);

            Console.WriteLine("Query user by date");
            Console.WriteLine("====================");

            foreach (var row in result.Rows)
            {
                var user = bucket.Get <string>(row.Id);
                Console.WriteLine(row.Id + "::" + user.Value);
            }
        }
        public override void Init(int flowCount, long flowRecordCount)
        {
            buckets = new IBucket[flowCount];

            ClientConfiguration client = new ClientConfiguration();

            client.Servers.Add(new Uri(ConnectionString));

            cluster = new Cluster(client);

            for (int i = 0; i < flowCount; i++)
            {
                buckets[i] = cluster.OpenBucket(CollectionName);
            }

            IBucket    bucket = buckets[0];
            IViewQuery query  = bucket.CreateQuery(DocDesignName, ViewName, false);

            // TODO: find a faster way for dropping the database.
            foreach (var item in buckets[0].Query <dynamic>(query).Rows)
            {
                buckets[0].Remove(item.Key.ToString());
            }
        }
 public void When_CreateQuery_Called_On_Memcached_Bucket_NotSupportedException_Is_Thrown()
 {
     Assert.Throws <NotSupportedException>(() => _bucket.CreateQuery("designdoc", "view", true));
 }