Example #1
0
        public void TestRestart3()
        {
            IGetInt32Property someGrain = null;

            _silo.OnHostStarted += () =>
            {
                someGrain = _silo.CreateGrain <IGetInt32Property, ReturnsPid>();
                _startHandle.Set();
            };
            _silo.Start();

            var pid = _silo.HostProcessId.Value;

            someGrain.Value.Should().Be(pid);

            _startHandle.Reset();
            var proc = Process.GetProcessById(pid);

            proc.Kill();

            _startHandle.WaitOne(TimeSpan.FromSeconds(10)).Should().BeTrue("because the silo should've restarted the host process automatically");
            var newPid = _silo.HostProcessId;

            someGrain.Value.Should().Be(newPid);
        }
Example #2
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");
                }
            }
        }
Example #3
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);
            }
        }
Example #4
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");
            }
        }
Example #5
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>();
            }
        }
Example #6
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>();
            }
        }
Example #7
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);
        }