def test_loadbalancer_groups_items(): # N.B.: relyaing on the fact that hash(n) == n for integers result = load_balancer.group([0,1,2,3,4], [0,1,2], lambda _: 0) eq_([[0,3]], result[0]) eq_([[1,4]], result[1]) eq_([[2]], result[2])
def test_loadbalancer_groups_items_respecting_maxsize(): # N.B.: relyaing on the fact that hash(n) == n for integers result = load_balancer.group([0,1,2,3,4], [0,1,2], lambda _: 1, 1) eq_([[0],[3]], result[0]) eq_([[1],[4]], result[1]) eq_([[2]], result[2])
def send(self, es): f = lambda e: len(e.serialize()) g = load_balancer.group(es, self.l, f) for (addr, ess) in g.iteritems(): for es in ess: self.s.sendto(event.serialize_list(es), 0, addr)