def test_should_call_get_routing_tables_with_context(self):
     with StubCluster({9001: "get_routing_table_with_context.script"}):
         address = ("127.0.0.1", 9001)
         routing_context = {"name": "molly", "age": "1"}
         with RoutingConnectionPool(connector, UNREACHABLE_ADDRESS,
                                    routing_context) as pool:
             pool.fetch_routing_info(address)
 def test_try_initial_server_first_if_missing_writer(self):
     with StubCluster({9001: "router.script"}):
         initial_address = ("127.0.0.1", 9001)
         with RoutingConnectionPool(connector, initial_address, {}) as pool:
             pool.missing_writer = True
             pool.update_routing_table()
             table = pool.routing_table
             assert table.routers == {("127.0.0.1", 9001),
                                      ("127.0.0.1", 9002),
                                      ("127.0.0.1", 9003)}
             assert table.readers == {("127.0.0.1", 9004),
                                      ("127.0.0.1", 9005)}
             assert table.writers == {("127.0.0.1", 9006)}
             assert table.ttl == 300
             assert not pool.missing_writer
 def test_roll_back_to_initial_server_if_failed_update_with_existing_routers(
         self):
     with StubCluster({9001: "router.script"}):
         initial_address = ("127.0.0.1", 9001)  # roll back addresses
         routers = [("127.0.0.1", 9002),
                    ("127.0.0.1", 9003)]  # not reachable servers
         with RoutingConnectionPool(connector, initial_address, {},
                                    *routers) as pool:
             pool.update_routing_table()
             table = pool.routing_table
             assert table.routers == {("127.0.0.1", 9001),
                                      ("127.0.0.1", 9002),
                                      ("127.0.0.1", 9003)}
             assert table.readers == {("127.0.0.1", 9004),
                                      ("127.0.0.1", 9005)}
             assert table.writers == {("127.0.0.1", 9006)}
             assert table.ttl == 300
def RoutingPool(*routers):
    return RoutingConnectionPool(connector, UNREACHABLE_ADDRESS, {}, *routers)
 def test_should_call_get_routing_tables(self):
     with StubCluster({9001: "get_routing_table.script"}):
         address = ("127.0.0.1", 9001)
         with RoutingConnectionPool(connector, UNREACHABLE_ADDRESS,
                                    {}) as pool:
             pool.fetch_routing_info(address)