Ejemplo n.º 1
0
        public Artist[] Init(TestEnvironment environment)
        {
            if (_artists != null && _artists.Any())
            {
                return(_artists);
            }

            IntegrationTestsRuntime.EnsureCleanEnvironment();

            _artists = ClientTestData.Artists.CreateArtists(10);

            using (var client = IntegrationTestsRuntime.CreateDbClient())
            {
                var bulk = new BulkRequest();
                bulk.Include(_artists.Select(i => client.Entities.Serializer.Serialize(i)).ToArray());

                var bulkResponse = client.Documents.BulkAsync(bulk).Result;

                foreach (var row in bulkResponse.Rows)
                {
                    var artist = _artists.Single(i => i.ArtistId == row.Id);
                    client.Entities.Reflector.RevMember.SetValueTo(artist, row.Rev);
                }

                client.Documents.PostAsync(ClientTestData.Views.ArtistsViews).Wait();

                var queryRequests = ClientTestData.Views.AllViewIds.Select(id => new QueryViewRequest(id).Configure(q => q.Stale(Stale.UpdateAfter)));
                var queries       = queryRequests.Select(q => client.Views.QueryAsync(q) as Task).ToArray();
                Task.WaitAll(queries);
            }

            return(_artists);
        }
Ejemplo n.º 2
0
        public Artist[] Init(TestEnvironment environment)
        {
            if (_artists != null && _artists.Any())
            {
                return(_artists);
            }

            IntegrationTestsRuntime.EnsureCleanEnvironment();

            _artists = ClientTestData.Artists.CreateArtists(2);

            using (var client = IntegrationTestsRuntime.CreateDbClient())
            {
                var bulk = new BulkRequest();
                bulk.Include(_artists.Select(i => client.Entities.Serializer.Serialize(i)).ToArray());

                var bulkResponse = client.Documents.BulkAsync(bulk).Result;

                foreach (var row in bulkResponse.Rows)
                {
                    var artist = _artists.Single(i => i.ArtistId == row.Id);
                    client.Entities.Reflector.RevMember.SetValueTo(artist, row.Rev);
                }

                client.Documents.PostAsync(ClientTestData.Shows.ArtistsShows).Wait();
            }

            return(_artists);
        }
Ejemplo n.º 3
0
        public ViewsFixture()
        {
            Artists = ClientTestData.Artists.CreateArtists(10);

            using (var client = IntegrationTestsRuntime.CreateNormalClient())
            {
                var bulk = new BulkRequest();
                bulk.Include(Artists.Select(i => client.Entities.Serializer.Serialize(i)).ToArray());

                var bulkResponse = client.Documents.BulkAsync(bulk).Result;

                foreach (var row in bulkResponse.Rows)
                {
                    var artist = Artists.Single(i => i.ArtistId == row.Id);
                    client.Entities.Reflector.RevMember.SetValueTo(artist, row.Rev);
                }

                var tmp = client.Documents.PostAsync(ClientTestData.Views.ArtistsViews).Result;

                var touchView1 = new QueryViewRequest(ClientTestData.Views.ArtistsAlbumsViewId).Configure(q => q.Stale(Stale.UpdateAfter));
                var touchView2 = new QueryViewRequest(ClientTestData.Views.ArtistsNameNoValueViewId).Configure(q => q.Stale(Stale.UpdateAfter));
                var touchView3 = new QueryViewRequest(ClientTestData.Views.ArtistsTotalNumOfAlbumsViewId).Configure(q => q.Stale(Stale.UpdateAfter));

                client.Views.QueryAsync(touchView1).Wait();
                client.Views.QueryAsync(touchView2).Wait();
                client.Views.QueryAsync(touchView3).Wait();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Bulks the async.
        /// </summary>
        /// <returns>The async.</returns>
        /// <param name="ideasJson">Ideas json.</param>
        public async Task BulkAsync(List <string> ideasJson)
        {
            var request = new BulkRequest();

            request.Include(ideasJson.ToArray());
            var response = await Documents.BulkAsync(request);
        }
Ejemplo n.º 5
0
        public SearchFixture()
        {
            Animals = CloudantTestData.Animals.CreateAll();

            Client = IntegrationTestsRuntime.CreateCloudantClient();

            var bulk = new BulkRequest();

            bulk.Include(Animals.Select(i => Client.Entities.Serializer.Serialize(i)).ToArray());

            var bulkResponse = Client.Documents.BulkAsync(bulk).Result;

            foreach (var row in bulkResponse.Rows)
            {
                var animal = Animals.Single(i => i.AnimalId == row.Id);
                Client.Entities.Reflector.RevMember.SetValueTo(animal, row.Rev);
            }

            Client.Documents.PostAsync(CloudantTestData.Views.Views101).Wait();

            var queries = CloudantTestData.Views.AllViewIds.Select(id => new QueryViewRequest(id).Configure(q => q.Stale(Stale.UpdateAfter)));

            foreach (var query in queries)
            {
                Client.Views.QueryAsync(query).Wait();
            }
        }
Ejemplo n.º 6
0
        private void InsertIntoCouchDB(string databaseName, string tableName, List <DatabaseRecord> rows, RowTransformer rowTransformer)
        {
            const int chunkSize = 1000;

            using (var client = new MyCouchClient(CouchDbUrl, databaseName))
            {
                Parallel.ForEach(rows.Chunk(chunkSize), new ParallelOptions {
                    MaxDegreeOfParallelism = 20
                }, chunkEnumerable =>
                {
                    var chunk = chunkEnumerable.ToArray();
                    IEnumerable <DatabaseRecord> transformedChunk;

                    if (rowTransformer == null)
                    {
                        transformedChunk = chunk;
                    }
                    else
                    {
                        transformedChunk = chunk.Select(row => rowTransformer(tableName, row));
                    }

                    var documents = transformedChunk.Select(JsonConvert.SerializeObject).ToArray();

                    var request = new BulkRequest();
                    request.Include(documents);

                    client.Documents.BulkAsync(request).Wait();
                });
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Bulks the async.
        /// </summary>
        /// <returns>The async.</returns>
        /// <param name="items">Ideas json.</param>
        public TaskResult BulkAsync(List <string> items)
        {
            Logger.Info($"performing bulk imports for broker transaction total: {items.Count}");
            var request = new BulkRequest();

            request.Include(items.ToArray());
            var response = Documents.BulkAsync(request);

            Logger.Info($"operaton reason: {response.Result.StatusCode}");
            return(new TaskResult());
        }
        /// <summary>
        /// Bulks the async.
        /// </summary>
        /// <returns>The async.</returns>
        /// <param name="imports">Ideas json.</param>
        public async Task <Result> BulkAsync(List <string> imports)
        {
            Logger.Info($"performing bulk imports for broker transaction total: {imports.Count}");
            var request = new BulkRequest();

            request.Include(imports.ToArray());
            var response = await Documents.BulkAsync(request);

            Logger.Info($"operaton reason: {response.Reason}");
            return(new TaskResult {
                IsSuccessful = true
            });
        }
        /// <summary>
        /// Add the specified ideas.
        /// </summary>
        /// <returns>The add.</returns>
        /// <param name="ideas">Ideas.</param>
        public async Task <Result> BulkAsync(List <string> ideasJson)
        {
            var request = new BulkRequest();

            request.Include(ideasJson.ToArray());
            var response = await Documents.BulkAsync(request);

            return(new TaskResult
            {
                IsSuccessful = response.IsSuccess,
                StatusCode = response.StatusCode.ToString(),
                Reason = response.Reason
            });
        }
        /// <summary>
        /// Bulks the insert.
        /// </summary>
        /// <param name="transactions">Transactions.</param>
        public async Task <Result> BulkAsync(List <string> transactions)
        {
            var request = new BulkRequest();

            request.Include(transactions.ToArray());
            var response = await Documents.BulkAsync(request);

            Logger.Info("bulk transaction opeartion completed.");
            var taskResult = new TaskResult {
                IsSuccessful = true
            };

            taskResult.SetData(response);
            return(taskResult);
        }
Ejemplo n.º 11
0
        internal void Init(TestEnvironment environment)
        {
            if (_blogs != null && _blogs.Any())
            {
                return;
            }

            IntegrationTestsRuntime.EnsureCleanEnvironment();

            _blogs = CloudantTestData.Blogs.CreateAll();

            using (var client = IntegrationTestsRuntime.CreateDbClient())
            {
                var bulk = new BulkRequest();
                bulk.Include(_blogs.Select(i => client.Entities.Serializer.Serialize(i)).ToArray());

                var bulkResponse = client.Documents.BulkAsync(bulk).Result;

                CreateIndex1(client);
                CreateIndex2(client);
            }
        }
Ejemplo n.º 12
0
        public async Task <BatchResponse> Store(string bucketName, BatchSet batch)
        {
            using (var client = new MyCouchClient(DbServerUrl, bucketName))
            {
                var dbExists = await client.Database.HeadAsync();

                if (dbExists.IsSuccess)
                {
                    BulkRequest bulkRequest = new BulkRequest();

                    DateTime        start = DateTime.Now;
                    int             size  = 0;
                    SiaqodbDocument crObjForUpdateViews = null;
                    if (batch.ChangedDocuments != null)
                    {
                        foreach (SiaqodbDocument obj in batch.ChangedDocuments)
                        {
                            if (obj != null)
                            {
                                if (crObjForUpdateViews == null)
                                {
                                    crObjForUpdateViews = obj;
                                }

                                await CheckTagsViews(client, bucketName, obj.Tags);

                                CouchDBDocument doc = Mapper.ToCouchDBDoc(obj);
                                var             serializedObject = client.Serializer.Serialize <CouchDBDocument>(doc);
                                bulkRequest.Include(serializedObject);
                                size += serializedObject.Length;
                            }
                        }
                    }
                    if (batch.DeletedDocuments != null)
                    {
                        foreach (DeletedDocument obj in batch.DeletedDocuments)
                        {
                            if (obj != null)
                            {
                                if (obj.Version != null)//otherwise means is a non-existing object
                                {
                                    bulkRequest.Delete(obj.Key, obj.Version);
                                }
                            }
                        }
                    }
                    var response = await client.Documents.BulkAsync(bulkRequest);

                    if (response.IsSuccess)
                    {
                        var cnorResponse = new BatchResponse();
                        if (response.Rows != null)
                        {
                            cnorResponse.BatchItemResponses = new List <BatchItemResponse>();
                            SyncLogItem syncLogItem = new SyncLogItem();
                            syncLogItem.KeyVersion = new Dictionary <string, string>();
                            foreach (var row in response.Rows)
                            {
                                BatchItemResponse wresp = new BatchItemResponse();
                                if (!string.IsNullOrEmpty(row.Error))
                                {
                                    cnorResponse.ItemsWithErrors++;
                                }
                                wresp.Error     = row.Error;
                                wresp.ErrorDesc = row.Reason;
                                wresp.Key       = row.Id;
                                wresp.Version   = row.Rev;
                                cnorResponse.BatchItemResponses.Add(wresp);
                                if (string.IsNullOrEmpty(row.Error))
                                {
                                    syncLogItem.KeyVersion.Add(row.Id, row.Rev);
                                }
                            }
                            if (syncLogItem.KeyVersion.Count > 0)
                            {
                                syncLogItem.TimeInserted = DateTime.UtcNow;
                                using (var clientLog = new MyCouchClient(DbServerUrl, SyncLogBucket))
                                {
                                    string serLogItem = Newtonsoft.Json.JsonConvert.SerializeObject(syncLogItem);
                                    var    logResp    = await clientLog.Documents.PostAsync(serLogItem);

                                    cnorResponse.UploadAnchor = logResp.Id;
                                }
                            }
                        }
                        if (crObjForUpdateViews != null)
                        {
                            await this.StartRebuildViews(client, crObjForUpdateViews);
                        }

                        return(cnorResponse);
                    }
                    else
                    {
                        CheckBucketNotFound(bucketName, response);
                    }
                }
                else if (dbExists.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    throw new BucketNotFoundException(bucketName);
                }
                return(null);
            }
        }