Ejemplo n.º 1
0
 def test_should_return_routing_table_on_valid_record(self):
     table = RoutingTable.parse_routing_info([VALID_ROUTING_RECORD])
     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
Ejemplo n.º 2
0
 def test_should_return_all_distinct_servers_in_routing_table(self):
     routing_table = {
         "ttl": 300,
         "servers": [
             {"role": "ROUTE", "addresses": ["127.0.0.1:9001", "127.0.0.1:9002", "127.0.0.1:9003"]},
             {"role": "READ", "addresses": ["127.0.0.1:9001", "127.0.0.1:9005"]},
             {"role": "WRITE", "addresses": ["127.0.0.1:9002"]},
         ],
     }
     table = RoutingTable.parse_routing_info([routing_table])
     assert table.servers() == {('127.0.0.1', 9001), ('127.0.0.1', 9002), ('127.0.0.1', 9003), ('127.0.0.1', 9005)}
Ejemplo n.º 3
0
 def test_should_become_stale_if_no_writers(self):
     table = RoutingTable.parse_routing_info([VALID_ROUTING_RECORD])
     table.writers.clear()
     assert table.is_fresh(READ_ACCESS)
     assert not table.is_fresh(WRITE_ACCESS)
Ejemplo n.º 4
0
 def test_should_become_stale_on_expiry(self):
     table = RoutingTable.parse_routing_info([VALID_ROUTING_RECORD])
     table.ttl = 0
     assert not table.is_fresh(READ_ACCESS)
     assert not table.is_fresh(WRITE_ACCESS)
Ejemplo n.º 5
0
 def test_should_be_fresh_after_update(self):
     table = RoutingTable.parse_routing_info([VALID_ROUTING_RECORD])
     assert table.is_fresh(READ_ACCESS)
     assert table.is_fresh(WRITE_ACCESS)
Ejemplo n.º 6
0
 def test_should_fail_on_multiple_records(self):
     with self.assertRaises(RoutingProtocolError):
         _ = RoutingTable.parse_routing_info([VALID_ROUTING_RECORD, VALID_ROUTING_RECORD])
Ejemplo n.º 7
0
 def test_should_fail_on_zero_records(self):
     with self.assertRaises(RoutingProtocolError):
         _ = RoutingTable.parse_routing_info([])
Ejemplo n.º 8
0
 def test_should_fail_on_invalid_record(self):
     with self.assertRaises(RoutingProtocolError):
         _ = RoutingTable.parse_routing_info([INVALID_ROUTING_RECORD])