def test_partially_in_pool_writer_selection(self):
     strategy = LeastConnectedLoadBalancingStrategy(FakeConnectionPool(OrderedDict([
         ("1.1.1.1", 1),
         ("2.2.2.2", 0),
     ])))
     self.assertEqual(strategy.select_writer(["2.2.2.2", "3.3.3.3"]), "2.2.2.2")
     self.assertEqual(strategy.select_writer(["2.2.2.2", "3.3.3.3"]), "3.3.3.3")
 def test_simple_writer_selection(self):
     strategy = LeastConnectedLoadBalancingStrategy(FakeConnectionPool(OrderedDict([
         ("0.0.0.0", 2),
         ("1.1.1.1", 1),
         ("2.2.2.2", 0),
     ])))
     self.assertEqual(strategy.select_writer(["0.0.0.0", "1.1.1.1", "2.2.2.2"]), "2.2.2.2")
 def test_writer_selection_with_clash(self):
     strategy = LeastConnectedLoadBalancingStrategy(FakeConnectionPool(OrderedDict([
         ("0.0.0.0", 0),
         ("0.0.0.1", 0),
         ("1.1.1.1", 1),
     ])))
     self.assertEqual(strategy.select_writer(["0.0.0.0", "0.0.0.1", "1.1.1.1"]), "0.0.0.0")
     self.assertEqual(strategy.select_writer(["0.0.0.0", "0.0.0.1", "1.1.1.1"]), "0.0.0.1")
예제 #4
0
 def test_not_in_pool_reader_selection(self):
     strategy = LeastConnectedLoadBalancingStrategy(
         FakeConnectionPool(OrderedDict([
             ("1.1.1.1", 1),
             ("2.2.2.2", 2),
         ])))
     self.assertEqual(strategy.select_reader(["2.2.2.2", "3.3.3.3"]),
                      "3.3.3.3")
 def test_empty_writer_selection(self):
     strategy = LeastConnectedLoadBalancingStrategy(FakeConnectionPool(OrderedDict([
     ])))
     self.assertIsNone(strategy.select_writer([]))