Exemplo n.º 1
0
        public void TestRestart1()
        {
            _silo.Start();

            _silo.OnHostStarted += () => _startHandle.Set();
            var oldPid = _silo.HostProcessId.Value;
            var proc   = Process.GetProcessById(oldPid);

            proc.Kill();

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

            newPid.Should().HaveValue();
            newPid.Should().NotBe(oldPid);
        }
Exemplo n.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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);
        }