Created
October 16, 2015 22:02
-
-
Save ReubenBond/246abd329e9e1ee18e13 to your computer and use it in GitHub Desktop.
TestAzureSilo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace TestAzureSilo | |
{ | |
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Globalization; | |
using System.Net; | |
using Orleans; | |
using Orleans.Runtime; | |
using Orleans.Runtime.Configuration; | |
using Orleans.Storage; | |
using UnitTests.GrainInterfaces; | |
using UnitTests.Grains; | |
/// <summary> | |
/// The program. | |
/// </summary> | |
class Program | |
{ | |
/// <summary> | |
/// The deployment id. | |
/// </summary> | |
private const string DeploymentId = "testazuresilo"; | |
/// <summary> | |
/// The connection string. | |
/// </summary> | |
private const string ConnectionString = "UseDevelopmentStorage=true"; | |
/// <summary> | |
/// The main. | |
/// </summary> | |
/// <param name="args"> | |
/// The args. | |
/// </param> | |
public static void Main(string[] args) | |
{ | |
Trace.TraceInformation("Loaded {0} & {1}", typeof(SimpleGrain).Assembly, typeof(ISimpleGrain).Assembly); | |
var siloNum = 0; | |
if (args.Length > 0) | |
{ | |
if (args[0] == "c") | |
{ | |
RunClient(); | |
return; | |
} | |
siloNum = int.Parse(args[0]); | |
} | |
var config = GetClusterConfiguration(); | |
config.Defaults.ProxyGatewayEndpoint = new IPEndPoint(IPAddress.Loopback, 30000 + siloNum); | |
config.Defaults.HostNameOrIPAddress = IPAddress.Loopback.ToString(); | |
config.Defaults.Port = 11111 + siloNum; | |
var process = Process.GetCurrentProcess(); | |
var name = process.MachineName + "_" + process.Id + "_" + siloNum; | |
var silo = new Silo(name, Silo.SiloType.Primary, config); | |
Trace.TraceInformation("Silo Configuration:\n{0}", config.ToString(name)); | |
silo.Start(); | |
silo.SiloTerminatedEvent.WaitOne(); | |
} | |
/// <summary> | |
/// The run client. | |
/// </summary> | |
private static void RunClient() | |
{ | |
GrainClient.Initialize(GetConfiguration()); | |
Console.WriteLine("SetA(9)"); | |
var grain = GrainClient.GrainFactory.GetGrain<ISimpleGrain>(0); | |
grain.SetA(9).Wait(); | |
Console.WriteLine("GetA() = {0}", grain.GetA().Result); | |
Console.WriteLine("Done"); | |
Console.ReadKey(); | |
} | |
/// <summary> | |
/// The get configuration. | |
/// </summary> | |
/// <returns> | |
/// The <see cref="ClientConfiguration"/>. | |
/// </returns> | |
public static ClientConfiguration GetConfiguration() | |
{ | |
return new ClientConfiguration | |
{ | |
DataConnectionString = ConnectionString, | |
DeploymentId = DeploymentId, | |
PropagateActivityId = true, | |
DefaultTraceLevel = Logger.Severity.Info, | |
GatewayProvider = ClientConfiguration.GatewayProviderType.AzureTable, | |
TraceToConsole = true, | |
StatisticsCollectionLevel = StatisticsLevel.Critical, | |
StatisticsLogWriteInterval = TimeSpan.FromDays(6), | |
TraceFileName = null, | |
TraceFilePattern = null, | |
WriteMessagingTraces = false, | |
TraceLevelOverrides = | |
{ | |
Tuple.Create("Catalog", Logger.Severity.Warning), | |
Tuple.Create("Dispatcher", Logger.Severity.Warning), | |
Tuple.Create("Runtime", Logger.Severity.Warning), | |
Tuple.Create("Orleans", Logger.Severity.Warning) | |
}, | |
ResponseTimeout = TimeSpan.FromSeconds(90), | |
StatisticsMetricsTableWriteInterval = TimeSpan.FromDays(6), | |
StatisticsPerfCountersWriteInterval = TimeSpan.FromDays(6), | |
}; | |
} | |
/// <summary> | |
/// The get cluster configuration. | |
/// </summary> | |
/// <returns> | |
/// The <see cref="ClusterConfiguration"/>. | |
/// </returns> | |
public static ClusterConfiguration GetClusterConfiguration() | |
{ | |
var config = new ClusterConfiguration | |
{ | |
Defaults = | |
{ | |
TraceFileName = null, | |
TraceFilePattern = null, | |
StatisticsCollectionLevel = StatisticsLevel.Info, | |
StatisticsLogWriteInterval = TimeSpan.FromDays(6), | |
TurnWarningLengthThreshold = TimeSpan.FromSeconds(15), | |
TraceToConsole = true, | |
WriteMessagingTraces = false, | |
DefaultTraceLevel = Logger.Severity.Warning | |
} | |
}; | |
config.Defaults.TraceLevelOverrides.Add(Tuple.Create("MembershipOracle", Logger.Severity.Verbose2)); | |
// Configure logging and metrics collection | |
/* | |
config.Defaults.TraceLevelOverrides.Add(Tuple.Create("Orleans", Logger.Severity.Warning)); | |
config.Defaults.TraceLevelOverrides.Add(Tuple.Create("Runtime", Logger.Severity.Warning)); | |
config.Defaults.TraceLevelOverrides.Add(Tuple.Create("Catalog", Logger.Severity.Warning)); | |
config.Defaults.TraceLevelOverrides.Add(Tuple.Create("Dispatcher", Logger.Severity.Warning)); | |
*/ | |
config.Defaults.TraceLevelOverrides.Add(Tuple.Create("sync.SafeTimerBase", Logger.Severity.Warning)); | |
config.Defaults.TraceLevelOverrides.Add(Tuple.Create("DeploymentLoadPublisher", Logger.Severity.Warning)); | |
config.Defaults.TraceLevelOverrides.Add(Tuple.Create("ReminderService", Logger.Severity.Warning)); | |
config.Defaults.TraceLevelOverrides.Add(Tuple.Create("SiloLogStatistics", Logger.Severity.Warning)); | |
config.Defaults.TraceLevelOverrides.Add(Tuple.Create("asynTask.SafeTimerBase", Logger.Severity.Warning)); | |
// Configure providers | |
config.Globals.RegisterStorageProvider<AzureTableStorage>( | |
"Default", | |
new Dictionary<string, string> | |
{ | |
{ "DataConnectionString", ConnectionString }, | |
{ "UseJsonFormat", true.ToString(CultureInfo.InvariantCulture) } | |
}); | |
config.Globals.ReminderServiceType = GlobalConfiguration.ReminderServiceProviderType.AzureTable; | |
config.Globals.LivenessType = GlobalConfiguration.LivenessProviderType.AzureTable; | |
config.Globals.DataConnectionString = ConnectionString; | |
// Configure clustering. | |
config.Globals.DeploymentId = DeploymentId; | |
config.Globals.ResponseTimeout = TimeSpan.FromSeconds(90); | |
return config; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment