Ejemplo n.º 1
0
        public void PurgeTest()
        {
            if (!MessageQueue.Exists(TESTQUEUENAME))
            {
                MessageQueue.Create(TESTQUEUENAME);
            }

            //Clean up
            MessageQueue queue = new MessageQueue(TESTQUEUENAME);

            queue.Purge();

            SendMessageCommandEx CommandEx = new SendMessageCommandEx(TESTQUEUENAME, 10);

            CommandEx.Message = new Message("testsendCommandEx_message#1");
            QueueCommandEx.Run(CommandEx);

            //Make sure there are messages before purging
            Assert.AreEqual(10, queue.GetAllMessages().Length);

            QueueCommandEx.Run(new PurgeQueueCommandEx(TESTQUEUENAME));

            //Make sure no messages
            Assert.AreEqual(0, queue.GetAllMessages().Length);
        }
Ejemplo n.º 2
0
        public void SendTest()
        {
            if (!MessageQueue.Exists(TESTQUEUENAME))
            {
                MessageQueue.Create(TESTQUEUENAME);
            }

            //Clean up
            MessageQueue queue = new MessageQueue(TESTQUEUENAME);

            queue.Purge();

            SendMessageCommandEx CommandEx = new SendMessageCommandEx(TESTQUEUENAME, 10);

            CommandEx.Message = new Message("testsendCommandEx_message#1");
            QueueCommandEx.Run(CommandEx);

            //Check count and content
            Assert.AreEqual(10, queue.GetAllMessages().Length);

            Message msg = queue.GetAllMessages()[0];

            msg.Formatter = new PlainTextFormatter();

            Assert.AreEqual("testsendCommandEx_message#1", msg.Body);

            msg           = queue.GetAllMessages()[9];
            msg.Formatter = new PlainTextFormatter();

            Assert.AreEqual("testsendCommandEx_message#1", msg.Body);
        }
Ejemplo n.º 3
0
        public void DecodeCopyCommandTest()
        {
            string[]       args   = "copy".Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            QueueCommandEx actual = CommandLineParser_Accessor.DecodeCopyCommand(args);

            Assert.IsNull(actual);

            args   = "copy notapath".Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            actual = CommandLineParser_Accessor.DecodeCopyCommand(args);
            Assert.IsNull(actual);

            args   = "copy /s sourcequeue /d destqueue ".Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            actual = CommandLineParser_Accessor.DecodeCopyCommand(args);
            Assert.IsNotNull(actual);
            Assert.AreEqual(".\\private$\\sourcequeue", ((CopyQueueCommandEx)actual).Path);
            //Assert.AreEqual(((CopyQueueCommandEx)actual).DestinationPath, ".\\private$\\destqueue");

            args   = "copy /s sourcequeue /d .\\private$\\destqueue garbage".Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            actual = CommandLineParser_Accessor.DecodeCopyCommand(args);
            Assert.IsNotNull(actual);

            args   = "copy /s .\\private$\\sourcequeue /d destqueue".Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            actual = CommandLineParser_Accessor.DecodeCopyCommand(args);
            Assert.IsNotNull(actual);
            Assert.AreEqual(((CopyQueueCommandEx)actual).Path, ".\\private$\\sourcequeue");
            //Assert.AreEqual(((CopyQueueCommandEx)actual).DestinationPath, ".\\private$\\destqueue");
        }
Ejemplo n.º 4
0
        public void SendPefTest()
        {
            if (!MessageQueue.Exists(TESTQUEUENAME))
            {
                MessageQueue.Create(TESTQUEUENAME);
            }

            //Clean up
            MessageQueue queue = new MessageQueue(TESTQUEUENAME);

            queue.Purge();

            SendMessageCommandEx command = new SendMessageCommandEx(TESTQUEUENAME, 100000);

            command.Message = new Message("testsendcommand_message#1"); //25 bytes

            Stopwatch stopwatch = Stopwatch.StartNew();

            QueueCommandEx.Run(command);

            stopwatch.Stop();
            //1M ~ 9 sec
            //100K < 1 sec
            Assert.AreEqual(true, stopwatch.ElapsedMilliseconds < 1100, string.Format("Perfomance for 100K messages size 25 bytes was less than expected 1 second, actual perfomance was {0} milliseconds", stopwatch.ElapsedMilliseconds));
        }
Ejemplo n.º 5
0
        public void DeleteTest()
        {
            if (!MessageQueue.Exists(TESTQUEUENAME))
            {
                MessageQueue.Create(TESTQUEUENAME);
            }

            QueueCommandEx.Run(new DeleteQueueCommandEx(TESTQUEUENAME));

            //Check if queue was deleted
            Assert.AreEqual(false, MessageQueue.Exists(TESTQUEUENAME));
        }
Ejemplo n.º 6
0
        public void CreateTest()
        {
            if (MessageQueue.Exists(TESTQUEUENAME))
            {
                MessageQueue.Delete(TESTQUEUENAME);
            }

            QueueCommandEx.Run(new CreateQueueCommandEx(TESTQUEUENAME, false));

            //Check if queue exists
            Assert.AreEqual(true, MessageQueue.Exists(TESTQUEUENAME));
        }
Ejemplo n.º 7
0
        public void ExportTest()
        {
            //Prepare
            if (!MessageQueue.Exists(TESTQUEUENAME))
            {
                MessageQueue.Create(TESTQUEUENAME);
            }

            if (File.Exists("testfile.xml"))
            {
                File.Delete("testfile.xml");
            }


            MessageQueue queue = new MessageQueue(TESTQUEUENAME);

            queue.Purge();

            SendMessageCommandEx CommandEx = new SendMessageCommandEx(TESTQUEUENAME, 3);

            CommandEx.Message = new Message("testsendCommandEx");
            QueueCommandEx.Run(CommandEx);

            //Make sure messages are there
            Assert.AreEqual(3, queue.GetAllMessages().Length);

            //preparations complete - export test
            QueueCommandEx.Run(new ExportQueueCommandEx(TESTQUEUENAME, "testfile.xml"));

            //Verify content
            string actual;

            using (StreamReader reader = new StreamReader("testfile.xml"))
            {
                actual = reader.ReadToEnd();
            }

            string expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?><messages><message><![CDATA[testsendCommandEx]]></message><message><![CDATA[testsendCommandEx]]></message><message><![CDATA[testsendCommandEx]]></message></messages>";

            Assert.AreEqual(expected, actual);

            //Clean up
            if (File.Exists("testfile.xml"))
            {
                File.Delete("testfile.xml");
            }
        }
Ejemplo n.º 8
0
        public void ImportTest()
        {
            //Prepare
            if (!MessageQueue.Exists(TESTQUEUENAME))
            {
                MessageQueue.Create(TESTQUEUENAME);
            }

            if (File.Exists("testfile.xml"))
            {
                File.Delete("testfile.xml");
            }

            MessageQueue queue = new MessageQueue(TESTQUEUENAME);

            queue.Purge();

            string data = "<?xml version=\"1.0\" encoding=\"utf-8\"?><messages><message><![CDATA[testsendCommandEx]]></message><message><![CDATA[testsendCommandEx]]></message><message><![CDATA[testsendCommandEx]]></message></messages>";

            using (StreamWriter writer = new StreamWriter("testfile.xml"))
            {
                writer.Write(data);
            }

            //Preparations complete - testing
            QueueCommandEx.Run(new ImportQueueCommandEx("testfile.xml", TESTQUEUENAME));

            //Make sure messages are there
            Assert.AreEqual(3, queue.GetAllMessages().Length);

            Message msg = queue.GetAllMessages()[0];

            msg.Formatter = new PlainTextFormatter();

            Assert.AreEqual("testsendCommandEx", msg.Body);

            //Clean up
            if (File.Exists("testfile.xml"))
            {
                File.Delete("testfile.xml");
            }
        }
Ejemplo n.º 9
0
        public void CopyPefTest()
        {
            if (!MessageQueue.Exists(TESTQUEUENAME))
            {
                MessageQueue.Create(TESTQUEUENAME);
            }

            if (!MessageQueue.Exists(TESTQUEUENAME2))
            {
                MessageQueue.Create(TESTQUEUENAME2);
            }

            //Clean up
            MessageQueue queue = new MessageQueue(TESTQUEUENAME);

            queue.Purge();

            queue = new MessageQueue(TESTQUEUENAME2);
            queue.Purge();

            //Fill the queue
            QueueCommandEx command = new SendMessageCommandEx(TESTQUEUENAME, 10000);

            command.Message = new Message("testsendcommand_message#1"); //25 bytes
            QueueCommandEx.Run(command);

            //Test

            command = new CopyQueueCommandEx(TESTQUEUENAME, TESTQUEUENAME2, (int?)null);

            Stopwatch stopwatch = Stopwatch.StartNew();

            QueueCommandEx.Run(command);

            stopwatch.Stop();
            //10K ~ 11 sec (queue opened every time)
            //10K ~ 2 sec (opening queue when creating instance of the class - ~6 times faster)
            Assert.AreEqual(true, stopwatch.ElapsedMilliseconds < 2500, string.Format("Perfomance for 10K messages size 25 bytes was less than expected 1 second, actual perfomance was {0} milliseconds", stopwatch.ElapsedMilliseconds));
        }
Ejemplo n.º 10
0
        public void CopyTest()
        {
            if (!MessageQueue.Exists(TESTQUEUENAME))
            {
                MessageQueue.Create(TESTQUEUENAME);
            }

            if (!MessageQueue.Exists(TESTQUEUENAME2))
            {
                MessageQueue.Create(TESTQUEUENAME2);
            }

            //Clean up
            MessageQueue queue = new MessageQueue(TESTQUEUENAME);

            queue.Purge();

            queue = new MessageQueue(TESTQUEUENAME2);
            queue.Purge();

            //Send messages to first queue
            SendMessageCommandEx CommandEx = new SendMessageCommandEx(TESTQUEUENAME, 110);

            CommandEx.Message = new Message("testsendCommandEx_message#1");
            QueueCommandEx.Run(CommandEx);

            //end of preparations, testing

            //Copy all
            QueueCommandEx.Run(new CopyQueueCommandEx(TESTQUEUENAME, TESTQUEUENAME2, (int?)null));
            Assert.AreEqual(110, queue.GetAllMessages().Length);

            //copy 10 more
            QueueCommandEx.Run(new CopyQueueCommandEx(TESTQUEUENAME, TESTQUEUENAME2, 10));
            Assert.AreEqual(120, queue.GetAllMessages().Length);
        }
Ejemplo n.º 11
0
        public void PeekTest()
        {
            if (!MessageQueue.Exists(TESTQUEUENAME))
            {
                MessageQueue.Create(TESTQUEUENAME);
            }

            //Clean up
            MessageQueue queue = new MessageQueue(TESTQUEUENAME);

            queue.Purge();

            SendMessageCommandEx CommandEx = new SendMessageCommandEx(TESTQUEUENAME, 10);

            CommandEx.Message = new Message("testpeekCommandEx_message#1");
            QueueCommandEx.Run(CommandEx);

            //Peek CommandEx saves last read message in internal message variable, therefore:
            //a) test first message
            PeekQueueCommandEx peekCommandEx = (new PeekQueueCommandEx(TESTQUEUENAME, 1));

            QueueCommandEx.Run(peekCommandEx);

            Assert.AreEqual("testpeekCommandEx_message#1", peekCommandEx.Message.Body);

            //b) test last message
            peekCommandEx = (new PeekQueueCommandEx(TESTQUEUENAME, (int?)null));
            QueueCommandEx.Run(peekCommandEx);

            Assert.AreEqual("testpeekCommandEx_message#1", peekCommandEx.Message.Body);

            Type      type  = typeof(PeekQueueCommandEx);
            FieldInfo finfo = type.GetField("_messagesRead", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance);

            Assert.AreEqual(10, (long)finfo.GetValue(peekCommandEx));
        }