Ejemplo n.º 1
0
        private async Task BuildDomainAsync(string version, DomainUpgradeMode upgradeMode, int?keyCacheSize, params Type[] types)
        {
            if (domain != null)
            {
                domain.Dispose();
            }

            var configuration = DomainConfigurationFactory.Create();

            configuration.UpgradeMode = upgradeMode;
            foreach (var type in types)
            {
                configuration.Types.Register(type);
            }

            if (keyCacheSize.HasValue)
            {
                configuration.KeyGeneratorCacheSize = keyCacheSize.Value;
            }

            configuration.Types.Register(typeof(Upgrader));
            using (Upgrader.Enable(version)) {
                domain = await Domain.BuildAsync(configuration);
            }
        }
Ejemplo n.º 2
0
        private Domain BuildDomain(DomainUpgradeMode mode)
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.UpgradeMode = mode;
            return(Domain.Build(configuration));
        }
        internal static SchemaUpgradeMode GetFinalStageUpgradeMode(this DomainUpgradeMode upgradeMode)
        {
            switch (upgradeMode)
            {
            case DomainUpgradeMode.Skip:
            case DomainUpgradeMode.LegacySkip:
                return(SchemaUpgradeMode.Skip);

            case DomainUpgradeMode.Validate:
                return(SchemaUpgradeMode.ValidateExact);

            case DomainUpgradeMode.LegacyValidate:
                return(SchemaUpgradeMode.ValidateLegacy);

            case DomainUpgradeMode.Recreate:
                return(SchemaUpgradeMode.Recreate);

            case DomainUpgradeMode.Perform:
            case DomainUpgradeMode.PerformSafely:
                // We need Perform here because after Upgrading stage
                // there may be some recycled columns/tables.
                // Perform will wipe them out.
                return(SchemaUpgradeMode.Perform);

            default:
                throw new ArgumentOutOfRangeException("upgradeMode");
            }
        }
Ejemplo n.º 4
0
        private Task <Domain> BuildDomainAsync(DomainUpgradeMode mode)
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.UpgradeMode = mode;
            return(Domain.BuildAsync(configuration));
        }
Ejemplo n.º 5
0
 protected virtual IEnumerable <NodeConfiguration> GetNodes(DomainUpgradeMode upgradeMode)
 {
     return(new[] { new NodeConfiguration(WellKnown.DefaultNodeId)
                    {
                        UpgradeMode = upgradeMode
                    } });
 }
Ejemplo n.º 6
0
        protected void RunTest(DomainUpgradeMode upgradeMode)
        {
            var configuration = BuildConfiguration();

            ApplyCustomSettingsToTestConfiguration(configuration);
            configuration.UpgradeMode = upgradeMode;
            configuration.ShareStorageSchemaOverNodes = true;
            var initialEntitiesCount = (upgradeMode != DomainUpgradeMode.Recreate) ? 1 : 0;

            using (var domain = Domain.Build(configuration)) {
                var nodes = GetNodes(upgradeMode);

                foreach (var storageNode in nodes.Where(n => n.NodeId != WellKnown.DefaultNodeId))
                {
                    domain.StorageNodeManager.AddNode(storageNode);
                }

                foreach (var storageNode in nodes)
                {
                    using (var session = domain.OpenSession()) {
                        session.SelectStorageNode(storageNode.NodeId);
                        using (var transaction = session.OpenTransaction()) {
                            Select(session, initialEntitiesCount);
                            var createdKeys = Insert(session, initialEntitiesCount);
                            Update(session, createdKeys, initialEntitiesCount);
                            Delete(session, createdKeys, initialEntitiesCount);
                            Select(session, initialEntitiesCount);
                        }
                    }
                }
            }
        }
        private IEnumerable <NodeConfiguration> GetConfigurations(DomainUpgradeMode upgradeMode)
        {
            var databases = new[] {
                "DO-Tests-1",
                "DO-Tests-2",
                "DO-Tests-3",
                "DO-Tests-4",
                "DO-Tests-5",
                "DO-Tests-6",
                "DO-Tests-7",
                "DO-Tests-8",
                "DO-Tests-9",
                "DO-Tests-10",
                "DO-Tests-11",
                "DO-Tests-12",
            };

            var index = 0;

            foreach (var database in databases)
            {
                index++;
                var node = new NodeConfiguration("Node" + index);
                node.UpgradeMode = upgradeMode;
                node.DatabaseMapping.Add("DO-Tests", database);
                yield return(node);
            }
        }
        private void TestWithChanges(DomainUpgradeMode secondBuildUpgradeMode, bool isExceptionExpected)
        {
            var configuration = BuildConfiguration(DomainUpgradeMode.Recreate, typeof(FirstModel.TestEntity));

            using (var domain = Domain.Build(configuration))
                using (var session = domain.OpenSession())
                    using (var tx = session.OpenTransaction()) {
                        new FirstModel.TestEntity {
                            FirstDateTimeOffset = defaultDateTimeOffset
                        };
                        tx.Complete();
                    }

            configuration = BuildConfiguration(secondBuildUpgradeMode, typeof(SecondModel.TestEntity));

            Action buildAction = () => {
                using (var domain = Domain.Build(configuration))
                    using (var session = domain.OpenSession())
                        using (var tx = session.OpenTransaction()) {
                            CheckTestEntity <SecondModel.TestEntity>();
                            tx.Complete();
                        }
            };

            if (isExceptionExpected)
            {
                Assert.Throws <SchemaSynchronizationException>(() => buildAction());
            }
            else
            {
                buildAction();
            }
        }
        private void BuildDomain(DomainUpgradeMode upgradeMode)
        {
            CleanDomain();

            var config = DomainConfigurationFactory.Create();

            config.NamingConvention.NamespacePolicy = NamespacePolicy.Synonymize;
            config.NamingConvention.NamespaceSynonyms[typeof(NonClustered.Root).Namespace]    = "NC";
            config.NamingConvention.NamespaceSynonyms[typeof(Clustered.Root).Namespace]       = "C";
            config.NamingConvention.NamespaceSynonyms[typeof(CustomClustered.Root).Namespace] = "CC";
            config.NamingConvention.NamespaceSynonyms[typeof(ErrorCases.DuplicateClusteredIndex).Namespace] = "E";

            foreach (var type in domainTypes)
            {
                config.Types.Register(type);
            }
            config.Types.Register(typeof(SingleTableSchemaModifier).Assembly, typeof(SingleTableSchemaModifier).Namespace);

            config.UpgradeMode = upgradeMode;
            if (inheritanceSchema != null)
            {
                InheritanceSchemaModifier.ActivateModifier(inheritanceSchema.Value);
            }
            else
            {
                InheritanceSchemaModifier.DeactivateModifiers();
            }

            domain = Domain.Build(config);
        }
        private void BuildDomain(Type type, DomainUpgradeMode upgradeMode)
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.Types.Register(type);
            configuration.UpgradeMode = upgradeMode;
            Domain.Build(configuration).Dispose();
        }
Ejemplo n.º 11
0
        private Dictionary <Type, int> BuildBookDomain(DomainUpgradeMode upgradeMode)
        {
            registerBook   = true;
            registerPerson = false;
            registerAuthor = false;

            return(BuildDomain("Book", upgradeMode, 1));
        }
Ejemplo n.º 12
0
        private Dictionary <Type, int> BuildFullDomain(DomainUpgradeMode upgradeMode)
        {
            registerBook   = true;
            registerPerson = true;
            registerAuthor = true;

            return(BuildDomain("Full", upgradeMode, 3));
        }
Ejemplo n.º 13
0
        public Domain BuildDomain(DomainUpgradeMode mode)
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.UpgradeMode = mode;
            configuration.Types.Register(typeof(Customer).Assembly, typeof(Customer).Namespace);
            return(Domain.Build(configuration));
        }
        private Task <Domain> BuildDomainAsync(Type sampleType, DomainUpgradeMode mode)
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.UpgradeMode = mode;
            configuration.Types.Register(sampleType.Assembly, sampleType.Namespace);
            return(Domain.BuildAsync(configuration));
        }
Ejemplo n.º 15
0
        private Domain BuildMultinodeDomain(DomainUpgradeMode domainUpgradeMode, DomainUpgradeMode nodeUpgradeMode, string masterSchema, string slaveSchema)
        {
            var pair   = BuildMultitnodeConfiguration(domainUpgradeMode, nodeUpgradeMode, masterSchema, slaveSchema);
            var domain = Domain.Build(pair.First);

            domain.StorageNodeManager.AddNode(pair.Second);
            return(domain);
        }
Ejemplo n.º 16
0
        private Task <Domain> BuildMultischemaDomainAsync(DomainUpgradeMode upgradeMode)
        {
            var configuration = BuildConfiguration(upgradeMode);

            configuration.DefaultSchema = "dbo";

            return(Domain.BuildAsync(configuration));
        }
Ejemplo n.º 17
0
        private Domain BuildDomain(DomainUpgradeMode upgradeMode, Type sampleType)
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.UpgradeMode = upgradeMode;
            configuration.Types.Register(sampleType.Assembly, sampleType.Namespace);
            return(Domain.Build(configuration));
        }
Ejemplo n.º 18
0
 protected virtual List <NodeConfiguration> GetNodes(DomainUpgradeMode upgradeMode) =>
 new List <NodeConfiguration>
 {
     new NodeConfiguration(WellKnown.DefaultNodeId)
     {
         UpgradeMode = upgradeMode
     }
 };
Ejemplo n.º 19
0
        private Domain BuildMultischemaDomain(DomainUpgradeMode upgradeMode)
        {
            var configuration = BuildConfiguration(upgradeMode);

            configuration.DefaultSchema = "dbo";

            return(Domain.Build(configuration));
        }
        private void RunTest(DomainUpgradeMode upgradeMode, bool shareStorageSchemaOverNodes, bool withModelChanges = false)
        {
            if (upgradeMode == DomainUpgradeMode.Recreate)
            {
                RunRecreateTest(shareStorageSchemaOverNodes);
                return;
            }

            var isMultinode   = nodeToSchemaMap.Count > 0;
            var configuration = BuildConfiguration();

            configuration.UpgradeMode = DomainUpgradeMode.Recreate;
            if (isMultinode)
            {
                configuration.DefaultSchema = nodeToSchemaMap[MainNodeId];
            }

            using (var initialDomain = BuildDomain(configuration)) {
                PopulateData(initialDomain, MainNodeId);
                if (isMultinode)
                {
                    var nodeConfiguration = new NodeConfiguration(AdditionalNodeId);
                    nodeConfiguration.SchemaMapping.Add(nodeToSchemaMap[MainNodeId], nodeToSchemaMap[AdditionalNodeId]);
                    nodeConfiguration.UpgradeMode = DomainUpgradeMode.Recreate;
                    initialDomain.StorageNodeManager.AddNode(nodeConfiguration);
                    PopulateData(initialDomain, AdditionalNodeId);
                }
            }

            configuration             = BuildConfiguration();
            configuration.UpgradeMode = upgradeMode;
            configuration.ShareStorageSchemaOverNodes = shareStorageSchemaOverNodes;
            configuration.Types.Register(typeof(Upgrader));
            if ((upgradeMode == DomainUpgradeMode.Perform || upgradeMode == DomainUpgradeMode.PerformSafely) && withModelChanges)
            {
                configuration.Types.Register(typeof(TypeForUgrade)); // that gives us schema cache reset
            }
            if (isMultinode)
            {
                configuration.DefaultSchema = nodeToSchemaMap[MainNodeId];
            }

            using (var domain = BuildDomain(configuration)) {
                ValidateMappings(domain, false);
                ValidateData(domain, MainNodeId);

                if (isMultinode)
                {
                    var nodeConfiguration = new NodeConfiguration(AdditionalNodeId);
                    nodeConfiguration.UpgradeMode = upgradeMode;
                    nodeConfiguration.SchemaMapping.Add(nodeToSchemaMap[MainNodeId], nodeToSchemaMap[AdditionalNodeId]);
                    domain.StorageNodeManager.AddNode(nodeConfiguration);

                    ValidateMappings(domain, true);
                    ValidateData(domain, AdditionalNodeId);
                }
            }
        }
        public void BuildWithMode(DomainUpgradeMode mode)
        {
            var configuration = BuildConfiguration();

            configuration.UpgradeMode = mode;
            var domain = BuildDomain(configuration);

            domain.Dispose();
        }
Ejemplo n.º 22
0
        private DomainConfiguration CreateConfiguration(Type type, DomainUpgradeMode upgradeMode, string defaultSchema)
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.UpgradeMode = upgradeMode;
            configuration.Types.Register(type.Assembly, type.Namespace);
            configuration.DefaultSchema = defaultSchema;
            return(configuration);
        }
        private DomainConfiguration BuildConfiguration(DomainUpgradeMode upgradeMode)
        {
            var config = DomainConfigurationFactory.Create();

            config.Types.Register(typeof(RecycledEntity).Assembly, typeof(RecycledEntity).Namespace);
            config.Types.Register(typeof(UpgradeCatcherHandler));
            config.UpgradeMode = upgradeMode;
            return(config);
        }
        private DomainConfiguration BuildDomainConfiguration(Type sampleType, DomainUpgradeMode mode)
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.UpgradeMode = mode;
            configuration.NamingConvention.NamingRules = NamingRules.UnderscoreDots;
            configuration.Types.Register(sampleType.Assembly, sampleType.Namespace);
            return(configuration);
        }
        private static DomainConfiguration BuildDomainConfiguration(DomainUpgradeMode upgradeMode, NamingRules namingRules, Type sampleType)
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.UpgradeMode = upgradeMode;
            configuration.NamingConvention.NamingRules = namingRules;
            configuration.Types.Register(sampleType.Assembly, sampleType.Namespace);
            return(configuration);
        }
Ejemplo n.º 26
0
        private Task <Domain> BuildDomainAsync(DomainUpgradeMode mode)
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.UpgradeMode = mode;
            configuration.Types.Register(typeof(A));
            configuration.Types.Register(typeof(B));
            return(Domain.BuildAsync(configuration));
        }
Ejemplo n.º 27
0
        private DomainConfiguration BuildDomainConfiguration(DomainUpgradeMode upgradeMode, TypeRegistration[] registrations)
        {
            var configuration = BuildDomainConfiguration();

            registrations.ForEach(t => configuration.Types.Register(t));
            configuration.UpgradeMode = upgradeMode;
            ApplyCustomConfigurationSettings(configuration);
            return(configuration);
        }
Ejemplo n.º 28
0
        private void AddStorageNode(Domain domain, DomainUpgradeMode upgradeMode)
        {
            var nodeConfiguration = new NodeConfiguration(additionalNodeName);

            nodeConfiguration.SchemaMapping.Add("dbo", "Model1");
            nodeConfiguration.UpgradeMode = upgradeMode;

            domain.StorageNodeManager.AddNode(nodeConfiguration);
        }
Ejemplo n.º 29
0
        private DomainConfiguration BuildConfiguration(DomainUpgradeMode upgradeMode)
        {
            var configuration = DomainConfigurationFactory.Create();

            configuration.UpgradeMode = upgradeMode;
            configuration.Types.Register(typeof(TestEntity));
            configuration.Types.Register(typeof(CustomUpgrader));
            return(configuration);
        }
Ejemplo n.º 30
0
        private async Task AddStorageNodeAsync(Domain domain, DomainUpgradeMode upgradeMode)
        {
            var nodeConfiguration = new NodeConfiguration(AdditionalNodeName);

            nodeConfiguration.SchemaMapping.Add("dbo", "Model1");
            nodeConfiguration.UpgradeMode = upgradeMode;

            _ = await domain.StorageNodeManager.AddNodeAsync(nodeConfiguration);
        }