Esempio n. 1
0
        public void TestAcitveMQ()
        {
            Locator  locator = new Locator();
            IAdapter sender  = (IAdapter)locator.GetComponent("ActiveMQAdapter");

            sender.SetParameter("ActiveMQConnectionString", "tcp://localhost:61616");
            sender.SetParameter("ReceiveDestinationName", "queue/first");
            sender.SetParameter("SendDestinationName", "queue/second");

            IAdapter receiver = (IAdapter)locator.GetComponent("ActiveMQAdapter");

            receiver.SetParameter("ActiveMQConnectionString", "tcp://localhost:61616");
            receiver.SetParameter("ReceiveDestinationName", "queue/second");
            receiver.SetParameter("SendDestinationName", "queue/first");

            sender.Start();
            receiver.Start();
            try
            {
                sender.Begin();
                sender.Send("ЙЦУКЕН");
                sender.Commit();

                Thread.Sleep(3000);

                receiver.Begin();
                Assert.IsTrue(receiver.HasMessage());
                Assert.AreEqual(receiver.Receive(), "ЙЦУКЕН");
                receiver.Commit();
            }
            finally
            {
                sender.Stop();
                receiver.Stop();
            }
        }
Esempio n. 2
0
        public void TestSimpleLoad()
        {
            Locator  locator = new Locator();
            IAdapter sender  = (IAdapter)locator.GetComponent("ActiveMQAdapter");

            sender.SetParameter("ActiveMQConnectionString", "tcp://localhost:61616");
            sender.SetParameter("ReceiveDestinationName", "queue/first");
            sender.SetParameter("SendDestinationName", "queue/second");

            IAdapter receiver = (IAdapter)locator.GetComponent("ActiveMQAdapter");

            receiver.SetParameter("ActiveMQConnectionString", "tcp://localhost:61616");
            receiver.SetParameter("ReceiveDestinationName", "queue/second");
            receiver.SetParameter("SendDestinationName", "queue/first");

            sender.Start();
            receiver.Start();
            try
            {
                Thread senderThread = new Thread(
                    delegate()
                {
                    long counter = 0;
                    while (true)
                    {
                        sender.Begin();
                        sender.Send("ЙЦУКЕН " + counter);
                        sender.Commit();
                        counter++;
                        Thread.Sleep(10);
                    }
                }
                    );

                Thread receiverThread = new Thread(
                    delegate()
                {
                    long counter = 0;
                    while (true)
                    {
                        receiver.Begin();
                        while (receiver.HasMessage())
                        {
                            string s = receiver.Receive();
                            Assert.AreEqual(counter, Convert.ToInt64(s.Split(' ')[1]));
                            Console.WriteLine(s + "|" + Convert.ToInt64(s.Split(' ')[1]) + "|" + counter);
                            counter++;
                        }
                        receiver.Commit();
                        Thread.Sleep(1000);
                    }
                }
                    );

                senderThread.Start();
                Thread.Sleep(3000);
                receiverThread.Start();
                receiverThread.Join();
            }
            finally
            {
                sender.Stop();
                receiver.Stop();
            }
        }
Esempio n. 3
0
        public void TestHighLoadActiveMQ()
        {
            Locator  locator = new Locator();
            IAdapter sender  = (IAdapter)locator.GetComponent("ActiveMQAdapter");

            sender.SetParameter("ActiveMQConnectionString", "tcp://localhost:61616");
            sender.SetParameter("ReceiveDestinationName", "queue/first");
            sender.SetParameter("SendDestinationName", "queue/second");

            IAdapter receiver = (IAdapter)locator.GetComponent("ActiveMQAdapter");

            receiver.SetParameter("ActiveMQConnectionString", "tcp://localhost:61616");
            receiver.SetParameter("ReceiveDestinationName", "queue/second");
            receiver.SetParameter("SendDestinationName", "queue/first");

            sender.Start();
            receiver.Start();
            try
            {
                Thread senderThread = new Thread(
                    delegate()
                {
                    long counter = 0;
                    while (true)
                    {
                        sender.Begin();
                        sender.Send("ЙЦУКЕН " + counter);
                        //Console.WriteLine(">"+counter);
                        sender.Commit();
                        counter++;
                        Thread.Sleep(10);
                    }
                }
                    );

                Thread receiverThread = new Thread(
                    delegate()
                {
                    long counter = 0;
                    while (true)
                    {
                        receiver.Begin();
                        if (counter < 100)
                        {
                            counter++;
                            receiver.Receive();
                            receiver.Rollback();
                        }
                        else
                        {
                            counter = 0;
                            while (receiver.HasMessage())
                            {
                                Console.WriteLine(receiver.Receive());
                            }
                            receiver.Commit();
                        }
                    }
                }
                    );

                senderThread.Start();
                Thread.Sleep(3000);
                receiverThread.Start();
                receiverThread.Join();
            }
            finally
            {
                sender.Stop();
                receiver.Stop();
            }
        }