-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
59 lines (52 loc) · 2.1 KB
/
Program.cs
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
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LockDemo {
public enum ServerType {
MsSql,
MySql,
Postgres,
Oracle
}
class Program {
public static ServerType ServerType;
public static string ConnectionString;
public static bool UseLocks;
public static int ThreadCount;
public static int RepeatCount;
static void Main(string[] args) {
try {
// If useLocks=true, test should complete without errors.
// Try running with 'useLocks:false' to see errors - deadlocks and inconsistent reads
LoadConfig();
Console.WriteLine(string.Format("Running locking demo." +
"\r\n Server type: {0}, thread count: {1}, repeat count: {2}, use locks: {3}",
ServerType, ThreadCount, RepeatCount, UseLocks));
var runner = new TestRunner();
runner.RunParallelRandomOps();
Console.WriteLine();
Console.WriteLine("=========================================================================");
Console.WriteLine(string.Format("Done. DB errors/deadlocks: {0}, Inconsistent reads: : {1}",
runner.DbErrorCount, runner.InconsistentReadCount));
} catch (Exception ex) {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Error: " + ex.ToString());
Console.ForegroundColor = ConsoleColor.White;
}
Console.WriteLine("Press any key.");
Console.ReadKey();
}
private static void LoadConfig() {
var strServerType = ConfigurationManager.AppSettings["ServerType"];
if(!Enum.TryParse(strServerType, out ServerType))
throw new Exception("Config error, invalid server type: " + strServerType);
ConnectionString = ConfigurationManager.AppSettings[ServerType + "ConnectionString"];
UseLocks = ConfigurationManager.AppSettings["UseLocks"] == "true";
ThreadCount = int.Parse(ConfigurationManager.AppSettings["ThreadCount"]);
RepeatCount = int.Parse(ConfigurationManager.AppSettings["RepeatCount"]);
}
}
}