public void TestConnect27() { var heartbeatSettings = new HeartbeatSettings { UseHeartbeatFailureDetection = false }; var latencySettings = new LatencySettings { PerformLatencyMeasurements = false }; for (int i = 0; i < 100; ++i) { using ( var client = CreateClient(name: "perf_client", latencySettings: latencySettings, heartbeatSettings: heartbeatSettings)) { using ( var server = CreateServer(name: "perf_server", latencySettings: latencySettings, heartbeatSettings: heartbeatSettings)) { Bind(server); Connect(client, server.LocalEndPoint); client.Disconnect(); } } } }
public void TestCtor() { var @default = new HeartbeatSettings(); @default.Interval.Should().Be(TimeSpan.FromSeconds(1)); @default.ReportSkippedHeartbeatsAsFailureWithDebuggerAttached.Should().BeFalse(); @default.AllowRemoteHeartbeatDisable.Should().BeFalse(); @default.UseHeartbeatFailureDetection.Should().BeTrue(); @default.SkippedHeartbeatThreshold.Should().Be(10); @default.ReportDebuggerAttached.Should().BeTrue(); }
internal override IRemotingEndPoint CreateClient(string name = null, IAuthenticator clientAuthenticator = null, IAuthenticator serverAuthenticator = null, LatencySettings latencySettings = null, HeartbeatSettings heartbeatSettings = null, NetworkServiceDiscoverer networkServiceDiscoverer = null) { return(new NamedPipeRemotingEndPointClient(name, clientAuthenticator, serverAuthenticator, heartbeatSettings: heartbeatSettings, latencySettings: latencySettings)); }
internal override IRemotingEndPoint CreateServer(string name = null, IAuthenticator clientAuthenticator = null, IAuthenticator serverAuthenticator = null, LatencySettings latencySettings = null, EndPointSettings endPointSettings = null, HeartbeatSettings heartbeatSettings = null, NetworkServiceDiscoverer networkServiceDiscoverer = null) { return(new SocketEndPoint(EndPointType.Server, name, clientAuthenticator, serverAuthenticator, networkServiceDiscoverer: null, latencySettings: latencySettings, endPointSettings: endPointSettings, heartbeatSettings: heartbeatSettings)); }
public void TestTaskExceptionObservation() { var settings = new HeartbeatSettings { Interval = TimeSpan.FromMilliseconds(value: 10) }; var exceptions = new List <Exception>(); TaskScheduler.UnobservedTaskException += (sender, args) => exceptions.Add(args.Exception); using (var heartbeatFailure = new ManualResetEvent(initialState: false)) using ( var monitor = new HeartbeatMonitor(_heartbeat.Object, _debugger.Object, settings, _connectionId, "Test", _localEndPoint, _remoteEndPoint)) { _heartbeat.Setup(x => x.Beat()) .Returns(() => { var task = new Task(() => { heartbeatFailure.WaitOne(); throw new ConnectionLostException(); }); task.Start(); return(task); }); monitor.OnFailure += id => heartbeatFailure.Set(); monitor.Start(); heartbeatFailure.WaitOne(TimeSpan.FromMilliseconds(value: 500)) .Should().BeTrue("Because the task doesn't return before a failure was reported"); } GC.Collect(generation: 2, mode: GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); exceptions.Should().Equal(); }
/// <summary> /// Initializes a new silo server. /// </summary> /// <param name="args">The command line arguments given to the Main() method</param> /// <param name="customTypeResolver">The type resolver, if any, responsible for resolving Type objects by their assembly qualified name</param> /// <param name="codeGenerator">The code generator to create proxy and servant types</param> /// <param name="heartbeatSettings">The settings for heartbeat mechanism, if none are specified, then default settings are used</param> /// <param name="latencySettings">The settings for latency measurements, if none are specified, then default settings are used</param> /// <param name="endPointSettings">The settings for the endpoint itself (max. number of concurrent calls, etc...)</param> /// <param name="endPointName">The name of this silo, used for debugging (and logging)</param> public OutOfProcessSiloServer(string[] args, ITypeResolver customTypeResolver = null, ICodeGenerator codeGenerator = null, HeartbeatSettings heartbeatSettings = null, LatencySettings latencySettings = null, EndPointSettings endPointSettings = null, string endPointName = null) { Log.InfoFormat("Silo Server starting, args ({0}): \"{1}\", {2} custom type resolver", args.Length, string.Join(" ", args), customTypeResolver != null ? "with" : "without" ); int pid; if (args.Length >= 1 && int.TryParse(args[0], out pid)) { _parentProcessId = pid; _parentProcess = Process.GetProcessById(pid); _parentProcess.EnableRaisingEvents = true; _parentProcess.Exited += ParentProcessOnExited; } if (Log.IsDebugEnabled) { Log.DebugFormat("Args.Length: {0}", args.Length); } _registry = new DefaultImplementationRegistry(); _waitHandle = new ManualResetEvent(false); _customTypeResolver = customTypeResolver; _endPoint = new SocketEndPoint(EndPointType.Server, endPointName, codeGenerator: codeGenerator, heartbeatSettings: heartbeatSettings, latencySettings: latencySettings, endPointSettings: endPointSettings ); _endPoint.OnConnected += EndPointOnOnConnected; _endPoint.OnDisconnected += EndPointOnOnDisconnected; _endPoint.OnFailure += EndPointOnOnFailure; }
public void TestCtor1() { var args = new[] { Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture), }; var heartbeatSettings = new HeartbeatSettings { Interval = TimeSpan.FromSeconds(1.5), ReportSkippedHeartbeatsAsFailureWithDebuggerAttached = true, SkippedHeartbeatThreshold = 11 }; var latencySettings = new LatencySettings { Interval = TimeSpan.FromSeconds(1.5), NumSamples = 8, PerformLatencyMeasurements = true }; using (var server = new OutOfProcessSiloServer(args, heartbeatSettings: heartbeatSettings, latencySettings: latencySettings)) { var endPoint = server.EndPoint; endPoint.Should().NotBeNull(); endPoint.LatencySettings.Should().BeSameAs(latencySettings); endPoint.LatencySettings.Interval.Should().Be(TimeSpan.FromSeconds(1.5)); endPoint.LatencySettings.NumSamples.Should().Be(8); endPoint.LatencySettings.PerformLatencyMeasurements.Should().BeTrue(); endPoint.HeartbeatSettings.Should().BeSameAs(heartbeatSettings); endPoint.HeartbeatSettings.Interval.Should().Be(TimeSpan.FromSeconds(1.5)); endPoint.HeartbeatSettings.ReportSkippedHeartbeatsAsFailureWithDebuggerAttached.Should().BeTrue(); endPoint.HeartbeatSettings.SkippedHeartbeatThreshold.Should().Be(11); Task.Factory.StartNew(() => server.Run(IPAddress.Loopback, 60000, 60010)); WaitFor(() => endPoint.LocalEndPoint != null && Enumerable.Range(60000, 10).Contains(endPoint.LocalEndPoint.Port), TimeSpan.FromSeconds(10)) .Should() .BeTrue(); } }
public void TestCtor7() { var args = new[] { Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture), }; var heartbeatSettings = new HeartbeatSettings { Interval = TimeSpan.FromSeconds(1.5), ReportSkippedHeartbeatsAsFailureWithDebuggerAttached = true, SkippedHeartbeatThreshold = 11 }; var latencySettings = new LatencySettings { Interval = TimeSpan.FromSeconds(1.5), NumSamples = 8, PerformLatencyMeasurements = true }; using (var server = new OutOfProcessSiloServer(args, heartbeatSettings: heartbeatSettings, latencySettings: latencySettings)) { var endPoint = server.EndPoint; endPoint.Should().NotBeNull(); endPoint.LatencySettings.Should().BeSameAs(latencySettings); endPoint.LatencySettings.Interval.Should().Be(TimeSpan.FromSeconds(1.5)); endPoint.LatencySettings.NumSamples.Should().Be(8); endPoint.LatencySettings.PerformLatencyMeasurements.Should().BeTrue(); endPoint.HeartbeatSettings.Should().BeSameAs(heartbeatSettings); endPoint.HeartbeatSettings.Interval.Should().Be(TimeSpan.FromSeconds(1.5)); endPoint.HeartbeatSettings.ReportSkippedHeartbeatsAsFailureWithDebuggerAttached.Should().BeTrue(); endPoint.HeartbeatSettings.SkippedHeartbeatThreshold.Should().Be(11); } }
/// <summary> /// /// </summary> public FailureSettings() { ProcessReadyTimeout = TimeSpan.FromSeconds(10); EndPointConnectTimeout = TimeSpan.FromSeconds(2); HeartbeatSettings = new HeartbeatSettings(); }
internal abstract IRemotingEndPoint CreateServer(string name = null, IAuthenticator clientAuthenticator = null, IAuthenticator serverAuthenticator = null, LatencySettings latencySettings = null, EndPointSettings endPointSettings = null, HeartbeatSettings heartbeatSettings = null, NetworkServiceDiscoverer networkServiceDiscoverer = null);
/// <summary> /// Initializes a new silo server. /// </summary> /// <param name="args">The command line arguments given to the Main() method</param> /// <param name="customTypeResolver">The type resolver, if any, responsible for resolving Type objects by their assembly qualified name</param> /// <param name="codeGenerator">The code generator to create proxy and servant types</param> /// <param name="postMortemSettings"> /// Settings to control how and if minidumps are collected - when set to null, default values are used ( /// <see /// cref="PostMortemSettings" /> /// ) /// </param> /// <param name="heartbeatSettings">The settings for heartbeat mechanism, if none are specified, then default settings are used</param> /// <param name="latencySettings">The settings for latency measurements, if none are specified, then default settings are used</param> /// <param name="endPointSettings">The settings for the endpoint itself (max. number of concurrent calls, etc...)</param> /// <param name="endPointName">The name of this silo, used for debugging (and logging)</param> public OutOfProcessSiloServer(string[] args, ITypeResolver customTypeResolver = null, ICodeGenerator codeGenerator = null, PostMortemSettings postMortemSettings = null, HeartbeatSettings heartbeatSettings = null, LatencySettings latencySettings = null, EndPointSettings endPointSettings = null, string endPointName = null) { if (postMortemSettings != null && !postMortemSettings.IsValid) { throw new ArgumentException("postMortemSettings"); } Log.InfoFormat("Silo Server starting, args ({0}): \"{1}\", {2} custom type resolver", args.Length, string.Join(" ", args), customTypeResolver != null ? "with" : "without" ); int pid; if (args.Length >= 1 && int.TryParse(args[0], out pid)) { _parentProcessId = pid; _parentProcess = Process.GetProcessById(pid); _parentProcess.EnableRaisingEvents = true; _parentProcess.Exited += ParentProcessOnExited; } if (Log.IsDebugEnabled) { Log.DebugFormat("Args.Length: {0}", args.Length); } if (args.Length >= 10) { if (postMortemSettings != null) { Log.Info("Ignoring post-mortem settings specified from the command-line"); } else { var settings = new PostMortemSettings(); bool.TryParse(args[1], out settings.CollectMinidumps); bool.TryParse(args[2], out settings.SuppressErrorWindows); bool.TryParse(args[3], out settings.HandleAccessViolations); bool.TryParse(args[4], out settings.HandleCrtAsserts); bool.TryParse(args[5], out settings.HandleCrtPureVirtualFunctionCalls); int tmp; int.TryParse(args[6], out tmp); settings.RuntimeVersions = (CRuntimeVersions)tmp; int.TryParse(args[7], out settings.NumMinidumpsRetained); settings.MinidumpFolder = args[8]; settings.MinidumpName = args[9]; if (!settings.IsValid) { Log.ErrorFormat("Received invalid post-mortem debugger settings: {0}", settings); } else { postMortemSettings = settings; } } } _registry = new DefaultImplementationRegistry(); _waitHandle = new ManualResetEvent(false); _customTypeResolver = customTypeResolver; _postMortemSettings = postMortemSettings; if (_postMortemSettings != null) { Log.InfoFormat("Using post-mortem debugger: {0}", _postMortemSettings); if (!NativeMethods.LoadPostmortemDebugger()) { int err = Marshal.GetLastWin32Error(); Log.ErrorFormat("Unable to load the post-mortem debugger dll: {0}", err); } if (_postMortemSettings.CollectMinidumps) { if (NativeMethods.InitDumpCollection(_postMortemSettings.NumMinidumpsRetained, _postMortemSettings.MinidumpFolder, _postMortemSettings.MinidumpName)) { Log.InfoFormat("Installed post-mortem debugger; up to {0} mini dumps will automatically be saved to: {1}", _postMortemSettings.NumMinidumpsRetained, _postMortemSettings.MinidumpFolder ); } } NativeMethods.InstallPostmortemDebugger(_postMortemSettings.HandleAccessViolations, _postMortemSettings.SuppressErrorWindows, _postMortemSettings.HandleCrtAsserts, _postMortemSettings.HandleCrtPureVirtualFunctionCalls, _postMortemSettings.RuntimeVersions); } _endPoint = new SocketEndPoint(EndPointType.Server, endPointName, codeGenerator: codeGenerator, heartbeatSettings: heartbeatSettings, latencySettings: latencySettings, endPointSettings: endPointSettings ); _endPoint.OnConnected += EndPointOnOnConnected; _endPoint.OnDisconnected += EndPointOnOnDisconnected; _endPoint.OnFailure += EndPointOnOnFailure; }