Datei: StressTests/StressTest/StressTestOptions.cs

Last Commit (9de6a8c)
1 -- File didn't exist --
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
New 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