示例#1
0
        public async Task BackupWithIdentityAndCompareExchangeShouldHaveOnlyOwnValues()
        {
            var backupPath = NewDataPath(suffix: "BackupFolder1");
            var cmpXchg1   = new User {
                Name = "👺"
            };

            using (var store = GetDocumentStore(new Options {
                ModifyDatabaseName = s => "a"
            }))
                using (var store2 = GetDocumentStore(new Options
                {
                    ModifyDatabaseName = s => "aa"
                }))
                {
                    using (var session = store.OpenAsyncSession())
                    {
                        var bestUser = new User
                        {
                            Name = "Egor1"
                        };
                        await session.StoreAsync(bestUser, "a|");

                        await session.SaveChangesAsync();
                    }

                    await store.Operations.SendAsync(new PutCompareExchangeValueOperation <User>("emojis/goblin", cmpXchg1, 0));

                    using (var session = store2.OpenAsyncSession())
                    {
                        var bestUser = new User
                        {
                            Name = "Egor2"
                        };
                        await session.StoreAsync(bestUser, "aa|");

                        await session.SaveChangesAsync();
                    }

                    var cmpXchg2 = new User {
                        Name = "🤡"
                    };
                    await store2.Operations.SendAsync(new PutCompareExchangeValueOperation <User>("emojis/clown", cmpXchg2, 0));

                    var config = new PeriodicBackupConfiguration
                    {
                        LocalSettings = new LocalSettings
                        {
                            FolderPath = backupPath
                        },
                        Name = "full",
                        FullBackupFrequency = "* */6 * * *",
                        BackupType          = BackupType.Backup
                    };
                    var result = await store.Maintenance.SendAsync(new UpdatePeriodicBackupOperation(config));

                    var documentDatabase = (await GetDocumentDatabaseInstanceFor(store));
                    PeriodicBackupTestsSlow.RunBackup(result.TaskId, documentDatabase, true, store); // FULL BACKUP
                }

            var backupDirectory = Directory.GetDirectories(backupPath).First();
            var databaseName    = GetDatabaseName() + "restore";

            var files = Directory.GetFiles(backupDirectory)
                        .Where(BackupUtils.IsBackupFile)
                        .OrderBackups()
                        .ToArray();

            var restoreConfig = new RestoreBackupConfiguration
            {
                BackupLocation        = backupDirectory,
                DatabaseName          = databaseName,
                LastFileNameToRestore = files.Last()
            };

            using (var store2 = GetDocumentStore(new Options
            {
                CreateDatabase = false,
                ModifyDatabaseName = s => databaseName
            }))
            {
                var restoreOperation = new RestoreBackupOperation(restoreConfig);
                store2.Maintenance.Server.Send(restoreOperation)
                .WaitForCompletion(TimeSpan.FromSeconds(30));
                using (var session = store2.OpenAsyncSession(new SessionOptions
                {
                    TransactionMode = TransactionMode.ClusterWide
                }))
                {
                    var stats = store2.Maintenance.ForDatabase(databaseName).Send(new GetDetailedStatisticsOperation());
                    Assert.Equal(1, stats.CountOfIdentities);
                    Assert.Equal(1, stats.CountOfCompareExchange);
                    Assert.Equal(1, stats.CountOfDocuments);

                    var bestUser = await session.LoadAsync <User>("a/1");

                    var mediocreUser1 = await session.LoadAsync <User>("aa/1");

                    Assert.NotNull(bestUser);
                    Assert.Null(mediocreUser1);

                    Assert.Equal("Egor1", bestUser.Name);

                    var cmpXchg = await session.Advanced.ClusterTransaction.GetCompareExchangeValueAsync <User>("emojis/goblin");

                    Assert.Equal(cmpXchg1.Name, cmpXchg.Value.Name);
                    var cmpXchg2 = await session.Advanced.ClusterTransaction.GetCompareExchangeValueAsync <User>("emojis/clown");

                    Assert.Null(cmpXchg2);
                }
            }
        }
示例#2
0
        public async Task CreateFullAndIncrementalBackupWithIdentitiesInTheMiddle()
        {
            var backupPath = NewDataPath(suffix: "BackupFolder");

            using (var store = GetDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(new User
                    {
                        Id   = "users|",
                        Name = "Toli"
                    });

                    session.Store(new User
                    {
                        Id   = "users|",
                        Name = "Mitzi"
                    });
                    session.SaveChanges();
                }

                var config = new PeriodicBackupConfiguration
                {
                    LocalSettings = new LocalSettings
                    {
                        FolderPath = backupPath
                    },
                    Name = "full",
                    FullBackupFrequency = "* */6 * * *",
                    BackupType          = BackupType.Backup
                };

                var result = await store.Maintenance.SendAsync(new UpdatePeriodicBackupOperation(config));

                var documentDatabase = (await GetDocumentDatabaseInstanceFor(store));
                PeriodicBackupTestsSlow.RunBackup(result.TaskId, documentDatabase, true, store);

                Dictionary <string, long> identities = store.Maintenance.Send(new GetIdentitiesOperation());

                config.IncrementalBackupFrequency = "* */2 * * *";
                config.TaskId = result.TaskId;
                result        = await store.Maintenance.SendAsync(new UpdatePeriodicBackupOperation(config));

                PeriodicBackupTestsSlow.RunBackup(result.TaskId, documentDatabase, false, store);

                var backupDirectory = Directory.GetDirectories(backupPath).First();

                var databaseName = GetDatabaseName() + "restore";

                var files = Directory.GetFiles(backupDirectory)
                            .Where(BackupUtils.IsBackupFile)
                            .OrderBackups()
                            .ToArray();

                RestoreBackupConfiguration config2 = new RestoreBackupConfiguration()
                {
                    BackupLocation        = backupDirectory,
                    DatabaseName          = databaseName,
                    LastFileNameToRestore = files.Last()
                };

                RestoreBackupOperation restoreOperation = new RestoreBackupOperation(config2);
                store.Maintenance.Server.Send(restoreOperation)
                .WaitForCompletion();

                using (var store2 = GetDocumentStore(new Options()
                {
                    CreateDatabase = false,
                    ModifyDatabaseName = s => databaseName
                }))
                {
                    Dictionary <string, long> identities2 = store2.Maintenance.Send(new GetIdentitiesOperation());

                    Assert.Equal(identities.First().Key, identities2.First().Key);
                    Assert.Equal(identities.First().Value, identities2.First().Value);
                };
            }
        }
示例#3
0
        public async Task CreateFullAndIncrementalBackupWithIndexInTheMiddle()
        {
            var backupPath = NewDataPath(suffix: "BackupFolder");

            using (var store = GetDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(new User
                    {
                        Name = "Toli"
                    }, "users/1");
                    session.SaveChanges();
                }

                var config = new PeriodicBackupConfiguration
                {
                    LocalSettings = new LocalSettings
                    {
                        FolderPath = backupPath
                    },
                    Name = "full",
                    FullBackupFrequency = "* */6 * * *",
                    BackupType          = BackupType.Backup
                };

                var result = await store.Maintenance.SendAsync(new UpdatePeriodicBackupOperation(config));

                var documentDatabase = (await GetDocumentDatabaseInstanceFor(store));
                PeriodicBackupTestsSlow.RunBackup(result.TaskId, documentDatabase, true, store);

                var input = new IndexDefinition
                {
                    Name = "Users_ByName",
                    Maps =
                    {
                        "from user in docs.Users select new { user.Name }"
                    },
                    Type = IndexType.Map
                };

                await store
                .Maintenance
                .SendAsync(new PutIndexesOperation(new[] { input }));

                config.IncrementalBackupFrequency = "* */300 * * *";
                config.TaskId = result.TaskId;
                result        = await store.Maintenance.SendAsync(new UpdatePeriodicBackupOperation(config));

                PeriodicBackupTestsSlow.RunBackup(result.TaskId, documentDatabase, false, store);

                var backupDirectory = Directory.GetDirectories(backupPath).First();

                var databaseName = GetDatabaseName() + "restore";

                var files = Directory.GetFiles(backupDirectory)
                            .Where(BackupUtils.IsBackupFile)
                            .OrderBackups()
                            .ToArray();

                RestoreBackupConfiguration config2 = new RestoreBackupConfiguration()
                {
                    BackupLocation        = backupDirectory,
                    DatabaseName          = databaseName,
                    LastFileNameToRestore = files.Last()
                };

                RestoreBackupOperation restoreOperation = new RestoreBackupOperation(config2);
                store.Maintenance.Server.Send(restoreOperation)
                .WaitForCompletion(TimeSpan.FromSeconds(30));

                using (var store2 = GetDocumentStore(new Options()
                {
                    CreateDatabase = false,
                    ModifyDatabaseName = s => databaseName
                }))
                {
                    var stats = store2.Maintenance.ForDatabase(databaseName).Send(new GetStatisticsOperation());
                    Assert.Equal(1, stats.CountOfIndexes);
                    Assert.Equal(1, stats.CountOfDocuments);
                };
            }
        }
示例#4
0
        public async Task CreateFullAndIncrementalBackupWithCompareExchangeInTheMiddle()
        {
            var backupPath = NewDataPath(suffix: "BackupFolder");

            using (var store = GetDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(new User
                    {
                        Name = "Toli"
                    }, "users/1");
                    session.SaveChanges();
                }

                var config = new PeriodicBackupConfiguration
                {
                    LocalSettings = new LocalSettings
                    {
                        FolderPath = backupPath
                    },
                    Name = "full",
                    FullBackupFrequency = "* */6 * * *",
                    BackupType          = BackupType.Backup
                };

                var result = await store.Maintenance.SendAsync(new UpdatePeriodicBackupOperation(config));

                var documentDatabase = (await GetDocumentDatabaseInstanceFor(store));
                PeriodicBackupTestsSlow.RunBackup(result.TaskId, documentDatabase, true, store);


                CompareExchangeResult <string> compareExchangeResult
                    = store.Operations.Send(
                          new PutCompareExchangeValueOperation <string>("users/1", "Mitzi", 0));

                WaitForValue(() => compareExchangeResult.Successful, true);

                config.IncrementalBackupFrequency = "* */2 * * *";
                config.TaskId = result.TaskId;
                result        = await store.Maintenance.SendAsync(new UpdatePeriodicBackupOperation(config));

                PeriodicBackupTestsSlow.RunBackup(result.TaskId, documentDatabase, false, store);

                compareExchangeResult
                    = store.Operations.Send(
                          new PutCompareExchangeValueOperation <string>("users/1", "Mitzi2", compareExchangeResult.Index));

                WaitForValue(() => compareExchangeResult.Successful, true);

                config.IncrementalBackupFrequency = "* */2 * * *";
                config.TaskId = result.TaskId;
                result        = await store.Maintenance.SendAsync(new UpdatePeriodicBackupOperation(config));

                PeriodicBackupTestsSlow.RunBackup(result.TaskId, documentDatabase, false, store);

                var backupDirectory = Directory.GetDirectories(backupPath).First();

                var databaseName = GetDatabaseName() + "restore";

                var files = Directory.GetFiles(backupDirectory)
                            .Where(BackupUtils.IsBackupFile)
                            .OrderBackups()
                            .ToArray();

                RestoreBackupConfiguration config2 = new RestoreBackupConfiguration()
                {
                    BackupLocation        = backupDirectory,
                    DatabaseName          = databaseName,
                    LastFileNameToRestore = files.Last()
                };

                RestoreBackupOperation restoreOperation = new RestoreBackupOperation(config2);
                store.Maintenance.Server.Send(restoreOperation)
                .WaitForCompletion();

                using (var store2 = GetDocumentStore(new Options()
                {
                    CreateDatabase = false,
                    ModifyDatabaseName = s => databaseName
                }))
                {
                    using (var session = store2.OpenSession())
                    {
                        var doc = session.Load <User>("users/1");
                        Assert.NotNull(doc);
                    };
                    CompareExchangeValue <string> readResult =
                        store2.Operations.Send(new GetCompareExchangeValueOperation <string>("users/1"));

                    Assert.Equal("Mitzi2", readResult.Value);
                };
            }
        }