public void TestKillHostingProcess()
        {
            using (var logCollector = new LogCollector("SharpRemote", Level.Info, Level.Warn, Level.Error, Level.Fatal))
            {
                int?pid;
                using (var silo = new SharpRemote.Hosting.OutOfProcessSilo())
                {
                    silo.Start();

                    pid = silo.HostProcessId;
                    var process = Process.GetProcessById(pid.Value);
                    process.Kill();

                    Thread.Sleep(TimeSpan.FromMilliseconds(100));
                }

                var expectedMessage = string.Format("Host '{0}' (PID: {1}) exited unexpectedly with error code -1",
                                                    ProcessWatchdog.SharpRemoteHost,
                                                    pid);
                var @event = logCollector.Events.FirstOrDefault(x => x.RenderedMessage.Contains(expectedMessage));
                @event.Should().NotBeNull("because a message should've been logged that the process exited unexpectedly");
                @event.Level.Should().Be(Level.Error);

                logCollector.Events.Should()
                .NotContain(x => x.RenderedMessage.Contains("Caught exception while disposing "));
            }
        }
        public void TestDispose3()
        {
            var silo = new SharpRemote.Hosting.OutOfProcessSilo();

            new Action(silo.Dispose)
            .ShouldNotThrow();
        }
示例#3
0
        public void TestFailureDetection2()
        {
            Failure?   failure    = null;
            Decision?  decision   = null;
            Resolution?resolution = null;

            var handler = new Mock <IFailureHandler>();

            handler.Setup(x => x.OnResolutionFinished(It.IsAny <Failure>(), It.IsAny <Decision>(), It.IsAny <Resolution>()))
            .Callback((Failure f, Decision d, Resolution r) =>
            {
                failure    = f;
                decision   = d;
                resolution = r;
            });

            using (var silo = new SharpRemote.Hosting.OutOfProcessSilo(failureHandler: handler.Object))
            {
                silo.Start();

                var proxy = silo.CreateGrain <IVoidMethodNoParameters>(typeof(AbortsThread));
                new Action(proxy.Do)
                .ShouldThrow <ConnectionLostException>(
                    "Because the host process is lost while the method is invoked and therefore the connection to the host process was lost and is the reason for the method to not execute properly");

                WaitFor(() => silo.HasProcessFailed, TimeSpan.FromSeconds(1))
                .Should().BeTrue("Because an unexpected exit of the host process counts as a failure");
                silo.IsProcessRunning.Should().BeFalse();

                WaitFor(() => resolution != null, TimeSpan.FromSeconds(1)).Should().BeTrue();
                (failure == Failure.ConnectionFailure ||
                 failure == Failure.HostProcessExited).Should().BeTrue("because we expected either a ConnectionFailure or HostProcessExited, but found: {0}", failure);
                resolution.Should().Be(Resolution.Stopped);
            }
        }
示例#4
0
        public void TestFailureDetection1()
        {
            Failure?failure = null;
            var     handler = new Mock <IFailureHandler>();

            handler.Setup(x => x.OnFailure(It.IsAny <Failure>()))
            .Callback((Failure x) => failure = x);

            using (var silo = new SharpRemote.Hosting.OutOfProcessSilo(failureHandler: handler.Object))
            {
                silo.Start();

                var proxy = silo.CreateGrain <IVoidMethodNoParameters>(typeof(KillsProcess));
                new Action(proxy.Do)
                .ShouldThrow <ConnectionLostException>(
                    "Because the host process is lost while the method is invoked and therefore the connection to the host process was lost and is the reason for the method to not execute properly");

                WaitFor(() => silo.HasProcessFailed, TimeSpan.FromSeconds(1))
                .Should()
                .BeTrue(
                    "Because an aborted thread that is currently invoking a remote method call should cause SharpRemote to kill the host process and report failure");
                silo.IsProcessRunning.Should().BeFalse();

                WaitFor(() => failure != null, TimeSpan.FromSeconds(1))
                .Should().BeTrue("Because the IFailureHandler should've been notified in time");

                (failure == Failure.ConnectionFailure ||
                 failure == Failure.HostProcessExited).Should().BeTrue();
            }
        }
示例#5
0
        public void TestFailureDetection4()
        {
            using (var handle = new ManualResetEvent(false))
            {
                Resolution?resolution = null;

                var handler = new Mock <IFailureHandler>();
                handler.Setup(x => x.OnResolutionFinished(It.IsAny <Failure>(), It.IsAny <Decision>(), It.IsAny <Resolution>()))
                .Callback((Failure f, Decision d, Resolution r) =>
                {
                    resolution = r;
                    handle.Set();
                });

                using (var silo = new SharpRemote.Hosting.OutOfProcessSilo(failureHandler: handler.Object))
                {
                    silo.Start();
                    IVoidMethodNoParameters proxy = silo.CreateGrain <IVoidMethodNoParameters, CausesAccessViolation>();

                    new Action(proxy.Do).ShouldThrow <ConnectionLostException>();

                    handle.WaitOne(TimeSpan.FromSeconds(5)).Should().BeTrue();
                    resolution.Should().Be(Resolution.Stopped);
                }
            }
        }
        public void TestDispose2()
        {
            bool failureDetected = false;
            var  settings        = new FailureSettings
            {
                HeartbeatSettings =
                {
                    Interval = TimeSpan.FromMilliseconds(10)
                }
            };

            var handler = new Mock <IFailureHandler>();

            handler.Setup(x => x.OnFailure(It.IsAny <Failure>()))
            .Callback((Failure unused) => failureDetected = true);

            using (var silo = new SharpRemote.Hosting.OutOfProcessSilo(failureSettings: settings, failureHandler: handler.Object))
            {
                silo.Start();
                failureDetected.Should().BeFalse("Because the host process shouldn't have failed now");
            }

            Thread.Sleep(100);

            failureDetected.Should()
            .BeFalse(
                "Because even though the process is no longer running, the silo shouldn't have reported a failure because it's been properly disposed of");
        }
        protected override ISilo Create()
        {
            var silo = new SharpRemote.Hosting.OutOfProcessSilo();

            silo.Start();
            return(silo);
        }
示例#8
0
        public void TestFailureDetection10()
        {
            using (var handle1 = new ManualResetEvent(false))
                using (var handle2 = new ManualResetEvent(false))
                {
                    Failure?   failure1   = null;
                    Failure?   failure2   = null;
                    Resolution?resolution = null;

                    var handler = new Mock <IFailureHandler>();
                    handler.Setup(x => x.OnFailure(It.IsAny <Failure>()))
                    .Callback((Failure f) =>
                    {
                        failure1 = f;
                        handle1.Set();
                    });
                    handler.Setup(x => x.OnResolutionFinished(It.IsAny <Failure>(), It.IsAny <Decision>(), It.IsAny <Resolution>()))
                    .Callback((Failure f, Decision d, Resolution r) =>
                    {
                        failure2   = f;
                        resolution = r;
                        handle2.Set();
                    });

                    var settings = new FailureSettings
                    {
                        HeartbeatSettings =
                        {
                            ReportSkippedHeartbeatsAsFailureWithDebuggerAttached = true,
                            Interval                                             = TimeSpan.FromMilliseconds(100),
                            SkippedHeartbeatThreshold                            = 4
                        }
                    };

                    using (var log = new LogCollector("SharpRemote", Level.Info, Level.Warn, Level.Error))
                        using (var silo = new SharpRemote.Hosting.OutOfProcessSilo(failureSettings: settings, failureHandler: handler.Object))
                        {
                            silo.Start();
                            int?pid = silo.HostProcessId;
                            pid.Should().HaveValue();

                            Process hostProcess = Process.GetProcessById(pid.Value);
                            hostProcess.Kill();

                            WaitHandle.WaitAll(new[] { handle1, handle2 }, TimeSpan.FromSeconds(2))
                            .Should().BeTrue("Because the failure should've been detected as well as handled");

                            failure1.Should().Be(Failure.HostProcessExited);
                            failure2.Should().Be(failure1);
                            resolution.Should().Be(Resolution.Stopped);

                            var expectedMessage = string.Format("Host '{0}' (PID: {1}) exited unexpectedly with error code -1",
                                                                ProcessWatchdog.SharpRemoteHost,
                                                                pid.Value);
                            log.Events.Should().Contain(x => x.Level == Level.Error &&
                                                        x.RenderedMessage.Contains(expectedMessage));
                        }
                }
        }
 public void TestCreateServant()
 {
     using (var silo = new SharpRemote.Hosting.OutOfProcessSilo())
     {
         var servant = silo.CreateServant(42, new Mock <IVoidMethod>().Object);
         servant.Should().NotBeNull();
     }
 }
示例#10
0
        public void TestPerformanceManyClients()
        {
            TimeSpan time = TimeSpan.FromSeconds(5);
            int      num  = 0;

            using (var silo = new SharpRemote.Hosting.OutOfProcessSilo())
            {
                silo.Start();

                IVoidMethod grain = silo.CreateGrain <IVoidMethod, DoesNothing>();
                // Optimization phase
                const int numOptPasses = 100;

                for (int i = 0; i < numOptPasses; ++i)
                {
                    grain.DoStuff();
                }

                // Measurement phase
                const int numClients = 16;
                var       clients    = new Thread[numClients];
                for (int clientIndex = 0; clientIndex < numClients; ++clientIndex)
                {
                    clients[clientIndex] = new Thread(() =>
                    {
                        var watch           = new Stopwatch();
                        const int batchSize = 64;
                        watch.Start();
                        while (watch.Elapsed < time)
                        {
                            for (int i = 0; i < batchSize; ++i)
                            {
                                grain.DoStuff();
                            }
                            num += batchSize;
                        }
                        watch.Stop();
                    });
                    clients[clientIndex].Start();
                }


                foreach (Thread thread in clients)
                {
                    thread.Join();
                }

                int    numSeconds = 5;
                double ops        = 1.0 * num / numSeconds;
                Console.WriteLine("Total calls: {0}", num);
                Console.WriteLine("OP/s: {0:F2}k/s", ops / 1000);
                Console.WriteLine("Sent: {0}, {1}/s", FormatSize(silo.NumBytesSent), FormatSize(silo.NumBytesSent / numSeconds));
                Console.WriteLine("Received: {0}, {1}/s", FormatSize(silo.NumBytesReceived),
                                  FormatSize(silo.NumBytesReceived / numSeconds));
                Console.WriteLine("Latency: {0}ns", (int)silo.RoundtripTime.Ticks * 100);
            }
        }
示例#11
0
        public void TestFailureDetection9()
        {
            using (var handle = new ManualResetEvent(false))
            {
                Resolution?resolution = null;

                var handler = new Mock <IFailureHandler>();
                handler.Setup(x => x.OnResolutionFinished(It.IsAny <Failure>(), It.IsAny <Decision>(), It.IsAny <Resolution>()))
                .Callback((Failure f, Decision d, Resolution r) =>
                {
                    resolution = r;
                    handle.Set();
                });

                var settings = new PostMortemSettings
                {
                    CollectMinidumps     = true,
                    SuppressErrorWindows = true,
                    HandleCrtPureVirtualFunctionCalls = true,
#if DEBUG
                    RuntimeVersions = CRuntimeVersions._110 | CRuntimeVersions.Debug,
#else
                    RuntimeVersions = CRuntimeVersions._110 | CRuntimeVersions.Release,
#endif
                    NumMinidumpsRetained = 1,
                    MinidumpFolder       = Path.Combine(Path.GetTempPath(), "SharpRemote", "dumps"),
                    MinidumpName         = "Host"
                };

                if (Directory.Exists(settings.MinidumpFolder))
                {
                    Directory.Delete(settings.MinidumpFolder, true);
                }

                using (var silo = new SharpRemote.Hosting.OutOfProcessSilo(postMortemSettings: settings))
                {
                    silo.Start();
                    IVoidMethodNoParameters proxy = silo.CreateGrain <IVoidMethodNoParameters, CausesPureVirtualFunctionCall>();

                    DateTime beforeFailure = DateTime.Now;
                    new Action(proxy.Do).ShouldThrow <ConnectionLostException>();
                    DateTime afterFailure = DateTime.Now;


                    // Not only should a failure have been detected, but a dump should've been created and stored
                    // on disk..

                    List <string> files = Directory.EnumerateFiles(settings.MinidumpFolder).ToList();
                    files.Count.Should().Be(1, "Because exactly one minidump should've been created");

                    var file = new FileInfo(files[0]);
                    file.Name.Should().EndWith(".dmp");
                    file.LastWriteTime.Should().BeOnOrAfter(beforeFailure);
                    file.LastWriteTime.Should().BeOnOrBefore(afterFailure);
                }
            }
        }
示例#12
0
        private void RestartHost(SharpRemote.Hosting.OutOfProcessSilo silo)
        {
            var pid     = silo.HostProcessId;
            var process = Process.GetProcessById(pid.Value);

            process.Kill();
            silo.Property(x => x.IsProcessRunning).ShouldEventually().BeFalse();
            silo.Property(x => x.IsProcessRunning).ShouldEventually().BeTrue();
            silo.Property(x => x.IsConnected).ShouldEventually().BeTrue();
        }
示例#13
0
 public void TestGetProperty()
 {
     using (var silo = new SharpRemote.Hosting.OutOfProcessSilo())
     {
         silo.Start();
         IGetInt64Property grain = silo.CreateGrain <IGetInt64Property, ReturnsInt64Max>();
         grain.Value.Should().Be(Int64.MaxValue);
         grain.Value.Should().Be(Int64.MaxValue);
     }
 }
示例#14
0
        public void TestCreateGrain1()
        {
            using (var silo = new SharpRemote.Hosting.OutOfProcessSilo())
            {
                silo.Start();

                var proxy = silo.CreateGrain <IGetStringProperty>(typeof(GetStringPropertyImplementation));
                proxy.Value.Should().Be("Foobar");
            }
        }
示例#15
0
        public void TestFailureDetection3()
        {
            Failure?   failure1   = null;
            Failure?   failure2   = null;
            Decision?  decision   = null;
            Resolution?resolution = null;

            var handler = new Mock <IFailureHandler>();

            handler.Setup(x => x.OnFailure(It.IsAny <Failure>()))
            .Callback((Failure f) => failure1 = f);
            handler.Setup(x => x.OnResolutionFinished(It.IsAny <Failure>(), It.IsAny <Decision>(), It.IsAny <Resolution>()))
            .Callback((Failure f, Decision d, Resolution r) =>
            {
                failure2   = f;
                decision   = d;
                resolution = r;
            });

            var settings = new FailureSettings
            {
                HeartbeatSettings =
                {
                    ReportSkippedHeartbeatsAsFailureWithDebuggerAttached = true,
                    Interval                                             = TimeSpan.FromMilliseconds(100),
                    SkippedHeartbeatThreshold                            = 4
                }
            };

            using (var silo = new SharpRemote.Hosting.OutOfProcessSilo(failureSettings: settings, failureHandler: handler.Object))
            {
                silo.Start();

                var proxy = silo.CreateGrain <IVoidMethodNoParameters>(typeof(DeadlocksProcess));
                new Action(() =>
                {
                    Task.Factory.StartNew(proxy.Do, TaskCreationOptions.LongRunning)
                    .Wait(TimeSpan.FromSeconds(10))
                    .Should().BeTrue("Because the silo should've detected the deadlock in time");
                })
                .ShouldThrow <ConnectionLostException>(
                    "Because the host process is lost while the method is invoked and therefore the connection to the host process was lost and is the reason for the method to not execute properly");

                WaitFor(() => silo.HasProcessFailed, TimeSpan.FromSeconds(1))
                .Should()
                .BeTrue("Because the heartbeat mechanism should have detected that the endpoint doesn't respond anymore");
                WaitFor(() => failure1 != null, TimeSpan.FromSeconds(1)).Should().BeTrue();
                WaitFor(() => failure2 != null, TimeSpan.FromSeconds(1)).Should().BeTrue();

                silo.IsProcessRunning.Should().BeFalse();
                failure1.Should().Be(Failure.HeartbeatFailure);
                failure2.Should().Be(failure1);
                resolution.Should().Be(Resolution.Stopped);
            }
        }
示例#16
0
        public void TestStartStop2()
        {
            using (var silo = new SharpRemote.Hosting.OutOfProcessSilo())
            {
                silo.Start();
                silo.Stop();

                Thread.Sleep(TimeSpan.FromSeconds(1));
                silo.IsProcessRunning.Should().BeFalse();
                silo.HostProcessId.Should().NotHaveValue();
            }
        }
示例#17
0
        public void TestFailureDetection10()
        {
            using (var handle1 = new ManualResetEvent(false))
                using (var handle2 = new ManualResetEvent(false))
                {
                    Failure?   failure1   = null;
                    Failure?   failure2   = null;
                    Resolution?resolution = null;

                    var handler = new Mock <IFailureHandler>();
                    handler.Setup(x => x.OnFailure(It.IsAny <Failure>()))
                    .Callback((Failure f) =>
                    {
                        failure1 = f;
                        handle1.Set();
                    });
                    handler.Setup(x => x.OnResolutionFinished(It.IsAny <Failure>(), It.IsAny <Decision>(), It.IsAny <Resolution>()))
                    .Callback((Failure f, Decision d, Resolution r) =>
                    {
                        failure2   = f;
                        resolution = r;
                        handle2.Set();
                    });

                    var settings = new FailureSettings
                    {
                        HeartbeatSettings =
                        {
                            ReportSkippedHeartbeatsAsFailureWithDebuggerAttached = true,
                            Interval                                             = TimeSpan.FromMilliseconds(100),
                            SkippedHeartbeatThreshold                            = 4
                        }
                    };

                    using (var silo = new SharpRemote.Hosting.OutOfProcessSilo(failureSettings: settings, failureHandler: handler.Object))
                    {
                        silo.Start();
                        int?id = silo.HostProcessId;
                        id.Should().HaveValue();

                        Process hostProcess = Process.GetProcessById(id.Value);
                        hostProcess.Kill();

                        WaitHandle.WaitAll(new[] { handle1, handle2 }, TimeSpan.FromSeconds(2))
                        .Should().BeTrue("Because the failure should've been detected as well as handled");

                        (failure1 == Failure.ConnectionFailure ||
                         failure1 == Failure.HostProcessExited).Should().BeTrue();
                        failure2.Should().Be(failure1);
                        resolution.Should().Be(Resolution.Stopped);
                    }
                }
        }
示例#18
0
        public void TestDispose1()
        {
            SharpRemote.Hosting.OutOfProcessSilo silo;
            using (silo = new SharpRemote.Hosting.OutOfProcessSilo())
            {
                silo.Start();
                silo.IsProcessRunning.Should().BeTrue();
            }

            silo.IsDisposed.Should().BeTrue();
            silo.IsProcessRunning.Should().BeFalse();
        }
示例#19
0
        public void TestDispose4()
        {
            using (var logCollector = new LogCollector("SharpRemote", Level.Info,
                                                       Level.Warn, Level.Error, Level.Fatal))
            {
                var silo = new SharpRemote.Hosting.OutOfProcessSilo();
                new Action(silo.Dispose)
                .ShouldNotThrow();

                logCollector.Log.Should().NotContain("Caught exception while disposing");
                logCollector.Log.Should().NotContain("SharpRemote.NotConnectedException");
            }
        }
示例#20
0
        public void TestPerformanceOneClientAsync()
        {
            TimeSpan time  = TimeSpan.FromSeconds(5);
            var      watch = new Stopwatch();
            int      num   = 0;

            using (var silo = new SharpRemote.Hosting.OutOfProcessSilo())
            {
                silo.Start();

                IReturnsTask grain = silo.CreateGrain <IReturnsTask, ReturnsTask>();

                // Optimization phase
                const int numOptPasses = 100;
                var       opts         = new Task[numOptPasses];
                for (int i = 0; i < numOptPasses; ++i)
                {
                    opts[i] = grain.DoStuff();
                }

                Task.WaitAll(opts);

                // Measurement phase

                const int batchSize = 1000;
                var       tasks     = new Task[batchSize];

                watch.Start();
                while (watch.Elapsed < time)
                {
                    for (int i = 0; i < batchSize; ++i)
                    {
                        tasks[i] = grain.DoStuff();
                    }
                    Task.WaitAll(tasks);

                    num += batchSize;
                }
                watch.Stop();

                double numSeconds = watch.Elapsed.TotalSeconds;
                double ops        = 1.0 * num / numSeconds;
                Console.WriteLine("Total calls: {0}", num);
                Console.WriteLine("OP/s: {0:F2}k/s", ops / 1000);
                Console.WriteLine("Sent: {0}, {1}/s", FormatSize(silo.NumBytesSent),
                                  FormatSize((long)(silo.NumBytesSent / numSeconds)));
                Console.WriteLine("Received: {0}, {1}/s", FormatSize(silo.NumBytesReceived),
                                  FormatSize((long)(silo.NumBytesReceived / numSeconds)));
                Console.WriteLine("Latency: {0}ns", (int)silo.RoundtripTime.Ticks * 100);
            }
        }
示例#21
0
        public void TestStartStopStart1()
        {
            using (var silo = new SharpRemote.Hosting.OutOfProcessSilo())
            {
                silo.Start();
                silo.Stop();

                silo.Start();
                silo.IsProcessRunning.Should().BeTrue();
                var pid = silo.HostProcessId;
                pid.Should().HaveValue();
                ProcessShouldBeRunning(pid.Value);
            }
        }
示例#22
0
        public void TestStartStop4()
        {
            using (var collector = new LogCollector("SharpRemote", Level.Warn, Level.Error, Level.Fatal))
                using (var silo = new SharpRemote.Hosting.OutOfProcessSilo())
                {
                    silo.Start();
                    silo.Stop();

                    Thread.Sleep(TimeSpan.FromSeconds(1));

                    collector.Events.Should().NotContain(x => x.RenderedMessage.Contains("exited unexpectedly"));
                    collector.Events.Should().NotContain(x => x.Level >= Level.Warn);
                }
        }
示例#23
0
        public void TestStop()
        {
            using (var silo = new SharpRemote.Hosting.OutOfProcessSilo())
            {
                silo.IsProcessRunning.Should().BeFalse("because Start() hasn't been called yet");
                silo.HostProcessId.Should().NotHaveValue("because Start() hasn't been called yet");
                silo.IsConnected.Should().BeFalse("because Start() hasn't been called yet");

                silo.Stop();
                silo.IsProcessRunning.Should().BeFalse("because Start() hasn't been called yet");
                silo.HostProcessId.Should().NotHaveValue("because Start() hasn't been called yet");
                silo.IsConnected.Should().BeFalse("because Start() hasn't been called yet");
            }
        }
示例#24
0
        public void TestStartStop1()
        {
            using (var silo = new SharpRemote.Hosting.OutOfProcessSilo())
            {
                silo.Start();
                silo.IsProcessRunning.Should().BeTrue("because Start() has been called and the host should be running now");
                silo.IsConnected.Should().BeTrue("because Start() has been called and the connection to the host should be running");
                var pid = silo.HostProcessId;
                pid.Should().HaveValue();
                ProcessShouldBeRunning(pid.Value);

                silo.Stop();
                silo.IsProcessRunning.Should().BeFalse();
                silo.HostProcessId.Should().NotHaveValue();

                ProcessShouldNotBeRunning(pid.Value);
            }
        }
示例#25
0
        public void TestCreate()
        {
            var customTypeResolver = new CustomTypeResolver1();

            using (var silo = new SharpRemote.Hosting.OutOfProcessSilo(codeGenerator: new CodeGenerator(customTypeResolver)))
            {
                silo.Start();

                customTypeResolver.GetTypeCalled.Should().Be(0);
                var grain = silo.CreateGrain <IReturnsType>(typeof(ReturnsTypeofString));
                customTypeResolver.GetTypeCalled.Should()
                .Be(0, "because the custom type resolver in this process didn't need to resolve anything yet");

                grain.Do().Should().Be <string>();
                customTypeResolver.GetTypeCalled.Should()
                .Be(1,
                    "Because the custom type resolver in this process should've been used to resolve typeof(string)");
            }
        }
示例#26
0
        public void TestStartStop3()
        {
            var failureHandler = new FailureHandlerMock();

            using (var silo = new SharpRemote.Hosting.OutOfProcessSilo(failureHandler: failureHandler))
            {
                silo.Start();
                silo.Stop();

                Thread.Sleep(TimeSpan.FromSeconds(1));

                const string reason =
                    "because no failure should've occured (due to the intentional shutdown) and therefore the callback may not have been invoked";
                failureHandler.NumStartFailure.Should().Be(0, reason);
                failureHandler.NumFailure.Should().Be(0, reason);
                failureHandler.NumResolutionFailed.Should().Be(0, reason);
                failureHandler.NumResolutionFinished.Should().Be(0, reason);
            }
        }
示例#27
0
        public void TestPerformanceOneClientSync()
        {
            TimeSpan time  = TimeSpan.FromSeconds(5);
            var      watch = new Stopwatch();
            int      num   = 0;

            using (var silo = new SharpRemote.Hosting.OutOfProcessSilo())
            {
                silo.Start();

                IVoidMethod grain = silo.CreateGrain <IVoidMethod, DoesNothing>();

                // Optimization phase
                for (int i = 0; i < 100; ++i)
                {
                    grain.DoStuff();
                }

                // Measurement phase
                watch.Start();
                while (watch.Elapsed < time)
                {
                    for (int i = 0; i < 100; ++i)
                    {
                        grain.DoStuff();
                    }
                    num += 100;
                }
                watch.Stop();

                double numSeconds = watch.Elapsed.TotalSeconds;
                double ops        = 1.0 * num / numSeconds;
                Console.WriteLine("Total calls: {0}", num);
                Console.WriteLine("OP/s: {0:F2}k/s", ops / 1000);
                Console.WriteLine("Sent: {0}, {1}/s", FormatSize(silo.NumBytesSent),
                                  FormatSize((long)(silo.NumBytesSent / numSeconds)));
                Console.WriteLine("Received: {0}, {1}/s", FormatSize(silo.NumBytesReceived),
                                  FormatSize((long)(silo.NumBytesReceived / numSeconds)));
                Console.WriteLine("Latency: {0}ns", (int)silo.RoundtripTime.Ticks * 100);
            }
        }
示例#28
0
        public void TestRoundtripTime()
        {
            var settings = new LatencySettings
            {
                Interval   = TimeSpan.FromMilliseconds(1),
                NumSamples = 100
            };

            SharpRemote.Hosting.OutOfProcessSilo silo;
            using (silo = new SharpRemote.Hosting.OutOfProcessSilo(latencySettings: settings))
            {
                silo.RoundtripTime.Should().Be(TimeSpan.Zero, "because without being started, no latency is measured");
                silo.Start();

                Thread.Sleep(TimeSpan.FromMilliseconds(200));
                TimeSpan rtt = silo.RoundtripTime;
                Console.WriteLine("RTT: {0}Ticks", rtt.Ticks);
                rtt.Should().BeGreaterThan(TimeSpan.Zero);
                rtt.Should().BeLessOrEqualTo(TimeSpan.FromMilliseconds(10));
            }
        }
示例#29
0
        public void TestUseByReferenceTypeAfterRestart()
        {
            using (var logCollector = new LogCollector(new [] { "SharpRemote.EndPoints.ProxyStorage" }, new [] { Level.Debug }))
                using (var silo = new SharpRemote.Hosting.OutOfProcessSilo(failureHandler: new RestartOnFailureStrategy()))
                {
                    logCollector.AutoPrint(TestContext.Progress);
                    silo.Start();

                    var factory = silo.CreateGrain <IAdvancedFactory>(typeof(AdvancedFactory));
                    var proxyToByReferenceClass = factory.Create(typeof(ByReferenceClass));
                    var id = GetIdOf(proxyToByReferenceClass);
                    Console.WriteLine("ObjectId: {0}", id);

                    RestartHost(silo);

                    factory = silo.CreateGrain <IAdvancedFactory>(typeof(AdvancedFactory));
                    var proxyToObject = factory.Create(typeof(Handle));
                    var otherId       = GetIdOf(proxyToObject);
                    Console.WriteLine("ObjectId: {0}", otherId);
                }
        }
示例#30
0
        public void TestFailureDetection11()
        {
            var handler = new Mock <IFailureHandler>();

            var settings = new FailureSettings
            {
                HeartbeatSettings =
                {
                    ReportSkippedHeartbeatsAsFailureWithDebuggerAttached = true,
                    Interval                                             = TimeSpan.FromMilliseconds(100),
                    SkippedHeartbeatThreshold                            = 4
                }
            };

            using (var silo = new SharpRemote.Hosting.OutOfProcessSilo(failureSettings: settings, failureHandler: handler.Object))
                using (var handle = new ManualResetEvent(false))
                {
                    handler.Setup(x => x.OnResolutionFinished(It.IsAny <Failure>(), It.IsAny <Decision>(), It.IsAny <Resolution>()))
                    .Callback((Failure f, Decision d, Resolution r) =>
                    {
                        silo.Dispose();
                        handle.Set();
                    });

                    silo.Start();
                    int?id = silo.HostProcessId;
                    id.Should().HaveValue();

                    Process hostProcess = Process.GetProcessById(id.Value);
                    hostProcess.Kill();

                    handle.WaitOne(TimeSpan.FromSeconds(2))
                    .Should().BeTrue("Because the failure should've been detected as well as handled");

                    silo.IsDisposed.Should().BeTrue();
                    silo.HasProcessFailed.Should().BeTrue();
                    silo.IsProcessRunning.Should().BeFalse();
                }
        }