Datei: StressTests/StressTest/StressTestOptions.cs

Last Commit (bbf1d57)
1 using System;
2 using System.Data;
3 using System.Text;
4 using NDO;
5
6 namespace StressTest
7 {
8 ····/// <summary>
9 ····/// Options of the stress test. Bound to the section "StressTest" of the configuration.
10 ····/// </summary>
11 ····public class StressTestOptions
12 ····{
13 ········public string Provider { get; set; } = "Sqlite";
14 ········public string ConnectionString { get; set; }
15 ········public int Threads { get; set; } = 32;
16 ········public int Iterations { get; set; } = 25;
17 ········public int DurationSeconds { get; set; }
18 ········public int LinesPerOrder { get; set; } = 5;
19 ········public int TagCount { get; set; } = 8;
20 ········public TransactionMode TransactionMode { get; set; } = TransactionMode.Optimistic;
21 ········/// <summary>
22 ········/// Isolation level of the transactions. Null means: use the default of NDO.
23 ········/// </summary>
24 ········public IsolationLevel? IsolationLevel { get; set; }
25 ········public bool SharedMapping { get; set; } = true;
26 ········public bool RecreateSchema { get; set; } = true;
27 ········public bool DropSchemaAfterTest { get; set; }
28 ········public bool StopOnFirstError { get; set; }
 
 
 
 
29 ········public int MaxErrorsToPrint { get; set; } = 20;
30 ········public int ProgressIntervalSeconds { get; set; } = 5;
31
32 ········public void Validate()
33 ········{
34 ············if (String.IsNullOrEmpty( Provider ))
35 ················throw new ArgumentException( "No provider given." );
36 ············if (String.IsNullOrEmpty( ConnectionString ))
37 ················throw new ArgumentException( $"No connection string for provider '{Provider}' given. Add it to the section ConnectionStrings in appsettings.json or use --connection." );
38 ············if (Threads < 1)
39 ················throw new ArgumentException( "Threads must be > 0." );
40 ············if (Iterations < 1 && DurationSeconds < 1)
41 ················throw new ArgumentException( "Either Iterations or DurationSeconds must be > 0." );
42 ············// The worker removes one line and adds one line, so we need at least two lines
43 ············if (LinesPerOrder < 2)
44 ················throw new ArgumentException( "LinesPerOrder must be >= 2." );
45 ············// Each order gets two tags, the update replaces one of them by a third tag
46 ············if (TagCount < 3)
47 ················throw new ArgumentException( "TagCount must be >= 3." );
 
 
48 ········}
49
50 ········public override string ToString()
51 ········{
52 ············var sb = new StringBuilder();
53 ············sb.AppendLine( $"Provider:··········{Provider}" );
54 ············sb.AppendLine( $"Connection string: {MaskPassword( ConnectionString )}" );
55 ············sb.AppendLine( $"Threads:·········· {Threads}" );
56 ············if (DurationSeconds > 0)
57 ················sb.AppendLine( $"Duration:··········{DurationSeconds} s" );
58 ············else
59 ················sb.AppendLine( $"Iterations:········{Iterations} per thread" );
60 ············sb.AppendLine( $"Lines per order:·· {LinesPerOrder}" );
61 ············sb.AppendLine( $"Tags:··············{TagCount}" );
62 ············sb.AppendLine( $"TransactionMode:·· {TransactionMode}" );
63 ············sb.AppendLine( $"IsolationLevel:····{(IsolationLevel.HasValue ? IsolationLevel.ToString() : "NDO default")}" );
64 sb. Append( $"Shared mapping: { SharedMapping} " ) ;
 
65 ············return sb.ToString();
66 ········}
67
68 ········static string MaskPassword( string connectionString )
69 ········{
70 ············if (connectionString == null)
71 ················return null;
72 ············var parts = connectionString.Split( ';' );
73 ············for (int i = 0; i < parts.Length; i++)
74 ············{
75 ················int eq = parts[i].IndexOf( '=' );
76 ················if (eq < 0)
77 ····················continue;
78 ················string key = parts[i].Substring( 0, eq ).Trim();
79 ················if (key.Equals( "Password", StringComparison.OrdinalIgnoreCase ) || key.Equals( "Pwd", StringComparison.OrdinalIgnoreCase ))
80 ····················parts[i] = key + "=***";
81 ············}
82 ············return String.Join( ";", parts );
83 ········}
84 ····}
85 }
86
New Commit (4a40b5b)
1 using System;
2 using System.Data;
3 using System.Text;
4 using NDO;
5
6 namespace StressTest
7 {
8 ····/// <summary>
9 ····/// Options of the stress test. Bound to the section "StressTest" of the configuration.
10 ····/// </summary>
11 ····public class StressTestOptions
12 ····{
13 ········public string Provider { get; set; } = "Sqlite";
14 ········public string ConnectionString { get; set; }
15 ········public int Threads { get; set; } = 32;
16 ········public int Iterations { get; set; } = 25;
17 ········public int DurationSeconds { get; set; }
18 ········public int LinesPerOrder { get; set; } = 5;
19 ········public int TagCount { get; set; } = 8;
20 ········public TransactionMode TransactionMode { get; set; } = TransactionMode.Optimistic;
21 ········/// <summary>
22 ········/// Isolation level of the transactions. Null means: use the default of NDO.
23 ········/// </summary>
24 ········public IsolationLevel? IsolationLevel { get; set; }
25 ········public bool SharedMapping { get; set; } = true;
26 ········public bool RecreateSchema { get; set; } = true;
27 ········public bool DropSchemaAfterTest { get; set; }
28 ········public bool StopOnFirstError { get; set; }
29 ········/// <summary>
30 ········/// Number of retries of a step, if the database chose the transaction as deadlock victim. 0 turns off the retries.
31 ········/// </summary>
32 ········public int DeadlockRetries { get; set; } = 5;
33 ········public int MaxErrorsToPrint { get; set; } = 20;
34 ········public int ProgressIntervalSeconds { get; set; } = 5;
35
36 ········public void Validate()
37 ········{
38 ············if (String.IsNullOrEmpty( Provider ))
39 ················throw new ArgumentException( "No provider given." );
40 ············if (String.IsNullOrEmpty( ConnectionString ))
41 ················throw new ArgumentException( $"No connection string for provider '{Provider}' given. Add it to the section ConnectionStrings in appsettings.json or use --connection." );
42 ············if (Threads < 1)
43 ················throw new ArgumentException( "Threads must be > 0." );
44 ············if (Iterations < 1 && DurationSeconds < 1)
45 ················throw new ArgumentException( "Either Iterations or DurationSeconds must be > 0." );
46 ············// The worker removes one line and adds one line, so we need at least two lines
47 ············if (LinesPerOrder < 2)
48 ················throw new ArgumentException( "LinesPerOrder must be >= 2." );
49 ············// Each order gets two tags, the update replaces one of them by a third tag
50 ············if (TagCount < 3)
51 ················throw new ArgumentException( "TagCount must be >= 3." );
52 ············if (DeadlockRetries < 0)
53 ················throw new ArgumentException( "DeadlockRetries must be >= 0." );
54 ········}
55
56 ········public override string ToString()
57 ········{
58 ············var sb = new StringBuilder();
59 ············sb.AppendLine( $"Provider:··········{Provider}" );
60 ············sb.AppendLine( $"Connection string: {MaskPassword( ConnectionString )}" );
61 ············sb.AppendLine( $"Threads:·········· {Threads}" );
62 ············if (DurationSeconds > 0)
63 ················sb.AppendLine( $"Duration:··········{DurationSeconds} s" );
64 ············else
65 ················sb.AppendLine( $"Iterations:········{Iterations} per thread" );
66 ············sb.AppendLine( $"Lines per order:·· {LinesPerOrder}" );
67 ············sb.AppendLine( $"Tags:··············{TagCount}" );
68 ············sb.AppendLine( $"TransactionMode:·· {TransactionMode}" );
69 ············sb.AppendLine( $"IsolationLevel:····{(IsolationLevel.HasValue ? IsolationLevel.ToString() : "NDO default")}" );
70 sb. AppendLine( $"Shared mapping: { SharedMapping} " ) ;
71 ············sb.Append(···· $"Deadlock retries:··{DeadlockRetries}" );
72 ············return sb.ToString();
73 ········}
74
75 ········static string MaskPassword( string connectionString )
76 ········{
77 ············if (connectionString == null)
78 ················return null;
79 ············var parts = connectionString.Split( ';' );
80 ············for (int i = 0; i < parts.Length; i++)
81 ············{
82 ················int eq = parts[i].IndexOf( '=' );
83 ················if (eq < 0)
84 ····················continue;
85 ················string key = parts[i].Substring( 0, eq ).Trim();
86 ················if (key.Equals( "Password", StringComparison.OrdinalIgnoreCase ) || key.Equals( "Pwd", StringComparison.OrdinalIgnoreCase ))
87 ····················parts[i] = key + "=***";
88 ············}
89 ············return String.Join( ";", parts );
90 ········}
91 ····}
92 }
93