Exemplo n.º 1
0
        public void ConfigurationCheckFailedTest()
        {
            this.CreateConfiguration();
            var resourceName = Path.Combine(Path.GetFullPath("."), Guid.NewGuid().ToString("N"));

            using (var context = this.GetContext())
            {
                var activeConfiguration = context.Configurations.First(r => r.Id == 1);
                activeConfiguration.Settings.MigratorTemplates.First().Configuration = $@"
                {{
                    TestMigrator.DefinedMigrationPoints = [
                        ""first"",
                        ""second"",
                    ]
                    TestMigrator.Resources = [
                        ""{resourceName.Replace("\\", "\\\\")}""
                    ]
                    KlusterKite.NodeManager.Migrators = [
                        ""KlusterKite.NodeManager.Tests.Migrations.TestMigrator, KlusterKite.NodeManager.Tests""
                    ]

                    TestMigrator.ThrowOnGetMigratableResources = true
                }}
                ";
                context.SaveChanges();
            }

            try
            {
                TestMigrator.SetMigrationPoint(resourceName, "first");

                this.ActorOf(
                    () => new MigratorForwarder(
                        this.TestActor,
                        this.Container.Resolve <UniversalContextFactory>(),
                        this.Container.Resolve <IPackageRepository>()),
                    "migrationActor");
                this.ExpectMsg <ProcessingTheRequest>();
                this.ExpectMsg <MigrationActorInitializationFailed>(TimeSpan.FromSeconds(30));
                this.ExpectNoMsg();
            }
            finally
            {
                File.Delete(resourceName);
            }
        }
Exemplo n.º 2
0
        public void MigrationUpgradeMigrationFailedTest()
        {
            this.CreateConfiguration();
            var resourceName = Path.Combine(Path.GetFullPath("."), Guid.NewGuid().ToString("N"));

            using (var context = this.GetContext())
            {
                var activeConfiguration = context.Configurations.First(r => r.Id == 1);
                var nextConfiguration   = context.Configurations.First(r => r.Id == 2);

                activeConfiguration.Settings.MigratorTemplates.First().Configuration = $@"
                {{
                    TestMigrator.Dir = ""{Path.GetFullPath(".").Replace("\\", "\\\\")}""
                    TestMigrator.Dependence.DefinedMigrationPoints = [
                        ""first""
                    ]
                    TestMigrator.Dependence.Resources = [
                        ""{resourceName.Replace("\\", "\\\\")}""
                    ]
                    KlusterKite.NodeManager.Migrators = [
                        ""KlusterKite.NodeManager.Tests.Migrations.TestMigrator+Dependence, KlusterKite.NodeManager.Tests""
                    ]
                }}
                ";

                nextConfiguration.Settings.MigratorTemplates.First().Configuration = $@"
                {{
                    TestMigrator.Dir = ""{Path.GetFullPath(".").Replace("\\", "\\\\")}""
                    TestMigrator.Dependence.DefinedMigrationPoints = [
                        ""first"",
                        ""second"",
                    ]

                    TestMigrator.Dependence.Resources = [
                        ""{resourceName.Replace("\\", "\\\\")}""
                    ]
                    KlusterKite.NodeManager.Migrators = [
                        ""KlusterKite.NodeManager.Tests.Migrations.TestMigrator+Dependence, KlusterKite.NodeManager.Tests""
                    ]

                    TestMigrator.ThrowOnMigrate = true
                }}
                ";
                context.SaveChanges();
            }

            try
            {
                TestMigrator.SetMigrationPoint(resourceName, "first");
                this.CreateMigration();

                var actor = this.ActorOf(
                    () => new MigratorForwarder(
                        this.TestActor,
                        this.Container.Resolve <UniversalContextFactory>(),
                        this.Container.Resolve <IPackageRepository>()),
                    "migrationActor");
                this.ExpectMsg <ProcessingTheRequest>();

                var state = this.ExpectMsg <MigrationActorMigrationState>(TimeSpan.FromSeconds(30));
                this.ExpectNoMsg();
                Assert.Equal(1, state.TemplateStates.Count);
                Assert.Equal(EnMigratorPosition.Present, state.TemplateStates[0].Position);
                Assert.Equal(1, state.TemplateStates[0].Migrators.Count);
                Assert.Equal(EnMigratorPosition.Present, state.TemplateStates[0].Migrators[0].Position);
                Assert.Equal(EnMigrationDirection.Upgrade, state.TemplateStates[0].Migrators[0].Direction);
                Assert.Equal(1, state.TemplateStates[0].Migrators[0].Resources.Count);
                Assert.Equal(EnResourcePosition.Source, state.TemplateStates[0].Migrators[0].Resources[0].Position);

                var resourceUpgrade = new ResourceUpgrade
                {
                    TemplateCode     = "migrator",
                    MigratorTypeName =
                        "KlusterKite.NodeManager.Tests.Migrations.TestMigrator+Dependence",
                    ResourceCode = Path.GetFileName(resourceName),
                    Target       = EnMigrationSide.Destination
                };

                actor.Tell(new[] { resourceUpgrade }.ToList());
                var log = this.ExpectMsg <List <MigrationLogRecord> >();
                Assert.Equal(1, log.Count);
                var record = log.First();
                Assert.Equal(EnMigrationLogRecordType.OperationError, record.Type);
                Assert.Equal(1, record.MigrationId);
                Assert.Equal(2, record.ConfigurationId);
                Assert.Equal("migrator", record.MigratorTemplateCode);
                Assert.Equal("first", record.SourcePoint);
                Assert.Equal("second", record.DestinationPoint);
                Assert.Equal("Exception while migrating resource: Migrate failed", record.Message);

                state = this.ExpectMsg <MigrationActorMigrationState>(TimeSpan.FromSeconds(5));
                this.ExpectNoMsg();
                Assert.Equal(1, state.TemplateStates.Count);
                Assert.Equal(EnMigratorPosition.Present, state.TemplateStates[0].Position);
                Assert.Equal(1, state.TemplateStates[0].Migrators.Count);
                Assert.Equal(EnMigratorPosition.Present, state.TemplateStates[0].Migrators[0].Position);
                Assert.Equal(EnMigrationDirection.Upgrade, state.TemplateStates[0].Migrators[0].Direction);
                Assert.Equal(1, state.TemplateStates[0].Migrators[0].Resources.Count);
                Assert.Equal(EnResourcePosition.Source, state.TemplateStates[0].Migrators[0].Resources[0].Position);
            }
            finally
            {
                File.Delete(resourceName);
            }
        }
Exemplo n.º 3
0
        public void MigrationNoChangeTest()
        {
            this.CreateConfiguration();
            var resourceName = Path.Combine(Path.GetFullPath("."), Guid.NewGuid().ToString("N"));

            using (var context = this.GetContext())
            {
                var activeConfiguration = context.Configurations.First(r => r.Id == 1);
                var nextConfiguration   = context.Configurations.First(r => r.Id == 2);

                nextConfiguration.Settings.MigratorTemplates.First().Configuration = $@"
                {{
                    TestMigrator.Dir = ""{Path.GetFullPath(".").Replace("\\", "\\\\")}""
                    TestMigrator.Dependence.DefinedMigrationPoints = [
                        ""first""
                    ]
                    TestMigrator.Dependence.Resources = [
                        ""{resourceName.Replace("\\", "\\\\")}""
                    ]
                    KlusterKite.NodeManager.Migrators = [
                        ""KlusterKite.NodeManager.Tests.Migrations.TestMigrator+Dependence, KlusterKite.NodeManager.Tests""
                    ]
                }}
                ";

                activeConfiguration.Settings.MigratorTemplates.First().Configuration = $@"
                {{
                    TestMigrator.Dir = ""{Path.GetFullPath(".").Replace("\\", "\\\\")}""
                    TestMigrator.Dependence.DefinedMigrationPoints = [
                        ""first"",
                    ]
                    TestMigrator.Dependence.Resources = [
                        ""{resourceName.Replace("\\", "\\\\")}""
                    ]
                    KlusterKite.NodeManager.Migrators = [
                        ""KlusterKite.NodeManager.Tests.Migrations.TestMigrator+Dependence, KlusterKite.NodeManager.Tests""
                    ]
                }}
                ";
                context.SaveChanges();
            }

            try
            {
                TestMigrator.SetMigrationPoint(resourceName, "first");
                this.CreateMigration();

                this.ActorOf(
                    () => new MigratorForwarder(
                        this.TestActor,
                        this.Container.Resolve <UniversalContextFactory>(),
                        this.Container.Resolve <IPackageRepository>()),
                    "migrationActor");
                this.ExpectMsg <ProcessingTheRequest>();

                var state = this.ExpectMsg <MigrationActorMigrationState>(TimeSpan.FromSeconds(30));
                this.ExpectNoMsg();
                Assert.Equal(1, state.TemplateStates.Count);
                Assert.Equal(EnMigratorPosition.Present, state.TemplateStates[0].Position);
                Assert.Equal(1, state.TemplateStates[0].Migrators.Count);
                Assert.Equal(EnMigratorPosition.Present, state.TemplateStates[0].Migrators[0].Position);
                Assert.Equal(EnMigrationDirection.Stay, state.TemplateStates[0].Migrators[0].Direction);
                Assert.Equal(1, state.TemplateStates[0].Migrators[0].Resources.Count);
                Assert.Equal(
                    EnResourcePosition.SourceAndDestination,
                    state.TemplateStates[0].Migrators[0].Resources[0].Position);
            }
            finally
            {
                File.Delete(resourceName);
            }
        }