Example #1
0
        public virtual async Task InvokeAsync(IPipelineContext <DomainName> context, PipelineTaskDelegate <DomainName> nextMiddleware)
        {
            string log  = $"Ping {context.Resource.Value}...";
            bool   isOk = await _pingService.PingAsync(context.Resource.Value);

            log += isOk ? "Ok" : "Error";
            Log(log);
            context.Items[context.Resource.Value] = isOk;
            await nextMiddleware(context);
        }
Example #2
0
        public async Task RoundRobinPolicy()
        {
            WampPlayground playground = new WampPlayground();

            playground.Host.Open();

            IPingService pingService = await GetCaller(playground);

            List <int> calls = new List <int>();

            List <Registration> registrations =
                await RegisterCallees(playground, calls, 10, "roundrobin");

            for (int i = 0; i < 15; i++)
            {
                await pingService.PingAsync();
            }

            await registrations[0].DisposeAsync();
            await registrations[7].DisposeAsync();

            for (int i = 0; i < 15; i++)
            {
                await pingService.PingAsync();
            }

            List <int> modifiedIndexes =
                Enumerable.Range(0, 10).Where(x => x != 0 && x != 7).ToList();

            IEnumerable <int> expected =
                Enumerable.Range(0, 15)
                .Select(x => x % 10)
                .Concat(Enumerable.Range(15 % 10, 15)
                        .Select(x => x % 8)
                        .Select(x => modifiedIndexes[x]))
                .ToList();

            CollectionAssert.AreEquivalent(expected, calls);
        }
        private async Task TryPing()
        {
            try
            {
                await _pingService.PingAsync();

                ServerStatusMessage = ConnectionStatuses.ONLINE.ToLower();
                if (NotificationType == NotificationType.Server)
                {
                    ClearNotification();
                }
            }
            catch (Exception ex)
            {
                ServerStatusMessage = ConnectionStatuses.OFFLINE.ToLower();
                SetNotification(ex.Message, NotificationType.Server);
            }
        }
Example #4
0
        private async Task TryPing()
        {
            try
            {
                await _pingService.PingAsync();

                ServerStatusMessage = ConnectionStatus.ONLINE.ToLower();
                if (LastErrorType == ErrorType.Server)
                {
                    LastErrorType = ErrorType.No;
                    ErrorMessage  = null;
                }
            }
            catch (Exception ex)
            {
                ServerStatusMessage = ConnectionStatus.OFFLINE.ToLower();
                LastErrorType       = ErrorType.Server;
                ErrorMessage        = ex.Message;
            }
        }
Example #5
0
        public async Task LastPolicyCallsLastCallee()
        {
            WampPlayground playground = new WampPlayground();

            playground.Host.Open();

            IPingService pingService = await GetCaller(playground);

            List <int> calls = new List <int>();

            List <Registration> registrations =
                await RegisterCallees(playground, calls, 10, "last");

            await pingService.PingAsync();

            await registrations[0].DisposeAsync();
            await pingService.PingAsync();

            await pingService.PingAsync();

            await registrations[9].DisposeAsync();
            await pingService.PingAsync();

            await registrations[1].DisposeAsync();
            await pingService.PingAsync();

            await registrations[8].DisposeAsync();
            await registrations[2].DisposeAsync();
            await pingService.PingAsync();

            await registrations[7].DisposeAsync();
            await registrations[3].DisposeAsync();
            await registrations[6].DisposeAsync();
            await registrations[4].DisposeAsync();
            await pingService.PingAsync();

            CollectionAssert.AreEquivalent(new[] { 9, 9, 9, 8, 8, 7, 5 }, calls);
        }
Example #6
0
        public async Task <HttpResponseMessage> Ping()
        {
            var result = await service.PingAsync().ConfigureAwait(false);

            return(Request.CreateResponse(result));
        }