Exemplo n.º 1
0
        public void TestStart8()
        {
            var dir = Path.Combine(Path.GetTempPath(), "SharpRemote", Guid.NewGuid().ToString());

            var failureHandler       = new MyFailureHandler(dir);
            var onStartFailureCalled = new List <KeyValuePair <int, Exception> >();

            failureHandler.OnStartFailureCalled += (numFailures, exception) => onStartFailureCalled.Add(new KeyValuePair <int, Exception>(numFailures, exception));

            // Let's start by copying the host executable to a new folder, but let's conveniently forget
            // an import assembly. This way Start will definately fail...
            var executable = Copy("SharpRemote.Host.exe", dir);

            Copy("log4net.dll", dir);

            using (var silo = new SharpRemote.Hosting.OutOfProcessSilo(executable,
                                                                       failureHandler: failureHandler))
            {
                new Action(silo.Start)
                .Should().NotThrow("Because the error will be corrected after the first start fails");

                onStartFailureCalled.Count.Should().Be(1, "Because starting the application should've failed only once");
                onStartFailureCalled[0].Key.Should().Be(1);
                onStartFailureCalled[0].Value.Should().BeOfType <HandshakeException>();
                silo.IsProcessRunning.Should().BeTrue();
            }
        }
Exemplo n.º 2
0
 public void TestStart5()
 {
     using (var silo = new SharpRemote.Hosting.OutOfProcessSilo())
     {
         new Action(silo.Start).Should().NotThrow();
         new Action(silo.Start).Should().Throw <InvalidOperationException>();
     }
 }
Exemplo n.º 3
0
 public void TestCtor1()
 {
     using (var silo = new SharpRemote.Hosting.OutOfProcessSilo())
     {
         silo.IsDisposed.Should().BeFalse();
         silo.HasProcessFailed.Should().BeFalse();
         silo.IsProcessRunning.Should().BeFalse();
     }
 }
Exemplo n.º 4
0
        public void TestStart1()
        {
            using (var silo = new SharpRemote.Hosting.OutOfProcessSilo())
            {
                silo.IsProcessRunning.Should().BeFalse();
                silo.Start();

                silo.IsProcessRunning.Should().BeTrue();
                silo.HasProcessFailed.Should().BeFalse();
            }
        }
Exemplo n.º 5
0
        public void TestStart7()
        {
            using (var silo = new SharpRemote.Hosting.OutOfProcessSilo("SharpRemote.Host.FailsStartup.exe",
                                                                       failureHandler: new RestartOnFailureStrategy(startFailureThreshold: 20)))
            {
                new Action(silo.Start)
                .Should().Throw <AggregateException>();

                silo.IsProcessRunning.Should().BeFalse();
            }
        }
Exemplo n.º 6
0
        public void Test1MinuteFullLoadMultipleAsynchronous()
        {
            const int numServants = 16;

            var  handler = new ZeroFailureToleranceStrategy();
            bool failed  = false;

            handler.OnResolutionFailedEvent += () => failed = true;

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

                var proxies = Enumerable.Range(0, numServants)
                              .Select(unused => silo.CreateGrain <IDoImportStuff, DoesImportantStuff>()).ToArray();

                long numCalls = 0;
                var  start    = DateTime.Now;
                var  last     = start;
                var  now      = start;
                while ((now = DateTime.Now) - start < TimeSpan.FromMinutes(1))
                {
                    var input = new Input
                    {
                        ImportantName   = "Kittyfisto",
                        ImportantNumber = 42
                    };

                    foreach (var proxy in proxies)
                    {
                        proxy.WorkAsync(input);
                    }

                    ++numCalls;
                    var rtt      = silo.RoundtripTime;
                    var received = silo.NumBytesReceived;
                    var sent     = silo.NumBytesSent;

                    if (now - last > TimeSpan.FromSeconds(10))
                    {
                        TestContext.Progress.WriteLine("#{0} calls, {1}μs rtt, {2} received, {3} sent",
                                                       numCalls,
                                                       rtt.Ticks / 10,
                                                       FormatSize(received),
                                                       FormatSize(sent)
                                                       );

                        last = now;
                    }

                    failed.Should().BeFalse("Because the connection shouldn't have failed");
                }
            }
        }
Exemplo n.º 7
0
 public void TestStart6()
 {
     using (var silo = new SharpRemote.Hosting.OutOfProcessSilo("SharpRemote.Host.FailsStartup.exe"))
     {
         new Action(silo.Start)
         .Should().Throw <HandshakeException>()
         .WithMessage(
             "Process 'SharpRemote.Host.FailsStartup.exe' caught an unexpected exception during startup and subsequently failed")
         .WithInnerException <FileNotFoundException>()
         .WithMessage("Shit happens");
     }
 }
Exemplo n.º 8
0
        public void Test1MinuteFullLoadSynchronous()
        {
            var  handler = new ZeroFailureToleranceStrategy();
            bool failed  = false;

            handler.OnResolutionFailedEvent += () => failed = true;

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

                long numCalls = 0;
                var  start    = DateTime.Now;
                var  last     = start;
                var  now      = start;
                while ((now = DateTime.Now) - start < TimeSpan.FromMinutes(1))
                {
                    proxy.Work(new Input
                    {
                        ImportantName   = "Kittyfisto",
                        ImportantNumber = 42
                    });

                    ++numCalls;
                    var rtt      = silo.RoundtripTime;
                    var received = silo.NumBytesReceived;
                    var sent     = silo.NumBytesSent;

                    if (now - last > TimeSpan.FromSeconds(10))
                    {
                        TestContext.Progress.WriteLine("#{0} calls, {1}μs rtt, {2} received, {3} sent",
                                                       numCalls,
                                                       rtt.Ticks / 10,
                                                       FormatSize(received),
                                                       FormatSize(sent)
                                                       );

                        last = now;
                    }

                    failed.Should().BeFalse("Because the connection shouldn't have failed");
                }

                var result = proxy.Result;
                result.Should().NotBeNull();
                result.NumInputs.Should().Be(numCalls);
                result.NumCharacters.Should().Be("Kittyfisto".Length * numCalls);
                result.Sum.Should().Be(42 * numCalls);
            }
        }
Exemplo n.º 9
0
        public new void SetUp()
        {
            _restartOnFailureHandler = new RestartOnFailureStrategy();
            _settings = new FailureSettings
            {
                HeartbeatSettings =
                {
                    ReportSkippedHeartbeatsAsFailureWithDebuggerAttached = true,
                    Interval                                             = TimeSpan.FromMilliseconds(100)
                }
            };
            _silo = new SharpRemote.Hosting.OutOfProcessSilo(failureSettings: _settings, failureHandler: _restartOnFailureHandler);

            _startHandle = new ManualResetEvent(false);
        }
Exemplo n.º 10
0
        public void TestCtor5()
        {
            var serializer = new BinarySerializer();

            serializer.IsTypeRegistered <Tree>().Should().BeFalse();
            var codeGenerator = new CodeGenerator(serializer);

            using (var silo = new SharpRemote.Hosting.OutOfProcessSilo(codeGenerator: codeGenerator))
            {
                silo.Start();
                var grain = silo.CreateGrain <IReturnsObjectMethod, ReturnsTree>();
                var tree  = grain.GetListener();
                tree.Should().NotBeNull();
                tree.Should().BeOfType <Tree>();
                serializer.IsTypeRegistered <Tree>().Should().BeTrue("Because the serializer specified in the ctor should've been used to deserialize the value returned by the grain; in turn registering it with said serializer");
            }
        }
Exemplo n.º 11
0
        public void TestStart3()
        {
            using (var silo = new SharpRemote.Hosting.OutOfProcessSilo("SharpRemote.dll"))
            {
                silo.IsProcessRunning.Should().BeFalse();

                new Action(silo.Start)
                .Should().Throw <Win32Exception>()
                .WithMessage("The specified executable is not a valid application for this OS platform.");

                silo.IsProcessRunning.Should().BeFalse();
                silo.HasProcessFailed.Should().BeFalse();

                new Action(() => silo.CreateGrain <IVoidMethodInt32Parameter>())
                .Should().Throw <NotConnectedException>();
            }
        }
Exemplo n.º 12
0
        public void TestStart2()
        {
            using (var silo = new SharpRemote.Hosting.OutOfProcessSilo("Doesntexist.exe"))
            {
                silo.IsProcessRunning.Should().BeFalse();

                new Action(silo.Start)
                .Should().Throw <FileNotFoundException>()
                .WithMessage("The system cannot find the file specified");

                silo.IsProcessRunning.Should().BeFalse("because we shouldn't have been able to start the process");
                silo.HasProcessFailed.Should().BeFalse();

                new Action(() => silo.CreateGrain <IVoidMethodInt32Parameter>())
                .Should().Throw <NotConnectedException>();
            }
        }
Exemplo n.º 13
0
        public void TestStart4()
        {
            const int taskCount      = 16;
            var       failureHandler = new RestartOnFailureStrategy();
            var       tasks          = new Task[taskCount];

            for (int i = 0; i < taskCount; ++i)
            {
                tasks[i] = new Task(() =>
                {
                    using (var silo = new SharpRemote.Hosting.OutOfProcessSilo(failureHandler: failureHandler))
                    {
                        silo.IsProcessRunning.Should().BeFalse();
                        silo.Start();
                        silo.IsProcessRunning.Should().BeTrue();

                        var proxy = silo.CreateGrain <IGetStringProperty>(typeof(GetStringPropertyImplementation));
                        proxy.Value.Should().Be("Foobar");
                    }
                });
                tasks[i].Start();
            }
            Task.WaitAll(tasks);
        }