public void HundredOf2mbPacket_transmitsViaTcp_oneByOne()
        {
            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 receivedList = new List <Company>(200);

                tcpPair.OriginContract.SayCalled
                    += (Sender, received) => receivedList.Add(received);
                var company   = IntegrationTestsHelper.CreateCompany(2000);
                int sendCount = 100;
                for (int i = 0; i < sendCount; i++)
                {
                    tcpPair.ProxyConnection.Contract.Ask(company);
                }
                Assert.AreEqual(sendCount, receivedList.Count);
                foreach (var received in receivedList)
                {
                    received.AssertIsSameTo(company);
                }
            }
        }
예제 #2
0
        private static void SerializeAndDeserializeProtobuffMessage(int companySize)
        {
            var company = IntegrationTestsHelper.CreateCompany(companySize);

            using (var stream = new MemoryStream())
            {
                var serializer = new TNT.Presentation.Serializers.ProtoSerializer <Company>();
                serializer.SerializeT(company, stream);
                stream.Position = 0;
                var deserializer = new TNT.Presentation.Deserializers.ProtoDeserializer <Company>();
                var deserialized = deserializer.DeserializeT(stream, (int)stream.Length);
                company.AssertIsSameTo(deserialized);
            }
        }
        public void HundredOf2mbPacket_transmitsViaTcp_concurent()
        {
            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 receivedList = new List <Company>(200);

                tcpPair.OriginContract.SayCalled
                    += (Sender, received) => receivedList.Add(received);
                tcpPair.ClientChannel.OnDisconnect += (s, err) =>
                {
                    Console.WriteLine("asdasd");
                };
                var company   = IntegrationTestsHelper.CreateCompany(2000);
                int sendCount = 100;

                List <Task> sendTasks = new List <Task>(sendCount);
                for (int i = 0; i < sendCount; i++)
                {
                    sendTasks.Add(new Task(() => tcpPair.ProxyConnection.Contract.Ask(company)));
                }

                foreach (Task task in sendTasks)
                {
                    task.Start();
                }
                if (!Task.WaitAll(sendTasks.ToArray(), 5 * 60 * 1000))
                {
                    Assert.Fail("Test timeout ");
                }


                Assert.AreEqual(sendCount, receivedList.Count);
                foreach (var received in receivedList)
                {
                    received.AssertIsSameTo(company);
                }
            }
        }
예제 #4
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 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
            }
        }