Esempio n. 1
0
        public async Task LifeTimeTest(int count)
        {
            int failMod   = 7;
            int cancelMod = 13;

            var clients = Enumerable.Range(0, 35).Select(x => ClientMoq.Get(() => x % failMod == 0 ? "fail" : "good", () =>
            {
                if (x % failMod == 0)
                {
                    throw new SuccessException(x.ToString());
                }
                if (x % cancelMod == 0)
                {
                    throw new TaskCanceledException(x.ToString());
                }
                return(x.ToString());
            }).Object);
            var rollup = new TestRollup(clients);
            var waiter = new TestAwaitable(5000);
            var coord  = new TestedCoordinator(rollup,
                                               onRemove: (x) =>
            {
                if (Interlocked.Increment(ref _lifeTestCounter) == count)
                {
                    waiter.Complete();
                }
            }, msLife: 1);
            var list = await Task.WhenAll(Enumerable.Range(0, count).AsParallel()
                                          .Select((x) => coord.GetToken(new RequestMoq(x.ToString()))).ToList());

            await waiter.Awaiter();

            Assert.IsTrue(_lifeTestCounter == count);
            await Task.CompletedTask;
        }
Esempio n. 2
0
        public async Task SimpleTest(int count)
        {
            var waiter     = new TestAwaitable(count);
            var moqClients = Enumerable.Range(0, 4).Select(x => ClientMoq.Get(() => $"SimpleTest{x}", () => x.ToString())).ToList();
            var rollup     = new TestRollup(moqClients.Select(x => x.Object));
            var coord      = new TestedCoordinator(rollup, (x, y, e) => waiter.Fail($"Client Error Sended {x.GetIdentifier()}\n ex: {e}"), (x) => waiter.Fail($"Canceled {x.GetIdentifier()}"),
                                                   onComplete: (x, y) =>
            {
                if (Interlocked.Increment(ref _simpleTestReadCounter) == count)
                {
                    waiter.Complete();
                }
            });

            await SuccessResults(count, waiter, coord, x => x.ToString());

            moqClients.ForEach(x => x.Verify(y => y.AskAsync(It.IsAny <RequestMoq>(), It.IsAny <CancellationToken>()), Times.AtLeastOnce));
            await Task.CompletedTask;
        }
Esempio n. 3
0
        public async Task RepeatTest(int count)
        {
            var waiter              = new TestAwaitable(count);
            var clients             = new[] { ClientMoq.Get(() => "wait", () => "wait", 100) };
            var rollupSingleWaiting = new TestRollup(clients.Select(x => x.Object));
            var coord = new TestedCoordinator(rollupSingleWaiting, (x, c, e) => Assert.Fail(), (x) => Assert.Fail(), onComplete: (x, y) =>
            {
                if (Interlocked.Increment(ref _repeatTestReadCounter) == 2)
                {
                    waiter.Complete();
                }
            });

            await SuccessResults(count, waiter, coord, x => (x % 2).ToString());

            foreach (var x in clients)
            {
                x.Verify(y => y.AskAsync(It.IsAny <RequestMoq>(), It.IsAny <CancellationToken>()), Times.AtMost(2));
                x.Verify(y => y.AskAsync(It.IsAny <RequestMoq>(), It.IsAny <CancellationToken>()), Times.AtLeastOnce);
            }
            await Task.CompletedTask;
        }
Esempio n. 4
0
        public async Task CancelTest(int wait)
        {
            var          waiter              = new TestAwaitable(wait);
            var          clients             = new[] { ClientMoq.Get(() => "", () => "wait", wait) };
            var          rollupSingleWaiting = new TestRollup(clients.Select(x => x.Object));
            var          coord = new TestedCoordinator(rollupSingleWaiting, (x, y, e) => waiter.Fail($"Client Error Sended {x.GetIdentifier()}\n ex: {e}"), (x) => waiter.Complete());
            const string name  = "cancel";
            string       id    = await coord.GetToken(new RequestMoq(name));

            await coord.Cancel(id);

            Models.Response <ResponseMoq> r = new Models.Response <ResponseMoq>();
            var t = coord.Result(id);

            r = await t;
            await waiter.Awaiter();

            Assert.IsTrue(r.GetState() == Models.ResponseState.Deleted);
            await Task.CompletedTask;
        }