public void ValidateSharedPorts()
        {
            // Arrange
            IOperationDispatcher serverDisaptcher = new OperationDispatcher()
                                                    .RegisterHandler <ICalculator>(new Calculator());

            IOperationDispatcher clienDispatcher = new OperationDispatcher();

            // Act
            using (StatelessServerEndpoint server1 = new StatelessServerEndpoint(url, serverDisaptcher))
                using (StatelessServerEndpoint server2 = new StatelessServerEndpoint(url2, serverDisaptcher))
                {
                    using (ClientConnection c1 = CreateClientConnection("a", Port, clienDispatcher))
                        using (ClientConnection c2 = CreateClientConnection("a", Port2, clienDispatcher))
                        {
                            server1.Start();
                            server2.Start();
                            c1.Open();
                            c2.Open();

                            // Assert
                            Assert.AreEqual(c1.GetClientEndpoint(), c2.GetClientEndpoint());
                        }
                }
        }
        public void ValidateSharedActuallyWorks()
        {
            // Arrange
            IOperationDispatcher serverDispatcher = new OperationDispatcher()
                                                    .RegisterHandler <ICalculator>(new Calculator());

            IOperationDispatcher clienDispatcher = new OperationDispatcher();

            // Act
            using (StatelessServerEndpoint server2 = new StatelessServerEndpoint(url2, serverDispatcher))
                using (StatelessServerEndpoint server3 = new StatelessServerEndpoint(url3, serverDispatcher))
                {
                    using (ClientConnection c1 = CreateClientConnection("a", Port2, clienDispatcher))
                        using (ClientConnection c2 = CreateClientConnection("a", Port3, clienDispatcher))
                        {
                            server2.Start();
                            server3.Start();
                            c1.Open();
                            c2.Open();

                            // Assert
                            Assert.AreEqual(4, c1.RemoteExecutor.Create <ICalculator>().Add(2, 2));
                            Assert.AreEqual(4, c2.RemoteExecutor.Create <ICalculator>().Add(2, 2));
                        }
                }
        }
        public void ValidateCloseShared()
        {
            // Arrange
            bool exceptionThrown = false;
            IOperationDispatcher serverDispatcher = new OperationDispatcher()
                                                    .RegisterHandler <ICalculator>(new Calculator());

            IOperationDispatcher clienDispatcher = new OperationDispatcher();

            // Act
            using (StatelessServerEndpoint server1 = new StatelessServerEndpoint(url2, serverDispatcher))
                using (StatelessServerEndpoint server2 = new StatelessServerEndpoint(url3, serverDispatcher))
                {
                    using (ClientConnection c1 = CreateClientConnection("a", Port2, clienDispatcher))
                        using (ClientConnection c2 = CreateClientConnection("a", Port3, clienDispatcher))
                        {
                            server1.Start();
                            server2.Start();
                            c1.Open();
                            c2.Open();

                            c1.Dispose();
                            try
                            {
                                c2.RemoteExecutor.Create <ICalculator>().Add(2, 2);
                            }
                            catch (NotConnectedException)
                            {
                                exceptionThrown = true;
                            }
                        }
                }
            // Assert
            Assert.IsTrue(exceptionThrown);
        }
        public void ValidateStartWithDistinct()
        {
            // Arrange
            IOperationDispatcher dispatcher = new OperationDispatcher()
                                              .RegisterHandler <ICalculator>(new Calculator());

            // Act
            using (StatelessServerEndpoint server = new StatelessServerEndpoint(url, dispatcher))
                using (StatelessServerEndpoint server2 = new StatelessServerEndpoint(url2, dispatcher))
                    using (StatelessServerEndpoint server3 = new StatelessServerEndpoint(url3, dispatcher))
                    {
                        using (ClientConnection c1 = new ClientConnection(url))
                            using (ClientConnection c2 = CreateClientConnection("a", Port2, new OperationDispatcher()))
                                using (ClientConnection c3 = CreateClientConnection("b", Port3, new OperationDispatcher()))
                                {
                                    server.Start();
                                    server2.Start();
                                    server3.Start();
                                    c1.Open();
                                    c2.Open();
                                    c3.Open();

                                    // Assert
                                    Assert.AreEqual(4, c1.RemoteExecutor.Create <ICalculator>().Add(2, 2));
                                    Assert.AreEqual(4, c2.RemoteExecutor.Create <ICalculator>().Add(2, 2));
                                    Assert.AreEqual(4, c3.RemoteExecutor.Create <ICalculator>().Add(2, 2));
                                    Assert.AreNotEqual(c1.GetClientEndpoint(), c2.GetClientEndpoint());
                                    Assert.AreNotEqual(c2.GetClientEndpoint(), c3.GetClientEndpoint());
                                }
                    }
        }
Esempio n. 5
0
        public void ValidateDurableAbortReconnection()
        {
            IOperationDispatcher    serverDispatcher = new OperationDispatcher();
            StatelessServerEndpoint server           = new StatelessServerEndpoint(url, serverDispatcher);

            serverDispatcher.RegisterHandler <IWeakCalculator>(new WeakCalculator {
                Destroyed = () => server.Dispose()
            });
            server.Start();
            using (DurableClientConnection client = new DurableClientConnection(url))
            {
                client.ConnectionPaused = response => response.Abort = true;
                client.Open();
                IWeakCalculator calculator = client.RemoteExecutor.Create <IWeakCalculator>();
                Assert.AreEqual(4, calculator.Add(2, 2));
                calculator.Destroy();
                server = new StatelessServerEndpoint(url2, serverDispatcher);
                server.Start();
                bool exceptionThrown = false;
                try
                {
                    calculator.Add(5, 6);
                }
                catch (NotConnectedException ex)
                {
                    exceptionThrown = ex.Message == "Network connection is not opened.";
                }
                Assert.IsTrue(exceptionThrown);
                server.Dispose();
            }
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            SharedConfigurator.Configure();

            var dispatcher = new OperationDispatcher()
                             .RegisterHandler <IBasicService>(new BasicService());


            using (var host = new StatelessServerEndpoint("net://127.0.0.1:3132/SharedAppId", dispatcher))
            {
                host.Start();
                Console.WriteLine("Server started...\nPress enter to stop");
                Console.ReadLine();
            }
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            Configurator.Configure();

            var dispatcher = new OperationDispatcher()
                             .RegisterHandler <ICalculator>(new CalculatorService())
                             .RegisterHandler <IGreeter>(new GreeterService());


            using (var host = new StatelessServerEndpoint("net://127.0.0.1:3131/StatelessServices", dispatcher))
            {
                host.Start();
                Console.WriteLine("Server started...\nPress enter to stop");
                Console.ReadLine();
            }
        }
        public void ValidateBasicMethodCall()
        {
            IOperationDispatcher serverDisaptcher = new OperationDispatcher()
                                                    .RegisterHandler <ICalculator>(new Calculator());

            using (StatelessServerEndpoint server = new StatelessServerEndpoint(Url, serverDisaptcher))
            {
                server.Start();
                using (ClientConnection client = MakeFacadeConnection(AppId, Host, Port))
                {
                    client.Open();
                    ICalculator calculator = client.RemoteExecutor.Create <ICalculator>();
                    Assert.AreEqual(4, calculator.Add(2, 2));
                }
            }
        }
        public void ValidateSingle()
        {
            // Arrange
            IOperationDispatcher dispatcher = new OperationDispatcher()
                                              .RegisterHandler <ICalculator>(new Calculator());

            // Act
            using (StatelessServerEndpoint server1 = new StatelessServerEndpoint(url, dispatcher))
            {
                using (ClientConnection c1 = CreateClientConnection("a", Port, new OperationDispatcher()))
                {
                    server1.Start();
                    c1.Open();

                    Assert.AreEqual(4, c1.RemoteExecutor.Create <ICalculator>().Add(2, 2));
                }
            }
        }
Esempio n. 10
0
        public void ValidateDurableSilentFailover()
        {
            IOperationDispatcher    serverDispatcher = new OperationDispatcher();
            StatelessServerEndpoint server           = new StatelessServerEndpoint(url, serverDispatcher);

            serverDispatcher.RegisterHandler <IWeakCalculator>(new WeakCalculator {
                Destroyed = () => server.Dispose()
            });
            server.Start();
            using (ClientConnection client = new ClientConnection(url))
            {
                client.Open();
                IWeakCalculator calculator = client.RemoteExecutor.Create <IWeakCalculator>();
                Assert.AreEqual(4, calculator.Add(2, 2));
                calculator.Destroy();
                server = new StatelessServerEndpoint(url, serverDispatcher);
                server.Start();
                Assert.AreEqual(11, calculator.Add(5, 6));
                server.Dispose();
            }
        }