Beispiel #1
0
 /// <summary>
 /// 第一次消息队列测试清除历史数据
 /// </summary>
 /// <param name="queue"></param>
 /// <param name="isStart"></param>
 /// <returns></returns>
 private static bool checkFirst(QueueConsumers <int> queue, bool isStart)
 {
     if (isFirst)
     {
         isFirst = false;
         using (QueueConsumers consumer1 = new QueueConsumers(queue, 1, true))
             using (QueueConsumers consumer2 = new QueueConsumers(queue, 2, true))
             {
                 ReturnValue <bool> isEnqueue = queue.Enqueue(7);
                 if (!isEnqueue.Value)
                 {
                     return(false);
                 }
                 consumer1.wait.WaitOne();
                 consumer2.wait.WaitOne();
                 if (!consumer1.isSuccess || !consumer2.isSuccess)
                 {
                     return(false);
                 }
             }
         if (!isStart && !start(queue))
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #2
0
        /// <summary>
        /// 消息队列测试
        /// </summary>
        /// <returns></returns>
        internal static bool TestCase(Client masterClient, bool isStart)
        {
            string name = "messageQueueConsumers";
            QueueConsumers <int> queue = masterClient.GetOrCreateDataStructure <QueueConsumers <int> >(name).Value;

            if (queue == null)
            {
                return(false);
            }
            if (!checkFirst(queue, isStart))
            {
                return(false);
            }
            if (isStart)
            {
                if (!start(queue))
                {
                    return(false);
                }
            }
            else
            {
                using (QueueConsumers consumer1 = new QueueConsumers(queue, 1, false))
                    using (QueueConsumers consumer2 = new QueueConsumers(queue, 2, false))
                    {
                        ReturnValue <bool> isEnqueue = queue.Enqueue(5);
                        if (!isEnqueue.Value)
                        {
                            return(false);
                        }
                        isEnqueue = queue.Enqueue(3);
                        if (!isEnqueue.Value)
                        {
                            return(false);
                        }
                        isEnqueue = queue.Enqueue(1);
                        if (!isEnqueue.Value)
                        {
                            return(false);
                        }
                        consumer1.wait.WaitOne();
                        consumer2.wait.WaitOne();
                        return(consumer1.isSuccess && consumer2.isSuccess);
                    }
            }
            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// 消息队列测试
        /// </summary>
        /// <param name="queue"></param>
        /// <returns></returns>
        private static bool start(QueueConsumers <int> queue)
        {
            ReturnValue <bool> isEnqueue = queue.Enqueue(2);

            if (!isEnqueue.Value)
            {
                return(false);
            }
            isEnqueue = queue.Enqueue(4);
            if (!isEnqueue.Value)
            {
                return(false);
            }
            isEnqueue = queue.Enqueue(6);
            if (!isEnqueue.Value)
            {
                return(false);
            }
            return(true);
        }
Beispiel #4
0
 /// <summary>
 /// 消息队列测试
 /// </summary>
 /// <param name="queue"></param>
 /// <param name="readerIndex"></param>
 /// <param name="isFirst"></param>
 private QueueConsumers(QueueConsumers <int> queue, int readerIndex, bool isFirst)
 {
     consumer = queue.CreateConsumer(readerIndex, isFirst ? (Action <int>)first : check, new AutoCSer.CacheServer.MessageQueue.ConsumerConfig {
         MemoryCacheNodeCount = 0
     });
 }