public async Task CanUpdatePatternReferencesCollectionNameWithoutConflicts()
        {
            var cluster = await CreateRaftCluster(numberOfNodes : 3, watcherCluster : true, shouldRunInMemory : false);

            using (var store = GetDocumentStore(new Options {
                Server = cluster.Leader, ReplicationFactor = 3
            }))
            {
                using (var session = store.OpenSession())
                {
                    PutOrders(session);

                    session.SaveChanges();
                }

                var indexToCreate = new Orders_ProfitByProductAndOrderedAt(referencesCollectionName: "Foo");
                await indexToCreate.ExecuteAsync(store);

                WaitForIndexingInTheCluster(store);

                indexToCreate = new Orders_ProfitByProductAndOrderedAt(referencesCollectionName: "Bar");
                await indexToCreate.ExecuteAsync(store);

                WaitForIndexingInTheCluster(store);

                indexToCreate = new Orders_ProfitByProductAndOrderedAt(referencesCollectionName: "Baz");
                await indexToCreate.ExecuteAsync(store);

                WaitForIndexingInTheCluster(store);

                var stats = await store.Maintenance.SendAsync(new GetStatisticsOperation());

                Assert.Equal(0, stats.CountOfRevisionDocuments);
            }
        }
Esempio n. 2
0
        public void ShouldEnsureThatIdsAreUniqueAfterIndexReset()
        {
            using (var store = GetDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(
                        new Order()
                    {
                        OrderedAt = new DateTime(2019, 10, 26),
                        Lines     = new List <OrderLine>()
                        {
                            new OrderLine()
                            {
                                Product = "products/1",
                            }, new OrderLine()
                            {
                                Product = "products/2",
                            }
                        }
                    }, "orders/1");

                    session.SaveChanges();
                }

                var index = new Orders_ProfitByProductAndOrderedAt();
                index.Execute(store);

                Indexes.WaitForIndexing(store);

                store.Maintenance.Send(new ResetIndexOperation(index.IndexName));

                Indexes.WaitForIndexing(store);

                using (var session = store.OpenSession())
                {
                    // 2019-10-26
                    var doc = session.Load <OutputReduceToCollectionReference>("reports/daily/2019-10-26", x => x.IncludeDocuments(y => y.ReduceOutputs));

                    Assert.Equal(2, doc.ReduceOutputs.Count);

                    Orders_ProfitByProductAndOrderedAt.Result output;

                    foreach (var docReduceOutput in doc.ReduceOutputs)
                    {
                        output = session.Load <Orders_ProfitByProductAndOrderedAt.Result>(docReduceOutput);

                        Assert.NotNull(output);
                    }

                    Assert.Equal(new HashSet <string>(doc.ReduceOutputs).Count, doc.ReduceOutputs.Count);
                }
            }
        }
Esempio n. 3
0
        public async Task CanPersistPatternForOutputReduceToCollectionReferences()
        {
            using (var store = GetDocumentStore())
            {
                var indexToCreate = new Orders_ProfitByProductAndOrderedAt();
                indexToCreate.Execute(store);

                var database = await GetDatabase(store.Database);

                var index = database.IndexStore.GetIndexes().First();

                var definition = MapIndexDefinition.Load(index._environment);
                Assert.NotNull(definition.PatternForOutputReduceToCollectionReferences);
            }
        }
Esempio n. 4
0
        public async Task CanPersistPatternForOutputReduceToCollectionReferences()
        {
            using (var store = GetDocumentStore())
            {
                var indexToCreate = new Orders_ProfitByProductAndOrderedAt(referencesCollectionName: "CustomCollection");
                indexToCreate.Execute(store);

                var database = await GetDatabase(store.Database);

                var index = database.IndexStore.GetIndexes().First();

                var definition = MapIndexDefinition.Load(index._environment, out var version);
                Assert.NotNull(definition.PatternForOutputReduceToCollectionReferences);
                Assert.Equal(IndexDefinitionBaseServerSide.IndexVersion.CurrentVersion, version);

                Assert.Equal("CustomCollection", definition.PatternReferencesCollectionName);
            }
        }
Esempio n. 5
0
    public async Task DeleteIndexInternalWillNotThrowAccessDeniedWhenDeletingInMemoryReplacementIndex()
    {
        using (var store = GetDocumentStore(new Options()
        {
            RunInMemory = true
        }))
        {
            var indexToCreate = new Orders_ProfitByProductAndOrderedAt(referencesCollectionName: "Foo");
            await indexToCreate.ExecuteAsync(store);

            Indexes.WaitForIndexing(store);

            indexToCreate = new Orders_ProfitByProductAndOrderedAt(referencesCollectionName: "Bar");
            await indexToCreate.ExecuteAsync(store);

            Indexes.WaitForIndexing(store);

            store.Maintenance.Send(new StopIndexingOperation());

            indexToCreate = new Orders_ProfitByProductAndOrderedAt(referencesCollectionName: "Baz");
            await indexToCreate.ExecuteAsync(store);

            var database = await GetDatabase(store.Database);

            var index   = database.IndexStore.GetIndex(Constants.Documents.Indexing.SideBySideIndexNamePrefix + indexToCreate.IndexName);
            var options = index._environment.Options as StorageEnvironmentOptions.PureMemoryStorageEnvironmentOptions;


            var replacementIndex        = database.IndexStore.GetIndex(Constants.Documents.Indexing.SideBySideIndexNamePrefix + indexToCreate.IndexName);
            var replacementIndexOptions = replacementIndex._environment.Options as StorageEnvironmentOptions.PureMemoryStorageEnvironmentOptions;

            Assert.Equal(options.TempPath, replacementIndexOptions.TempPath);

            database.IndexStore.DeleteIndexInternal(replacementIndex, false);
        }
    }
Esempio n. 6
0
        public void ShouldErrorOnInvalidReferenceDocumentId()
        {
            using (var store = GetDocumentStore())
            {
                Order entity = new Order()
                {
                    OrderedAt = null,
                    Lines     = new List <OrderLine>()
                    {
                        new OrderLine()
                        {
                            Product = "products/1",
                        }
                    }
                };

                using (var session = store.OpenSession())
                {
                    session.Store(entity, "orders/1");

                    session.SaveChanges();
                }

                var index1 = new Orders_ProfitByProductAndOrderedAt();
                index1.Execute(store);

                WaitForIndexing(store, allowErrors: true);
                var errors = WaitForIndexingErrors(store, indexNames: new[] { index1.IndexName });

                Assert.Contains("Invalid pattern reference document ID. Field 'OrderedAt' was null", errors[0].Errors[0].Error);

                using (var session = store.OpenSession())
                {
                    Assert.Equal(0, session.Query <object>(collectionName: "Profits/References").Count());
                }

                var now = DateTime.Now;

                using (var session = store.OpenSession())
                {
                    entity.OrderedAt = now;

                    session.Store(entity, "orders/1");

                    session.SaveChanges();
                }

                WaitForIndexing(store);

                using (var session = store.OpenSession())
                {
                    Assert.Equal(1, session.Query <object>(collectionName: "Profits/References").Count());
                }

                var index2 = new Orders_ProfitByProductAndOrderedAtEndsWithPipe();
                index2.Execute(store);

                WaitForIndexing(store, allowErrors: true);
                errors = WaitForIndexingErrors(store, indexNames: new[] { index2.IndexName });

                Assert.Contains($"Invalid pattern reference document ID: 'reports/daily/{now:yyyy-MM-dd}|'. Error: reference ID must not end with '|' character", errors[0].Errors[0].Error);

                using (var session = store.OpenSession())
                {
                    Assert.Equal(0, session.Query <object>(collectionName: "Profits2/References").Count());
                }
            }
        }