Beispiel #1
0
        public void GetNextQueueMessageItemWithAddedItemTest()
        {
            using (var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING, BASE_QUEUE_PATH))
            {
                // delete all pending requests
                int res = manager.Db.ExecuteNonQuery("delete from queuemessageItems where started is null");
                Console.WriteLine(res);

                // delete all queued ids - otherwise no items will match :-)
                var queue = manager.GetQueue("");
                queue.Purge();

                // creates sql and msmq items
                manager.SubmitRequest(messageText: "Next Complete Test " + DateTime.Now.ToString("t"));
                Assert.IsTrue(manager.Save(), manager.ErrorMessage);
            }

            using (var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING, BASE_QUEUE_PATH))
            {
                var item = manager.GetNextQueueMessage();
                Assert.IsNotNull(item, manager.ErrorMessage);

                Console.WriteLine(item.Message);

                manager.CompleteRequest(item, "Next Complete complete " + DateTime.Now.ToString("t"));

                Assert.IsTrue(manager.Save(), manager.ErrorMessage);
            }
        }
Beispiel #2
0
        public void ScaleRetrievalTest()
        {
            string queueName = "Queue1";

            var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING, BASE_QUEUE_PATH);

            manager.Db.ExecuteNonQuery("delete from queuemessageitems");
            manager.GetQueue(queueName).Purge();

            var sw = new Stopwatch();

            sw.Start();

            for (int i = 0; i < 40000; 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 = queueName;
                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();
            }

            //Task.Run(() =>
            //{
            //    for (int i = 0; i < 100; i++)
            //    {
            //        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.QueueName = "Queue1";
            //        item.TextInput = DataUtils.GenerateUniqueId(15);

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

            //    Thread.Sleep(60);
            //});

            for (int i = 0; i < 500; 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 = queueName;
                item.TextInput = DataUtils.GenerateUniqueId(15);

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

                Thread.Sleep(4);
            }


            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 ScaleRetrievalTest()
        {
            string queueName = "Queue1";

            var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING,BASE_QUEUE_PATH);

            manager.Db.ExecuteNonQuery("delete from queuemessageitems");
            manager.GetQueue(queueName).Purge();

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

            for (int i = 0; i < 40000; 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 = queueName;
                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();
            }

            //Task.Run(() =>
            //{
            //    for (int i = 0; i < 100; i++)
            //    {
            //        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.QueueName = "Queue1";
            //        item.TextInput = DataUtils.GenerateUniqueId(15);

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

            //    Thread.Sleep(60);
            //});

            for (int i = 0; i < 500; 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 = queueName;
                item.TextInput = DataUtils.GenerateUniqueId(15);

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

                Thread.Sleep(4);
            }


            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 GetNextQueueMessageItemWithAddedItemTest()
        {
            using (var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING,BASE_QUEUE_PATH))
            {
                // delete all pending requests
                int res = manager.Db.ExecuteNonQuery("delete from queuemessageItems where started is null");
                Console.WriteLine(res);

                // delete all queued ids - otherwise no items will match :-)
                var queue = manager.GetQueue("");
                queue.Purge();

                // creates sql and msmq items
                manager.SubmitRequest(messageText: "Next Complete Test " + DateTime.Now.ToString("t"));
                Assert.IsTrue(manager.Save(), manager.ErrorMessage);
            }

            using (var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING,BASE_QUEUE_PATH))
            {
                var item = manager.GetNextQueueMessage();
                Assert.IsNotNull(item, manager.ErrorMessage);

                Console.WriteLine(item.Message);

                manager.CompleteRequest(item, "Next Complete complete " + DateTime.Now.ToString("t"));

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