Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var host    = "8.8.8.8";
            var ping    = new Ping();
            var isAlive = ping.IsAlive(host);

            Console.WriteLine(host + " alive: " + isAlive);
        }
Exemplo n.º 2
0
        public async void CommandTest()
        {
            var balancer = LoadBalancerBuilder.NewBuilder()
                           .WithPing(Ping)
                           .WithRule(new Thrifty.MicroServices.Ribbon.Rules.RoundRobinRule()).Build("demo", 1 * 1000);

            balancer.AddServers(Servers);
            var command = new LoadBalancerCommand(balancer, null, null, null);
            var x       = await command.Submit(s => Task.FromResult(Ping.IsAlive(s)));

            Assert.True(x);
        }
Exemplo n.º 3
0
        public async void WeightedResponseTimeRuleTest()
        {
            var collector   = new DefaultServerStatusCollector();
            var accumulater = new DefaultServerWeightAccumulater(collector);
            var rule        = new Thrifty.MicroServices.Ribbon.Rules.WeightedResponseTimeRule(accumulater);
            var balancer    = new BaseLoadBalancer(1 * 1000, "demo", rule, Ping, new SerialPingStrategy(), LoggerFactory);

            accumulater.LoadBalancer = balancer;
            balancer.AddServers(Servers);
            var       command = new LoadBalancerCommand(balancer, null, null, null);
            const int count   = 1000;
            var       index   = 0;

            while (index++ < count)
            {
                Assert.True(await command.Submit(server => Task.FromResult(Ping.IsAlive(server))));
            }
        }