コード例 #1
0
ファイル: IndexationTests.cs プロジェクト: tryadiadi/ravendb
        public void IndexerTest()
        {
            using (var store = NewDocumentStore(requestedStorage: "esent", configureStore: s => s.Conventions.AcceptGzipContent = false))
            {
                var index = new RavenDocumentsByEntityName();
                index.Execute(store);

                var tasks = new List <Task>();
                for (var i = 1; i <= 20; i++)
                {
                    var taskNumber = i;
                    tasks.Add(Save(store, taskNumber));
                }

                Task.WaitAll(tasks.ToArray());

                WaitForIndexing(store);

                Assert.Equal(20000, store.DatabaseCommands.GetStatistics().CountOfDocuments);

                using (var session = store.OpenSession())
                {
                    var count = session.Query <Person>(index.IndexName)
                                .Customize(x => x.WaitForNonStaleResults())
                                .Count();

                    Assert.Equal(20000, count);
                }
            }
        }
コード例 #2
0
        public async Task <long> StoreDataAsNew(T[] data)
        {
            var sw = new Stopwatch();

            sw.Start();

            DeleteData();
            await CreateDatabase();

            //using (var instance = ConnectInstance(DatabaseName()))
            {
                using (var bulkInsert = instanceDefault.BulkInsert(DatabaseName()))
                {
                    foreach (var id in data)
                    {
                        bulkInsert.Store(id, id.ID);
                    }
                }

                var dbc      = instanceDefault.DatabaseCommands.ForDatabase(DatabaseName());
                var defIndex = new RavenDocumentsByEntityName();

                defIndex.Execute(dbc, new DocumentConvention()
                {
                    DefaultUseOptimisticConcurrency = true
                });
                instanceDefault.ExecuteIndex(defIndex);
            }
            sw.Stop();

            await Task.Delay(2000);//to can retrieve after

            return(sw.ElapsedMilliseconds);
        }
コード例 #3
0
ファイル: RavenDB_4269.cs プロジェクト: xinix00/ravendb
        public void AddingMultipleSideBySideIndexesShouldSetValidPriority()
        {
            using (var store = NewDocumentStore())
            {
                var definition = new RavenDocumentsByEntityName().CreateIndexDefinition();

                var indexesToAdd = new List <IndexToAdd>();
                indexesToAdd.Add(new IndexToAdd
                {
                    Name       = "Index1",
                    Definition = definition,
                    Priority   = IndexingPriority.Error
                });

                indexesToAdd.Add(new IndexToAdd
                {
                    Name       = "Index2",
                    Definition = definition,
                    Priority   = IndexingPriority.Idle
                });

                store.DatabaseCommands.Admin.StopIndexing();
                store.DatabaseCommands.PutSideBySideIndexes(indexesToAdd.ToArray());

                var i1 = store.DocumentDatabase.IndexStorage.GetIndexInstance("Index1");
                var i2 = store.DocumentDatabase.IndexStorage.GetIndexInstance("Index2");

                Assert.Equal(IndexingPriority.Error, i1.Priority);
                Assert.Equal(IndexingPriority.Idle, i2.Priority);
            }
        }
コード例 #4
0
        public IEnumerable <T> RetrieveData()
        {
            if (!ExistsData())
            {
                yield break;
            }


            //using (var instance = ConnectInstance(DatabaseName()))
            {
                var config = instanceDefault.DatabaseCommands.ForDatabase(DatabaseName()).Admin.GetDatabaseConfiguration();
                using (var session = instanceDefault.OpenSession(DatabaseName()))
                {
                    session.Advanced.UseOptimisticConcurrency = true;
                    var indexName = new RavenDocumentsByEntityName().IndexName;

                    var query = session.Query <T>(indexName);
                    using (var res = session.Advanced.Stream(query))
                    {
                        while (res.MoveNext())
                        {
                            yield return(res.Current.Document);
                        }
                    }
                }
            }
        }
コード例 #5
0
        private void DeleteIndex(string deleteItems)
        {
            var ravenDocumentsByEntityNameIndexName = new RavenDocumentsByEntityName().IndexName;
            var tasks = (from indexListItem in model.IndexesOfPriority(deleteItems)
                         select indexListItem.Name
                         into indexName
                         where indexName != ravenDocumentsByEntityNameIndexName
                         select new { Task = DatabaseCommands.DeleteIndexAsync(indexName), Name = indexName }).ToArray();

            Task.Factory.ContinueWhenAll(tasks.Select(x => x.Task).ToArray(), taskslist =>
            {
                foreach (var task in taskslist)
                {
                    var indexName = tasks.First(x => x.Task == task).Name;
                    if (task.IsFaulted)
                    {
                        ApplicationModel.Current.AddErrorNotification(task.Exception, "index " + indexName + " could not be deleted");
                    }
                    else
                    {
                        ApplicationModel.Current.AddInfoNotification("Index " + indexName + " successfully deleted");
                        var deletedItem = model.GroupedIndexes.OfType <IndexItem>().FirstOrDefault(item => item.Name == indexName);
                        model.GroupedIndexes.Remove(deletedItem);
                    }
                }

                UrlUtil.Navigate("/indexes");
            });
        }
コード例 #6
0
        public void SilverlightWasRequested(DocumentDatabase database)
        {
            var ravenDocumentsByEntityName = new RavenDocumentsByEntityName {
            };

            database.Indexes.PutIndex(Constants.DocumentsByEntityNameIndex,
                                      ravenDocumentsByEntityName.CreateIndexDefinition());
        }
コード例 #7
0
ファイル: ResettingIndex.cs プロジェクト: xinix00/ravendb
 public void CanResetIndex()
 {
     using (var store = NewDocumentStore())
     {
         var ravenDocumentsByEntityName = new RavenDocumentsByEntityName();
         ravenDocumentsByEntityName.Execute(store);
         store.SystemDatabase.Indexes.ResetIndex(ravenDocumentsByEntityName.IndexName);
     }
 }
コード例 #8
0
 public void CanResetIndexInMuninStorage()
 {
     using (var store = NewDocumentStore("munin", false))
     {
         var ravenDocumentsByEntityName = new RavenDocumentsByEntityName();
         ravenDocumentsByEntityName.Execute(store);
         store.DocumentDatabase.ResetIndex(ravenDocumentsByEntityName.IndexName);
     }
 }
コード例 #9
0
        public void StreamQueryShouldHandleFailover()
        {
            var index = new RavenDocumentsByEntityName();

            using (var store1 = CreateStore(configureStore: store => store.Conventions.FailoverBehavior = FailoverBehavior.AllowReadsFromSecondaries))
                using (var store2 = CreateStore())
                {
                    TellFirstInstanceToReplicateToSecondInstance();

                    var replicationInformerForDatabase = store1.GetReplicationInformerForDatabase(store1.DefaultDatabase);
                    replicationInformerForDatabase.ClearReplicationInformationLocalCache((ServerClient)store1.DatabaseCommands);
                    replicationInformerForDatabase.RefreshReplicationInformation((ServerClient)store1.DatabaseCommands);

                    var people       = InitializeData(store1);
                    var lastPersonId = people.Last().Id;

                    WaitForIndexing(store1);
                    WaitForReplication(store2, lastPersonId);
                    WaitForIndexing(store2);

                    var count = 0;
                    QueryHeaderInformation queryHeaderInfo;
                    var enumerator = store1.DatabaseCommands.StreamQuery(index.IndexName, new IndexQuery(), out queryHeaderInfo);
                    while (enumerator.MoveNext())
                    {
                        count++;
                    }

                    Assert.Equal(10, count);

                    count      = 0;
                    enumerator = store2.DatabaseCommands.StreamQuery(index.IndexName, new IndexQuery(), out queryHeaderInfo);
                    while (enumerator.MoveNext())
                    {
                        count++;
                    }

                    Assert.Equal(10, count);

                    StopDatabase(0);

                    count = 0;

                    var failed = false;

                    replicationInformerForDatabase.FailoverStatusChanged += (sender, args) => failed = true;
                    enumerator = store1.DatabaseCommands.StreamQuery(index.IndexName, new IndexQuery(), out queryHeaderInfo);
                    while (enumerator.MoveNext())
                    {
                        count++;
                    }

                    Assert.Equal(10, count);
                    Assert.True(failed);
                }
        }
コード例 #10
0
        private void DeleteIndex(string deleteItems)
        {
            var ravenDocumentsByEntityNameIndexName = new RavenDocumentsByEntityName().IndexName;
            var indexes = (from indexListItem in model.IndexesOfPriority(deleteItems)
                           where indexListItem.Name != ravenDocumentsByEntityNameIndexName
                           select indexListItem.Name);


            DeleteIndexes(indexes);
        }
コード例 #11
0
ファイル: IndexationTests.cs プロジェクト: tryadiadi/ravendb
        public void ReducerTest()
        {
            using (var store = NewDocumentStore(requestedStorage: "esent", configureStore: documentStore => documentStore.Conventions.AcceptGzipContent = false))
            {
                var index1 = new RavenDocumentsByEntityName();
                index1.Execute(store);
                var index2 = new PersonCount();
                index2.Execute(store);

                var tasks = new List <Task>();
                for (var i = 1; i <= 20; i++)
                {
                    var taskNumber = i;
                    tasks.Add(Save(store, taskNumber));
                }

                Task.WaitAll(tasks.ToArray());

                WaitForIndexing(store, timeout: TimeSpan.FromMinutes(1));

                Assert.Equal(20000, store.DatabaseCommands.GetStatistics().CountOfDocuments);

                using (var session = store.OpenSession())
                {
                    var count = session.Query <Person>(index1.IndexName)
                                .Customize(x => x.WaitForNonStaleResults())
                                .Count();

                    Assert.Equal(20000, count);

                    var results = session.Query <PersonCount.ReduceResult, PersonCount>()
                                  .Customize(customization => customization.WaitForNonStaleResults())
                                  .Take(1001)
                                  .ToList();


                    WaitForUserToContinueTheTest(store);

                    Assert.Equal(1000, results.Count);

                    foreach (var result in results)
                    {
                        Assert.Equal(20, result.Count);
                    }
                }
            }
        }
コード例 #12
0
        public void Reset_index_in_database_with_replication_should_not_corrupt_etag_indice()
        {
            var sb = new StringBuilder();

            for (int i = 0; i < 1000; i++)
            {
                sb.Append(Guid.NewGuid());
            }
            var aLongString = sb.ToString();

            using (var store = NewDocumentStore())
            {
                var ravenDocumentsByEntityName = new RavenDocumentsByEntityName();
                ravenDocumentsByEntityName.Execute(store);

                using (var operation = store.BulkInsert(options: new BulkInsertOptions
                {
                    BatchSize = 1
                }))
                {
                    for (int i = 0; i < 10; i++)
                    {
                        operation.Store(new { Foo = aLongString }, "Foo/" + i);
                    }
                }
                WaitForIndexing(store);

                using (var session = store.OpenSession())
                {
                    var count = session.Query <dynamic>().Count();
                    Assert.Equal(10, count);
                }

                store.SystemDatabase.Indexes.ResetIndex(ravenDocumentsByEntityName.IndexName);

                WaitForIndexing(store);

                using (var session = store.OpenSession())
                {
                    var count  = session.Query <dynamic>().Count();
                    var errors = store.DatabaseCommands.GetStatistics().Errors;
                    Assert.Empty(errors);
                    Assert.Equal(10, count);
                }
            }
        }
コード例 #13
0
        public override void Execute(object parameter)
        {
            var group = model.SelectedGroup;

            if (group != null)
            {
                var ravenDocumentsByEntityNameIndexName = new RavenDocumentsByEntityName().IndexName;
                AskUser.ConfirmationAsync("Confirm Delete",
                                          string.Format("Are you sure that you want to delete all indexes in the group {0}?", group.GroupName))
                .ContinueWhenTrue(() => DeleteIndexes(group.Items.Select(item => item.Name).Where(indexName => indexName != ravenDocumentsByEntityNameIndexName)));
            }
            else
            {
                var deleteItems = parameter as string;
                AskUser.ConfirmationAsync("Confirm Delete",
                                          string.Format("Are you sure that you want to delete all " + deleteItems + " indexes?"))
                .ContinueWhenTrue(() => DeleteIndex(deleteItems));
            }
        }