Example #1
0
        public void ClientDisconnected_ServerRaisesErrorMessage()
        {
            var failedOrigin = IntegrationTestsHelper
                               .GetOriginBuilder()
                               .UseSerializer(IntegrationTestsHelper.GetThrowsSerializationRuleFor <string>());

            using (var tcpPair = new TcpConnectionPair <ITestContract, ITestContract, TestContractMock>
                                     (failedOrigin, IntegrationTestsHelper.GetProxyBuilder()))
            {
                var awaiter = new EventAwaiter <ClientDisconnectEventArgs <ITestContract, TcpChannel> >();
                tcpPair.Server.Disconnected += awaiter.EventRaised;

                //provokes exception at origin-side serialization
                try
                {
                    tcpPair.ProxyContract.Ask("some string");
                }
                catch (RemoteSerializationException) {}

                var receivedArgs = awaiter.WaitOneOrDefault(500);
                //Client disconnected event is expected
                Assert.IsNotNull(receivedArgs);
                Assert.IsNotNull(receivedArgs.ErrorMessageOrNull);
                Assert.AreEqual(ErrorType.SerializationError, receivedArgs.ErrorMessageOrNull.ErrorType);
            }
        }
Example #2
0
 public void Connect()
 {
     _eventAwaiter        = new EventAwaiter <IConnection <TOriginContractInterface, TestChannel> >();
     Server.AfterConnect += _eventAwaiter.EventRaised;
     Server.StartListening();
     Server.TestListener.ImmitateAccept(ClientChannel);
     OriginConnection = _eventAwaiter.WaitOneOrDefault(500);
     Assert.IsNotNull(OriginConnection);
 }
Example #3
0
 public void Connect()
 {
     _eventAwaiter        = new EventAwaiter <IConnection <TOriginContractInterface, TcpChannel> >();
     Server.AfterConnect += _eventAwaiter.EventRaised;
     Server.StartListening();
     ClientChannel.Connect(new IPEndPoint(IPAddress.Loopback, 12345));
     OriginConnection = _eventAwaiter.WaitOneOrDefault(500);
     Assert.IsNotNull(OriginConnection);
 }
Example #4
0
        public void ProxySayCall_NoThreadDispatcher_OriginSayCalled(string sentMessage)
        {
            using (var tcpPair = new TcpConnectionPair())
            {
                EventAwaiter <string> callAwaiter = new EventAwaiter <string>();
                tcpPair.OriginContract.SayMethodWasCalled += callAwaiter.EventRaised;

                tcpPair.ProxyConnection.Contract.Say(sentMessage);
                var received = callAwaiter.WaitOneOrDefault(500);

                Assert.AreEqual(sentMessage, received);
            }
        }
Example #5
0
 private static void CheckProtobuffEchoTransaction(int itemsSize)
 {
     using (var tcpPair = new TcpConnectionPair
                          <ISingleMessageContract <Company>,
                           ISingleMessageContract <Company>,
                           SingleMessageContract <Company> >())
     {
         EventAwaiter <Company> callAwaiter = new EventAwaiter <Company>();
         tcpPair.OriginContract.SayCalled += callAwaiter.EventRaised;
         var company = IntegrationTestsHelper.CreateCompany(itemsSize);
         tcpPair.ProxyConnection.Contract.Ask(company);
         var received = callAwaiter.WaitOneOrDefault(5000);
         Assert.IsNotNull(received);
         received.AssertIsSameTo(company);
     }
 }
        public void StringPackets_transmitsViaTcp_concurent(int stringLengthInBytes)
        {
            using (var tcpPair = new TcpConnectionPair
                                 <ISingleMessageContract <string>,
                                  ISingleMessageContract <string>,
                                  SingleMessageContract <string> >())
            {
                //Tasks count:
                int sentCount = 10;

                string originStringArgument = generateRandomString(stringLengthInBytes / 2);

                var receivedList = new List <string>(200);
                tcpPair.OriginContract.SayCalled
                    += (Sender, received) => receivedList.Add(received);

                //start monitoring disconnection events.
                var serverDisconnectAwaiter
                    = new EventAwaiter <ClientDisconnectEventArgs <ISingleMessageContract <string>, TcpChannel> >();
                tcpPair.Server.Disconnected += serverDisconnectAwaiter.EventRaised;

                var clientDisconnectAwaiter
                    = new EventAwaiter <ErrorMessage>();
                tcpPair.ClientChannel.OnDisconnect += clientDisconnectAwaiter.EventRaised;

                #region sending
                var sentTasks = new List <Task>(sentCount);
                for (var i = 0; i < sentCount; i++)
                {
                    sentTasks.Add(new Task(() => tcpPair.ProxyConnection.Contract.Ask(originStringArgument)));
                }
                foreach (var task in sentTasks)
                {
                    task.Start();
                }
                #endregion


                #region checking for exceptions

                bool      allDoneSucc   = false;
                Exception doneException = null;
                try
                {
                    allDoneSucc = Task.WaitAll(sentTasks.ToArray(), 60000);
                }
                catch (Exception e) { doneException = e; }
                //Check for client disconnection
                var clientDisconnectArgs = clientDisconnectAwaiter.WaitOneOrDefault(500);

                //Check for server disconnection
                var serverDisconnectedArg = serverDisconnectAwaiter.WaitOneOrDefault(500);
                if (clientDisconnectArgs != null || serverDisconnectedArg != null)
                {
                    if (clientDisconnectArgs != null)
                    {
                        Assert.Fail("Client disconnected. Reason: " + clientDisconnectArgs);
                    }
                    else if (serverDisconnectedArg != null)
                    {
                        Assert.Fail("Server disconnected. Reason: " + serverDisconnectedArg.ErrorMessageOrNull);
                    }
                }
                //check for tasks agregate exception
                if (doneException != null)
                {
                    Assert.Fail("Client side thrown exception during the interaction: " + doneException.ToString());
                }
                //Check for timeout
                if (!allDoneSucc)
                {
                    Assert.Fail("Test timeout ");
                }

                #endregion

                #region checking for  serialization results
                Assert.AreEqual(sentCount, receivedList.Count);
                foreach (var received in receivedList)
                {
                    Assert.AreEqual(originStringArgument, received);
                }
                #endregion
            }
        }
        public void ProtobuffPackets_transmitViaTcp_concurent(int sizeOfCompanyInUsers, int parralelTasksCount)
        {
            //1000 = 0.5mb
            //2000 = 2mb
            //5000 = 10mb
            //10000 = 50mb  5

            var origin = TntBuilder
                         .UseContract <ISingleMessageContract <Company>, SingleMessageContract <Company> >()
                         .SetMaxAnsDelay(5 * 60 * 1000);
            var proxy = TntBuilder
                        .UseContract <ISingleMessageContract <Company> >()
                        .SetMaxAnsDelay(5 * 60 * 1000);

            using (var tcpPair = new TcpConnectionPair
                                 <ISingleMessageContract <Company>,
                                  ISingleMessageContract <Company>,
                                  SingleMessageContract <Company> >(origin, proxy))
            {
                var originCompany = IntegrationTestsHelper.CreateCompany(sizeOfCompanyInUsers);
                var receivedList  = new List <Company>(parralelTasksCount);
                tcpPair.OriginContract.SayCalled
                    += (Sender, received) => receivedList.Add(received);

                //start monitoring the server disconnection event.
                var serverDisconnectAwaiter
                    = new EventAwaiter <ClientDisconnectEventArgs <ISingleMessageContract <Company>, TcpChannel> >();
                tcpPair.Server.Disconnected += serverDisconnectAwaiter.EventRaised;

                var clientDisconnectAwaiter
                    = new EventAwaiter <ErrorMessage>();
                tcpPair.ClientChannel.OnDisconnect += clientDisconnectAwaiter.EventRaised;
                tcpPair.ClientChannel.OnDisconnect += (s, arg) =>
                {
                    Console.WriteLine();
                };
                #region sending
                var sentTasks = new List <Task>(parralelTasksCount);
                for (var i = 0; i < parralelTasksCount; i++)
                {
                    sentTasks.Add(new Task(() => tcpPair.ProxyConnection.Contract.Ask(originCompany)));
                }
                foreach (var task in sentTasks)
                {
                    task.Start();
                }
                #endregion

                #region checking for exceptions

                bool      allDoneSucc   = false;
                Exception doneException = null;
                try
                {
                    allDoneSucc = Task.WaitAll(sentTasks.ToArray(), 60000);
                }
                catch (Exception e) { doneException = e; }
                //Check for client disconnection
                var clientDisconnectArgs = clientDisconnectAwaiter.WaitOneOrDefault(500);

                //Check for server disconnection
                var serverDisconnectedArg = serverDisconnectAwaiter.WaitOneOrDefault(500);
                if (clientDisconnectArgs != null || serverDisconnectedArg != null)
                {
                    if (clientDisconnectArgs != null)
                    {
                        Assert.Fail("Client disconnected. Reason: " + clientDisconnectArgs);
                    }
                    else if (serverDisconnectedArg != null)
                    {
                        Assert.Fail("Server disconnected. Reason: " + serverDisconnectedArg.ErrorMessageOrNull);
                    }
                }
                //check for tasks agregate exception
                if (doneException != null)
                {
                    Assert.Fail("Client side thrown exception during the interaction: " + doneException.ToString());
                }
                //Check for timeout
                if (!allDoneSucc)
                {
                    Assert.Fail("Test timeout ");
                }

                #endregion


                #region checking for  serialization results
                Assert.AreEqual(parralelTasksCount, receivedList.Count);
                foreach (var received in receivedList)
                {
                    received.AssertIsSameTo(originCompany);
                }
                #endregion
            }
        }