-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSqlTaskInParallelTests.cs
More file actions
74 lines (70 loc) · 2.23 KB
/
SqlTaskInParallelTests.cs
File metadata and controls
74 lines (70 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System.Threading.Tasks;
using ALE.ETLBox;
using ALE.ETLBox.ControlFlow;
using TestControlFlowTasks.Fixtures;
using TestShared.Attributes;
namespace TestControlFlowTasks;
public class SqlTaskInParallelTests : ControlFlowTestBase
{
public SqlTaskInParallelTests(ControlFlowDatabaseFixture fixture)
: base(fixture)
{
CreateTableTask.Create(
SqlConnection,
"FastParallel",
new List<TableColumn> { new("id", "int") }
);
}
[MultiprocessorOnlyFact]
public void FastExecutingSqlsInParallel()
{
//Arrange
var array = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
//Act
Parallel.ForEach(
array,
new ParallelOptions { MaxDegreeOfParallelism = 8 },
curNr =>
SqlTask.ExecuteNonQuery(
SqlConnection,
$"Test statement {curNr}",
$"INSERT INTO FastParallel VALUES({curNr})"
)
);
//Assert
Assert.Equal(10, RowCountTask.Count(SqlConnection, "FastParallel"));
}
[MultiprocessorOnlyFact]
[Trait("Category", "Performance")]
public void LongExecutingSqlTaskInParallel()
{
//Arrange
var array = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
//Act
Parallel.ForEach(
array,
new ParallelOptions { MaxDegreeOfParallelism = 8 },
curNr =>
SqlTask.ExecuteNonQuery(
SqlConnection,
$"Test statement {curNr}",
$@"
DECLARE @counter INT = 0;
CREATE TABLE dbo.LongParallel{curNr} (
Col1 nvarchar(50)
)
WHILE @counter < 5000
BEGIN
SET @counter = @counter + 1;
INSERT INTO dbo.LongParallel{curNr} values('Lorem ipsum Lorem ipsum Lorem ipsum Lorem')
END
"
)
);
//Assert
Parallel.ForEach(
array,
curNr => Assert.Equal(5000, RowCountTask.Count(SqlConnection, $"LongParallel{curNr}"))
);
}
}