Exemple #1
0
        public static void LoadBalancer_OddNumberOfChannels()
        {
            List <IRpcWorkerChannel> results = new List <IRpcWorkerChannel>();
            int totalInvocations             = 100;

            IEnumerable <IRpcWorkerChannel> workerChannels = new List <IRpcWorkerChannel>()
            {
                new TestRpcWorkerChannel("1"),
                new TestRpcWorkerChannel("2"),
                new TestRpcWorkerChannel("3")
            };

            int expectedInvocationsPerChannel = totalInvocations / workerChannels.Count();

            IRpcFunctionInvocationDispatcherLoadBalancer loadBalancer = new RpcFunctionInvocationDispatcherLoadBalancer();

            for (int index = 0; index < 100; index++)
            {
                results.Add(loadBalancer.GetLanguageWorkerChannel(workerChannels, workerChannels.Count()));
            }
            var channelGroupsQuery = results.GroupBy(r => r.Id)
                                     .Select(g => new { Value = g.Key, Count = g.Count() });

            foreach (var channelGroup in channelGroupsQuery)
            {
                Assert.True(channelGroup.Count >= expectedInvocationsPerChannel);
            }
        }
Exemple #2
0
        public static void LoadBalancer_Throws_InvalidOperationException_NoWorkerChannels()
        {
            List <IRpcWorkerChannel>        results                   = new List <IRpcWorkerChannel>();
            IEnumerable <IRpcWorkerChannel> workerChannels            = new List <IRpcWorkerChannel>();
            IRpcFunctionInvocationDispatcherLoadBalancer loadBalancer = new RpcFunctionInvocationDispatcherLoadBalancer();

            var ex = Assert.Throws <InvalidOperationException>(() =>
            {
                loadBalancer.GetLanguageWorkerChannel(workerChannels, workerChannels.Count());
            });

            Assert.Equal($"Did not find any initialized language workers", ex.Message);
        }
Exemple #3
0
        public static void LoadBalancer_SingleProcess_VerifyCounter()
        {
            List <IRpcWorkerChannel> results = new List <IRpcWorkerChannel>();

            IEnumerable <IRpcWorkerChannel> workerChannels = new List <IRpcWorkerChannel>()
            {
                new TestRpcWorkerChannel("1"),
            };

            IRpcFunctionInvocationDispatcherLoadBalancer loadBalancer = new RpcFunctionInvocationDispatcherLoadBalancer();
            RpcFunctionInvocationDispatcherLoadBalancer  functionDispatcherLoadBalancer = loadBalancer as RpcFunctionInvocationDispatcherLoadBalancer;

            for (int index = 0; index < 10; index++)
            {
                loadBalancer.GetLanguageWorkerChannel(workerChannels, 1);
                Assert.Equal(0, functionDispatcherLoadBalancer.Counter);
            }
        }