|
1 | | -using System; |
2 | | -using System.Collections.Generic; |
3 | | -using System.Threading.Tasks; |
4 | | -using NUnit.Framework; |
5 | | -using Xtensive.Orm.Configuration; |
6 | | -using Xtensive.Orm.Tests.Upgrade.HugeModelUpgrade; |
7 | | -using Xtensive.Orm.Tests.Upgrade.HugeModelUpgrade.TwoPartsModel; |
8 | | - |
9 | | -namespace Xtensive.Orm.Tests.Upgrade.HugeModelUpgrade |
10 | | -{ |
11 | | - [TestFixture] |
12 | | - [Explicit] |
13 | | - public class TwoSchemasPerNode |
14 | | - { |
15 | | - [Test] |
16 | | - [Explicit] |
17 | | - public void SequentialBuildingTest() |
18 | | - { |
19 | | - CheckRequirements(); |
20 | | - using (var domain = BuildDomain(BuildConfiguration(), false)) { |
21 | | - PopulateData(domain); |
22 | | - } |
23 | | - |
24 | | - var configuration = BuildConfiguration(); |
25 | | - configuration.UpgradeMode = DomainUpgradeMode.Skip; |
26 | | - GC.Collect(); |
27 | | - using (var domain = BuildDomain(configuration, false)) |
28 | | - { |
29 | | - var counters = domain.Extensions.Get<PerformanceResultContainer>(); |
30 | | - Console.WriteLine(counters.ToString()); |
31 | | - CheckIfQueriesWork(domain); |
32 | | - } |
33 | | - } |
34 | | - |
35 | | - protected void CheckRequirements() |
36 | | - { |
37 | | - Require.ProviderIs(StorageProvider.SqlServer); |
38 | | - } |
39 | | - |
40 | | - protected DomainConfiguration BuildConfiguration() |
41 | | - { |
42 | | - var configuration = DomainConfigurationFactory.Create(); |
43 | | - configuration.UpgradeMode = DomainUpgradeMode.Recreate; |
44 | | - //configuration.DefaultDatabase = "DO-Tests"; |
45 | | - configuration.DefaultSchema = "dbo"; |
46 | | - configuration.Types.Register(typeof(HugeModelUpgrade.TwoPartsModel.PartOne.TestEntityOne0).Assembly, typeof(HugeModelUpgrade.TwoPartsModel.PartOne.TestEntityOne0).Namespace); |
47 | | - configuration.Types.Register(typeof(HugeModelUpgrade.TwoPartsModel.PartTwo.TestEntityTwo0).Assembly, typeof(HugeModelUpgrade.TwoPartsModel.PartTwo.TestEntityTwo0).Namespace); |
48 | | - |
49 | | - configuration.MappingRules |
50 | | - .Map(typeof(HugeModelUpgrade.TwoPartsModel.PartOne.TestEntityOne0).Assembly, typeof(HugeModelUpgrade.TwoPartsModel.PartOne.TestEntityOne0).Namespace) |
51 | | - .ToSchema("dbo"); |
52 | | - configuration.MappingRules |
53 | | - .Map(typeof(HugeModelUpgrade.TwoPartsModel.PartTwo.TestEntityTwo0).Assembly, typeof(HugeModelUpgrade.TwoPartsModel.PartTwo.TestEntityTwo0).Namespace) |
54 | | - .ToSchema("Model1"); |
55 | | - configuration.Types.Register(typeof(UpgradePerformanceCounter)); |
56 | | - return configuration; |
57 | | - } |
58 | | - |
59 | | - protected Domain BuildDomain(DomainConfiguration configuration, bool isParallel) |
60 | | - { |
61 | | - var domain = Domain.Build(configuration); |
62 | | - var nodes = GetConfigurations(configuration.UpgradeMode); |
63 | | - if (isParallel) { |
64 | | - Action<object> action = nodeConfg => domain.StorageNodeManager.AddNode((NodeConfiguration) nodeConfg); |
65 | | - var tasks = new List<Task>(); |
66 | | - foreach (var nodeConfiguration in nodes) |
67 | | - tasks.Add(Task.Factory.StartNew(action, nodeConfiguration)); |
68 | | - Task.WaitAll(tasks.ToArray()); |
69 | | - } |
70 | | - else { |
71 | | - foreach (var nodeConfiguration in nodes) |
72 | | - domain.StorageNodeManager.AddNode(nodeConfiguration); |
73 | | - } |
74 | | - |
75 | | - return domain; |
76 | | - } |
77 | | - |
78 | | - private void PopulateData(Domain domain) |
79 | | - { |
80 | | - var nodes = new[] { |
81 | | - WellKnown.DefaultNodeId, |
82 | | - "Node1", "Node2", "Node3", "Node4", "Node5", |
83 | | - }; |
84 | | - |
85 | | - foreach (var node in nodes) { |
86 | | - using (var session = domain.OpenSession()) { |
87 | | - session.SelectStorageNode(node); |
88 | | - using (var transaction = session.OpenTransaction()) { |
89 | | - var populator = new ModelPopulator(); |
90 | | - populator.Run(); |
91 | | - transaction.Complete(); |
92 | | - } |
93 | | - } |
94 | | - } |
95 | | - } |
96 | | - |
97 | | - private void CheckIfQueriesWork(Domain domain) |
98 | | - { |
99 | | - var nodes = new[] { |
100 | | - WellKnown.DefaultNodeId, |
101 | | - "Node1", "Node2", "Node3", "Node4", "Node5", |
102 | | - }; |
103 | | - |
104 | | - foreach (var node in nodes) { |
105 | | - using (var session = domain.OpenSession()) { |
106 | | - session.SelectStorageNode(node); |
107 | | - using (var transaction = session.OpenTransaction()) { |
108 | | - var populator = new ModelChecker(); |
109 | | - populator.Run(session); |
110 | | - } |
111 | | - } |
112 | | - } |
113 | | - } |
114 | | - |
115 | | - private IEnumerable<NodeConfiguration> GetConfigurations(DomainUpgradeMode upgradeMode) |
116 | | - { |
117 | | - var schemas = new[] { |
118 | | - "Model2", "Model3", |
119 | | - "Model4", "Model5", |
120 | | - "Model6", "Model7", |
121 | | - "Model8", "Model9", |
122 | | - "Model10", "Model11", |
123 | | - }; |
124 | | - |
125 | | - for (int index = 0, nodeIndex = 1; index < 10; index += 2, nodeIndex++) |
126 | | - { |
127 | | - var node = new NodeConfiguration("Node" + nodeIndex); |
128 | | - node.UpgradeMode = upgradeMode; |
129 | | - node.SchemaMapping.Add("dbo", schemas[index]); |
130 | | - node.SchemaMapping.Add("Model1", schemas[index + 1]); |
131 | | - yield return node; |
132 | | - } |
133 | | - } |
134 | | - } |
135 | | -} |
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Threading.Tasks; |
| 4 | +using NUnit.Framework; |
| 5 | +using Xtensive.Orm.Configuration; |
| 6 | +using Xtensive.Orm.Tests.Upgrade.HugeModelUpgrade; |
| 7 | +using Xtensive.Orm.Tests.Upgrade.HugeModelUpgrade.TwoPartsModel; |
| 8 | + |
| 9 | +namespace Xtensive.Orm.Tests.Upgrade.HugeModelUpgrade |
| 10 | +{ |
| 11 | + [TestFixture] |
| 12 | + [Explicit] |
| 13 | + public class TwoSchemasPerNode |
| 14 | + { |
| 15 | + [Test] |
| 16 | + [Explicit] |
| 17 | + public void SequentialBuildingTest() |
| 18 | + { |
| 19 | + CheckRequirements(); |
| 20 | + using (var domain = BuildDomain(BuildConfiguration(), false)) { |
| 21 | + PopulateData(domain); |
| 22 | + } |
| 23 | + |
| 24 | + var configuration = BuildConfiguration(); |
| 25 | + configuration.UpgradeMode = DomainUpgradeMode.Skip; |
| 26 | + GC.Collect(); |
| 27 | + using (var domain = BuildDomain(configuration, false)) { |
| 28 | + var counters = domain.Extensions.Get<PerformanceResultContainer>(); |
| 29 | + Console.WriteLine(counters.ToString()); |
| 30 | + CheckIfQueriesWork(domain); |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + protected void CheckRequirements() |
| 35 | + { |
| 36 | + Require.ProviderIs(StorageProvider.SqlServer); |
| 37 | + } |
| 38 | + |
| 39 | + protected DomainConfiguration BuildConfiguration() |
| 40 | + { |
| 41 | + var configuration = DomainConfigurationFactory.Create(); |
| 42 | + configuration.UpgradeMode = DomainUpgradeMode.Recreate; |
| 43 | + //configuration.DefaultDatabase = "DO-Tests"; |
| 44 | + configuration.DefaultSchema = "dbo"; |
| 45 | + configuration.Types.Register(typeof(HugeModelUpgrade.TwoPartsModel.PartOne.TestEntityOne0).Assembly, typeof(HugeModelUpgrade.TwoPartsModel.PartOne.TestEntityOne0).Namespace); |
| 46 | + configuration.Types.Register(typeof(HugeModelUpgrade.TwoPartsModel.PartTwo.TestEntityTwo0).Assembly, typeof(HugeModelUpgrade.TwoPartsModel.PartTwo.TestEntityTwo0).Namespace); |
| 47 | + |
| 48 | + configuration.MappingRules |
| 49 | + .Map(typeof(HugeModelUpgrade.TwoPartsModel.PartOne.TestEntityOne0).Assembly, typeof(HugeModelUpgrade.TwoPartsModel.PartOne.TestEntityOne0).Namespace) |
| 50 | + .ToSchema("dbo"); |
| 51 | + configuration.MappingRules |
| 52 | + .Map(typeof(HugeModelUpgrade.TwoPartsModel.PartTwo.TestEntityTwo0).Assembly, typeof(HugeModelUpgrade.TwoPartsModel.PartTwo.TestEntityTwo0).Namespace) |
| 53 | + .ToSchema("Model1"); |
| 54 | + configuration.Types.Register(typeof(UpgradePerformanceCounter)); |
| 55 | + return configuration; |
| 56 | + } |
| 57 | + |
| 58 | + protected Domain BuildDomain(DomainConfiguration configuration, bool isParallel) |
| 59 | + { |
| 60 | + var domain = Domain.Build(configuration); |
| 61 | + var nodes = GetConfigurations(configuration.UpgradeMode); |
| 62 | + if (isParallel) { |
| 63 | + Action<object> action = nodeConfg => domain.StorageNodeManager.AddNode((NodeConfiguration) nodeConfg); |
| 64 | + var tasks = new List<Task>(); |
| 65 | + foreach (var nodeConfiguration in nodes) |
| 66 | + tasks.Add(Task.Factory.StartNew(action, nodeConfiguration)); |
| 67 | + Task.WaitAll(tasks.ToArray()); |
| 68 | + } |
| 69 | + else { |
| 70 | + foreach (var nodeConfiguration in nodes) |
| 71 | + domain.StorageNodeManager.AddNode(nodeConfiguration); |
| 72 | + } |
| 73 | + |
| 74 | + return domain; |
| 75 | + } |
| 76 | + |
| 77 | + private void PopulateData(Domain domain) |
| 78 | + { |
| 79 | + var nodes = new[] { |
| 80 | + WellKnown.DefaultNodeId, |
| 81 | + "Node1", "Node2", "Node3", "Node4", "Node5", |
| 82 | + }; |
| 83 | + |
| 84 | + foreach (var node in nodes) { |
| 85 | + using (var session = domain.OpenSession()) { |
| 86 | + session.SelectStorageNode(node); |
| 87 | + using (var transaction = session.OpenTransaction()) { |
| 88 | + var populator = new ModelPopulator(); |
| 89 | + populator.Run(); |
| 90 | + transaction.Complete(); |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + private void CheckIfQueriesWork(Domain domain) |
| 97 | + { |
| 98 | + var nodes = new[] { |
| 99 | + WellKnown.DefaultNodeId, |
| 100 | + "Node1", "Node2", "Node3", "Node4", "Node5", |
| 101 | + }; |
| 102 | + |
| 103 | + foreach (var node in nodes) { |
| 104 | + using (var session = domain.OpenSession()) { |
| 105 | + session.SelectStorageNode(node); |
| 106 | + using (var transaction = session.OpenTransaction()) { |
| 107 | + var populator = new ModelChecker(); |
| 108 | + populator.Run(session); |
| 109 | + } |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + private IEnumerable<NodeConfiguration> GetConfigurations(DomainUpgradeMode upgradeMode) |
| 115 | + { |
| 116 | + var schemas = new[] { |
| 117 | + "Model2", "Model3", |
| 118 | + "Model4", "Model5", |
| 119 | + "Model6", "Model7", |
| 120 | + "Model8", "Model9", |
| 121 | + "Model10", "Model11", |
| 122 | + }; |
| 123 | + |
| 124 | + for (int index = 0, nodeIndex = 1; index < 10; index += 2, nodeIndex++) { |
| 125 | + var node = new NodeConfiguration("Node" + nodeIndex); |
| 126 | + node.UpgradeMode = upgradeMode; |
| 127 | + node.SchemaMapping.Add("dbo", schemas[index]); |
| 128 | + node.SchemaMapping.Add("Model1", schemas[index + 1]); |
| 129 | + yield return node; |
| 130 | + } |
| 131 | + } |
| 132 | + } |
| 133 | +} |
0 commit comments