Ejemplo n.º 1
0
        /// <summary>
        /// WebApi判重。
        /// </summary>
        /// <param name="client">Http客户端。。</param>
        /// <returns>返回值。</returns>
        private static async Task WebApiDuplicateCheckTest(HttpClient client)
        {
            var randomBuider = new RandomBulider(0, 2000, _randomMax);

            foreach (var tag in randomBuider.Next())
            {
                var hrm = BuildStringHttpRequestMessage(new WebApiDuplicateCheckRequest {
                    Tag = tag.ToString()
                });
                var response = await client.SendAsync(hrm);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    var json = await response.Content.ReadAsStringAsync();

                    var entryReponse = JsonSerializer.Deserialize <WebApiDuplicateCheckResponse>(json);
                    if (entryReponse.Result)
                    {
                        Console.WriteLine($"通过WebApi:已存在,忽略。");
                    }
                    else
                    {
                        Console.WriteLine("通过WebApi:不存在,执行操作任务。");
                    }
                }

                SpinWait.SpinUntil(() => false, 100);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 入判重测试。
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        private static async Task EnterTest(Duplicater.DuplicaterClient client)
        {
            var entry         = client.EntryDuplicate();
            var randomBuilder = new RandomBulider(0, 2000, _randomMax);

            var token    = new CancellationToken();
            var response = Task.Run(async() =>
            {
                while (await entry.ResponseStream.MoveNext(token))
                {
                    if (entry.ResponseStream.Current.Result)
                    {
                        Console.WriteLine($"{entry.ResponseStream.Current.Msg}");
                    }
                    else
                    {
                        Console.WriteLine($"{entry.ResponseStream.Current.Msg}入判重失败。");
                    }
                }

                Console.WriteLine("响应完成。");
            });

            var request = Task.Run(async() =>
            {
                foreach (var tag in randomBuilder.Next())
                {
                    SpinWait.SpinUntil(() => false, 100);
                    var msg = tag.ToString();
                    await entry.RequestStream.WriteAsync(new EntryRequest {
                        Tag = msg
                    });
                }
            });

            await request;

            Console.WriteLine("等待释放链接。");
            await entry.RequestStream.CompleteAsync();

            await response;

            entry.Dispose();
            Console.WriteLine("测试入判重完成");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 判断是否已存在。
        /// </summary>
        /// <param name="client">客户端。</param>
        /// <returns>返回结果。</returns>
        private static async Task DuplicateCheckTest(Duplicater.DuplicaterClient client)
        {
            var dulicate = client.DuplicateCheck();
            var token    = new CancellationToken();

            var response = Task.Run(async() =>
            {
                while (await dulicate.ResponseStream.MoveNext(token))
                {
                    if (dulicate.ResponseStream.Current.Result)
                    {
                        Console.WriteLine($"已存在,忽略。");
                    }
                    else
                    {
                        Console.WriteLine("不存在,执行操作任务。");
                    }
                }

                Console.WriteLine("响应完成。");
            });

            var request = Task.Run(async() =>
            {
                var randomBuider = new RandomBulider(0, 2000, _randomMax);

                foreach (var tag in randomBuider.Next())
                {
                    SpinWait.SpinUntil(() => false, 100);
                    await dulicate.RequestStream.WriteAsync(new DuplicateCheckRequest {
                        Tag = tag.ToString()
                    });
                }
            });

            await request;

            Console.WriteLine("是否判重。");
            await dulicate.RequestStream.CompleteAsync();

            await response;

            dulicate.Dispose();
            Console.WriteLine("测试查判重完成。");
        }