Exemple #1
0
        public void Test_3()
        {
            var key = "Test_3";

            //先锁定
            Util.Helpers.Thread.ParallelExecute(() => _service.Execute(key), () => _service.Execute(key));

            //未解锁,无法执行
            var result = new List <string>();

            Util.Helpers.Thread.ParallelExecute(() => {
                result.Add(_service.Execute(key));
            }, () => {
                result.Add(_service.Execute(key));
            }, () => {
                result.Add(_service.Execute(key));
            }, () => {
                result.Add(_service.Execute(key));
            }, () => {
                result.Add(_service.Execute(key));
            });
            Assert.Empty(result.FindAll(t => t == "ok"));

            //解锁
            _service.UnLock();

            //再次执行
            Util.Helpers.Thread.ParallelExecute(() => {
                result.Add(_service.Execute(key));
            }, () => {
                result.Add(_service.Execute(key));
            }, () => {
                result.Add(_service.Execute(key));
            }, () => {
                result.Add(_service.Execute(key));
            }, () => {
                result.Add(_service.Execute(key));
            }, () => {
                result.Add(_service.Execute(key));
            });
            Assert.Single(result.FindAll(t => t == "ok"));
        }
 /// <summary>
 /// 测试清理
 /// </summary>
 public void Dispose()
 {
     Time.Reset();
     _service.UnLock();
 }