-
Notifications
You must be signed in to change notification settings - Fork 2k
/
TestClusterOptions.cs
105 lines (97 loc) · 4.69 KB
/
TestClusterOptions.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Collections.Generic;
using Orleans.Runtime;
namespace Orleans.TestingHost
{
public class TestClusterOptions
{
public string ClusterId { get; set; }
public string ServiceId { get; set; }
public int BaseSiloPort{ get; set; }
public int BaseGatewayPort { get; set; }
public bool UseTestClusterMembership { get; set; }
public bool InitializeClientOnDeploy { get; set; }
public short InitialSilosCount { get; set; }
public string ApplicationBaseDirectory { get; set; }
public bool ConfigureFileLogging { get; set; } = true;
public bool AssumeHomogenousSilosForTesting { get; set; }
public bool GatewayPerSilo { get; set; } = true;
public List<string> SiloBuilderConfiguratorTypes { get; } = new List<string>();
public List<string> ClientBuilderConfiguratorTypes { get; } = new List<string>();
public Dictionary<string, string> ToDictionary()
{
var result = new Dictionary<string, string>
{
[nameof(ClusterId)] = this.ClusterId,
[nameof(ServiceId)] = this.ServiceId,
[nameof(BaseSiloPort)] = this.BaseSiloPort.ToString(),
[nameof(BaseGatewayPort)] = this.BaseGatewayPort.ToString(),
[nameof(UseTestClusterMembership)] = this.UseTestClusterMembership.ToString(),
[nameof(InitializeClientOnDeploy)] = this.InitializeClientOnDeploy.ToString(),
[nameof(InitialSilosCount)] = this.InitialSilosCount.ToString(),
[nameof(ApplicationBaseDirectory)] = this.ApplicationBaseDirectory,
[nameof(ConfigureFileLogging)] = this.ConfigureFileLogging.ToString(),
[nameof(AssumeHomogenousSilosForTesting)] = this.AssumeHomogenousSilosForTesting.ToString(),
[nameof(GatewayPerSilo)] = this.GatewayPerSilo.ToString(),
};
if (this.SiloBuilderConfiguratorTypes != null)
{
for (int i = 0; i < this.SiloBuilderConfiguratorTypes.Count; i++)
{
result[$"{nameof(SiloBuilderConfiguratorTypes)}:{i}"] = this.SiloBuilderConfiguratorTypes[i];
}
}
if (this.ClientBuilderConfiguratorTypes != null)
{
for (int i = 0; i < this.ClientBuilderConfiguratorTypes.Count; i++)
{
result[$"{nameof(ClientBuilderConfiguratorTypes)}:{i}"] = this.ClientBuilderConfiguratorTypes[i];
}
}
return result;
}
}
public class TestSiloSpecificOptions
{
public int SiloPort { get; set; }
public int GatewayPort { get; set; }
public string SiloName { get; set; }
public int PrimarySiloPort { get; set; }
public static TestSiloSpecificOptions Create(TestCluster testCluster, TestClusterOptions testClusterOptions, int instanceNumber, bool assignNewPort = false)
{
var siloName = testClusterOptions.UseTestClusterMembership && instanceNumber == 0
? Silo.PrimarySiloName
: $"Secondary_{instanceNumber}";
if (assignNewPort)
{
(int siloPort, int gatewayPort) = testCluster.PortAllocator.AllocateConsecutivePortPairs(1);
var result = new TestSiloSpecificOptions
{
SiloPort = siloPort,
GatewayPort = (instanceNumber == 0 || testClusterOptions.GatewayPerSilo) ? gatewayPort : 0,
SiloName = siloName,
PrimarySiloPort = testClusterOptions.UseTestClusterMembership ? testClusterOptions.BaseSiloPort : 0,
};
return result;
}
else
{
var result = new TestSiloSpecificOptions
{
SiloPort = testClusterOptions.BaseSiloPort + instanceNumber,
GatewayPort = (instanceNumber == 0 || testClusterOptions.GatewayPerSilo) ? testClusterOptions.BaseGatewayPort + instanceNumber : 0,
SiloName = siloName,
PrimarySiloPort = testClusterOptions.UseTestClusterMembership ? testClusterOptions.BaseSiloPort : 0,
};
return result;
}
}
public Dictionary<string, string> ToDictionary() => new Dictionary<string, string>
{
[nameof(SiloPort)] = this.SiloPort.ToString(),
[nameof(GatewayPort)] = this.GatewayPort.ToString(),
[nameof(SiloName)] = this.SiloName,
[nameof(PrimarySiloPort)] = this.PrimarySiloPort.ToString()
};
}
}