Пример #1
0
        /// <summary>
        /// 消息分发测试
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        internal static bool TestCase(AutoCSer.CacheServer.Client client)
        {
            string name = "MesssageDistributor";

            #region  除名称为 MesssageDistributor 的缓存数据,防止未处理数据对测试验证产生副作用
            client.RemoveDataStructure(name);
            #endregion

            #region 创建名称为 MesssageDistributor 的 JSON 消息分发
            Distributor <Json <int> > distributor = client.GetOrCreateDataStructure <Distributor <Json <int> > >(name).Value;
            if (distributor == null)
            {
                return(false);
            }
            #endregion

            #region 添加消息 2
            ReturnValue <bool> isEnqueue = distributor.Enqueue(2);
            if (!isEnqueue.Value)
            {
                return(false);
            }
            #endregion

            isEnqueue = distributor.Enqueue(6);
            if (!isEnqueue.Value)
            {
                return(false);
            }
            isEnqueue = distributor.Enqueue(4);
            if (!isEnqueue.Value)
            {
                return(false);
            }

            #region 初始化消息消费状态(仅用于当前测试验证)
            checkValue = 0;
            wait.Reset();
            #endregion

            #region 创建消息分发的消费者
            using (AutoCSer.CacheServer.MessageQueue.DistributionConsumer <Json <int>, int> consumer = distributor.CreateConsumer(onMessage, new AutoCSer.CacheServer.MessageQueue.DistributionConsumerConfig {
                MemoryCacheNodeCount = 0
            }))
            #endregion
            {
                #region 等待消息处理完毕
                wait.WaitOne();
                #endregion
            }
            return(checkValue == successValue);
        }
Пример #2
0
        /// <summary>
        /// 消费者 线程池轮询缓冲区
        /// </summary>
        private void threadPool()
        {
            enqueue();

            start(CallbackType.ThreadPool, TestType.MessageDistributionDequeue);
            using (AutoCSer.CacheServer.MessageQueue.Abstract.DistributionConsumer consumer1 = distributor.CreateConsumer(onMessage, getConfig()))
                using (AutoCSer.CacheServer.MessageQueue.Abstract.DistributionConsumer consumer2 = distributor.CreateConsumer(onMessage, getConfig()))
                {
                    wait();
                }
            client.RemoveDataStructure(cacheName);
        }
Пример #3
0
 /// <summary>
 /// 消息分发测试
 /// </summary>
 /// <param name="distributor"></param>
 private MesssageDistributor(Distributor <Json <int> > distributor)
 {
     consumer = distributor.CreateConsumer(check, new AutoCSer.CacheServer.MessageQueue.DistributionConsumerConfig {
         MemoryCacheNodeCount = 0
     });
 }
Пример #4
0
 /// <summary>
 /// 消费者 线程池轮询缓冲区(生产消费实时并行测试)
 /// </summary>
 private void threadPoolMixing()
 {
     client.RemoveDataStructure(cacheName);
     distributor = client.GetOrCreateDataStructure <Distributor <Binary <Message> > >(cacheName);
     bitArray.SetAll(false);
     errorCount = messageIndex = 0;
     start(CallbackType.ThreadPool, TestType.MessageDistributionMixing, 2);
     using (AutoCSer.CacheServer.MessageQueue.Abstract.DistributionConsumer consumer1 = distributor.CreateConsumer(onMessageInterlocked, getConfig()))
         using (AutoCSer.CacheServer.MessageQueue.Abstract.DistributionConsumer consumer2 = distributor.CreateConsumer(onMessageInterlocked, getConfig()))
         {
             for (int index = 0; index != count; ++index)
             {
                 distributor.EnqueueStream(new Message {
                     Value = index
                 }, enqueueCallbackInterlockedReturnParameter);
             }
             wait();
         }
     client.RemoveDataStructure(cacheName);
 }