Beispiel #1
0
        public void CompleteMessageTest()
        {
            this.SubmitRequestWithPropertiesTest();

            var manager = new QueueMessageManagerSql();

            var item = new QueueMessageItem()
            {
                TextInput = "My input",
                Message   = "Getting started."
            };

            manager.CreateItem(item);

            manager.Properties["Time"] = DateTime.Now;

            Assert.IsTrue(manager.Save(), manager.ErrorMessage);

            string reqId = item.Id;

            manager = new QueueMessageManagerSql();
            item    = manager.GetNextQueueMessage();

            DateTime?time = manager.GetProperty("Time") as DateTime?;

            Assert.IsNotNull(time);

            manager.CompleteRequest(item, "Message completed @" + DateTime.Now.ToString("t"));

            Assert.IsTrue(manager.Save(), manager.ErrorMessage);
        }
Beispiel #2
0
        public void SubmitRequestTest()
        {
            var manager = new QueueMessageManagerSql();

            string imageId = "10";

            // Create a message object
            // item contains many properties for pushing
            // values back and forth as well as a  few message fields
            var item = manager.CreateItem();

            item.Action          = "PRINTIMAGE";
            item.TextInput       = imageId;
            item.Message         = "Print Image operation started at " + DateTime.Now.ToString();
            item.PercentComplete = 10;

            // *** you can also serialize objects directly into the Xml property
            // manager.Serialization.SerializeToXml(SomeObjectToSerialize);

            // add an arbitrary custom properties - serialized to Xml
            manager.Properties.Add("Time", DateTime.Now);
            manager.Properties.Add("User", "ricks");

            // Set the message status and timestamps as submitted
            manager.SubmitRequest(item);

            // actually save the queue message to disk
            Assert.IsTrue(manager.Save(), manager.ErrorMessage);
        }
        public void SubmitRequestTest()
        {
            var manager = new QueueMessageManagerSql();

            string imageId = "10";
           
            // Create a message object
            // item contains many properties for pushing
            // values back and forth as well as a  few message fields
            var item = manager.CreateItem();
            item.Action = "PRINTIMAGE";
            item.TextInput = imageId;
            item.Message = "Print Image operation started at " + DateTime.Now.ToString();
            item.PercentComplete = 10;

            // *** you can also serialize objects directly into the Xml property
            // manager.Serialization.SerializeToXml(SomeObjectToSerialize);

            // add an arbitrary custom properties - serialized to Xml
            manager.Properties.Add("Time", DateTime.Now);
            manager.Properties.Add("User", "ricks");

            // Set the message status and timestamps as submitted             
            manager.SubmitRequest(item);

            // actually save the queue message to disk
            Assert.IsTrue(manager.Save(), manager.ErrorMessage);
        }
        public void ScaleRetrievalTest()
        {
            var manager = new QueueMessageManagerSql();

            manager.Db.ExecuteNonQuery("delete from queuemessageitems");            

            var sw = new Stopwatch();
            sw.Start();

            for (int i = 0; i < 30000; i++)
            {
                string imageId = "10";

                // Create a message object
                // item contains many properties for pushing
                // values back and forth as well as a  few message fields
                var item = manager.CreateItem();
                item.QueueName = "Queue1";
                item.TextInput = DataUtils.GenerateUniqueId(15);

                // Set the message status and timestamps as submitted             
                manager.SubmitRequest(item,autoSave: true);
            }

            Console.WriteLine("Insert time: " + sw.ElapsedMilliseconds);

            IdList = new List<string>();
            IdErrors = new List<string>();

            for (int i = 0; i < 20; i++)
            {
                var thread = new Thread(ProcessGetNextItem);
                thread.Start();
            }


            for (int i = 0; i < 10000; i++)
            {
                if (CancelProcessing)
                    break;

                string imageId = "10";

                // Create a message object
                // item contains many properties for pushing
                // values back and forth as well as a  few message fields
                var item = manager.CreateItem();
                item.QueueName = "Queue1";
                item.TextInput = DataUtils.GenerateUniqueId(15);

                // Set the message status and timestamps as submitted             
                manager.SubmitRequest(item, autoSave: true);

                Thread.Sleep(2);
            }


            Console.WriteLine("Waiting for 5 seconds");
            Thread.Sleep(5000);
            CancelProcessing = true;
            Thread.Sleep(100);

            Console.WriteLine("Done");

            Console.WriteLine("Items processed: " + IdList.Count);

            var grouped = IdList.GroupBy(s => s);
            Console.WriteLine("Unique Count: " + grouped.Count());

            foreach (var error in IdErrors)
                Console.WriteLine("  " + error);

        }
        public void CompleteMessageTest()
        {
            this.SubmitRequestWithPropertiesTest();

            var manager = new QueueMessageManagerSql();

            var item = new QueueMessageItem()
            {
                 TextInput = "My input",
                 Message = "Getting started."
            };
            manager.CreateItem(item);

            manager.Properties["Time"] = DateTime.Now;

            Assert.IsTrue(manager.Save(),manager.ErrorMessage);

            string reqId = item.Id;

            manager = new QueueMessageManagerSql();            
            item = manager.GetNextQueueMessage();

            DateTime? time = manager.GetProperty("Time") as DateTime?;
            Assert.IsNotNull(time);

            manager.CompleteRequest(item,"Message completed @" + DateTime.Now.ToString("t"));

            Assert.IsTrue(manager.Save(), manager.ErrorMessage);
        }
Beispiel #6
0
        public void ScaleRetrievalTest()
        {
            var manager = new QueueMessageManagerSql();

            manager.Db.ExecuteNonQuery("delete from queuemessageitems");

            var sw = new Stopwatch();

            sw.Start();

            for (int i = 0; i < 30000; i++)
            {
                string imageId = "10";

                // Create a message object
                // item contains many properties for pushing
                // values back and forth as well as a  few message fields
                var item = manager.CreateItem();
                item.QueueName = "Queue1";
                item.TextInput = DataUtils.GenerateUniqueId(15);

                // Set the message status and timestamps as submitted
                manager.SubmitRequest(item, autoSave: true);
            }

            Console.WriteLine("Insert time: " + sw.ElapsedMilliseconds);

            IdList   = new List <string>();
            IdErrors = new List <string>();

            for (int i = 0; i < 20; i++)
            {
                var thread = new Thread(ProcessGetNextItem);
                thread.Start();
            }


            for (int i = 0; i < 10000; i++)
            {
                if (CancelProcessing)
                {
                    break;
                }

                string imageId = "10";

                // Create a message object
                // item contains many properties for pushing
                // values back and forth as well as a  few message fields
                var item = manager.CreateItem();
                item.QueueName = "Queue1";
                item.TextInput = DataUtils.GenerateUniqueId(15);

                // Set the message status and timestamps as submitted
                manager.SubmitRequest(item, autoSave: true);

                Thread.Sleep(2);
            }


            Console.WriteLine("Waiting for 5 seconds");
            Thread.Sleep(5000);
            CancelProcessing = true;
            Thread.Sleep(100);

            Console.WriteLine("Done");

            Console.WriteLine("Items processed: " + IdList.Count);

            var grouped = IdList.GroupBy(s => s);

            Console.WriteLine("Unique Count: " + grouped.Count());

            foreach (var error in IdErrors)
            {
                Console.WriteLine("  " + error);
            }
        }