def test_round_robin_lb_with_data_members(self): cluster = _MockClusterService(5, 0) lb = RoundRobinLB() lb.init(cluster) self.assertTrue(lb.can_get_next_data_member()) for i in range(10): self.assertEqual(i % 5, lb.next().id) for i in range(10): self.assertEqual(i % 5, lb.next_data_member().id)
def test_round_robin_lb_with_lite_members(self): cluster = _MockClusterService(0, 3) lb = RoundRobinLB() lb.init(cluster) for i in range(10): self.assertEqual(i % 3, lb.next().id) self.assertIsNone(lb.next_data_member())
def test_round_robin_load_balancer(self): client = HazelcastClient(cluster_name=self.cluster.id, load_balancer=RoundRobinLB()) self.assertTrue(client.lifecycle_service.is_running()) lb = client._load_balancer self.assertTrue(isinstance(lb, RoundRobinLB)) six.assertCountEqual(self, self.addresses, list(map(lambda m: m.address, lb._members))) for i in range(10): self.assertEqual(self.addresses[i % len(self.addresses)], lb.next().address) client.shutdown()
def test_round_robin_lb_with_mixed_members(self): cluster = _MockClusterService(3, 3) lb = RoundRobinLB() lb.init(cluster) for i in range(24): self.assertEqual(i % 6, lb.next().id) for i in range(24): self.assertEqual(i % 3, lb.next_data_member().id)
def test_round_robin_lb_with_members(self): cluster = _MockClusterService([0, 1, 2]) lb = RoundRobinLB() lb.init(cluster) for i in range(10): self.assertEqual(i % 3, lb.next())
def test_round_robin_lb_with_no_members(self): cluster = _MockClusterService([]) lb = RoundRobinLB() lb.init(cluster) self.assertIsNone(lb.next())
def _init_load_balancer(config): load_balancer = config.load_balancer if not load_balancer: load_balancer = RoundRobinLB() return load_balancer