Skip to content

Commit bdd9488

Browse files
committed
Refactors HugeModel upgrade tests
1 parent f1529d8 commit bdd9488

File tree

9 files changed

+219
-394
lines changed

9 files changed

+219
-394
lines changed

Orm/Xtensive.Orm.Tests/Upgrade/HugeModelUpgrade/DatabasePerNodeTest.cs

Lines changed: 13 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2016 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2016-2020 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Alexey Kulakov
55
// Created: 2016.10.19
66

@@ -17,84 +17,19 @@ namespace Xtensive.Orm.Tests.Upgrade.HugeModelUpgrade
1717
/// The test takes unnormal count of databases and time.
1818
/// Run it on local machine only!
1919
/// </summary>
20-
[TestFixture]
2120
[Explicit]
22-
public class DatabasePerNodeTest
21+
public sealed class DatabasePerNodeTest : HugeModelUpgradeTestBase
2322
{
24-
[Test]
25-
[Explicit]
26-
public void SequentialBuildingTest()
23+
protected override DomainConfiguration BuildConfiguration()
2724
{
28-
CheckRequirements();
29-
using (var domain = BuildDomain(BuildConfiguration(), false)) {
30-
PopulateData(domain);
31-
}
32-
33-
var configuration = BuildConfiguration();
34-
configuration.UpgradeMode = DomainUpgradeMode.Skip;
35-
GC.Collect();
36-
using (var domain = BuildDomain(configuration, false)) {
37-
var counters = domain.Extensions.Get<PerformanceResultContainer>();
38-
Console.WriteLine(counters.ToString());
39-
CheckIfQueriesWork(domain);
40-
}
41-
}
42-
43-
[Test]
44-
[Explicit]
45-
public void ParallelBuildingTest()
46-
{
47-
CheckRequirements();
48-
using (var domain = BuildDomain(BuildConfiguration(), false)) {
49-
PopulateData(domain);
50-
}
51-
52-
var configuration = BuildConfiguration();
53-
configuration.UpgradeMode = DomainUpgradeMode.Skip;
54-
GC.Collect();
55-
using (var domain = BuildDomain(configuration, true)) {
56-
var counters = domain.Extensions.Get<PerformanceResultContainer>();
57-
Console.WriteLine(counters.ToString());
58-
CheckIfQueriesWork(domain);
59-
}
60-
}
61-
62-
protected void CheckRequirements()
63-
{
64-
Require.ProviderIs(StorageProvider.SqlServer);
65-
}
66-
67-
protected DomainConfiguration BuildConfiguration()
68-
{
69-
var configuration = DomainConfigurationFactory.Create();
70-
configuration.UpgradeMode = DomainUpgradeMode.Recreate;
25+
var configuration = base.BuildConfiguration();
7126
configuration.DefaultDatabase = "DO-Tests";
7227
configuration.DefaultSchema = "dbo";
7328
configuration.Types.Register(typeof(TestEntity0).Assembly, typeof(TestEntity0).Namespace);
74-
configuration.Types.Register(typeof(UpgradePerformanceCounter));
7529
return configuration;
7630
}
7731

78-
protected Domain BuildDomain(DomainConfiguration configuration, bool isParallel)
79-
{
80-
var domain = Domain.Build(configuration);
81-
var nodes = GetConfigurations(configuration.UpgradeMode);
82-
if (isParallel) {
83-
Action<object> action = nodeConfg => domain.StorageNodeManager.AddNode((NodeConfiguration) nodeConfg);
84-
var tasks = new List<Task>();
85-
foreach (var nodeConfiguration in nodes)
86-
tasks.Add(Task.Factory.StartNew(action, nodeConfiguration));
87-
Task.WaitAll(tasks.ToArray());
88-
}
89-
else {
90-
foreach (var nodeConfiguration in nodes)
91-
domain.StorageNodeManager.AddNode(nodeConfiguration);
92-
}
93-
94-
return domain;
95-
}
96-
97-
private void PopulateData(Domain domain)
32+
protected override void PopulateData(Domain domain)
9833
{
9934
var nodes = new[] {
10035
WellKnown.DefaultNodeId,
@@ -114,7 +49,7 @@ private void PopulateData(Domain domain)
11449
}
11550
}
11651

117-
private void CheckIfQueriesWork(Domain domain)
52+
protected override void CheckIfQueriesWork(Domain domain)
11853
{
11954
var nodes = new[] {
12055
WellKnown.DefaultNodeId,
@@ -126,28 +61,18 @@ private void CheckIfQueriesWork(Domain domain)
12661
using (var session = domain.OpenSession()) {
12762
session.SelectStorageNode(node);
12863
using (var transaction = session.OpenTransaction()) {
129-
var populator = new ModelChecker();
130-
populator.Run(session);
64+
var checker = new ModelChecker();
65+
checker.Run(session);
13166
}
13267
}
13368
}
13469
}
13570

136-
private IEnumerable<NodeConfiguration> GetConfigurations(DomainUpgradeMode upgradeMode)
71+
protected override IEnumerable<NodeConfiguration> GetAdditionalNodeConfigurations(DomainUpgradeMode upgradeMode)
13772
{
13873
var databases = new[] {
139-
"DO-Tests-1",
140-
"DO-Tests-2",
141-
"DO-Tests-3",
142-
"DO-Tests-4",
143-
"DO-Tests-5",
144-
"DO-Tests-6",
145-
"DO-Tests-7",
146-
"DO-Tests-8",
147-
"DO-Tests-9",
148-
"DO-Tests-10",
149-
"DO-Tests-11",
150-
"DO-Tests-12",
74+
"DO-Tests-1", "DO-Tests-2", "DO-Tests-3", "DO-Tests-4", "DO-Tests-5", "DO-Tests-6",
75+
"DO-Tests-7", "DO-Tests-8", "DO-Tests-9", "DO-Tests-10", "DO-Tests-11", "DO-Tests-12",
15176
};
15277

15378
var index = 0;
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright (C) 2020 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using NUnit.Framework;
10+
using Xtensive.Orm.Configuration;
11+
12+
namespace Xtensive.Orm.Tests.Upgrade.HugeModelUpgrade
13+
{
14+
[TestFixture]
15+
public abstract class HugeModelUpgradeTestBase
16+
{
17+
protected virtual bool SupportsParallel => true;
18+
19+
[OneTimeSetUp]
20+
public void OneTimeSetUp() => Require.ProviderIs(StorageProvider.SqlServer);
21+
22+
[SetUp]
23+
public void SetUp()
24+
{
25+
var isParallelTest = TestContext.CurrentContext.Test.MethodName == nameof(ParallelTest);
26+
if (isParallelTest && !SupportsParallel) {
27+
throw new IgnoreException("Parallel test not supported.");
28+
}
29+
30+
using var domain = BuildDomain(BuildConfiguration(), false);
31+
PopulateData(domain);
32+
}
33+
34+
[Test]
35+
[Explicit]
36+
public void SequentialTest()
37+
{
38+
var configuration = BuildConfiguration();
39+
configuration.UpgradeMode = DomainUpgradeMode.Skip;
40+
GC.Collect();
41+
42+
using var domain = BuildDomain(configuration, false);
43+
var counters = domain.Extensions.Get<PerformanceResultContainer>();
44+
Console.WriteLine(counters.ToString());
45+
CheckIfQueriesWork(domain);
46+
}
47+
48+
[Test]
49+
[Explicit]
50+
public void ParallelTest()
51+
{
52+
var configuration = BuildConfiguration();
53+
configuration.UpgradeMode = DomainUpgradeMode.Skip;
54+
GC.Collect();
55+
56+
using var domain = BuildDomain(configuration, true);
57+
var counters = domain.Extensions.Get<PerformanceResultContainer>();
58+
Console.WriteLine(counters.ToString());
59+
CheckIfQueriesWork(domain);
60+
}
61+
62+
protected abstract void PopulateData(Domain domain);
63+
protected abstract void CheckIfQueriesWork(Domain domain);
64+
protected abstract IEnumerable<NodeConfiguration> GetAdditionalNodeConfigurations(DomainUpgradeMode upgradeMode);
65+
66+
protected virtual Domain BuildDomain(DomainConfiguration configuration, bool isParallel = false)
67+
{
68+
var domain = Domain.Build(configuration);
69+
var nodes = GetAdditionalNodeConfigurations(configuration.UpgradeMode);
70+
if (isParallel) {
71+
void BuildNode(object domainAndNodeToBuild)
72+
{
73+
var pair = ((Domain domain, NodeConfiguration nodeConfig)) domainAndNodeToBuild;
74+
_ = pair.domain.StorageNodeManager.AddNode(pair.nodeConfig);
75+
}
76+
77+
var tasks = new List<Task>();
78+
foreach (var nodeConfiguration in nodes) {
79+
tasks.Add(Task.Factory.StartNew(BuildNode, (domain, nodeConfiguration)));
80+
}
81+
Task.WaitAll(tasks.ToArray());
82+
}
83+
else {
84+
foreach (var nodeConfiguration in nodes) {
85+
_ = domain.StorageNodeManager.AddNode(nodeConfiguration);
86+
}
87+
}
88+
89+
return domain;
90+
}
91+
92+
protected virtual DomainConfiguration BuildConfiguration()
93+
{
94+
var configuration = DomainConfigurationFactory.Create();
95+
configuration.UpgradeMode = DomainUpgradeMode.Recreate;
96+
configuration.Types.Register(typeof(UpgradePerformanceCounter));
97+
return configuration;
98+
}
99+
}
100+
}

Orm/Xtensive.Orm.Tests/Upgrade/HugeModelUpgrade/MappedTypesNodesTest.cs

Lines changed: 18 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2016 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2016-2020 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Alexey Kulakov
55
// Created: 2016.10.19
66

@@ -13,85 +13,23 @@
1313

1414
namespace Xtensive.Orm.Tests.Upgrade.HugeModelUpgrade
1515
{
16-
[TestFixture]
16+
/// <summary>
17+
/// The test takes unnormal count of databases and time.
18+
/// Run it on local machine only!
19+
/// </summary>
1720
[Explicit]
18-
public class MappedTypesNodesTest
21+
public sealed class MappedTypesNodesTest : HugeModelUpgradeTestBase
1922
{
20-
[Test]
21-
[Explicit]
22-
public void SequentialBuildingTest()
23+
protected override DomainConfiguration BuildConfiguration()
2324
{
24-
CheckRequirements();
25-
using (var domain = BuildDomain(BuildConfiguration(), false)) {
26-
PopulateData(domain);
27-
}
28-
29-
var configuration = BuildConfiguration();
30-
configuration.UpgradeMode = DomainUpgradeMode.Skip;
31-
GC.Collect();
32-
using (var domain = BuildDomain(configuration, false))
33-
{
34-
var counters = domain.Extensions.Get<PerformanceResultContainer>();
35-
Console.WriteLine(counters.ToString());
36-
CheckIfQueriesWork(domain);
37-
}
38-
}
39-
40-
[Test]
41-
[Explicit]
42-
public void ParallelBuildingTest()
43-
{
44-
CheckRequirements();
45-
using (var domain = BuildDomain(BuildConfiguration(), false)) {
46-
PopulateData(domain);
47-
}
48-
49-
var configuration = BuildConfiguration();
50-
configuration.UpgradeMode = DomainUpgradeMode.Skip;
51-
GC.Collect();
52-
using (var domain = BuildDomain(configuration, true)) {
53-
var counters = domain.Extensions.Get<PerformanceResultContainer>();
54-
Console.WriteLine(counters.ToString());
55-
CheckIfQueriesWork(domain);
56-
}
57-
}
58-
59-
protected void CheckRequirements()
60-
{
61-
Require.ProviderIs(StorageProvider.SqlServer);
62-
}
63-
64-
protected DomainConfiguration BuildConfiguration()
65-
{
66-
var configuration = DomainConfigurationFactory.Create();
67-
configuration.UpgradeMode = DomainUpgradeMode.Recreate;
25+
var configuration = base.BuildConfiguration();
6826
configuration.DefaultDatabase = "DO-Tests";
6927
configuration.DefaultSchema = "dbo";
70-
configuration.Types.Register(typeof (TestEntity0).Assembly, typeof (TestEntity0).Namespace);
71-
configuration.Types.Register(typeof(UpgradePerformanceCounter));
28+
configuration.Types.Register(typeof(TestEntity0).Assembly, typeof(TestEntity0).Namespace);
7229
return configuration;
7330
}
7431

75-
protected Domain BuildDomain(DomainConfiguration configuration, bool isParallel)
76-
{
77-
var domain = Domain.Build(configuration);
78-
var nodes = GetConfigurations(configuration.UpgradeMode);
79-
if (isParallel) {
80-
Action<object> action = nodeConfg => domain.StorageNodeManager.AddNode((NodeConfiguration)nodeConfg);
81-
var tasks = new List<Task>();
82-
foreach (var nodeConfiguration in nodes)
83-
tasks.Add(Task.Factory.StartNew(action, nodeConfiguration));
84-
Task.WaitAll(tasks.ToArray());
85-
}
86-
else {
87-
foreach (var nodeConfiguration in nodes)
88-
domain.StorageNodeManager.AddNode(nodeConfiguration);
89-
}
90-
91-
return domain;
92-
}
93-
94-
private void PopulateData(Domain domain)
32+
protected override void PopulateData(Domain domain)
9533
{
9634
var nodes = new[] {
9735
WellKnown.DefaultNodeId,
@@ -111,7 +49,7 @@ private void PopulateData(Domain domain)
11149
}
11250
}
11351

114-
private void CheckIfQueriesWork(Domain domain)
52+
protected override void CheckIfQueriesWork(Domain domain)
11553
{
11654
var nodes = new[] {
11755
WellKnown.DefaultNodeId,
@@ -123,28 +61,18 @@ private void CheckIfQueriesWork(Domain domain)
12361
using (var session = domain.OpenSession()) {
12462
session.SelectStorageNode(node);
12563
using (var transaction = session.OpenTransaction()) {
126-
var populator = new ModelChecker();
127-
populator.Run(session);
64+
var checker = new ModelChecker();
65+
checker.Run(session);
12866
}
12967
}
13068
}
13169
}
13270

133-
private IEnumerable<NodeConfiguration> GetConfigurations(DomainUpgradeMode upgradeMode)
71+
protected override IEnumerable<NodeConfiguration> GetAdditionalNodeConfigurations(DomainUpgradeMode upgradeMode)
13472
{
13573
var databases = new[] {
136-
"DO-Tests-1",
137-
"DO-Tests-2",
138-
"DO-Tests-3",
139-
"DO-Tests-4",
140-
"DO-Tests-5",
141-
"DO-Tests-6",
142-
"DO-Tests-7",
143-
"DO-Tests-8",
144-
"DO-Tests-9",
145-
"DO-Tests-10",
146-
"DO-Tests-11",
147-
"DO-Tests-12",
74+
"DO-Tests-1", "DO-Tests-2", "DO-Tests-3", "DO-Tests-4", "DO-Tests-5", "DO-Tests-6",
75+
"DO-Tests-7", "DO-Tests-8", "DO-Tests-9", "DO-Tests-10", "DO-Tests-11", "DO-Tests-12",
14876
};
14977

15078
var index = 0;

0 commit comments

Comments
 (0)