Ejemplo n.º 1
0
 def test_next_with_new_conf(self):
     from relstorage.adapters.replica import ReplicaSelector
     rs = ReplicaSelector(self.fn, 600.0)
     self.assertEqual(rs.current(), 'example.com:1234')
     self.assertEqual(rs.next(), 'localhost:4321')
     # interrupt the iteration by changing the replica conf file
     with open(self.fn, 'w') as f:
         f.write('example.com:9999\n')
     rs._config_checked = 0
     rs._config_modified = 0
     self.assertEqual(rs.next(), 'example.com:9999')
     self.assertEqual(rs.next(), None)
Ejemplo n.º 2
0
 def test__is_config_modified(self):
     from relstorage.adapters.replica import ReplicaSelector
     import time
     rs = ReplicaSelector(self.fn, 600.0)
     self.assertEqual(rs._is_config_modified(), False)
     # change the file
     rs._config_modified = 0
     # don't check the file yet
     rs._config_checked = time.time() + 3600
     self.assertEqual(rs._is_config_modified(), False)
     # now check the file
     rs._config_checked = 0
     self.assertEqual(rs._is_config_modified(), True)
Ejemplo n.º 3
0
 def test_next_with_new_conf(self):
     from relstorage.adapters.replica import ReplicaSelector
     rs = ReplicaSelector(self.fn, 600.0)
     self.assertEqual(rs.current(), 'example.com:1234')
     self.assertEqual(rs.next(), 'localhost:4321')
     # interrupt the iteration by changing the replica conf file
     f = open(self.fn, 'w')
     f.write('example.com:9999\n')
     f.close()
     rs._config_checked = 0
     rs._config_modified = 0
     self.assertEqual(rs.next(), 'example.com:9999')
     self.assertEqual(rs.next(), None)
Ejemplo n.º 4
0
 def test__is_config_modified(self):
     from relstorage.adapters.replica import ReplicaSelector
     import time
     rs = ReplicaSelector(self.fn, 600.0)
     self.assertEqual(rs._is_config_modified(), False)
     # change the file
     rs._config_modified = 0
     # don't check the file yet
     rs._config_checked = time.time() + 3600
     self.assertEqual(rs._is_config_modified(), False)
     # now check the file
     rs._config_checked = 0
     self.assertEqual(rs._is_config_modified(), True)
Ejemplo n.º 5
0
 def test_current(self):
     from relstorage.adapters.replica import ReplicaSelector
     rs = ReplicaSelector(self.fn, 600.0)
     self.assertEqual(rs.current(), 'example.com:1234')
     # change the file and get the new current replica
     with open(self.fn, 'w') as f:
         f.write('localhost\nalternate\n')
     rs._config_checked = 0
     rs._config_modified = 0
     self.assertEqual(rs.current(), 'localhost')
     # switch to the alternate
     rs._select(1)
     self.assertEqual(rs.current(), 'alternate')
     # expire the alternate
     rs._expiration = 0
     self.assertEqual(rs.current(), 'localhost')
Ejemplo n.º 6
0
 def test_current(self):
     from relstorage.adapters.replica import ReplicaSelector
     rs = ReplicaSelector(self.fn, 600.0)
     self.assertEqual(rs.current(), 'example.com:1234')
     # change the file and get the new current replica
     f = open(self.fn, 'w')
     f.write('localhost\nalternate\n')
     f.close()
     rs._config_checked = 0
     rs._config_modified = 0
     self.assertEqual(rs.current(), 'localhost')
     # switch to the alternate
     rs._select(1)
     self.assertEqual(rs.current(), 'alternate')
     # expire the alternate
     rs._expiration = 0
     self.assertEqual(rs.current(), 'localhost')