Пример #1
0
        public async Task <ActionResult> Export()
        {
            // Setup an export using RavenDb's Smuggler API
            var exportTimestamp = DateTime.Now;
            var fileName        = $"augurk-{exportTimestamp.ToString("yyyy-dd-M-HHmmss")}.bak";
            var filePath        = Path.Combine(Path.GetTempPath(), fileName);

            // Setup the export options
            var exportOptions = new DatabaseSmugglerExportOptions
            {
                OperateOnTypes = DatabaseItemType.Documents,
                IncludeExpired = false,
                Collections    = new List <string>
                {
                    "DbFeatures",
                    "AnalysisReports",
                    "DbProducts",
                }
            };

            // Perform the export
            var operation = await _documentStore.Smuggler.ExportAsync(exportOptions, filePath);

            await operation.WaitForCompletionAsync();

            // Stream the backup back to the client
            return(File(System.IO.File.ReadAllBytes(filePath), "application/octet-stream", fileName));
        }
Пример #2
0
        public async Task CanExportFrom40AndImportTo41()
        {
            var  file = GetTempFileName();
            long countOfDocuments;
            long countOfAttachments;
            long countOfIndexes;
            long countOfRevisions;

            try
            {
                using (var store40 = await GetDocumentStoreAsync("4.0.7"))
                {
                    store40.Maintenance.Send(new CreateSampleDataOperation());

                    var options = new DatabaseSmugglerExportOptions();
#pragma warning disable CS0618 // Type or member is obsolete
                    options.OperateOnTypes &= ~DatabaseItemType.Counters;
#pragma warning restore CS0618 // Type or member is obsolete
                    options.OperateOnTypes &= ~DatabaseItemType.CounterGroups;
                    options.OperateOnTypes &= ~DatabaseItemType.Attachments;
                    options.OperateOnTypes &= ~DatabaseItemType.Subscriptions;
                    options.OperateOnTypes &= ~DatabaseItemType.CompareExchangeTombstones;

                    var operation = await store40.Smuggler.ExportAsync(options, file);

                    await operation.WaitForCompletionAsync(TimeSpan.FromMinutes(1));

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

                    countOfDocuments   = stats.CountOfDocuments;
                    countOfAttachments = stats.CountOfAttachments;
                    countOfIndexes     = stats.CountOfIndexes;
                    countOfRevisions   = stats.CountOfRevisionDocuments;
                }

                using (var store41 = GetDocumentStore())
                {
                    var options = new DatabaseSmugglerImportOptions
                    {
                        SkipRevisionCreation = true
                    };

                    var operation = await store41.Smuggler.ImportAsync(options, file);

                    await operation.WaitForCompletionAsync(TimeSpan.FromMinutes(1));

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

                    Assert.Equal(countOfDocuments, stats.CountOfDocuments);
                    Assert.Equal(countOfAttachments, stats.CountOfAttachments);
                    Assert.Equal(countOfIndexes, stats.CountOfIndexes);
                    Assert.Equal(countOfRevisions, stats.CountOfRevisionDocuments);
                }
            }
            finally
            {
                File.Delete(file);
            }
        }
Пример #3
0
        public async Task Smuggler_Export_And_Import_Should_Work_With_ForDatabase()
        {
            using (var server = GetNewServer())
            {
                using (var store = new DocumentStore
                {
                    Urls = new[] { server.WebUrl }
                }.Initialize())
                {
                    var createSrcDatabase = new CreateDatabaseOperation(new DatabaseRecord("SrcDatabase"));
                    await store.Maintenance.Server.SendAsync(createSrcDatabase);

                    var createDestDatabase = new CreateDatabaseOperation(new DatabaseRecord("DestDatabase"));
                    await store.Maintenance.Server.SendAsync(createDestDatabase);

                    const int documentCount = 10000;
                    using (var session = store.OpenAsyncSession("SrcDatabase"))
                    {
                        for (var i = 0; i < documentCount; i++)
                        {
                            var user = new User {
                                Name = $"User {i}"
                            };
                            await session.StoreAsync(user);
                        }

                        await session.SaveChangesAsync();
                    }

                    var exportOptions = new DatabaseSmugglerExportOptions
                    {
                        OperateOnTypes = DatabaseItemType.Documents
                    };
                    var destination = store.Smuggler.ForDatabase("DestDatabase");
                    var operation   = await store.Smuggler.ForDatabase("SrcDatabase").ExportAsync(exportOptions, destination);

                    await operation.WaitForCompletionAsync();


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

                    Assert.True(stats.CountOfDocuments >= documentCount);

                    await store.Maintenance.Server.SendAsync(new CreateDatabaseOperation(new DatabaseRecord("ImportDest")));

                    using (var stream = GetDump("RavenDB_11664.1.ravendbdump"))
                    {
                        await store.Smuggler.ForDatabase("ImportDest").ImportAsync(new DatabaseSmugglerImportOptions(), stream);
                    }

                    using (var session = store.OpenAsyncSession("ImportDest"))
                    {
                        var employee = await session.LoadAsync <Employee>("employees/9-A");

                        Assert.NotNull(employee);
                    }
                }
            }
        }
Пример #4
0
        public async Task Should_report_errors_on_attempt_to_import_counter_of_non_existing_document()
        {
            var file = GetTempFileName();

            try
            {
                using (var store1 = GetDocumentStore())
                    using (var store2 = GetDocumentStore())
                    {
                        using (var session = store1.OpenAsyncSession())
                        {
                            await session.StoreAsync(new Order(), "orders/1");

                            await session.StoreAsync(new Order(), "orders/2");

                            session.CountersFor("orders/1").Increment("downloads", 100);
                            session.CountersFor("orders/2").Increment("downloads", 200);

                            await session.SaveChangesAsync();
                        }

                        var exportOptions = new DatabaseSmugglerExportOptions();
                        exportOptions.OperateOnTypes &= ~DatabaseItemType.Documents;

                        var exportOperation = await store1.Smuggler.ExportAsync(exportOptions, file);

                        var exportResult = (SmugglerResult)await exportOperation.WaitForCompletionAsync(TimeSpan.FromMinutes(5));

                        var progress = (SmugglerResult.SmugglerProgress)exportResult.Progress;

                        Assert.Equal(0, progress.Documents.ReadCount);
                        Assert.Equal(2, progress.Counters.ReadCount);

                        var importOperation = await store2.Smuggler.ImportAsync(new DatabaseSmugglerImportOptions(), file);

                        var importResult = (SmugglerResult)await importOperation.WaitForCompletionAsync(TimeSpan.FromMinutes(5));

                        progress = (SmugglerResult.SmugglerProgress)importResult.Progress;

                        Assert.Equal(0, progress.Documents.ReadCount);
                        Assert.Equal(2, progress.Counters.ReadCount);
                        Assert.Equal(2, progress.Counters.ErroredCount);

                        Assert.True(importResult.Messages.Any(message =>
                                                              message.Contains("Document 'orders/1' does not exist. Cannot operate on counters of a missing document")));
                        Assert.True(importResult.Messages.Any(message =>
                                                              message.Contains("Document 'orders/2' does not exist. Cannot operate on counters of a missing document")));

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

                        Assert.Equal(0, stats.CountOfDocuments);
                        Assert.Equal(0, stats.CountOfCounterEntries);
                    }
            }
            finally
            {
                File.Delete(file);
            }
        }
Пример #5
0
        public async Task CanExportFrom40AndImportTo41()
        {
            var  file = Path.GetTempFileName();
            long countOfDocuments;
            long countOfAttachments;
            long countOfIndexes;
            long countOfRevisions;

            try
            {
                using (var store40 = await GetDocumentStoreAsync("4.0.6-patch-40047"))
                {
                    store40.Maintenance.Send(new CreateSampleDataOperation());

                    var options = new DatabaseSmugglerExportOptions();
                    options.OperateOnTypes &= ~DatabaseItemType.Counters;

                    var operation = await store40.Smuggler.ExportAsync(options, file);

                    await operation.WaitForCompletionAsync(TimeSpan.FromMinutes(1));

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

                    countOfDocuments   = stats.CountOfDocuments;
                    countOfAttachments = stats.CountOfAttachments;
                    countOfIndexes     = stats.CountOfIndexes;
                    countOfRevisions   = stats.CountOfRevisionDocuments;
                }

                using (var store41 = GetDocumentStore())
                {
                    var options = new DatabaseSmugglerImportOptions
                    {
                        SkipRevisionCreation = true
                    };

                    var operation = await store41.Smuggler.ImportAsync(options, file);

                    await operation.WaitForCompletionAsync(TimeSpan.FromMinutes(1));

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

                    Assert.Equal(countOfDocuments, stats.CountOfDocuments);
                    Assert.Equal(countOfAttachments, stats.CountOfAttachments);
                    Assert.Equal(countOfIndexes, stats.CountOfIndexes);
                    Assert.Equal(countOfRevisions, stats.CountOfRevisionDocuments);
                }
            }
            finally
            {
                File.Delete(file);
            }
        }
Пример #6
0
        public async Task CanExportFrom42AndImportTo5()
        {
            var file = GetTempFileName();

            using var store5 = await GetDocumentStoreAsync(Server5Version);

            using var store42 = GetDocumentStore();

            store42.Maintenance.Send(new CreateSampleDataOperation());
            using (var session = store42.OpenAsyncSession())
            {
                for (var i = 0; i < 5; i++)
                {
                    var user = new User {
                        Name = "raven" + i
                    };
                    await session.StoreAsync(user);

                    session.CountersFor(user).Increment("Like");
                }
                await session.SaveChangesAsync();
            }

            //Export
            var options = new DatabaseSmugglerExportOptions();

            var importOperation = await store42.Smuggler.ExportAsync(options, file);

            await importOperation.WaitForCompletionAsync(TimeSpan.FromMinutes(1));

            var expected = await store42.Maintenance.SendAsync(new GetStatisticsOperation());

            //Import
            var exportOperation = new DatabaseSmugglerImportOptions {
                SkipRevisionCreation = true
            };

            var operation = await store5.Smuggler.ImportAsync(exportOperation, file);

            await operation.WaitForCompletionAsync(TimeSpan.FromMinutes(1));

            var actual = await store5.Maintenance.SendAsync(new GetStatisticsOperation());

            //Assert
            Assert.Equal(expected.CountOfDocuments, actual.CountOfDocuments);
            Assert.Equal(expected.CountOfAttachments, actual.CountOfAttachments);
            Assert.Equal(expected.CountOfIndexes, actual.CountOfIndexes);
            Assert.Equal(expected.CountOfRevisionDocuments, actual.CountOfRevisionDocuments);
        }
Пример #7
0
        protected static async Task CanExportWithPulsatingReadTransaction_ActualTest(int numberOfUsers, int numberOfCountersPerUser, int numberOfRevisionsPerDocument,
                                                                                     int numberOfOrders, int deleteUserFactor, DocumentStore storeToExport, string file, DocumentStore storeToImport, string fileAfterDeletions,
                                                                                     DocumentStore storeToAfterDeletions)
        {
            if (numberOfRevisionsPerDocument > 0)
            {
                var configuration = new RevisionsConfiguration {
                    Default = new RevisionsCollectionConfiguration {
                        Disabled = false, MinimumRevisionsToKeep = 10
                    }
                };

                await storeToExport.Maintenance.SendAsync(new ConfigureRevisionsOperation(configuration));
            }

            using (var bulk = storeToExport.BulkInsert())
            {
                for (int i = 0; i < Math.Max(numberOfUsers, numberOfOrders); i++)
                {
                    if (i < numberOfUsers)
                    {
                        bulk.Store(new User(), "users/" + i);
                    }

                    if (i < numberOfOrders)
                    {
                        bulk.Store(new Order(), "orders/" + i);
                    }
                }
            }

            if (numberOfRevisionsPerDocument > 2)
            {
                for (int j = 0; j < numberOfRevisionsPerDocument; j++)
                {
                    using (var bulk = storeToExport.BulkInsert())
                    {
                        for (int i = 0; i < Math.Max(numberOfUsers, numberOfOrders); i++)
                        {
                            if (i < numberOfUsers)
                            {
                                bulk.Store(new User()
                                {
                                    Name = i + " " + j
                                }, "users/" + i);
                            }

                            if (i < numberOfOrders)
                            {
                                bulk.Store(new Order()
                                {
                                    Company = i + " " + j
                                }, "orders/" + i);
                            }
                        }
                    }
                }
            }

            using (var session = storeToExport.OpenSession())
            {
                for (int i = 0; i < numberOfUsers; i++)
                {
                    for (int j = 0; j < numberOfCountersPerUser; j++)
                    {
                        session.CountersFor("users/" + i).Increment("counter/" + j, 100);
                    }
                }

                session.SaveChanges();
            }

            var originalStats = await storeToExport.Maintenance.SendAsync(new GetStatisticsOperation());

            var options = new DatabaseSmugglerExportOptions();

            var operation = await storeToExport.Smuggler.ExportAsync(options, file);

            var result = await operation.WaitForCompletionAsync(TimeSpan.FromMinutes(2));

            SmugglerResult.SmugglerProgress progress = ((SmugglerResult)result).Progress as SmugglerResult.SmugglerProgress;

            Assert.Equal(originalStats.CountOfDocuments, progress.Documents.ReadCount);
            Assert.Equal(originalStats.CountOfCounterEntries, progress.Counters.ReadCount);
            Assert.Equal(originalStats.CountOfRevisionDocuments, progress.RevisionDocuments.ReadCount);

            operation = await storeToImport.Smuggler.ImportAsync(new DatabaseSmugglerImportOptions(), file);

            await operation.WaitForCompletionAsync(TimeSpan.FromMinutes(2));

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

            Assert.Equal(numberOfUsers + numberOfOrders, stats.CountOfDocuments);
            Assert.Equal(numberOfUsers, stats.CountOfCounterEntries);

            var expectedNumberOfRevisions = (numberOfUsers + numberOfOrders) * numberOfRevisionsPerDocument;

            if (numberOfCountersPerUser > 0)
            {
                // if we added counters then additional revisions were created
                expectedNumberOfRevisions += numberOfUsers;
            }

            Assert.Equal(expectedNumberOfRevisions, stats.CountOfRevisionDocuments);

            // deleting some docs

            var deletedUsers = 0;

            using (var session = storeToExport.OpenSession())
            {
                for (int i = 0; i < numberOfUsers; i++)
                {
                    if (i % deleteUserFactor != 0)
                    {
                        continue;
                    }

                    session.Delete("users/" + i);

                    deletedUsers++;
                }

                session.SaveChanges();
            }

            // import to new db

            var originalStatsAfterDeletions = await storeToExport.Maintenance.SendAsync(new GetStatisticsOperation());

            options.OperateOnTypes |= DatabaseItemType.Tombstones;

            operation = await storeToExport.Smuggler.ExportAsync(options, fileAfterDeletions);

            result = await operation.WaitForCompletionAsync(TimeSpan.FromMinutes(2));

            progress = ((SmugglerResult)result).Progress as SmugglerResult.SmugglerProgress;

            Assert.Equal(originalStatsAfterDeletions.CountOfDocuments, progress.Documents.ReadCount);
            Assert.Equal(originalStatsAfterDeletions.CountOfCounterEntries, progress.Counters.ReadCount);
            Assert.Equal(originalStatsAfterDeletions.CountOfRevisionDocuments, progress.RevisionDocuments.ReadCount);
            Assert.Equal(originalStatsAfterDeletions.CountOfTombstones, progress.Tombstones.ReadCount);

            var importOptions = new DatabaseSmugglerImportOptions();

            importOptions.OperateOnTypes |= DatabaseItemType.Tombstones;

            operation = await storeToAfterDeletions.Smuggler.ImportAsync(importOptions, fileAfterDeletions);

            await operation.WaitForCompletionAsync(TimeSpan.FromMinutes(2));

            var statsAfterDeletions = await storeToAfterDeletions.Maintenance.SendAsync(new GetStatisticsOperation());

            Assert.Equal(numberOfUsers - deletedUsers + numberOfOrders, statsAfterDeletions.CountOfDocuments);
            Assert.Equal(numberOfUsers - deletedUsers, statsAfterDeletions.CountOfCounterEntries);
            Assert.Equal(expectedNumberOfRevisions, statsAfterDeletions.CountOfRevisionDocuments);
            Assert.Equal(deletedUsers, statsAfterDeletions.CountOfTombstones);
        }
Пример #8
0
        public async Task CanExportAndImportCounterTombstones()
        {
            var file = GetTempFileName();

            try
            {
                using (var store1 = GetDocumentStore())
                    using (var store2 = GetDocumentStore())
                    {
                        using (var session = store1.OpenAsyncSession())
                        {
                            await session.StoreAsync(new User { Name = "Name1" }, "users/1");

                            await session.StoreAsync(new User { Name = "Name2" }, "users/2");

                            await session.StoreAsync(new User { Name = "Name3" }, "users/3");

                            await session.SaveChangesAsync();
                        }

                        using (var session = store1.OpenAsyncSession())
                        {
                            session.CountersFor("users/1").Increment("likes", 100);
                            session.CountersFor("users/1").Increment("dislikes", 200);
                            session.CountersFor("users/2").Increment("downloads", 500);
                            session.CountersFor("users/2").Increment("votes", 1000);

                            await session.SaveChangesAsync();
                        }

                        using (var session = store1.OpenAsyncSession())
                        {
                            session.Delete("users/3");
                            session.CountersFor("users/1").Delete("dislikes");
                            session.CountersFor("users/2").Delete("votes");
                            await session.SaveChangesAsync();
                        }

                        var db = await GetDocumentDatabaseInstanceFor(store1);

                        using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext ctx))
                            using (ctx.OpenReadTransaction())
                            {
                                var tombstones = db.DocumentsStorage.GetTombstonesFrom(ctx, 0, 0, int.MaxValue).ToList();
                                Assert.Equal(3, tombstones.Count);
                                Assert.Equal(Tombstone.TombstoneType.Document, tombstones[0].Type);
                                Assert.Equal(Tombstone.TombstoneType.Counter, tombstones[1].Type);
                                Assert.Equal(Tombstone.TombstoneType.Counter, tombstones[2].Type);
                            }

                        var exportOptions = new DatabaseSmugglerExportOptions();
                        var importOptions = new DatabaseSmugglerImportOptions();
                        exportOptions.OperateOnTypes |= DatabaseItemType.Tombstones;
                        importOptions.OperateOnTypes |= DatabaseItemType.Tombstones;

                        var operation = await store1.Smuggler.ExportAsync(exportOptions, file);

                        await operation.WaitForCompletionAsync(TimeSpan.FromMinutes(1));

                        operation = await store2.Smuggler.ImportAsync(importOptions, file);

                        await operation.WaitForCompletionAsync(TimeSpan.FromMinutes(1));

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

                        Assert.Equal(2, stats.CountOfCounters);
                        Assert.Equal(3, stats.CountOfTombstones);

                        db = await GetDocumentDatabaseInstanceFor(store2);

                        using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext ctx))
                            using (ctx.OpenReadTransaction())
                            {
                                var tombstones = db.DocumentsStorage.GetTombstonesFrom(ctx, 0, 0, int.MaxValue).ToList();
                                Assert.Equal(3, tombstones.Count);
                                Assert.Equal(Tombstone.TombstoneType.Document, tombstones[0].Type);
                                Assert.Equal(Tombstone.TombstoneType.Counter, tombstones[1].Type);
                                Assert.Equal(Tombstone.TombstoneType.Counter, tombstones[2].Type);
                            }
                    }
            }
            finally
            {
                File.Delete(file);
            }
        }
Пример #9
0
        public async Task CanExportFrom41AndImportTo42()
        {
            var file = GetTempFileName();

            try
            {
                long countOfDocuments;
                long countOfAttachments;
                long countOfIndexes;
                long countOfRevisions;
                using (var store41 = await GetDocumentStoreAsync("4.1.4", new InterversionTestOptions
                {
                    ModifyDatabaseRecord = record =>
                    {
                        record.Settings[RavenConfiguration.GetKey(x => x.Patching.MaxNumberOfCachedScripts)] = "1024";
                        record.ConflictSolverConfig = new ConflictSolver
                        {
                            ResolveToLatest = false,
                            ResolveByCollection = new Dictionary <string, ScriptResolver>
                            {
                                {
                                    "ConflictSolver", new ScriptResolver()
                                    {
                                        Script = "Script"
                                    }
                                }
                            }
                        };
                        record.Sorters = new Dictionary <string, SorterDefinition>
                        {
                            {
                                "MySorter", new SorterDefinition
                                {
                                    Name = "MySorter",
                                    Code = GetSorter("RavenDB_8355.MySorter.cs")
                                }
                            }
                        };
                        record.ExternalReplications = new List <ExternalReplication>
                        {
                            new ExternalReplication("tempDatabase", "ExternalReplication")
                            {
                                TaskId = 1,
                                Name = "External",
                                MentorNode = "B",
                                DelayReplicationFor = new TimeSpan(4),
                                Url = "http://127.0.0.1/",
                                Disabled = false
                            }
                        };
                        record.SinkPullReplications = new List <PullReplicationAsSink>
                        {
                            new PullReplicationAsSink()
                            {
                                Database = "sinkDatabase",
                                CertificatePassword = "******",
                                CertificateWithPrivateKey = "CertificateWithPrivateKey",
                                TaskId = 2,
                                Name = "Sink",
                                MentorNode = "A",
                                HubDefinitionName = "hub"
                            }
                        };
                        record.HubPullReplications = new List <PullReplicationDefinition>
                        {
                            new PullReplicationDefinition()
                            {
                                TaskId = 3,
                                Name = "hub",
                                MentorNode = "A",
                                DelayReplicationFor = new TimeSpan(3),
                            }
                        };
                        record.RavenEtls = new List <RavenEtlConfiguration>
                        {
                            new RavenEtlConfiguration()
                            {
                                AllowEtlOnNonEncryptedChannel = true,
                                ConnectionStringName = "ConnectionName",
                                MentorNode = "A",
                                Name = "Etl",
                                TaskId = 4
                            }
                        };
                        record.SqlEtls = new List <SqlEtlConfiguration>
                        {
                            new SqlEtlConfiguration()
                            {
                                AllowEtlOnNonEncryptedChannel = true,
                                ConnectionStringName = "connection",
                                ForceQueryRecompile = false,
                                Name = "sql",
                                ParameterizeDeletes = false,
                                TaskId = 5
                            }
                        };
                    }
                }))
                {
                    store41.Maintenance.Send(new CreateSampleDataOperation());

                    var options = new DatabaseSmugglerExportOptions();
#pragma warning disable 618
                    options.OperateOnTypes &= ~DatabaseItemType.CounterGroups;
                    options.OperateOnTypes &= ~DatabaseItemType.Subscriptions;
                    options.OperateOnTypes &= ~DatabaseItemType.CompareExchangeTombstones;
#pragma warning restore 618

                    var operation = await store41.Smuggler.ExportAsync(options, file);

                    await operation.WaitForCompletionAsync(TimeSpan.FromMinutes(1));

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

                    countOfDocuments   = stats.CountOfDocuments;
                    countOfAttachments = stats.CountOfAttachments;
                    countOfIndexes     = stats.CountOfIndexes;
                    countOfRevisions   = stats.CountOfRevisionDocuments;
                }

                using (var store42 = GetDocumentStore())
                {
                    var options = new DatabaseSmugglerImportOptions
                    {
                        SkipRevisionCreation = true
                    };

                    var operation = await store42.Smuggler.ImportAsync(options, file);

                    await operation.WaitForCompletionAsync(TimeSpan.FromMinutes(1));

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

                    Assert.Equal(countOfDocuments, stats.CountOfDocuments);
                    Assert.Equal(countOfAttachments, stats.CountOfAttachments);
                    Assert.Equal(countOfIndexes, stats.CountOfIndexes);
                    Assert.Equal(countOfRevisions, stats.CountOfRevisionDocuments);

                    var record = await store42.Maintenance.Server.SendAsync(new GetDatabaseRecordOperation(store42.Database));

                    record.Settings.TryGetValue("Patching.MaxNumberOfCachedScripts", out string value);
                    Assert.Null(value);
                    Assert.Null(record.ConflictSolverConfig);
                    Assert.Equal(0, record.Sorters.Count);
                    Assert.Equal(0, record.ExternalReplications.Count);
                    Assert.Equal(0, record.SinkPullReplications.Count);
                    Assert.Equal(0, record.HubPullReplications.Count);
                    Assert.Equal(0, record.RavenEtls.Count);
                    Assert.Equal(0, record.SqlEtls.Count);
                    Assert.Equal(0, record.PeriodicBackups.Count);
                }
            }
            finally
            {
                File.Delete(file);
            }
        }
Пример #10
0
        public async Task Counters_export_should_respect_collection_selection_2()
        {
            var file = GetTempFileName();

            try
            {
                using (var store1 = GetDocumentStore())
                    using (var store2 = GetDocumentStore())
                    {
                        using (var session = store1.OpenAsyncSession())
                        {
                            await session.StoreAsync(new User(), "users/1");

                            await session.StoreAsync(new User(), "users/2");

                            await session.StoreAsync(new User(), "users/3");


                            await session.StoreAsync(new Order(), "orders/1");

                            await session.StoreAsync(new Order(), "orders/2");

                            await session.SaveChangesAsync();
                        }

                        using (var session = store1.OpenAsyncSession())
                        {
                            session.CountersFor("users/1").Increment("likes", 100);
                            session.CountersFor("users/1").Increment("dislikes", 200);
                            session.CountersFor("users/2").Increment("downloads", 500);
                            session.CountersFor("users/3").Increment("downloads", 500);


                            session.CountersFor("orders/1").Increment("downloads", 100);
                            session.CountersFor("orders/2").Increment("downloads", 200);


                            await session.SaveChangesAsync();
                        }

                        var exportOptions = new DatabaseSmugglerExportOptions
                        {
                            Collections = new List <string>
                            {
                                "Orders"
                            }
                        };

                        var operation = await store1.Smuggler.ExportAsync(exportOptions, file);

                        await operation.WaitForCompletionAsync(TimeSpan.FromMinutes(1));

                        operation = await store2.Smuggler.ImportAsync(new DatabaseSmugglerImportOptions(), file);

                        await operation.WaitForCompletionAsync(TimeSpan.FromMinutes(1));

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

                        Assert.Equal(2, stats.CountOfDocuments);
                        Assert.Equal(2, stats.CountOfCounterEntries);

                        using (var session = store2.OpenAsyncSession())
                        {
                            var order1 = await session.LoadAsync <Order>("orders/1");

                            var counter = await session.CountersFor(order1).GetAsync("downloads");

                            Assert.Equal(100, counter);

                            var order2 = await session.LoadAsync <Order>("orders/2");

                            counter = await session.CountersFor(order2).GetAsync("downloads");

                            Assert.Equal(200, counter);
                        }
                    }
            }
            finally
            {
                File.Delete(file);
            }
        }
Пример #11
0
        public async Task CanExportFrom42AndImportToCurrent(ExcludeOn excludeOn)
        {
            var file = GetTempFileName();

            using var store42 = await GetDocumentStoreAsync(Server42Version);

            using var storeCurrent = GetDocumentStore();

            store42.Maintenance.Send(new CreateSampleDataOperation());
            using (var session = store42.OpenAsyncSession())
            {
                for (var i = 0; i < 5; i++)
                {
                    var user = new User {
                        Name = "raven" + i
                    };
                    await session.StoreAsync(user);

                    session.CountersFor(user).Increment("Like");
                }
                await session.SaveChangesAsync();
            }

            //Export
            var exportOptions = new DatabaseSmugglerExportOptions();

            exportOptions.OperateOnTypes &= ~DatabaseItemType.TimeSeries;
            if (excludeOn == ExcludeOn.Export)
            {
                exportOptions.OperateOnTypes &= ~(DatabaseItemType.Attachments | DatabaseItemType.RevisionDocuments | DatabaseItemType.CounterGroups);
            }
            var exportOperation = await store42.Smuggler.ExportAsync(exportOptions, file);

            await exportOperation.WaitForCompletionAsync(_operationTimeout);

            var expected = await store42.Maintenance.SendAsync(new GetStatisticsOperation());

            //Import
            var importOptions = new DatabaseSmugglerImportOptions {
                SkipRevisionCreation = true
            };

            if (excludeOn == ExcludeOn.Import)
            {
                importOptions.OperateOnTypes &= ~(DatabaseItemType.Attachments | DatabaseItemType.RevisionDocuments | DatabaseItemType.CounterGroups);
            }
            var importOperation = await storeCurrent.Smuggler.ImportAsync(importOptions, file);

            await importOperation.WaitForCompletionAsync(_operationTimeout);

            var actual = await storeCurrent.Maintenance.SendAsync(new GetStatisticsOperation());

            //Assert
            Assert.Equal(expected.CountOfIndexes, actual.CountOfIndexes);
            Assert.Equal(expected.CountOfDocuments, actual.CountOfDocuments);

            var export = await GetMetadataCounts(store42);

            var import = await GetMetadataCounts(storeCurrent);

            if (excludeOn == ExcludeOn.Non)
            {
                Assert.Equal(expected.CountOfAttachments, actual.CountOfAttachments);
                Assert.Equal(expected.CountOfRevisionDocuments, actual.CountOfRevisionDocuments);
                Assert.Equal(expected.CountOfCounterEntries, actual.CountOfCounterEntries);

                Assert.Equal(export, import);
            }
            else
            {
                Assert.Equal(0, actual.CountOfAttachments);
                Assert.Equal(0, actual.CountOfRevisionDocuments);
                Assert.Equal(0, actual.CountOfCounterEntries);

                Assert.Equal((0, 0, 0), import);
            }
        }